Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 1 | /* NS-over-IP proxy */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
Holger Hans Peter Freyther | 85531cc | 2010-10-06 20:37:09 +0800 | [diff] [blame] | 4 | * (C) 2010 by On-Waves |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU Affero General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 15 | * GNU Affero General Public License for more details. |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU Affero General Public License |
| 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <unistd.h> |
| 23 | #include <stdio.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <string.h> |
| 26 | #include <getopt.h> |
| 27 | #include <errno.h> |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 28 | #include <signal.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 29 | #include <sys/fcntl.h> |
| 30 | #include <sys/stat.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 31 | #include <sys/socket.h> |
| 32 | #include <netinet/in.h> |
| 33 | #include <arpa/inet.h> |
| 34 | |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 35 | #include <osmocom/core/application.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 36 | #include <osmocom/core/talloc.h> |
| 37 | #include <osmocom/core/select.h> |
| 38 | #include <osmocom/core/rate_ctr.h> |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 39 | #include <osmocom/core/stats.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 40 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 41 | #include <osmocom/gprs/gprs_ns2.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 42 | #include <osmocom/gprs/gprs_bssgp.h> |
| 43 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 44 | #include <osmocom/sgsn/signal.h> |
| 45 | #include <osmocom/sgsn/debug.h> |
| 46 | #include <osmocom/sgsn/vty.h> |
| 47 | #include <osmocom/sgsn/gb_proxy.h> |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 48 | |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 49 | #include <osmocom/ctrl/control_vty.h> |
| 50 | #include <osmocom/ctrl/control_if.h> |
| 51 | #include <osmocom/ctrl/ports.h> |
| 52 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 53 | #include <osmocom/vty/command.h> |
| 54 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 3848770 | 2011-03-23 08:49:00 +0100 | [diff] [blame] | 55 | #include <osmocom/vty/logging.h> |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 56 | #include <osmocom/vty/stats.h> |
Harald Welte | 55dc31e | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 57 | #include <osmocom/vty/ports.h> |
Harald Welte | 731930b | 2018-02-14 01:02:22 +0100 | [diff] [blame] | 58 | #include <osmocom/vty/misc.h> |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 59 | |
Harald Welte | e236596 | 2010-05-04 07:41:59 +0200 | [diff] [blame] | 60 | #include "../../bscconfig.h" |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 61 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 62 | #define _GNU_SOURCE |
| 63 | #include <getopt.h> |
| 64 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 65 | void *tall_sgsn_ctx; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 66 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 67 | const char *openbsc_copyright = |
Holger Hans Peter Freyther | 5f54075 | 2010-09-11 13:32:30 +0800 | [diff] [blame] | 68 | "Copyright (C) 2010 Harald Welte and On-Waves\r\n" |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 69 | "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n" |
Holger Hans Peter Freyther | 5f54075 | 2010-09-11 13:32:30 +0800 | [diff] [blame] | 70 | "This is free software: you are free to change and redistribute it.\r\n" |
| 71 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 72 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 73 | #define CONFIG_FILE_DEFAULT "osmo-gbproxy.cfg" |
| 74 | #define CONFIG_FILE_LEGACY "osmo_gbproxy.cfg" |
| 75 | |
| 76 | static char *config_file = NULL; |
Daniel Willmann | 3ab193c | 2018-06-01 07:21:08 +0200 | [diff] [blame] | 77 | struct gbproxy_config *gbcfg; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 78 | static int daemonize = 0; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 79 | |
| 80 | /* Pointer to the SGSN peer */ |
| 81 | extern struct gbprox_peer *gbprox_peer_sgsn; |
| 82 | |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 83 | static void signal_handler(int signal) |
| 84 | { |
| 85 | fprintf(stdout, "signal %u received\n", signal); |
| 86 | |
| 87 | switch (signal) { |
| 88 | case SIGINT: |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame] | 89 | case SIGTERM: |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 90 | osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 91 | sleep(1); |
| 92 | exit(0); |
| 93 | break; |
| 94 | case SIGABRT: |
| 95 | /* in case of abort, we want to obtain a talloc report |
| 96 | * and then return to the caller, who will abort the process */ |
| 97 | case SIGUSR1: |
| 98 | talloc_report(tall_vty_ctx, stderr); |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 99 | talloc_report_full(tall_sgsn_ctx, stderr); |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 100 | break; |
| 101 | case SIGUSR2: |
| 102 | talloc_report_full(tall_vty_ctx, stderr); |
| 103 | break; |
| 104 | default: |
| 105 | break; |
| 106 | } |
| 107 | } |
| 108 | |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 109 | static void print_usage() |
| 110 | { |
| 111 | printf("Usage: bsc_hack\n"); |
| 112 | } |
| 113 | |
| 114 | static void print_help() |
| 115 | { |
| 116 | printf(" Some useful help...\n"); |
| 117 | printf(" -h --help this text\n"); |
| 118 | printf(" -d option --debug=DNS:DGPRS,0:0 enable debugging\n"); |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 119 | printf(" -D --daemonize Fork the process into a background daemon\n"); |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 120 | printf(" -c --config-file filename The config file to use [%s]\n", CONFIG_FILE_DEFAULT); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 121 | printf(" -s --disable-color\n"); |
| 122 | printf(" -T --timestamp Prefix every log line with a timestamp\n"); |
Daniel Willmann | 03a2ed5 | 2019-07-26 11:56:31 +0200 | [diff] [blame] | 123 | printf(" -V --version. Print the version.\n"); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 124 | printf(" -e --log-level number. Set a global loglevel.\n"); |
| 125 | } |
| 126 | |
| 127 | static void handle_options(int argc, char **argv) |
| 128 | { |
| 129 | while (1) { |
| 130 | int option_index = 0, c; |
| 131 | static struct option long_options[] = { |
| 132 | { "help", 0, 0, 'h' }, |
| 133 | { "debug", 1, 0, 'd' }, |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 134 | { "daemonize", 0, 0, 'D' }, |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 135 | { "config-file", 1, 0, 'c' }, |
| 136 | { "disable-color", 0, 0, 's' }, |
| 137 | { "timestamp", 0, 0, 'T' }, |
| 138 | { "version", 0, 0, 'V' }, |
| 139 | { "log-level", 1, 0, 'e' }, |
| 140 | { 0, 0, 0, 0 } |
| 141 | }; |
| 142 | |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 143 | c = getopt_long(argc, argv, "hd:Dc:sTVe:", |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 144 | long_options, &option_index); |
| 145 | if (c == -1) |
| 146 | break; |
| 147 | |
| 148 | switch (c) { |
| 149 | case 'h': |
| 150 | print_usage(); |
| 151 | print_help(); |
| 152 | exit(0); |
| 153 | case 's': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 154 | log_set_use_color(osmo_stderr_target, 0); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 155 | break; |
| 156 | case 'd': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 157 | log_parse_category_mask(osmo_stderr_target, optarg); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 158 | break; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 159 | case 'D': |
| 160 | daemonize = 1; |
| 161 | break; |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 162 | case 'c': |
Holger Hans Peter Freyther | abb3478 | 2015-01-26 10:26:36 +0100 | [diff] [blame] | 163 | config_file = optarg; |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 164 | break; |
| 165 | case 'T': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 166 | log_set_print_timestamp(osmo_stderr_target, 1); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 167 | break; |
| 168 | case 'e': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 169 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 170 | break; |
| 171 | case 'V': |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 172 | print_version(1); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 173 | exit(0); |
| 174 | break; |
| 175 | default: |
| 176 | break; |
| 177 | } |
| 178 | } |
Harald Welte | de67c00 | 2019-12-03 22:28:19 +0100 | [diff] [blame] | 179 | |
| 180 | if (argc > optind) { |
| 181 | fprintf(stderr, "Unsupported positional arguments on command line\n"); |
| 182 | exit(2); |
| 183 | } |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 184 | } |
| 185 | |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 186 | int gbproxy_vty_is_config_node(struct vty *vty, int node) |
| 187 | { |
| 188 | switch (node) { |
| 189 | /* add items that are not config */ |
| 190 | case CONFIG_NODE: |
| 191 | return 0; |
| 192 | |
| 193 | default: |
| 194 | return 1; |
| 195 | } |
| 196 | } |
| 197 | |
| 198 | int gbproxy_vty_go_parent(struct vty *vty) |
| 199 | { |
| 200 | switch (vty->node) { |
| 201 | case GBPROXY_NODE: |
| 202 | default: |
| 203 | if (gbproxy_vty_is_config_node(vty, vty->node)) |
| 204 | vty->node = CONFIG_NODE; |
| 205 | else |
| 206 | vty->node = ENABLE_NODE; |
| 207 | |
| 208 | vty->index = NULL; |
| 209 | } |
| 210 | |
| 211 | return vty->node; |
| 212 | } |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 213 | |
| 214 | static struct vty_app_info vty_info = { |
Harald Welte | ec1921d | 2011-02-24 23:57:06 +0100 | [diff] [blame] | 215 | .name = "OsmoGbProxy", |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 216 | .version = PACKAGE_VERSION, |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 217 | .go_parent_cb = gbproxy_vty_go_parent, |
| 218 | .is_config_node = gbproxy_vty_is_config_node, |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
Harald Welte | 11461a6 | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 221 | /* default categories */ |
| 222 | static struct log_info_cat gprs_categories[] = { |
| 223 | [DGPRS] = { |
| 224 | .name = "DGPRS", |
| 225 | .description = "GPRS Packet Service", |
| 226 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 227 | }, |
| 228 | [DNS] = { |
| 229 | .name = "DNS", |
| 230 | .description = "GPRS Network Service (NS)", |
| 231 | .enabled = 1, .loglevel = LOGL_INFO, |
| 232 | }, |
| 233 | [DBSSGP] = { |
| 234 | .name = "DBSSGP", |
| 235 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 236 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 237 | }, |
| 238 | }; |
| 239 | |
| 240 | static const struct log_info gprs_log_info = { |
| 241 | .filter_fn = gprs_log_filter_fn, |
| 242 | .cat = gprs_categories, |
| 243 | .num_cat = ARRAY_SIZE(gprs_categories), |
| 244 | }; |
| 245 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 246 | static bool file_exists(const char *path) |
| 247 | { |
| 248 | struct stat sb; |
| 249 | return stat(path, &sb) ? false : true; |
| 250 | } |
| 251 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 252 | int gbprox_bssgp_send_cb(void *ctx, struct msgb *msg); |
| 253 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 254 | int main(int argc, char **argv) |
| 255 | { |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 256 | int rc; |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 257 | struct ctrl_handle *ctrl; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 258 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 259 | tall_sgsn_ctx = talloc_named_const(NULL, 0, "nsip_proxy"); |
| 260 | msgb_talloc_ctx_init(tall_sgsn_ctx, 0); |
| 261 | vty_info.tall_ctx = tall_sgsn_ctx; |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 262 | |
| 263 | signal(SIGINT, &signal_handler); |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame] | 264 | signal(SIGTERM, &signal_handler); |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 265 | signal(SIGABRT, &signal_handler); |
| 266 | signal(SIGUSR1, &signal_handler); |
| 267 | signal(SIGUSR2, &signal_handler); |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 268 | osmo_init_ignore_signals(); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 269 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 270 | osmo_init_logging2(tall_sgsn_ctx, &gprs_log_info); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 271 | |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 272 | vty_info.copyright = openbsc_copyright; |
| 273 | vty_init(&vty_info); |
Pau Espin Pedrol | e456e32 | 2019-08-05 16:03:39 +0200 | [diff] [blame] | 274 | logging_vty_add_cmds(); |
Harald Welte | 731930b | 2018-02-14 01:02:22 +0100 | [diff] [blame] | 275 | osmo_talloc_vty_add_cmds(); |
Pau Espin Pedrol | e456e32 | 2019-08-05 16:03:39 +0200 | [diff] [blame] | 276 | osmo_stats_vty_add_cmds(); |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 277 | gbproxy_vty_init(); |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 278 | |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 279 | handle_options(argc, argv); |
| 280 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 281 | /* Backwards compatibility: for years, the default config file name was |
| 282 | * osmo_gbproxy.cfg. All other Osmocom programs use osmo-*.cfg with a |
| 283 | * dash. To be able to use the new config file name without breaking |
| 284 | * previous setups that might rely on the legacy default config file |
| 285 | * name, we need to look for the old config file if no -c option was |
| 286 | * passed AND no file exists with the new default file name. */ |
| 287 | if (!config_file) { |
| 288 | /* No -c option was passed */ |
| 289 | if (file_exists(CONFIG_FILE_LEGACY) |
| 290 | && !file_exists(CONFIG_FILE_DEFAULT)) |
| 291 | config_file = CONFIG_FILE_LEGACY; |
| 292 | else |
| 293 | config_file = CONFIG_FILE_DEFAULT; |
| 294 | } |
| 295 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 296 | rate_ctr_init(tall_sgsn_ctx); |
| 297 | osmo_stats_init(tall_sgsn_ctx); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 298 | |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 299 | gbcfg = talloc_zero(tall_sgsn_ctx, struct gbproxy_config); |
Daniel Willmann | 3ab193c | 2018-06-01 07:21:08 +0200 | [diff] [blame] | 300 | if (!gbcfg) { |
| 301 | LOGP(DGPRS, LOGL_FATAL, "Unable to allocate config\n"); |
| 302 | exit(1); |
| 303 | } |
| 304 | gbproxy_init_config(gbcfg); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 305 | gbcfg->nsi = gprs_ns2_instantiate(tall_sgsn_ctx, gprs_ns2_prim_cb, gbcfg); |
| 306 | if (!gbcfg->nsi) { |
| 307 | LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); |
| 308 | exit(1); |
| 309 | } |
| 310 | |
| 311 | gprs_ns2_vty_init(gbcfg->nsi, NULL); |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 312 | bssgp_set_log_ss(DBSSGP); |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 313 | gprs_ns2_dynamic_create_nse(gbcfg->nsi, true); |
| 314 | |
| 315 | bssgp_set_bssgp_callback(gbprox_bssgp_send_cb, gbcfg); |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 316 | |
Daniel Willmann | 3ab193c | 2018-06-01 07:21:08 +0200 | [diff] [blame] | 317 | rc = gbproxy_parse_config(config_file, gbcfg); |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 318 | if (rc < 0) { |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 319 | LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file '%s'\n", config_file); |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 320 | exit(2); |
| 321 | } |
| 322 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 323 | gprs_ns2_vty_create(); |
| 324 | |
Neels Hofmeyr | fa0f715 | 2016-02-23 14:09:38 +0100 | [diff] [blame] | 325 | /* start telnet after reading config for vty_get_bind_addr() */ |
Pau Espin Pedrol | b1d1c24 | 2018-10-30 17:27:59 +0100 | [diff] [blame] | 326 | rc = telnet_init_dynif(tall_sgsn_ctx, NULL, |
Neels Hofmeyr | fa0f715 | 2016-02-23 14:09:38 +0100 | [diff] [blame] | 327 | vty_get_bind_addr(), OSMO_VTY_PORT_GBPROXY); |
| 328 | if (rc < 0) |
| 329 | exit(1); |
| 330 | |
Daniel Willmann | c977afa | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 331 | /* Start control interface after getting config for |
| 332 | * ctrl_vty_get_bind_addr() */ |
| 333 | ctrl = ctrl_interface_setup_dynip(gbcfg, ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_GBPROXY, NULL); |
| 334 | if (!ctrl) { |
| 335 | LOGP(DGPRS, LOGL_FATAL, "Failed to create CTRL interface.\n"); |
| 336 | exit(1); |
| 337 | } |
| 338 | |
| 339 | if (gb_ctrl_cmds_install() != 0) { |
| 340 | LOGP(DGPRS, LOGL_FATAL, "Failed to install CTRL commands.\n"); |
| 341 | exit(1); |
| 342 | } |
| 343 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame^] | 344 | if (!gprs_ns2_nse_by_nsei(gbcfg->nsi, gbcfg->nsip_sgsn_nsei)) { |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 345 | LOGP(DGPRS, LOGL_FATAL, "You cannot proxy to NSEI %u " |
| 346 | "without creating that NSEI before\n", |
Daniel Willmann | 3ab193c | 2018-06-01 07:21:08 +0200 | [diff] [blame] | 347 | gbcfg->nsip_sgsn_nsei); |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 348 | exit(2); |
| 349 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 350 | |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 351 | if (daemonize) { |
| 352 | rc = osmo_daemonize(); |
| 353 | if (rc < 0) { |
| 354 | perror("Error during daemonize"); |
| 355 | exit(1); |
| 356 | } |
| 357 | } |
| 358 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 359 | while (1) { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 360 | rc = osmo_select_main(0); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 361 | if (rc < 0) |
| 362 | exit(3); |
| 363 | } |
| 364 | |
| 365 | exit(0); |
| 366 | } |