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 | |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 41 | #include <osmocom/gprs/gprs_ns.h> |
| 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 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 49 | #include <osmocom/vty/command.h> |
| 50 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 3848770 | 2011-03-23 08:49:00 +0100 | [diff] [blame] | 51 | #include <osmocom/vty/logging.h> |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 52 | #include <osmocom/vty/stats.h> |
Harald Welte | 55dc31e | 2014-08-24 17:54:49 +0200 | [diff] [blame] | 53 | #include <osmocom/vty/ports.h> |
Harald Welte | 731930b | 2018-02-14 01:02:22 +0100 | [diff] [blame] | 54 | #include <osmocom/vty/misc.h> |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 55 | |
Harald Welte | e236596 | 2010-05-04 07:41:59 +0200 | [diff] [blame] | 56 | #include "../../bscconfig.h" |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 57 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 58 | #define _GNU_SOURCE |
| 59 | #include <getopt.h> |
| 60 | |
| 61 | void *tall_bsc_ctx; |
| 62 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 63 | const char *openbsc_copyright = |
Holger Hans Peter Freyther | 5f54075 | 2010-09-11 13:32:30 +0800 | [diff] [blame] | 64 | "Copyright (C) 2010 Harald Welte and On-Waves\r\n" |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 65 | "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] | 66 | "This is free software: you are free to change and redistribute it.\r\n" |
| 67 | "There is NO WARRANTY, to the extent permitted by law.\r\n"; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 68 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 69 | #define CONFIG_FILE_DEFAULT "osmo-gbproxy.cfg" |
| 70 | #define CONFIG_FILE_LEGACY "osmo_gbproxy.cfg" |
| 71 | |
| 72 | static char *config_file = NULL; |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 73 | struct gbproxy_config gbcfg = {0}; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 74 | static int daemonize = 0; |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 75 | |
| 76 | /* Pointer to the SGSN peer */ |
| 77 | extern struct gbprox_peer *gbprox_peer_sgsn; |
| 78 | |
| 79 | /* call-back function for the NS protocol */ |
| 80 | static int proxy_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc, |
Holger Hans Peter Freyther | c42ad8b | 2011-04-18 17:04:00 +0200 | [diff] [blame] | 81 | struct msgb *msg, uint16_t bvci) |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 82 | { |
| 83 | int rc = 0; |
| 84 | |
| 85 | switch (event) { |
| 86 | case GPRS_NS_EVT_UNIT_DATA: |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 87 | rc = gbprox_rcvmsg(&gbcfg, msg, nsvc->nsei, bvci, nsvc->nsvci); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 88 | break; |
| 89 | default: |
| 90 | LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event); |
| 91 | if (msg) |
Holger Hans Peter Freyther | a8ddb08 | 2012-03-01 20:30:32 +0100 | [diff] [blame] | 92 | msgb_free(msg); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 93 | rc = -EIO; |
| 94 | break; |
| 95 | } |
| 96 | return rc; |
| 97 | } |
| 98 | |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 99 | static void signal_handler(int signal) |
| 100 | { |
| 101 | fprintf(stdout, "signal %u received\n", signal); |
| 102 | |
| 103 | switch (signal) { |
| 104 | case SIGINT: |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame] | 105 | case SIGTERM: |
Pablo Neira Ayuso | ed5cacb | 2011-08-17 22:44:07 +0200 | [diff] [blame] | 106 | osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL); |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 107 | sleep(1); |
| 108 | exit(0); |
| 109 | break; |
| 110 | case SIGABRT: |
| 111 | /* in case of abort, we want to obtain a talloc report |
| 112 | * and then return to the caller, who will abort the process */ |
| 113 | case SIGUSR1: |
| 114 | talloc_report(tall_vty_ctx, stderr); |
| 115 | talloc_report_full(tall_bsc_ctx, stderr); |
| 116 | break; |
| 117 | case SIGUSR2: |
| 118 | talloc_report_full(tall_vty_ctx, stderr); |
| 119 | break; |
| 120 | default: |
| 121 | break; |
| 122 | } |
| 123 | } |
| 124 | |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 125 | static void print_usage() |
| 126 | { |
| 127 | printf("Usage: bsc_hack\n"); |
| 128 | } |
| 129 | |
| 130 | static void print_help() |
| 131 | { |
| 132 | printf(" Some useful help...\n"); |
| 133 | printf(" -h --help this text\n"); |
| 134 | printf(" -d option --debug=DNS:DGPRS,0:0 enable debugging\n"); |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 135 | printf(" -D --daemonize Fork the process into a background daemon\n"); |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 136 | 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] | 137 | printf(" -s --disable-color\n"); |
| 138 | printf(" -T --timestamp Prefix every log line with a timestamp\n"); |
| 139 | printf(" -V --version. Print the version of OpenBSC.\n"); |
| 140 | printf(" -e --log-level number. Set a global loglevel.\n"); |
| 141 | } |
| 142 | |
| 143 | static void handle_options(int argc, char **argv) |
| 144 | { |
| 145 | while (1) { |
| 146 | int option_index = 0, c; |
| 147 | static struct option long_options[] = { |
| 148 | { "help", 0, 0, 'h' }, |
| 149 | { "debug", 1, 0, 'd' }, |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 150 | { "daemonize", 0, 0, 'D' }, |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 151 | { "config-file", 1, 0, 'c' }, |
| 152 | { "disable-color", 0, 0, 's' }, |
| 153 | { "timestamp", 0, 0, 'T' }, |
| 154 | { "version", 0, 0, 'V' }, |
| 155 | { "log-level", 1, 0, 'e' }, |
| 156 | { 0, 0, 0, 0 } |
| 157 | }; |
| 158 | |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 159 | c = getopt_long(argc, argv, "hd:Dc:sTVe:", |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 160 | long_options, &option_index); |
| 161 | if (c == -1) |
| 162 | break; |
| 163 | |
| 164 | switch (c) { |
| 165 | case 'h': |
| 166 | print_usage(); |
| 167 | print_help(); |
| 168 | exit(0); |
| 169 | case 's': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 170 | log_set_use_color(osmo_stderr_target, 0); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 171 | break; |
| 172 | case 'd': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 173 | log_parse_category_mask(osmo_stderr_target, optarg); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 174 | break; |
Harald Welte | 2c869ef | 2010-08-25 19:43:54 +0200 | [diff] [blame] | 175 | case 'D': |
| 176 | daemonize = 1; |
| 177 | break; |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 178 | case 'c': |
Holger Hans Peter Freyther | abb3478 | 2015-01-26 10:26:36 +0100 | [diff] [blame] | 179 | config_file = optarg; |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 180 | break; |
| 181 | case 'T': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 182 | log_set_print_timestamp(osmo_stderr_target, 1); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 183 | break; |
| 184 | case 'e': |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 185 | log_set_log_level(osmo_stderr_target, atoi(optarg)); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 186 | break; |
| 187 | case 'V': |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 188 | print_version(1); |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 189 | exit(0); |
| 190 | break; |
| 191 | default: |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | } |
| 196 | |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 197 | int gbproxy_vty_is_config_node(struct vty *vty, int node) |
| 198 | { |
| 199 | switch (node) { |
| 200 | /* add items that are not config */ |
| 201 | case CONFIG_NODE: |
| 202 | return 0; |
| 203 | |
| 204 | default: |
| 205 | return 1; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | int gbproxy_vty_go_parent(struct vty *vty) |
| 210 | { |
| 211 | switch (vty->node) { |
| 212 | case GBPROXY_NODE: |
| 213 | default: |
| 214 | if (gbproxy_vty_is_config_node(vty, vty->node)) |
| 215 | vty->node = CONFIG_NODE; |
| 216 | else |
| 217 | vty->node = ENABLE_NODE; |
| 218 | |
| 219 | vty->index = NULL; |
| 220 | } |
| 221 | |
| 222 | return vty->node; |
| 223 | } |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 224 | |
| 225 | static struct vty_app_info vty_info = { |
Harald Welte | ec1921d | 2011-02-24 23:57:06 +0100 | [diff] [blame] | 226 | .name = "OsmoGbProxy", |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 227 | .version = PACKAGE_VERSION, |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 228 | .go_parent_cb = gbproxy_vty_go_parent, |
| 229 | .is_config_node = gbproxy_vty_is_config_node, |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 230 | }; |
| 231 | |
Harald Welte | 11461a6 | 2012-06-17 12:58:46 +0800 | [diff] [blame] | 232 | /* default categories */ |
| 233 | static struct log_info_cat gprs_categories[] = { |
| 234 | [DGPRS] = { |
| 235 | .name = "DGPRS", |
| 236 | .description = "GPRS Packet Service", |
| 237 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 238 | }, |
| 239 | [DNS] = { |
| 240 | .name = "DNS", |
| 241 | .description = "GPRS Network Service (NS)", |
| 242 | .enabled = 1, .loglevel = LOGL_INFO, |
| 243 | }, |
| 244 | [DBSSGP] = { |
| 245 | .name = "DBSSGP", |
| 246 | .description = "GPRS BSS Gateway Protocol (BSSGP)", |
| 247 | .enabled = 1, .loglevel = LOGL_DEBUG, |
| 248 | }, |
| 249 | }; |
| 250 | |
| 251 | static const struct log_info gprs_log_info = { |
| 252 | .filter_fn = gprs_log_filter_fn, |
| 253 | .cat = gprs_categories, |
| 254 | .num_cat = ARRAY_SIZE(gprs_categories), |
| 255 | }; |
| 256 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 257 | static bool file_exists(const char *path) |
| 258 | { |
| 259 | struct stat sb; |
| 260 | return stat(path, &sb) ? false : true; |
| 261 | } |
| 262 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 263 | int main(int argc, char **argv) |
| 264 | { |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 265 | int rc; |
| 266 | |
| 267 | tall_bsc_ctx = talloc_named_const(NULL, 0, "nsip_proxy"); |
Neels Hofmeyr | 39ae17f | 2016-09-16 01:49:08 +0200 | [diff] [blame] | 268 | msgb_talloc_ctx_init(tall_bsc_ctx, 0); |
Harald Welte | 731930b | 2018-02-14 01:02:22 +0100 | [diff] [blame] | 269 | vty_info.tall_ctx = tall_bsc_ctx; |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 270 | |
| 271 | signal(SIGINT, &signal_handler); |
Harald Welte | 6f750e6 | 2017-08-20 20:50:06 +0200 | [diff] [blame] | 272 | signal(SIGTERM, &signal_handler); |
Harald Welte | 6df0c51 | 2010-05-12 18:40:01 +0000 | [diff] [blame] | 273 | signal(SIGABRT, &signal_handler); |
| 274 | signal(SIGUSR1, &signal_handler); |
| 275 | signal(SIGUSR2, &signal_handler); |
Holger Hans Peter Freyther | 67cd75f | 2011-05-12 16:02:07 +0200 | [diff] [blame] | 276 | osmo_init_ignore_signals(); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 277 | |
Neels Hofmeyr | 5bd340e | 2018-04-16 00:57:10 +0200 | [diff] [blame^] | 278 | osmo_init_logging2(tall_bsc_ctx, &gprs_log_info); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 279 | |
Harald Welte | c31f480 | 2010-05-25 23:31:39 +0200 | [diff] [blame] | 280 | vty_info.copyright = openbsc_copyright; |
| 281 | vty_init(&vty_info); |
Max | db0e380 | 2017-01-12 19:35:11 +0100 | [diff] [blame] | 282 | logging_vty_add_cmds(NULL); |
Harald Welte | 731930b | 2018-02-14 01:02:22 +0100 | [diff] [blame] | 283 | osmo_talloc_vty_add_cmds(); |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 284 | osmo_stats_vty_add_cmds(&gprs_log_info); |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 285 | gbproxy_vty_init(); |
Harald Welte | 1353f96 | 2010-05-16 19:20:24 +0200 | [diff] [blame] | 286 | |
Harald Welte | 768f287 | 2010-05-14 11:22:33 +0000 | [diff] [blame] | 287 | handle_options(argc, argv); |
| 288 | |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 289 | /* Backwards compatibility: for years, the default config file name was |
| 290 | * osmo_gbproxy.cfg. All other Osmocom programs use osmo-*.cfg with a |
| 291 | * dash. To be able to use the new config file name without breaking |
| 292 | * previous setups that might rely on the legacy default config file |
| 293 | * name, we need to look for the old config file if no -c option was |
| 294 | * passed AND no file exists with the new default file name. */ |
| 295 | if (!config_file) { |
| 296 | /* No -c option was passed */ |
| 297 | if (file_exists(CONFIG_FILE_LEGACY) |
| 298 | && !file_exists(CONFIG_FILE_DEFAULT)) |
| 299 | config_file = CONFIG_FILE_LEGACY; |
| 300 | else |
| 301 | config_file = CONFIG_FILE_DEFAULT; |
| 302 | } |
| 303 | |
Harald Welte | f2b4cd7 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 304 | rate_ctr_init(tall_bsc_ctx); |
Jacob Erlbeck | 64630cc | 2015-10-26 16:25:37 +0100 | [diff] [blame] | 305 | osmo_stats_init(tall_bsc_ctx); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 306 | |
Harald Welte | fdd8b3b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 307 | bssgp_nsi = gprs_ns_instantiate(&proxy_ns_cb, tall_bsc_ctx); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 308 | if (!bssgp_nsi) { |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 309 | LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n"); |
| 310 | exit(1); |
| 311 | } |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 312 | gbproxy_init_config(&gbcfg); |
Harald Welte | 0a4050c | 2010-05-11 10:01:17 +0200 | [diff] [blame] | 313 | gbcfg.nsi = bssgp_nsi; |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 314 | gprs_ns_vty_init(bssgp_nsi); |
Harald Welte | 68d85d5 | 2012-06-16 17:45:59 +0800 | [diff] [blame] | 315 | gprs_ns_set_log_ss(DNS); |
Harald Welte | ce95b27 | 2012-06-17 13:04:02 +0800 | [diff] [blame] | 316 | bssgp_set_log_ss(DBSSGP); |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 317 | osmo_signal_register_handler(SS_L_NS, &gbprox_signal, &gbcfg); |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 318 | |
| 319 | rc = gbproxy_parse_config(config_file, &gbcfg); |
| 320 | if (rc < 0) { |
Neels Hofmeyr | 5343a8c | 2018-03-15 18:52:06 +0100 | [diff] [blame] | 321 | LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file '%s'\n", config_file); |
Harald Welte | 1194b58 | 2010-05-12 15:55:23 +0000 | [diff] [blame] | 322 | exit(2); |
| 323 | } |
| 324 | |
Neels Hofmeyr | fa0f715 | 2016-02-23 14:09:38 +0100 | [diff] [blame] | 325 | /* start telnet after reading config for vty_get_bind_addr() */ |
Neels Hofmeyr | ee6cfdc | 2017-07-13 02:03:50 +0200 | [diff] [blame] | 326 | rc = telnet_init_dynif(tall_bsc_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 | |
Harald Welte | e6599ee | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 331 | if (!gprs_nsvc_by_nsei(gbcfg.nsi, gbcfg.nsip_sgsn_nsei)) { |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 332 | LOGP(DGPRS, LOGL_FATAL, "You cannot proxy to NSEI %u " |
| 333 | "without creating that NSEI before\n", |
| 334 | gbcfg.nsip_sgsn_nsei); |
| 335 | exit(2); |
| 336 | } |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 337 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 338 | rc = gprs_ns_nsip_listen(bssgp_nsi); |
Harald Welte | 7af4962 | 2010-05-19 14:04:23 +0200 | [diff] [blame] | 339 | if (rc < 0) { |
| 340 | LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n"); |
| 341 | exit(2); |
| 342 | } |
Harald Welte | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 343 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 344 | rc = gprs_ns_frgre_listen(bssgp_nsi); |
| 345 | if (rc < 0) { |
| 346 | LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE " |
| 347 | "socket. Do you have CAP_NET_RAW?\n"); |
| 348 | exit(2); |
Harald Welte | 5540c4c | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 349 | } |
| 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 | 1ccbf44 | 2010-05-14 11:53:08 +0000 | [diff] [blame] | 359 | /* Reset all the persistent NS-VCs that we've read from the config */ |
| 360 | gbprox_reset_persistent_nsvcs(bssgp_nsi); |
| 361 | |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 362 | while (1) { |
Pablo Neira Ayuso | 4db9299 | 2011-05-06 12:11:23 +0200 | [diff] [blame] | 363 | rc = osmo_select_main(0); |
Harald Welte | 9f75c35 | 2010-04-30 20:26:32 +0200 | [diff] [blame] | 364 | if (rc < 0) |
| 365 | exit(3); |
| 366 | } |
| 367 | |
| 368 | exit(0); |
| 369 | } |