blob: 71cb18c96a2e42e297453709ae17d172edcf2988 [file] [log] [blame]
Harald Welte288be162010-05-01 16:48:27 +02001/* GPRS SGSN Implementation */
2
3/* (C) 2010 by Harald Welte <laforge@gnumonks.org>
Holger Hans Peter Freyther85531cc2010-10-06 20:37:09 +08004 * (C) 2010 by On-Waves
Harald Welte288be162010-05-01 16:48:27 +02005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-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 Welte288be162010-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 Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte288be162010-05-01 16:48:27 +020016 *
Harald Welte9af6ddf2011-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 Welte288be162010-05-01 16:48:27 +020019 *
20 */
21
22#include <unistd.h>
23#include <stdio.h>
Max4011e722016-07-05 15:19:12 +020024#include <time.h>
Harald Welte288be162010-05-01 16:48:27 +020025#include <stdlib.h>
26#include <string.h>
27#include <getopt.h>
28#include <errno.h>
Harald Welte66f793a2010-05-13 11:50:04 +020029#include <signal.h>
Harald Welte288be162010-05-01 16:48:27 +020030#include <sys/fcntl.h>
31#include <sys/stat.h>
Harald Welte288be162010-05-01 16:48:27 +020032#include <sys/socket.h>
33#include <netinet/in.h>
34#include <arpa/inet.h>
35
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +020036#include <osmocom/core/application.h>
Pablo Neira Ayuso136f4532011-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 Erlbeck64630cc2015-10-26 16:25:37 +010041#include <osmocom/core/stats.h>
Harald Welte288be162010-05-01 16:48:27 +020042
Harald Welte2483f1b2016-06-19 18:06:02 +020043#include <osmocom/gsm/gsup.h>
44
Harald Welteea34a4e2012-06-16 14:59:56 +080045#include <osmocom/gprs/gprs_ns.h>
46#include <osmocom/gprs/gprs_bssgp.h>
47
Harald Welte4b037e42010-05-19 19:45:32 +020048#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayuso38487702011-03-23 08:49:00 +010049#include <osmocom/vty/logging.h>
Jacob Erlbeck64630cc2015-10-26 16:25:37 +010050#include <osmocom/vty/stats.h>
Harald Welte55dc31e2014-08-24 17:54:49 +020051#include <osmocom/vty/ports.h>
Harald Welte4b037e42010-05-19 19:45:32 +020052
Neels Hofmeyr73828152016-02-23 15:10:33 +010053#include <osmocom/ctrl/control_vty.h>
54
Harald Welte288be162010-05-01 16:48:27 +020055#include <openbsc/signal.h>
56#include <openbsc/debug.h>
Harald Welte288be162010-05-01 16:48:27 +020057#include <openbsc/vty.h>
58#include <openbsc/sgsn.h>
Harald Welte2e918a82010-05-18 12:20:12 +020059#include <openbsc/gprs_llc.h>
Harald Welteb1fd9022012-06-17 12:16:31 +080060#include <openbsc/gprs_gmm.h>
Daniel Willmann6292c8d2016-05-21 17:35:57 +020061#include <openbsc/iu.h>
62
Harald Welteba874b82014-08-20 23:47:15 +020063#include <osmocom/ctrl/control_if.h>
Harald Welte55dc31e2014-08-24 17:54:49 +020064#include <osmocom/ctrl/ports.h>
Harald Welte288be162010-05-01 16:48:27 +020065
Harald Welte2720e732010-05-17 00:44:57 +020066#include <gtp.h>
67
Harald Weltee2365962010-05-04 07:41:59 +020068#include "../../bscconfig.h"
Harald Welte288be162010-05-01 16:48:27 +020069
Harald Welte288be162010-05-01 16:48:27 +020070#define _GNU_SOURCE
71#include <getopt.h>
72
73void *tall_bsc_ctx;
74
75struct gprs_ns_inst *sgsn_nsi;
Harald Welte9ae28a12010-08-27 09:26:44 +020076static int daemonize = 0;
Harald Welte288be162010-05-01 16:48:27 +020077const char *openbsc_copyright =
Holger Hans Peter Freyther5f540752010-09-11 13:32:30 +080078 "Copyright (C) 2010 Harald Welte and On-Waves\r\n"
Harald Welte69ca8f02015-10-29 10:35:24 +010079 "License AGPLv3+: GNU AGPL version 3 or later <http://gnu.org/licenses/agpl-3.0.html>\r\n"
Holger Hans Peter Freyther5f540752010-09-11 13:32:30 +080080 "This is free software: you are free to change and redistribute it.\r\n"
81 "There is NO WARRANTY, to the extent permitted by law.\r\n";
Harald Welte288be162010-05-01 16:48:27 +020082
Harald Welte8fc1a462010-05-17 00:53:10 +020083static struct sgsn_instance sgsn_inst = {
Harald Welte2720e732010-05-17 00:44:57 +020084 .config_file = "osmo_sgsn.cfg",
85 .cfg = {
86 .gtp_statedir = "./",
Jacob Erlbeck106f5472014-11-04 10:08:37 +010087 .auth_policy = SGSN_AUTH_POLICY_CLOSED,
Harald Welte2483f1b2016-06-19 18:06:02 +020088 .gsup_server_port = OSMO_GSUP_PORT,
Harald Welte2720e732010-05-17 00:44:57 +020089 },
90};
Harald Welte8fc1a462010-05-17 00:53:10 +020091struct sgsn_instance *sgsn = &sgsn_inst;
Harald Welte288be162010-05-01 16:48:27 +020092
93/* call-back function for the NS protocol */
94static int sgsn_ns_cb(enum gprs_ns_evt event, struct gprs_nsvc *nsvc,
Holger Hans Peter Freytherc42ad8b2011-04-18 17:04:00 +020095 struct msgb *msg, uint16_t bvci)
Harald Welte288be162010-05-01 16:48:27 +020096{
97 int rc = 0;
98
99 switch (event) {
100 case GPRS_NS_EVT_UNIT_DATA:
101 /* hand the message into the BSSGP implementation */
Harald Weltece95b272012-06-17 13:04:02 +0800102 rc = bssgp_rcvmsg(msg);
Harald Welte288be162010-05-01 16:48:27 +0200103 break;
104 default:
105 LOGP(DGPRS, LOGL_ERROR, "SGSN: Unknown event %u from NS\n", event);
106 if (msg)
Holger Hans Peter Freythera8ddb082012-03-01 20:30:32 +0100107 msgb_free(msg);
Harald Welte288be162010-05-01 16:48:27 +0200108 rc = -EIO;
109 break;
110 }
111 return rc;
112}
113
Harald Welteb1fd9022012-06-17 12:16:31 +0800114/* call-back function for the BSSGP protocol */
115int bssgp_prim_cb(struct osmo_prim_hdr *oph, void *ctx)
116{
117 struct osmo_bssgp_prim *bp;
118 bp = container_of(oph, struct osmo_bssgp_prim, oph);
119
120 switch (oph->sap) {
121 case SAP_BSSGP_LL:
122 switch (oph->primitive) {
123 case PRIM_BSSGP_UL_UD:
124 return gprs_llc_rcvmsg(oph->msg, bp->tp);
125 }
126 break;
127 case SAP_BSSGP_GMM:
128 switch (oph->primitive) {
129 case PRIM_BSSGP_GMM_SUSPEND:
130 return gprs_gmm_rx_suspend(bp->ra_id, bp->tlli);
131 case PRIM_BSSGP_GMM_RESUME:
132 return gprs_gmm_rx_resume(bp->ra_id, bp->tlli,
Holger Hans Peter Freyther9b5db282012-08-03 10:01:57 +0200133 bp->u.resume.suspend_ref);
Harald Welteb1fd9022012-06-17 12:16:31 +0800134 }
135 break;
136 case SAP_BSSGP_NM:
137 break;
138 }
139 return 0;
140}
141
Harald Welte66f793a2010-05-13 11:50:04 +0200142static void signal_handler(int signal)
143{
144 fprintf(stdout, "signal %u received\n", signal);
145
146 switch (signal) {
147 case SIGINT:
Pablo Neira Ayusoed5cacb2011-08-17 22:44:07 +0200148 osmo_signal_dispatch(SS_L_GLOBAL, S_L_GLOBAL_SHUTDOWN, NULL);
Harald Welte66f793a2010-05-13 11:50:04 +0200149 sleep(1);
150 exit(0);
151 break;
152 case SIGABRT:
153 /* in case of abort, we want to obtain a talloc report
154 * and then return to the caller, who will abort the process */
155 case SIGUSR1:
156 talloc_report(tall_vty_ctx, stderr);
157 talloc_report_full(tall_bsc_ctx, stderr);
158 break;
159 case SIGUSR2:
160 talloc_report_full(tall_vty_ctx, stderr);
161 break;
162 default:
163 break;
164 }
165}
166
Harald Welted6c74162010-05-02 21:29:17 +0200167/* NSI that BSSGP uses when transmitting on NS */
168extern struct gprs_ns_inst *bssgp_nsi;
Harald Welte288be162010-05-01 16:48:27 +0200169
Holger Hans Peter Freyther3e4e8cf2015-09-24 15:38:38 +0200170extern int bsc_vty_go_parent(struct vty *vty);
Harald Weltec31f4802010-05-25 23:31:39 +0200171
172static struct vty_app_info vty_info = {
Harald Welteec1921d2011-02-24 23:57:06 +0100173 .name = "OsmoSGSN",
Harald Weltec31f4802010-05-25 23:31:39 +0200174 .version = PACKAGE_VERSION,
175 .go_parent_cb = bsc_vty_go_parent,
Holger Hans Peter Freyther81506b42010-09-04 11:00:01 +0800176 .is_config_node = bsc_vty_is_config_node,
Harald Weltec31f4802010-05-25 23:31:39 +0200177};
178
Harald Welte9ae28a12010-08-27 09:26:44 +0200179static void print_help(void)
180{
181 printf("Some useful help...\n");
182 printf(" -h --help\tthis text\n");
183 printf(" -D --daemonize\tFork the process into a background daemon\n");
184 printf(" -d option --debug\tenable Debugging\n");
185 printf(" -s --disable-color\n");
Neels Hofmeyr130be402015-09-24 17:28:47 +0200186 printf(" -c --config-file\tThe config file to use [%s]\n", sgsn->config_file);
Harald Welte9ae28a12010-08-27 09:26:44 +0200187 printf(" -e --log-level number\tSet a global log level\n");
188}
189
190static void handle_options(int argc, char **argv)
191{
192 while (1) {
193 int option_index = 0, c;
194 static struct option long_options[] = {
195 {"help", 0, 0, 'h'},
196 {"debug", 1, 0, 'd'},
197 {"daemonize", 0, 0, 'D'},
198 {"config-file", 1, 0, 'c'},
199 {"disable-color", 0, 0, 's'},
200 {"timestamp", 0, 0, 'T'},
Philipp Maier99c97072017-03-14 17:32:35 +0100201 { "version", 0, 0, 'V' },
Harald Welte9ae28a12010-08-27 09:26:44 +0200202 {"log-level", 1, 0, 'e'},
203 {NULL, 0, 0, 0}
204 };
205
Philipp Maier99c97072017-03-14 17:32:35 +0100206 c = getopt_long(argc, argv, "hd:Dc:sTVe:",
Harald Welte9ae28a12010-08-27 09:26:44 +0200207 long_options, &option_index);
208 if (c == -1)
209 break;
210
211 switch (c) {
212 case 'h':
213 //print_usage();
214 print_help();
215 exit(0);
216 case 's':
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200217 log_set_use_color(osmo_stderr_target, 0);
Harald Welte9ae28a12010-08-27 09:26:44 +0200218 break;
219 case 'd':
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200220 log_parse_category_mask(osmo_stderr_target, optarg);
Harald Welte9ae28a12010-08-27 09:26:44 +0200221 break;
222 case 'D':
223 daemonize = 1;
224 break;
225 case 'c':
226 sgsn_inst.config_file = strdup(optarg);
227 break;
228 case 'T':
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200229 log_set_print_timestamp(osmo_stderr_target, 1);
Harald Welte9ae28a12010-08-27 09:26:44 +0200230 break;
Philipp Maier99c97072017-03-14 17:32:35 +0100231 case 'V':
232 print_version(1);
233 exit(0);
234 break;
Harald Welte9ae28a12010-08-27 09:26:44 +0200235 case 'e':
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200236 log_set_log_level(osmo_stderr_target, atoi(optarg));
Harald Welte9ae28a12010-08-27 09:26:44 +0200237 break;
238 default:
239 /* ignore */
240 break;
241 }
242 }
243}
244
Harald Welte11461a62012-06-17 12:58:46 +0800245/* default categories */
246static struct log_info_cat gprs_categories[] = {
247 [DMM] = {
248 .name = "DMM",
249 .description = "Layer3 Mobility Management (MM)",
250 .color = "\033[1;33m",
251 .enabled = 1, .loglevel = LOGL_NOTICE,
252 },
Harald Welte11461a62012-06-17 12:58:46 +0800253 [DPAG] = {
254 .name = "DPAG",
255 .description = "Paging Subsystem",
256 .color = "\033[1;38m",
257 .enabled = 1, .loglevel = LOGL_NOTICE,
258 },
259 [DMEAS] = {
260 .name = "DMEAS",
261 .description = "Radio Measurement Processing",
262 .enabled = 0, .loglevel = LOGL_NOTICE,
263 },
264 [DREF] = {
265 .name = "DREF",
266 .description = "Reference Counting",
267 .enabled = 0, .loglevel = LOGL_NOTICE,
268 },
269 [DGPRS] = {
270 .name = "DGPRS",
271 .description = "GPRS Packet Service",
272 .enabled = 1, .loglevel = LOGL_DEBUG,
273 },
274 [DNS] = {
275 .name = "DNS",
276 .description = "GPRS Network Service (NS)",
277 .enabled = 1, .loglevel = LOGL_INFO,
278 },
279 [DBSSGP] = {
280 .name = "DBSSGP",
281 .description = "GPRS BSS Gateway Protocol (BSSGP)",
282 .enabled = 1, .loglevel = LOGL_DEBUG,
283 },
284 [DLLC] = {
285 .name = "DLLC",
286 .description = "GPRS Logical Link Control Protocol (LLC)",
287 .enabled = 1, .loglevel = LOGL_DEBUG,
288 },
289 [DSNDCP] = {
290 .name = "DSNDCP",
291 .description = "GPRS Sub-Network Dependent Control Protocol (SNDCP)",
292 .enabled = 1, .loglevel = LOGL_DEBUG,
293 },
Daniel Willmann35a65ed2016-05-20 21:59:45 +0200294 [DRANAP] = {
295 .name = "DRANAP",
296 .description = "RAN Application Part (RANAP)",
297 .enabled = 1, .loglevel = LOGL_DEBUG,
298 },
Daniel Willmann3adb23c2016-05-20 21:59:35 +0200299 [DSUA] = {
300 .name = "DSUA",
301 .description = "SCCP User Adaptation (SUA)",
302 .enabled = 1, .loglevel = LOGL_DEBUG,
303 },
Philipp2c7f8372016-08-26 16:58:41 +0200304 [DSLHC] = {
305 .name = "DSLHC",
306 .description = "RFC1144 TCP/IP Header compression (SLHC)",
307 .enabled = 1, .loglevel = LOGL_DEBUG,
308 },
Philipp73f83d52016-09-02 13:38:01 +0200309 [DV42BIS] = {
310 .name = "DV42BIS",
311 .description = "V.42bis data compression (SNDCP)",
312 .enabled = 1, .loglevel = LOGL_DEBUG,
313 }
Harald Welte11461a62012-06-17 12:58:46 +0800314};
315
316static const struct log_info gprs_log_info = {
317 .filter_fn = gprs_log_filter_fn,
318 .cat = gprs_categories,
319 .num_cat = ARRAY_SIZE(gprs_categories),
320};
321
Daniel Willmann6292c8d2016-05-21 17:35:57 +0200322int sgsn_ranap_iu_event(struct ue_conn_ctx *ctx, enum iu_event_type type, void *data);
Harald Welte11461a62012-06-17 12:58:46 +0800323
Harald Welte288be162010-05-01 16:48:27 +0200324int main(int argc, char **argv)
325{
Holger Hans Peter Freythera2730302014-03-23 18:08:26 +0100326 struct ctrl_handle *ctrl;
Harald Welte288be162010-05-01 16:48:27 +0200327 struct gsm_network dummy_network;
Harald Welte288be162010-05-01 16:48:27 +0200328 int rc;
329
Max4011e722016-07-05 15:19:12 +0200330 srand(time(NULL));
Harald Welte288be162010-05-01 16:48:27 +0200331 tall_bsc_ctx = talloc_named_const(NULL, 0, "osmo_sgsn");
Neels Hofmeyr39ae17f2016-09-16 01:49:08 +0200332 msgb_talloc_ctx_init(tall_bsc_ctx, 0);
Harald Welte66f793a2010-05-13 11:50:04 +0200333
334 signal(SIGINT, &signal_handler);
335 signal(SIGABRT, &signal_handler);
336 signal(SIGUSR1, &signal_handler);
337 signal(SIGUSR2, &signal_handler);
Harald Welte288be162010-05-01 16:48:27 +0200338
Holger Hans Peter Freyther67cd75f2011-05-12 16:02:07 +0200339 osmo_init_ignore_signals();
Harald Welte11461a62012-06-17 12:58:46 +0800340 osmo_init_logging(&gprs_log_info);
Jacob Erlbeck64630cc2015-10-26 16:25:37 +0100341 osmo_stats_init(tall_bsc_ctx);
Harald Welte288be162010-05-01 16:48:27 +0200342
Harald Weltec31f4802010-05-25 23:31:39 +0200343 vty_info.copyright = openbsc_copyright;
344 vty_init(&vty_info);
Maxdb0e3802017-01-12 19:35:11 +0100345 logging_vty_add_cmds(NULL);
Jacob Erlbeck64630cc2015-10-26 16:25:37 +0100346 osmo_stats_vty_add_cmds(&gprs_log_info);
Neels Hofmeyr42836752017-07-20 14:41:20 +0200347 sgsn_vty_init(&sgsn_inst.cfg);
Neels Hofmeyr73828152016-02-23 15:10:33 +0100348 ctrl_vty_init(tall_bsc_ctx);
Harald Weltedcccb182010-05-16 20:52:23 +0200349
Harald Welte9ae28a12010-08-27 09:26:44 +0200350 handle_options(argc, argv);
351
Harald Welte66f793a2010-05-13 11:50:04 +0200352 rate_ctr_init(tall_bsc_ctx);
Harald Welte288be162010-05-01 16:48:27 +0200353
Harald Welte68d85d52012-06-16 17:45:59 +0800354 gprs_ns_set_log_ss(DNS);
Harald Weltece95b272012-06-17 13:04:02 +0800355 bssgp_set_log_ss(DBSSGP);
Harald Welte68d85d52012-06-16 17:45:59 +0800356
Harald Weltefdd8b3b2012-06-16 16:54:06 +0800357 sgsn_nsi = gprs_ns_instantiate(&sgsn_ns_cb, tall_bsc_ctx);
Harald Welte288be162010-05-01 16:48:27 +0200358 if (!sgsn_nsi) {
359 LOGP(DGPRS, LOGL_ERROR, "Unable to instantiate NS\n");
360 exit(1);
361 }
Harald Welte2720e732010-05-17 00:44:57 +0200362 bssgp_nsi = sgsn_inst.cfg.nsi = sgsn_nsi;
Harald Welte496aee42010-06-30 19:59:55 +0200363
364 gprs_llc_init("/usr/local/lib/osmocom/crypt/");
Alexander Couzens14314bd2016-07-05 09:52:52 +0200365 sgsn_rate_ctr_init();
Jacob Erlbeck81ffb742015-01-23 11:33:51 +0100366 sgsn_inst_init();
Harald Welte496aee42010-06-30 19:59:55 +0200367
Harald Welte66f793a2010-05-13 11:50:04 +0200368 gprs_ns_vty_init(bssgp_nsi);
Harald Weltece95b272012-06-17 13:04:02 +0800369 bssgp_vty_init();
Harald Welte2e918a82010-05-18 12:20:12 +0200370 gprs_llc_vty_init();
Harald Weltef78a3b22010-06-30 17:21:19 +0200371 gprs_sndcp_vty_init();
Jacob Erlbecka0b6efb2014-11-13 10:48:39 +0100372 sgsn_auth_init();
Holger Hans Peter Freyther4f5b8232015-05-05 22:25:48 +0200373 sgsn_cdr_init(&sgsn_inst);
Harald Weltea6a20b42012-06-16 16:40:42 +0800374 /* FIXME: register signal handler for SS_L_NS */
Harald Welte66f793a2010-05-13 11:50:04 +0200375
Neels Hofmeyr42836752017-07-20 14:41:20 +0200376 rc = sgsn_parse_config(sgsn_inst.config_file);
Harald Welte66f793a2010-05-13 11:50:04 +0200377 if (rc < 0) {
Neels Hofmeyr27355c92017-02-24 06:28:31 +0100378 LOGP(DGPRS, LOGL_FATAL, "Error in config file\n");
Harald Welte66f793a2010-05-13 11:50:04 +0200379 exit(2);
380 }
381
Neels Hofmeyrfa0f7152016-02-23 14:09:38 +0100382 /* start telnet after reading config for vty_get_bind_addr() */
Neels Hofmeyrfa0f7152016-02-23 14:09:38 +0100383 rc = telnet_init_dynif(tall_bsc_ctx, &dummy_network,
384 vty_get_bind_addr(), OSMO_VTY_PORT_SGSN);
385 if (rc < 0)
386 exit(1);
387
Neels Hofmeyr73828152016-02-23 15:10:33 +0100388 /* start control interface after reading config for
389 * ctrl_vty_get_bind_addr() */
Neels Hofmeyr73828152016-02-23 15:10:33 +0100390 ctrl = sgsn_controlif_setup(NULL, ctrl_vty_get_bind_addr(),
391 OSMO_CTRL_PORT_SGSN);
392 if (!ctrl) {
393 LOGP(DGPRS, LOGL_ERROR, "Failed to create CTRL interface.\n");
394 exit(1);
395 }
396
397 if (sgsn_ctrl_cmds_install() != 0) {
398 LOGP(DGPRS, LOGL_ERROR, "Failed to install CTRL commands.\n");
399 exit(1);
400 }
401
402
Harald Welte2720e732010-05-17 00:44:57 +0200403 rc = sgsn_gtp_init(&sgsn_inst);
Harald Welte6efc1762010-05-19 15:46:31 +0200404 if (rc) {
405 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on GTP socket\n");
Harald Welte269ae752010-05-18 14:44:31 +0200406 exit(2);
Harald Welte6efc1762010-05-19 15:46:31 +0200407 }
Harald Welte269ae752010-05-18 14:44:31 +0200408
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100409 rc = gprs_subscr_init(&sgsn_inst);
410 if (rc < 0) {
411 LOGP(DGPRS, LOGL_FATAL, "Cannot set up subscriber management\n");
412 exit(2);
413 }
414
Harald Welteff3bde82010-05-19 15:09:09 +0200415 rc = gprs_ns_nsip_listen(sgsn_nsi);
Harald Welte6efc1762010-05-19 15:46:31 +0200416 if (rc < 0) {
417 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen on NSIP socket\n");
Harald Welteff3bde82010-05-19 15:09:09 +0200418 exit(2);
Harald Welte6efc1762010-05-19 15:46:31 +0200419 }
420
421 rc = gprs_ns_frgre_listen(sgsn_nsi);
422 if (rc < 0) {
423 LOGP(DGPRS, LOGL_FATAL, "Cannot bind/listen GRE "
424 "socket. Do you have CAP_NET_RAW?\n");
425 exit(2);
426 }
Harald Welte288be162010-05-01 16:48:27 +0200427
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800428 if (sgsn->cfg.dynamic_lookup) {
429 if (sgsn_ares_init(sgsn) != 0) {
430 LOGP(DGPRS, LOGL_FATAL,
431 "Failed to initialize c-ares(%d)\n", rc);
432 exit(4);
433 }
434 }
435
Daniel Willmann6292c8d2016-05-21 17:35:57 +0200436#ifdef BUILD_IU
437 iu_init(tall_bsc_ctx, "127.0.0.2", 14001, gsm0408_gprs_rcvmsg_iu, sgsn_ranap_iu_event);
438#endif
439
Harald Welte9ae28a12010-08-27 09:26:44 +0200440 if (daemonize) {
441 rc = osmo_daemonize();
442 if (rc < 0) {
443 perror("Error during daemonize");
444 exit(1);
445 }
446 }
447
Harald Welte288be162010-05-01 16:48:27 +0200448 while (1) {
Pablo Neira Ayuso4db92992011-05-06 12:11:23 +0200449 rc = osmo_select_main(0);
Harald Welte288be162010-05-01 16:48:27 +0200450 if (rc < 0)
451 exit(3);
452 }
453
Harald Weltebaf77002011-07-16 13:47:01 +0200454 /* not reached */
Harald Welte288be162010-05-01 16:48:27 +0200455 exit(0);
456}