blob: 93848f5e23404b9dc93d935ecde2470d2767a930 [file] [log] [blame]
Harald Welte55fe0552010-05-01 16:48:27 +02001/* GPRS SGSN Implementation */
2
3/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther51808442010-10-06 20:37:09 +08004 * (C) 2010 by On-Waves
Harald Welte55fe0552010-05-01 16:48:27 +02005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte0e3e88e2011-01-01 15:25:50 +01008 * 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 Welte55fe0552010-05-01 16:48:27 +020010 * (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 Welte0e3e88e2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte55fe0552010-05-01 16:48:27 +020016 *
Harald Welte0e3e88e2011-01-01 15:25:50 +010017 * 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 Welte55fe0552010-05-01 16:48:27 +020019 *
20 */
21
22#include <unistd.h>
23#include <stdio.h>
Max9943d7a2016-07-05 15:19:12 +020024#include <time.h>
Harald Welte55fe0552010-05-01 16:48:27 +020025#include <stdlib.h>
26#include <string.h>
27#include <getopt.h>
28#include <errno.h>
Harald Weltefae1fbc2010-05-13 11:50:04 +020029#include <signal.h>
Harald Welte55fe0552010-05-01 16:48:27 +020030#include <sys/fcntl.h>
31#include <sys/stat.h>
Harald Welte55fe0552010-05-01 16:48:27 +020032#include <sys/socket.h>
33#include <netinet/in.h>
34#include <arpa/inet.h>
35
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +020036#include <osmocom/core/application.h>
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +010037#include <osmocom/core/talloc.h>
38#include <osmocom/core/select.h>
39#include <osmocom/core/rate_ctr.h>
40#include <osmocom/core/logging.h>
Jacob Erlbeck63fac682015-10-26 16:25:37 +010041#include <osmocom/core/stats.h>
Harald Welte55fe0552010-05-01 16:48:27 +020042
Harald Weltecfb6b282012-06-16 14:59:56 +080043#include <osmocom/gprs/gprs_ns.h>
44#include <osmocom/gprs/gprs_bssgp.h>
45
Harald Weltebd9591f2010-05-19 19:45:32 +020046#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayusof3046782011-03-23 08:49:00 +010047#include <osmocom/vty/logging.h>
Jacob Erlbeck63fac682015-10-26 16:25:37 +010048#include <osmocom/vty/stats.h>
Harald Welte6bcd3032014-08-24 17:54:49 +020049#include <osmocom/vty/ports.h>
Harald Weltebd9591f2010-05-19 19:45:32 +020050
Neels Hofmeyr4d92c432016-02-23 15:10:33 +010051#include <osmocom/ctrl/control_vty.h>
52
Harald Welte55fe0552010-05-01 16:48:27 +020053#include <openbsc/signal.h>
54#include <openbsc/debug.h>
Harald Welte55fe0552010-05-01 16:48:27 +020055#include <openbsc/vty.h>
56#include <openbsc/sgsn.h>
Harald Welte0c938b72010-05-18 12:20:12 +020057#include <openbsc/gprs_llc.h>
Harald Weltea62e9fe2012-06-17 12:16:31 +080058#include <openbsc/gprs_gmm.h>
Daniel Willmann945f6082016-05-21 17:35:57 +020059#include <openbsc/iu.h>
60
Harald Welte5919b6a2014-08-20 23:47:15 +020061#include <osmocom/ctrl/control_if.h>
Harald Welte6bcd3032014-08-24 17:54:49 +020062#include <osmocom/ctrl/ports.h>
Harald Welte55fe0552010-05-01 16:48:27 +020063
Harald Welte8f77f192010-05-17 00:44:57 +020064#include <gtp.h>
65
Harald Welte48030cf2010-05-04 07:41:59 +020066#include "../../bscconfig.h"
Harald Welte55fe0552010-05-01 16:48:27 +020067
Harald Welte55fe0552010-05-01 16:48:27 +020068#define _GNU_SOURCE
69#include <getopt.h>
70
71void *tall_bsc_ctx;
72
73struct gprs_ns_inst *sgsn_nsi;
Harald Welte599a9572010-08-27 09:26:44 +020074static int daemonize = 0;
Harald Welte55fe0552010-05-01 16:48:27 +020075const char *openbsc_copyright =
Holger Hans Peter Freyther260646d2010-09-11 13:32:30 +080076 "Copyright (C) 2010 Harald Welte and On-Waves\r\n"
Harald Welteadf4d792015-10-29 10:35:24 +010077 "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
Holger Hans Peter Freyther260646d2010-09-11 13:32:30 +080078 "This is free software: you are free to change and redistribute it.\r\n"
79 "There is NO WARRANTY, to the extent permitted by law.\r\n";
Harald Welte55fe0552010-05-01 16:48:27 +020080
Harald Welte17072d12010-05-17 00:53:10 +020081static struct sgsn_instance sgsn_inst = {
Harald Welte8f77f192010-05-17 00:44:57 +020082 .config_file = "osmo_sgsn.cfg",
83 .cfg = {
84 .gtp_statedir = "./",
Jacob Erlbeckd7b77732014-11-04 10:08:37 +010085 .auth_policy = SGSN_AUTH_POLICY_CLOSED,
Harald Welte8f77f192010-05-17 00:44:57 +020086 },
87};
Harald Welte17072d12010-05-17 00:53:10 +020088struct sgsn_instance *sgsn = &sgsn_inst;
Harald Welte55fe0552010-05-01 16:48:27 +020089
90/* call-back function for the NS protocol */
91static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
Holger Hans Peter Freyther7eb8a9a2011-04-18 17:04:00 +020092 struct msgb *msg, uint16_t bvci)
Harald Welte55fe0552010-05-01 16:48:27 +020093{
94 int rc = 0;
95
96 switch (event) {
97 case GPRS_NS_EVT_UNIT_DATA:
98 /* hand the message into the BSSGP implementation */
Harald Weltea084f122012-06-17 13:04:02 +080099 rc = bssgp_rcvmsg(msg);
Harald Welte55fe0552010-05-01 16:48:27 +0200100 break;
101 default:
102 LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event);
103 if (msg)
Holger Hans Peter Freyther1bcd6372012-03-01 20:30:32 +0100104 msgb_free(msg);
Harald Welte55fe0552010-05-01 16:48:27 +0200105 rc = -EIO;
106 break;
107 }
108 return rc;
109}
110
Harald Weltea62e9fe2012-06-17 12:16:31 +0800111/* call-back function for the BSSGP protocol */
112int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
113{
114 struct osmo_bssgp_prim *bp;
115 bp = container_of(oph, struct osmo_bssgp_prim, oph);
116
117 switch (oph->sap) {
118 case SAP_BSSGP_LL:
119 switch (oph->primitive) {
120 case PRIM_BSSGP_UL_UD:
121 return gprs_llc_rcvmsg(oph->msg, bp->tp);
122 }
123 break;
124 case SAP_BSSGP_GMM:
125 switch (oph->primitive) {
126 case PRIM_BSSGP_GMM_SUSPEND:
127 return gprs_gmm_rx_suspend(bp->ra_id, bp->tlli);
128 case PRIM_BSSGP_GMM_RESUME:
129 return gprs_gmm_rx_resume(bp->ra_id, bp->tlli,
Holger Hans Peter Freytherb6f053c2012-08-03 10:01:57 +0200130 bp->u.resume.suspend_ref);
Harald Weltea62e9fe2012-06-17 12:16:31 +0800131 }
132 break;
133 case SAP_BSSGP_NM:
134 break;
135 }
136 return 0;
137}
138
Harald Weltefae1fbc2010-05-13 11:50:04 +0200139static void signal_handler(int signal)
140{
141 fprintf(stdout, "signal %u received\n", signal);
142
143 switch (signal) {
144 case SIGINT:
Pablo Neira Ayuso42e41df2011-08-17 22:44:07 +0200145 osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
Harald Weltefae1fbc2010-05-13 11:50:04 +0200146 sleep(1);
147 exit(0);
148 break;
149 case SIGABRT:
150 /* in case of abort, we want to obtain a talloc report
151 * and then return to the caller, who will abort the process */
152 case SIGUSR1:
153 talloc_report(tall_vty_ctx, stderr);
154 talloc_report_full(tall_bsc_ctx, stderr);
155 break;
156 case SIGUSR2:
157 talloc_report_full(tall_vty_ctx, stderr);
158 break;
159 default:
160 break;
161 }
162}
163
Harald Welte29a4b8c2010-05-02 21:29:17 +0200164/* NSI that BSSGP uses when transmitting on NS */
165extern struct gprs_ns_inst *bssgp_nsi;
Harald Weltefae1fbc2010-05-13 11:50:04 +0200166extern void *tall_msgb_ctx;
Harald Welte55fe0552010-05-01 16:48:27 +0200167
Holger Hans Peter Freyther4ac8cd12015-09-24 15:38:38 +0200168extern int bsc_vty_go_parent(struct vty *vty);
Harald Welte778c4b92010-05-25 23:31:39 +0200169
170static struct vty_app_info vty_info = {
Harald Welte9af42c32011-02-24 23:57:06 +0100171 .name = "OsmoSGSN",
Harald Welte778c4b92010-05-25 23:31:39 +0200172 .version = PACKAGE_VERSION,
173 .go_parent_cb = bsc_vty_go_parent,
Holger Hans Peter Freytherba289d02010-09-04 11:00:01 +0800174 .is_config_node = bsc_vty_is_config_node,
Harald Welte778c4b92010-05-25 23:31:39 +0200175};
176
Harald Welte599a9572010-08-27 09:26:44 +0200177static void print_help(void)
178{
179 printf("Some useful help...\n");
180 printf(" -h --help\tthis text\n");
181 printf(" -D --daemonize\tFork the process into a background daemon\n");
182 printf(" -d option --debug\tenable Debugging\n");
183 printf(" -s --disable-color\n");
Neels Hofmeyr42c64ad2015-09-24 17:28:47 +0200184 printf(" -c --config-file\tThe config file to use [%s]\n", sgsn->config_file);
Harald Welte599a9572010-08-27 09:26:44 +0200185 printf(" -e --log-level number\tSet a global log level\n");
186}
187
188static void handle_options(int argc, char **argv)
189{
190 while (1) {
191 int option_index = 0, c;
192 static struct option long_options[] = {
193 {"help", 0, 0, 'h'},
194 {"debug", 1, 0, 'd'},
195 {"daemonize", 0, 0, 'D'},
196 {"config-file", 1, 0, 'c'},
197 {"disable-color", 0, 0, 's'},
198 {"timestamp", 0, 0, 'T'},
199 {"log-level", 1, 0, 'e'},
200 {NULL, 0, 0, 0}
201 };
202
203 c = getopt_long(argc, argv, "hd:Dc:sTe:",
204 long_options, &option_index);
205 if (c == -1)
206 break;
207
208 switch (c) {
209 case 'h':
210 //print_usage();
211 print_help();
212 exit(0);
213 case 's':
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +0200214 log_set_use_color(osmo_stderr_target, 0);
Harald Welte599a9572010-08-27 09:26:44 +0200215 break;
216 case 'd':
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +0200217 log_parse_category_mask(osmo_stderr_target, optarg);
Harald Welte599a9572010-08-27 09:26:44 +0200218 break;
219 case 'D':
220 daemonize = 1;
221 break;
222 case 'c':
223 sgsn_inst.config_file = strdup(optarg);
224 break;
225 case 'T':
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +0200226 log_set_print_timestamp(osmo_stderr_target, 1);
Harald Welte599a9572010-08-27 09:26:44 +0200227 break;
228 case 'e':
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +0200229 log_set_log_level(osmo_stderr_target, atoi(optarg));
Harald Welte599a9572010-08-27 09:26:44 +0200230 break;
231 default:
232 /* ignore */
233 break;
234 }
235 }
236}
237
Harald Welte40b25752012-06-17 12:58:46 +0800238/* default categories */
239static struct log_info_cat gprs_categories[] = {
240 [DMM] = {
241 .name = "DMM",
242 .description = "Layer3 Mobility Management (MM)",
243 .color = "\033[1;33m",
244 .enabled = 1, .loglevel = LOGL_NOTICE,
245 },
Harald Welte40b25752012-06-17 12:58:46 +0800246 [DPAG] = {
247 .name = "DPAG",
248 .description = "Paging Subsystem",
249 .color = "\033[1;38m",
250 .enabled = 1, .loglevel = LOGL_NOTICE,
251 },
252 [DMEAS] = {
253 .name = "DMEAS",
254 .description = "Radio Measurement Processing",
255 .enabled = 0, .loglevel = LOGL_NOTICE,
256 },
257 [DREF] = {
258 .name = "DREF",
259 .description = "Reference Counting",
260 .enabled = 0, .loglevel = LOGL_NOTICE,
261 },
262 [DGPRS] = {
263 .name = "DGPRS",
264 .description = "GPRS Packet Service",
265 .enabled = 1, .loglevel = LOGL_DEBUG,
266 },
267 [DNS] = {
268 .name = "DNS",
269 .description = "GPRS Network Service (NS)",
270 .enabled = 1, .loglevel = LOGL_INFO,
271 },
272 [DBSSGP] = {
273 .name = "DBSSGP",
274 .description = "GPRS BSS Gateway Protocol (BSSGP)",
275 .enabled = 1, .loglevel = LOGL_DEBUG,
276 },
277 [DLLC] = {
278 .name = "DLLC",
279 .description = "GPRS Logical Link Control Protocol (LLC)",
280 .enabled = 1, .loglevel = LOGL_DEBUG,
281 },
282 [DSNDCP] = {
283 .name = "DSNDCP",
284 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
285 .enabled = 1, .loglevel = LOGL_DEBUG,
286 },
Daniel Willmann59525c32016-05-20 21:59:45 +0200287 [DRANAP] = {
288 .name = "DRANAP",
289 .description = "RAN Application Part (RANAP)",
290 .enabled = 1, .loglevel = LOGL_DEBUG,
291 },
Daniel Willmann67286df2016-05-20 21:59:35 +0200292 [DSUA] = {
293 .name = "DSUA",
294 .description = "SCCP User Adaptation (SUA)",
295 .enabled = 1, .loglevel = LOGL_DEBUG,
296 },
Philipp49482092016-08-26 16:58:41 +0200297 [DSLHC] = {
298 .name = "DSLHC",
299 .description = "RFC1144 TCP/IP Header compression (SLHC)",
300 .enabled = 1, .loglevel = LOGL_DEBUG,
301 },
Philipp2c6dd812016-09-02 13:38:01 +0200302 [DV42BIS] = {
303 .name = "DV42BIS",
304 .description = "V.42bis data compression (SNDCP)",
305 .enabled = 1, .loglevel = LOGL_DEBUG,
306 }
Harald Welte40b25752012-06-17 12:58:46 +0800307};
308
309static const struct log_info gprs_log_info = {
310 .filter_fn = gprs_log_filter_fn,
311 .cat = gprs_categories,
312 .num_cat = ARRAY_SIZE(gprs_categories),
313};
314
Daniel Willmann945f6082016-05-21 17:35:57 +0200315/* Implement the extern asn_debug from libasn1c to indicate whether the ASN.1
316 * binary code decoded and encoded during Iu communication should be logged to
317 * stderr. See osmocom's libasn1c, asn_internal.h, at "if (asn_debug)":
318 * http://git.osmocom.org/libasn1c/tree/include/asn1c/asn_internal.h */
319int asn_debug = 0;
320
321int sgsn_ranap_iu_event(struct ue_conn_ctx *ctx, enum iu_event_type type, void *data);
Harald Welte40b25752012-06-17 12:58:46 +0800322
Harald Welte55fe0552010-05-01 16:48:27 +0200323int main(int argc, char **argv)
324{
Holger Hans Peter Freythere8e5ef22014-03-23 18:08:26 +0100325 struct ctrl_handle *ctrl;
Harald Welte55fe0552010-05-01 16:48:27 +0200326 struct gsm_network dummy_network;
Harald Welte55fe0552010-05-01 16:48:27 +0200327 int rc;
328
Max9943d7a2016-07-05 15:19:12 +0200329 srand(time(NULL));
Harald Welte55fe0552010-05-01 16:48:27 +0200330 tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
Harald Weltefae1fbc2010-05-13 11:50:04 +0200331 tall_msgb_ctx = talloc_named_const(tall_bsc_ctx, 0, "msgb");
332
333 signal(SIGINT, &signal_handler);
334 signal(SIGABRT, &signal_handler);
335 signal(SIGUSR1, &signal_handler);
336 signal(SIGUSR2, &signal_handler);
Harald Welte55fe0552010-05-01 16:48:27 +0200337
Holger Hans Peter Freyther2d59cc62011-05-12 16:02:07 +0200338 osmo_init_ignore_signals();
Harald Welte40b25752012-06-17 12:58:46 +0800339 osmo_init_logging(&gprs_log_info);
Jacob Erlbeck63fac682015-10-26 16:25:37 +0100340 osmo_stats_init(tall_bsc_ctx);
Harald Welte55fe0552010-05-01 16:48:27 +0200341
Harald Welte778c4b92010-05-25 23:31:39 +0200342 vty_info.copyright = openbsc_copyright;
343 vty_init(&vty_info);
Harald Welte40b25752012-06-17 12:58:46 +0800344 logging_vty_add_cmds(&gprs_log_info);
Jacob Erlbeck63fac682015-10-26 16:25:37 +0100345 osmo_stats_vty_add_cmds(&gprs_log_info);
346 sgsn_vty_init();
Neels Hofmeyr4d92c432016-02-23 15:10:33 +0100347 ctrl_vty_init(tall_bsc_ctx);
Daniel Willmann945f6082016-05-21 17:35:57 +0200348#ifdef BUILD_IU
349 iu_vty_init(&asn_debug);
350#endif
Harald Welte40152872010-05-16 20:52:23 +0200351
Harald Welte599a9572010-08-27 09:26:44 +0200352 handle_options(argc, argv);
353
Harald Weltefae1fbc2010-05-13 11:50:04 +0200354 rate_ctr_init(tall_bsc_ctx);
Harald Welte55fe0552010-05-01 16:48:27 +0200355
Harald Weltedeb90172012-06-16 17:45:59 +0800356 gprs_ns_set_log_ss(DNS);
Harald Weltea084f122012-06-17 13:04:02 +0800357 bssgp_set_log_ss(DBSSGP);
Harald Weltedeb90172012-06-16 17:45:59 +0800358
Harald Welte1d123382012-06-16 16:54:06 +0800359 sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx);
Harald Welte55fe0552010-05-01 16:48:27 +0200360 if (!sgsn_nsi) {
361 LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
362 exit(1);
363 }
Harald Welte8f77f192010-05-17 00:44:57 +0200364 bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi;
Harald Welte81fb3582010-06-30 19:59:55 +0200365
366 gprs_llc_init("/usr/local/lib/osmocom/crypt/");
Alexander Couzens32fdba02016-07-05 09:52:52 +0200367 sgsn_rate_ctr_init();
Jacob Erlbecke6140d02015-01-23 11:33:51 +0100368 sgsn_inst_init();
Harald Welte81fb3582010-06-30 19:59:55 +0200369
Harald Weltefae1fbc2010-05-13 11:50:04 +0200370 gprs_ns_vty_init(bssgp_nsi);
Harald Weltea084f122012-06-17 13:04:02 +0800371 bssgp_vty_init();
Harald Welte0c938b72010-05-18 12:20:12 +0200372 gprs_llc_vty_init();
Harald Welte94135032010-06-30 17:21:19 +0200373 gprs_sndcp_vty_init();
Jacob Erlbeckb2acd742014-11-13 10:48:39 +0100374 sgsn_auth_init();
Holger Hans Peter Freyther33d469b2015-05-05 22:25:48 +0200375 sgsn_cdr_init(&sgsn_inst);
Harald Welte7ed98e32012-06-16 16:40:42 +0800376 /* FIXME: register signal handler for SS_L_NS */
Harald Weltefae1fbc2010-05-13 11:50:04 +0200377
Harald Welte8f77f192010-05-17 00:44:57 +0200378 rc = sgsn_parse_config(sgsn_inst.config_file, &sgsn_inst.cfg);
Harald Weltefae1fbc2010-05-13 11:50:04 +0200379 if (rc < 0) {
380 LOGP(DGPRS, LOGL_FATAL, "Cannot parse config file\n");
381 exit(2);
382 }
383
Neels Hofmeyr737252c2016-02-23 14:09:38 +0100384 /* start telnet after reading config for vty_get_bind_addr() */
Neels Hofmeyr737252c2016-02-23 14:09:38 +0100385 rc = telnet_init_dynif(tall_bsc_ctx, &dummy_network,
386 vty_get_bind_addr(), OSMO_VTY_PORT_SGSN);
387 if (rc < 0)
388 exit(1);
389
Neels Hofmeyr4d92c432016-02-23 15:10:33 +0100390 /* start control interface after reading config for
391 * ctrl_vty_get_bind_addr() */
392 LOGP(DGPRS, LOGL_NOTICE, "CTRL at %s %d\n",
393 ctrl_vty_get_bind_addr(), OSMO_CTRL_PORT_SGSN);
394 ctrl = sgsn_controlif_setup(NULL, ctrl_vty_get_bind_addr(),
395 OSMO_CTRL_PORT_SGSN);
396 if (!ctrl) {
397 LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
398 exit(1);
399 }
400
401 if (sgsn_ctrl_cmds_install() != 0) {
402 LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
403 exit(1);
404 }
405
406
Harald Welte8f77f192010-05-17 00:44:57 +0200407 rc = sgsn_gtp_init(&sgsn_inst);
Harald Welte047a6882010-05-19 15:46:31 +0200408 if (rc) {
409 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n");
Harald Weltee59c56e2010-05-18 14:44:31 +0200410 exit(2);
Harald Welte047a6882010-05-19 15:46:31 +0200411 }
Harald Weltee59c56e2010-05-18 14:44:31 +0200412
Jacob Erlbeck233715c2014-12-18 12:46:47 +0100413 rc = gprs_subscr_init(&sgsn_inst);
414 if (rc < 0) {
415 LOGP(DGPRS, LOGL_FATAL, "Cannot set up subscriber management\n");
416 exit(2);
417 }
418
Harald Welte31f0a232010-05-19 15:09:09 +0200419 rc = gprs_ns_nsip_listen(sgsn_nsi);
Harald Welte047a6882010-05-19 15:46:31 +0200420 if (rc < 0) {
421 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n");
Harald Welte31f0a232010-05-19 15:09:09 +0200422 exit(2);
Harald Welte047a6882010-05-19 15:46:31 +0200423 }
424
425 rc = gprs_ns_frgre_listen(sgsn_nsi);
426 if (rc < 0) {
427 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE "
428 "socket. Do you have CAP_NET_RAW?\n");
429 exit(2);
430 }
Harald Welte55fe0552010-05-01 16:48:27 +0200431
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800432 if (sgsn->cfg.dynamic_lookup) {
433 if (sgsn_ares_init(sgsn) != 0) {
434 LOGP(DGPRS, LOGL_FATAL,
435 "Failed to initialize c-ares(%d)\n", rc);
436 exit(4);
437 }
438 }
439
Daniel Willmann945f6082016-05-21 17:35:57 +0200440#ifdef BUILD_IU
441 iu_init(tall_bsc_ctx, "127.0.0.2", 14001, gsm0408_gprs_rcvmsg_iu, sgsn_ranap_iu_event);
442#endif
443
Harald Welte599a9572010-08-27 09:26:44 +0200444 if (daemonize) {
445 rc = osmo_daemonize();
446 if (rc < 0) {
447 perror("Error during daemonize");
448 exit(1);
449 }
450 }
451
Harald Welte55fe0552010-05-01 16:48:27 +0200452 while (1) {
Pablo Neira Ayuso04d24cd2011-05-06 12:11:23 +0200453 rc = osmo_select_main(0);
Harald Welte55fe0552010-05-01 16:48:27 +0200454 if (rc < 0)
455 exit(3);
456 }
457
Harald Welte5c71db22011-07-16 13:47:01 +0200458 /* not reached */
Harald Welte55fe0552010-05-01 16:48:27 +0200459 exit(0);
460}