blob: 462b395e549318e148257f08c94338495587d8d4 [file] [log] [blame]
jjako52c24142002-12-16 13:33:51 +00001/*
Harald Welte632e8432017-09-05 18:12:14 +02002 * OsmoGGSN - Gateway GPRS Support Node
jjako0fe0df02004-09-17 11:30:40 +00003 * Copyright (C) 2002, 2003, 2004 Mondru AB.
Harald Weltedda21ed2017-08-12 15:07:02 +02004 * Copyright (C) 2017 by Harald Welte <laforge@gnumonks.org>
jjako52c24142002-12-16 13:33:51 +00005 *
jjakoa7cd2492003-04-11 09:40:12 +00006 * The contents of this file may be used under the terms of the GNU
7 * General Public License Version 2, provided that the above copyright
8 * notice and this permission notice is included in all copies or
9 * substantial portions of the software.
jjako52c24142002-12-16 13:33:51 +000010 *
jjako52c24142002-12-16 13:33:51 +000011 */
12
13/* ggsn.c
14 *
15 */
16
17#ifdef __linux__
18#define _GNU_SOURCE 1 /* strdup() prototype, broken arpa/inet.h */
19#endif
20
jjako0fe0df02004-09-17 11:30:40 +000021#include "../config.h"
22
23#ifdef HAVE_STDINT_H
24#include <stdint.h>
25#endif
jjako52c24142002-12-16 13:33:51 +000026
Harald Weltedda21ed2017-08-12 15:07:02 +020027#include <getopt.h>
jjako52c24142002-12-16 13:33:51 +000028#include <ctype.h>
jjako52c24142002-12-16 13:33:51 +000029#include <signal.h>
30#include <stdio.h>
31#include <string.h>
32#include <stdlib.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020033#include <unistd.h>
34#include <inttypes.h>
35#include <errno.h>
jjako52c24142002-12-16 13:33:51 +000036#include <sys/types.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020037#include <sys/ioctl.h>
38
39#include <net/if.h>
40#include <arpa/inet.h>
jjako52c24142002-12-16 13:33:51 +000041#include <netinet/in.h>
Harald Welte63ebccd2017-08-02 21:10:09 +020042#include <netinet/ip.h>
Harald Weltea0d281d2017-08-02 21:48:16 +020043#include <netinet/ip6.h>
jjako52c24142002-12-16 13:33:51 +000044
Harald Weltedda21ed2017-08-12 15:07:02 +020045#include <osmocom/core/application.h>
Max727417d2016-08-02 17:10:38 +020046#include <osmocom/core/select.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020047#include <osmocom/core/stats.h>
48#include <osmocom/core/rate_ctr.h>
49#include <osmocom/core/timer.h>
Max727417d2016-08-02 17:10:38 +020050#include <osmocom/ctrl/control_if.h>
51#include <osmocom/ctrl/control_cmd.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020052#include <osmocom/ctrl/control_vty.h>
Max727417d2016-08-02 17:10:38 +020053#include <osmocom/ctrl/ports.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020054#include <osmocom/vty/telnet_interface.h>
55#include <osmocom/vty/logging.h>
56#include <osmocom/vty/stats.h>
57#include <osmocom/vty/ports.h>
58#include <osmocom/vty/command.h>
59#include <osmocom/gsm/apn.h>
Max727417d2016-08-02 17:10:38 +020060
Emmanuel Bretelle2a103682010-09-07 17:01:20 +020061#include "../lib/tun.h"
62#include "../lib/ippool.h"
63#include "../lib/syserr.h"
Harald Welted12eab92017-08-02 19:49:47 +020064#include "../lib/in46_addr.h"
jjako52c24142002-12-16 13:33:51 +000065#include "../gtp/pdp.h"
66#include "../gtp/gtp.h"
Pablo Neira Ayuso4b075b62015-11-17 12:22:42 +010067#include "gtp-kernel.h"
Harald Welted46bcd22017-08-08 23:27:22 +020068#include "icmpv6.h"
Harald Weltedda21ed2017-08-12 15:07:02 +020069#include "ggsn.h"
jjako52c24142002-12-16 13:33:51 +000070
Harald Weltedda21ed2017-08-12 15:07:02 +020071void *tall_ggsn_ctx;
jjakoa7cd2492003-04-11 09:40:12 +000072
Harald Weltedda21ed2017-08-12 15:07:02 +020073static int end = 0;
74static int daemonize = 0;
75static struct ctrl_handle *g_ctrlh;
76
jjakoa7cd2492003-04-11 09:40:12 +000077struct ul255_t qos;
78struct ul255_t apn;
79
Harald Weltedda21ed2017-08-12 15:07:02 +020080#define LOGPAPN(level, apn, fmt, args...) \
81 LOGP(DGGSN, level, "APN(%s): " fmt, (apn)->cfg.name, ## args)
jjako52c24142002-12-16 13:33:51 +000082
Harald Weltedda21ed2017-08-12 15:07:02 +020083#define LOGPGGSN(level, ggsn, fmt, args...) \
84 LOGP(DGGSN, level, "GGSN(%s): " fmt, (ggsn)->cfg.name, ## args)
85
Max6a215272017-09-25 10:35:34 +020086#define LOGPPDP(level, pdp, fmt, args...) LOGPDPX(DGGSN, level, pdp, fmt, ## args)
Harald Weltedda21ed2017-08-12 15:07:02 +020087
88static int ggsn_tun_fd_cb(struct osmo_fd *fd, unsigned int what);
89static int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len);
90
91
92static void pool_close_all_pdp(struct ippool_t *pool)
Harald Weltebed35df2011-11-02 13:06:18 +010093{
Harald Weltedda21ed2017-08-12 15:07:02 +020094 unsigned int i;
jjako52c24142002-12-16 13:33:51 +000095
Harald Weltedda21ed2017-08-12 15:07:02 +020096 if (!pool)
Harald Weltebed35df2011-11-02 13:06:18 +010097 return;
Harald Weltedda21ed2017-08-12 15:07:02 +020098
99 for (i = 0; i < pool->listsize; i++) {
100 struct ippoolm_t *member = &pool->member[i];
101 struct pdp_t *pdp;
102
103 if (!member->inuse)
104 continue;
105 pdp = member->peer;
106 if (!pdp)
107 continue;
108 LOGPPDP(LOGL_DEBUG, pdp, "Sending DELETE PDP CTX due to shutdown\n");
109 gtp_delete_context_req(pdp->gsn, pdp, NULL, 1);
Harald Weltebed35df2011-11-02 13:06:18 +0100110 }
jjako52c24142002-12-16 13:33:51 +0000111}
112
Harald Weltedda21ed2017-08-12 15:07:02 +0200113int apn_stop(struct apn_ctx *apn, bool force)
Harald Weltebed35df2011-11-02 13:06:18 +0100114{
Harald Weltedda21ed2017-08-12 15:07:02 +0200115 if (!apn->started)
116 return 0;
jjako0141d202004-01-09 15:19:20 +0000117
Harald Weltedda21ed2017-08-12 15:07:02 +0200118 LOGPAPN(LOGL_NOTICE, apn, "%sStopping\n", force ? "FORCED " : "");
119 /* check if pools have any active PDP contexts and bail out */
120 pool_close_all_pdp(apn->v4.pool);
121 pool_close_all_pdp(apn->v6.pool);
122
123 /* shutdown whatever old state might be left */
124 if (apn->tun.tun) {
125 /* run ip-down script */
126 if (apn->tun.cfg.ipdown_script) {
127 LOGPAPN( LOGL_INFO, apn, "Running %s\n", apn->tun.cfg.ipdown_script);
128 tun_runscript(apn->tun.tun, apn->tun.cfg.ipdown_script);
129 }
130 /* release tun device */
131 LOGPAPN(LOGL_INFO, apn, "Closing TUN device\n");
132 osmo_fd_unregister(&apn->tun.fd);
133 tun_free(apn->tun.tun);
134 apn->tun.tun = NULL;
135 }
136
137 if (apn->v4.pool) {
138 LOGPAPN(LOGL_INFO, apn, "Releasing IPv4 pool\n");
139 ippool_free(apn->v4.pool);
140 apn->v4.pool = NULL;
141 }
142 if (apn->v6.pool) {
143 LOGPAPN(LOGL_INFO, apn, "Releasing IPv6 pool\n");
144 ippool_free(apn->v6.pool);
145 apn->v6.pool = NULL;
146 }
147
148 apn->started = false;
149 return 0;
150}
151
152/* actually start the APN with its current config */
153int apn_start(struct apn_ctx *apn)
154{
155 if (apn->started)
156 return 0;
157
158 LOGPAPN(LOGL_INFO, apn, "Starting\n");
159 switch (apn->cfg.gtpu_mode) {
160 case APN_GTPU_MODE_TUN:
161 LOGPAPN(LOGL_INFO, apn, "Opening TUN device %s\n", apn->tun.cfg.dev_name);
162 if (tun_new(&apn->tun.tun, apn->tun.cfg.dev_name)) {
163 LOGPAPN(LOGL_ERROR, apn, "Failed to configure tun device\n");
164 return -1;
165 }
166 LOGPAPN(LOGL_INFO, apn, "Opened TUN device %s\n", apn->tun.tun->devname);
167
168 /* Register with libosmcoore */
169 osmo_fd_setup(&apn->tun.fd, apn->tun.tun->fd, BSC_FD_READ, ggsn_tun_fd_cb, apn, 0);
170 osmo_fd_register(&apn->tun.fd);
171
172 /* Set TUN library callback */
173 tun_set_cb_ind(apn->tun.tun, cb_tun_ind);
174
175 if (apn->v4.cfg.ifconfig_prefix.addr.len) {
176 LOGPAPN(LOGL_INFO, apn, "Setting tun IP address %s\n",
177 in46p_ntoa(&apn->v4.cfg.ifconfig_prefix));
178 if (tun_setaddr(apn->tun.tun, &apn->v4.cfg.ifconfig_prefix.addr, NULL,
179 apn->v4.cfg.ifconfig_prefix.prefixlen)) {
180 LOGPAPN(LOGL_ERROR, apn, "Failed to set tun IPv4 address %s: %s\n",
181 in46p_ntoa(&apn->v4.cfg.ifconfig_prefix), strerror(errno));
182 apn_stop(apn, false);
183 return -1;
184 }
185 }
186
187 if (apn->v6.cfg.ifconfig_prefix.addr.len) {
188 LOGPAPN(LOGL_INFO, apn, "Setting tun IPv6 address %s\n",
189 in46p_ntoa(&apn->v6.cfg.ifconfig_prefix));
190 if (tun_setaddr(apn->tun.tun, &apn->v6.cfg.ifconfig_prefix.addr, NULL,
191 apn->v6.cfg.ifconfig_prefix.prefixlen)) {
192 LOGPAPN(LOGL_ERROR, apn, "Failed to set tun IPv6 address %s: %s\n",
193 in46p_ntoa(&apn->v6.cfg.ifconfig_prefix), strerror(errno));
194 apn_stop(apn, false);
195 return -1;
196 }
197 }
198
199 if (apn->tun.cfg.ipup_script) {
200 LOGPAPN(LOGL_INFO, apn, "Running ip-up script %s\n",
201 apn->tun.cfg.ipup_script);
202 tun_runscript(apn->tun.tun, apn->tun.cfg.ipup_script);
203 }
Harald Weltef85fe972017-09-24 20:00:34 +0800204
205 if (apn->cfg.apn_type_mask & (APN_TYPE_IPv6|APN_TYPE_IPv4v6)) {
206 if (tun_ipv6_linklocal_get(apn->tun.tun, &apn->v6_lladdr) < 0) {
207 LOGPAPN(LOGL_ERROR, apn, "Cannot obtain IPv6 link-local address of "
208 "interface: %s\n", strerror(errno));
209 apn_stop(apn, false);
210 return -1;
211 }
212 }
213
Harald Weltedda21ed2017-08-12 15:07:02 +0200214 /* set back-pointer from TUN device to APN */
215 apn->tun.tun->priv = apn;
216 break;
217 case APN_GTPU_MODE_KERNEL_GTP:
218 LOGPAPN(LOGL_ERROR, apn, "FIXME: Kernel GTP\n");
219#if 0
220 /* use GTP kernel module for data packet encapsulation */
221 if (gtp_kernel_init(gsn, &net.v4, prefixlen, net_arg) < 0)
222 goto err;
223#endif
Harald Weltebed35df2011-11-02 13:06:18 +0100224 break;
225 default:
Harald Weltedda21ed2017-08-12 15:07:02 +0200226 LOGPAPN(LOGL_ERROR, apn, "Unknown GTPU Mode %d\n", apn->cfg.gtpu_mode);
227 return -1;
Harald Weltebed35df2011-11-02 13:06:18 +0100228 }
jjako0141d202004-01-09 15:19:20 +0000229
Harald Weltedda21ed2017-08-12 15:07:02 +0200230 /* Create IPv4 pool */
231 if (apn->v4.cfg.dynamic_prefix.addr.len) {
232 LOGPAPN(LOGL_INFO, apn, "Creating IPv4 pool %s\n",
233 in46p_ntoa(&apn->v4.cfg.dynamic_prefix));
234 if (ippool_new(&apn->v4.pool, &apn->v4.cfg.dynamic_prefix,
235 &apn->v4.cfg.static_prefix, 0)) {
236 LOGPAPN(LOGL_ERROR, apn, "Failed to create IPv4 pool\n");
237 apn_stop(apn, false);
238 return -1;
239 }
Harald Weltebed35df2011-11-02 13:06:18 +0100240 }
Harald Weltedda21ed2017-08-12 15:07:02 +0200241
242 /* Create IPv6 pool */
243 if (apn->v6.cfg.dynamic_prefix.addr.len) {
244 LOGPAPN(LOGL_INFO, apn, "Creating IPv6 pool %s\n",
245 in46p_ntoa(&apn->v6.cfg.dynamic_prefix));
246 if (ippool_new(&apn->v6.pool, &apn->v6.cfg.dynamic_prefix,
247 &apn->v6.cfg.static_prefix, 0)) {
248 LOGPAPN(LOGL_ERROR, apn, "Failed to create IPv6 pool\n");
249 apn_stop(apn, false);
250 return -1;
251 }
252 }
253
254 LOGPAPN(LOGL_NOTICE, apn, "Successfully started\n");
255 apn->started = true;
256 return 0;
jjako0141d202004-01-09 15:19:20 +0000257}
jjako0141d202004-01-09 15:19:20 +0000258
Max3142d8d2017-05-04 17:45:10 +0200259static bool send_trap(const struct gsn_t *gsn, const struct pdp_t *pdp, const struct ippoolm_t *member, const char *var)
260{
Harald Welted12eab92017-08-02 19:49:47 +0200261 char addrbuf[256];
Max3142d8d2017-05-04 17:45:10 +0200262 char val[NAMESIZE];
263
Harald Welted12eab92017-08-02 19:49:47 +0200264 const char *addrstr = in46a_ntop(&member->addr, addrbuf, sizeof(addrbuf));
265
Harald Welteb10ee082017-08-12 19:29:16 +0200266 snprintf(val, sizeof(val), "%s,%s", imsi_gtp2str(&pdp->imsi), addrstr);
Max3142d8d2017-05-04 17:45:10 +0200267
Harald Weltedda21ed2017-08-12 15:07:02 +0200268 if (ctrl_cmd_send_trap(g_ctrlh, var, val) < 0) {
269 LOGPPDP(LOGL_ERROR, pdp, "Failed to create and send TRAP %s\n", var);
Max3142d8d2017-05-04 17:45:10 +0200270 return false;
271 }
272 return true;
273}
274
Harald Weltedda21ed2017-08-12 15:07:02 +0200275static int delete_context(struct pdp_t *pdp)
Harald Weltebed35df2011-11-02 13:06:18 +0100276{
Harald Weltedda21ed2017-08-12 15:07:02 +0200277 struct gsn_t *gsn = pdp->gsn;
278 struct ippoolm_t *ipp = (struct ippoolm_t *)pdp->peer;
279
280 LOGPPDP(LOGL_INFO, pdp, "Deleting PDP context\n");
Max727417d2016-08-02 17:10:38 +0200281 struct ippoolm_t *member = pdp->peer;
Maxdbd70242016-10-14 13:38:05 +0200282
283 if (pdp->peer) {
Max3142d8d2017-05-04 17:45:10 +0200284 send_trap(gsn, pdp, member, "imsi-rem-ip"); /* TRAP with IP removal */
Harald Weltedda21ed2017-08-12 15:07:02 +0200285 ippool_freeip(ipp->pool, ipp);
Maxdbd70242016-10-14 13:38:05 +0200286 } else
Harald Weltedda21ed2017-08-12 15:07:02 +0200287 LOGPPDP(LOGL_ERROR, pdp, "Cannot find/free IP Pool member\n");
Pablo Neira Ayuso4b075b62015-11-17 12:22:42 +0100288
289 if (gtp_kernel_tunnel_del(pdp)) {
Harald Weltedda21ed2017-08-12 15:07:02 +0200290 LOGPPDP(LOGL_ERROR, pdp, "Cannot delete tunnel from kernel:%s\n",
Pablo Neira Ayuso4b075b62015-11-17 12:22:42 +0100291 strerror(errno));
292 }
293
Harald Weltebed35df2011-11-02 13:06:18 +0100294 return 0;
jjako52c24142002-12-16 13:33:51 +0000295}
296
Harald Welte1ae98772017-08-09 20:28:52 +0200297#include <osmocom/gsm/tlv.h>
298
299/* 3GPP TS 24.008 10.6.5.3 */
300enum pco_protocols {
301 PCO_P_LCP = 0xC021,
302 PCO_P_PAP = 0xC023,
303 PCO_P_CHAP = 0xC223,
304 PCO_P_IPCP = 0x8021,
305 PCO_P_PCSCF_ADDR = 0x0001,
306 PCO_P_IM_CN_SS_F = 0x0002,
307 PCO_P_DNS_IPv6_ADDR = 0x0003,
308 PCO_P_POLICY_CTRL_REJ = 0x0004, /* only in Network->MS */
309 PCO_P_MS_SUP_NETREQ_BCI = 0x0005,
310 /* reserved */
311 PCO_P_DSMIPv6_HA_ADDR = 0x0007,
312 PCO_P_DSMIPv6_HN_PREF = 0x0008,
313 PCO_P_DSMIPv6_v4_HA_ADDR= 0x0009,
314 PCO_P_IP_ADDR_VIA_NAS = 0x000a, /* only MS->Network */
315 PCO_P_IPv4_ADDR_VIA_DHCP= 0x000b, /* only MS->Netowrk */
316 PCO_P_PCSCF_IPv4_ADDR = 0x000c,
317 PCO_P_DNS_IPv4_ADDR = 0x000d,
318 PCO_P_MSISDN = 0x000e,
319 PCO_P_IFOM_SUPPORT = 0x000f,
320 PCO_P_IPv4_LINK_MTU = 0x0010,
321 PCO_P_MS_SUPP_LOC_A_TFT = 0x0011,
322 PCO_P_PCSCF_RESEL_SUP = 0x0012, /* only MS->Network */
323 PCO_P_NBIFOM_REQ = 0x0013,
324 PCO_P_NBIFOM_MODE = 0x0014,
325 PCO_P_NONIP_LINK_MTU = 0x0015,
326 PCO_P_APN_RATE_CTRL_SUP = 0x0016,
327 PCO_P_PS_DATA_OFF_UE = 0x0017,
328 PCO_P_REL_DATA_SVC = 0x0018,
329};
330
331/* determine if PCO contains given protocol */
332static bool pco_contains_proto(struct ul255_t *pco, uint16_t prot)
333{
334 uint8_t *cur = pco->v + 1;
335
336 /* iterate over PCO and check if protocol contained */
Pau Espin Pedrol0ab62fe2017-08-30 15:51:24 +0200337 while (cur + 3 <= pco->v + pco->l) {
Harald Welte1ae98772017-08-09 20:28:52 +0200338 uint16_t cur_prot = osmo_load16be(cur);
339 uint8_t cur_len = cur[2];
340 if (cur_prot == prot)
341 return true;
342 if (cur_len == 0)
343 break;
Pau Espin Pedrol0ab62fe2017-08-30 15:51:24 +0200344 cur += cur_len + 3;
Harald Welte1ae98772017-08-09 20:28:52 +0200345 }
346 return false;
347}
348
349/* determine if PDP context has IPv6 support */
350static bool pdp_has_v4(struct pdp_t *pdp)
351{
352 if (pdp->eua.l == 4+2)
353 return true;
354 else
355 return false;
356}
357
Harald Weltedda21ed2017-08-12 15:07:02 +0200358/* construct an IPCP PCO from up to two given DNS addreses */
359static int build_ipcp_pco(struct msgb *msg, uint8_t id, const struct in46_addr *dns1,
360 const struct in46_addr *dns2)
361{
362 uint8_t *len1, *len2;
363 uint8_t *start = msg->tail;
364 unsigned int len_appended;
365
366 /* Three byte T16L header */
367 msgb_put_u16(msg, 0x8021); /* IPCP */
368 len1 = msgb_put(msg, 1); /* Length of contents: delay */
369
370 msgb_put_u8(msg, 0x02); /* ACK */
371 msgb_put_u8(msg, id); /* ID: Needs to match request */
372 msgb_put_u8(msg, 0x00); /* Length MSB */
373 len2 = msgb_put(msg, 1); /* Length LSB: delay */
374
375 if (dns1 && dns1->len == 4) {
376 msgb_put_u8(msg, 0x81); /* DNS1 Tag */
377 msgb_put_u8(msg, 2 + dns1->len);/* DNS1 Length, incl. TL */
378 msgb_put_u32(msg, dns1->v4.s_addr);
379 }
380
381 if (dns2 && dns2->len == 4) {
382 msgb_put_u8(msg, 0x83); /* DNS2 Tag */
383 msgb_put_u8(msg, 2 + dns2->len);/* DNS2 Length, incl. TL */
384 msgb_put_u32(msg, dns2->v4.s_addr);
385 }
386
387 /* patch in length values */
388 len_appended = msg->tail - start;
389 *len1 = len_appended - 3;
390 *len2 = len_appended - 3;
391
392 return 0;
393}
394
Harald Welte1ae98772017-08-09 20:28:52 +0200395/* process one PCO request from a MS/UE, putting together the proper responses */
Harald Weltedda21ed2017-08-12 15:07:02 +0200396static void process_pco(struct apn_ctx *apn, struct pdp_t *pdp)
Harald Welte1ae98772017-08-09 20:28:52 +0200397{
398 struct msgb *msg = msgb_alloc(256, "PCO");
Harald Weltedda21ed2017-08-12 15:07:02 +0200399 unsigned int i;
400
401 OSMO_ASSERT(msg);
Harald Welte1ae98772017-08-09 20:28:52 +0200402 msgb_put_u8(msg, 0x80); /* ext-bit + configuration protocol byte */
403
404 /* FIXME: also check if primary / secondary DNS was requested */
405 if (pdp_has_v4(pdp) && pco_contains_proto(&pdp->pco_req, PCO_P_IPCP)) {
406 /* FIXME: properly implement this for IPCP */
Harald Weltedda21ed2017-08-12 15:07:02 +0200407 build_ipcp_pco(msg, 0, &apn->v4.cfg.dns[0], &apn->v4.cfg.dns[1]);
Harald Welte1ae98772017-08-09 20:28:52 +0200408 }
409
410 if (pco_contains_proto(&pdp->pco_req, PCO_P_DNS_IPv6_ADDR)) {
Harald Weltedda21ed2017-08-12 15:07:02 +0200411 for (i = 0; i < ARRAY_SIZE(apn->v6.cfg.dns); i++) {
412 struct in46_addr *i46a = &apn->v6.cfg.dns[i];
413 if (i46a->len != 16)
414 continue;
415 msgb_t16lv_put(msg, PCO_P_DNS_IPv6_ADDR, i46a->len, i46a->v6.s6_addr);
416 }
Harald Welte1ae98772017-08-09 20:28:52 +0200417 }
418
419 if (pco_contains_proto(&pdp->pco_req, PCO_P_DNS_IPv4_ADDR)) {
Harald Weltedda21ed2017-08-12 15:07:02 +0200420 for (i = 0; i < ARRAY_SIZE(apn->v4.cfg.dns); i++) {
421 struct in46_addr *i46a = &apn->v4.cfg.dns[i];
422 if (i46a->len != 4)
423 continue;
424 msgb_t16lv_put(msg, PCO_P_DNS_IPv4_ADDR, i46a->len, (uint8_t *)&i46a->v4);
425 }
Harald Welte1ae98772017-08-09 20:28:52 +0200426 }
427
428 if (msgb_length(msg) > 1) {
429 memcpy(pdp->pco_neg.v, msgb_data(msg), msgb_length(msg));
430 pdp->pco_neg.l = msgb_length(msg);
431 } else
432 pdp->pco_neg.l = 0;
433
434 msgb_free(msg);
435}
436
Harald Weltebed35df2011-11-02 13:06:18 +0100437int create_context_ind(struct pdp_t *pdp)
438{
Harald Weltedda21ed2017-08-12 15:07:02 +0200439 static char name_buf[256];
440 struct gsn_t *gsn = pdp->gsn;
441 struct ggsn_ctx *ggsn = gsn->priv;
Harald Welted12eab92017-08-02 19:49:47 +0200442 struct in46_addr addr;
Harald Weltebed35df2011-11-02 13:06:18 +0100443 struct ippoolm_t *member;
Harald Weltedda21ed2017-08-12 15:07:02 +0200444 struct apn_ctx *apn;
Harald Welted1bf1e12017-08-03 00:00:23 +0200445 int rc;
jjako52c24142002-12-16 13:33:51 +0000446
Harald Weltedda21ed2017-08-12 15:07:02 +0200447 osmo_apn_to_str(name_buf, pdp->apn_req.v, pdp->apn_req.l);
448
449 LOGPPDP(LOGL_DEBUG, pdp, "Processing create PDP context request for APN '%s'\n", name_buf);
450
451 /* First find an exact APN name match */
452 apn = ggsn_find_apn(ggsn, name_buf);
453 /* then try default (if any) */
454 if (!apn)
455 apn = ggsn->cfg.default_apn;
456 if (!apn) {
457 /* no APN found for what user requested */
458 LOGPPDP(LOGL_NOTICE, pdp, "Unknown APN '%s', rejecting\n", name_buf);
459 gtp_create_context_resp(gsn, pdp, GTPCAUSE_MISSING_APN);
460 return 0;
461 }
jjako52c24142002-12-16 13:33:51 +0000462
Harald Welted9d88622017-08-04 00:22:35 +0200463 /* FIXME: we manually force all context requests to dynamic here! */
464 if (pdp->eua.l > 2)
465 pdp->eua.l = 2;
jjako52c24142002-12-16 13:33:51 +0000466
Harald Weltebed35df2011-11-02 13:06:18 +0100467 memcpy(pdp->qos_neg0, pdp->qos_req0, sizeof(pdp->qos_req0));
jjako52c24142002-12-16 13:33:51 +0000468
Harald Weltebed35df2011-11-02 13:06:18 +0100469 memcpy(pdp->qos_neg.v, pdp->qos_req.v, pdp->qos_req.l); /* TODO */
470 pdp->qos_neg.l = pdp->qos_req.l;
jjako52c24142002-12-16 13:33:51 +0000471
Harald Weltea0d281d2017-08-02 21:48:16 +0200472 if (in46a_from_eua(&pdp->eua, &addr)) {
Harald Weltedda21ed2017-08-12 15:07:02 +0200473 LOGPPDP(LOGL_ERROR, pdp, "Cannot decode EUA from MS/SGSN: %s\n",
Harald Welted1bf1e12017-08-03 00:00:23 +0200474 osmo_hexdump(pdp->eua.v, pdp->eua.l));
475 gtp_create_context_resp(gsn, pdp, GTPCAUSE_UNKNOWN_PDP);
476 return 0;
Harald Weltebed35df2011-11-02 13:06:18 +0100477 }
jjakoa7cd2492003-04-11 09:40:12 +0000478
Harald Weltedda21ed2017-08-12 15:07:02 +0200479 if (addr.len == sizeof(struct in_addr)) {
480 rc = ippool_newip(apn->v4.pool, &member, &addr, 0);
481 if (rc < 0)
482 goto err_pool_full;
483 in46a_to_eua(&member->addr, &pdp->eua);
jjakoa7cd2492003-04-11 09:40:12 +0000484
Harald Weltedda21ed2017-08-12 15:07:02 +0200485 /* TODO: In IPv6, EUA doesn't contain the actual IP addr/prefix! */
486 if (gtp_kernel_tunnel_add(pdp) < 0) {
487 LOGPPDP(LOGL_ERROR, pdp, "Cannot add tunnel to kernel: %s\n", strerror(errno));
488 gtp_create_context_resp(gsn, pdp, GTPCAUSE_SYS_FAIL);
489 return 0;
490 }
491 } else if (addr.len == sizeof(struct in6_addr)) {
Harald Welted46bcd22017-08-08 23:27:22 +0200492 struct in46_addr tmp;
Harald Weltedda21ed2017-08-12 15:07:02 +0200493 rc = ippool_newip(apn->v6.pool, &member, &addr, 0);
494 if (rc < 0)
495 goto err_pool_full;
496
Harald Welted46bcd22017-08-08 23:27:22 +0200497 /* IPv6 doesn't really send the real/allocated address at this point, but just
498 * the link-identifier which the MS shall use for router solicitation */
499 tmp.len = addr.len;
500 /* initialize upper 64 bits to prefix, they are discarded by MS anyway */
501 memcpy(tmp.v6.s6_addr, &member->addr.v6, 8);
502 /* use allocated 64bit prefix as lower 64bit, used as link id by MS */
503 memcpy(tmp.v6.s6_addr+8, &member->addr.v6, 8);
504 in46a_to_eua(&tmp, &pdp->eua);
505 } else
Harald Weltedda21ed2017-08-12 15:07:02 +0200506 OSMO_ASSERT(0);
jjako52c24142002-12-16 13:33:51 +0000507
Harald Weltedda21ed2017-08-12 15:07:02 +0200508 pdp->peer = member;
509 pdp->ipif = apn->tun.tun; /* TODO */
510 member->peer = pdp;
Max3142d8d2017-05-04 17:45:10 +0200511
512 if (!send_trap(gsn, pdp, member, "imsi-ass-ip")) { /* TRAP with IP assignment */
Max727417d2016-08-02 17:10:38 +0200513 gtp_create_context_resp(gsn, pdp, GTPCAUSE_NO_RESOURCES);
514 return 0;
515 }
Pablo Neira Ayuso4b075b62015-11-17 12:22:42 +0100516
Harald Weltedda21ed2017-08-12 15:07:02 +0200517 process_pco(apn, pdp);
Harald Welte1ae98772017-08-09 20:28:52 +0200518
Harald Welte93fed3b2017-09-24 11:43:17 +0800519 /* Transmit G-PDU sequence numbers (only) if configured in APN */
520 pdp->tx_gpdu_seq = apn->cfg.tx_gpdu_seq;
521
Harald Weltedda21ed2017-08-12 15:07:02 +0200522 LOGPPDP(LOGL_INFO, pdp, "Successful PDP Context Creation: APN=%s(%s), TEIC=%u, IP=%s\n",
523 name_buf, apn->cfg.name, pdp->teic_own, in46a_ntoa(&member->addr));
Harald Weltebed35df2011-11-02 13:06:18 +0100524 gtp_create_context_resp(gsn, pdp, GTPCAUSE_ACC_REQ);
525 return 0; /* Success */
Harald Weltedda21ed2017-08-12 15:07:02 +0200526
527err_pool_full:
528 LOGPPDP(LOGL_ERROR, pdp, "Cannot allocate IP address from pool (full!)\n");
529 gtp_create_context_resp(gsn, pdp, -rc);
530 return 0; /* Already in use, or no more available */
jjako52c24142002-12-16 13:33:51 +0000531}
532
Harald Weltedda21ed2017-08-12 15:07:02 +0200533/* Internet-originated IP packet, needs to be sent via GTP towards MS */
534static int cb_tun_ind(struct tun_t *tun, void *pack, unsigned len)
Harald Weltebed35df2011-11-02 13:06:18 +0100535{
Harald Weltedda21ed2017-08-12 15:07:02 +0200536 struct apn_ctx *apn = tun->priv;
Harald Weltebed35df2011-11-02 13:06:18 +0100537 struct ippoolm_t *ipm;
Harald Welted12eab92017-08-02 19:49:47 +0200538 struct in46_addr dst;
Harald Welte63ebccd2017-08-02 21:10:09 +0200539 struct iphdr *iph = (struct iphdr *)pack;
Harald Weltea0d281d2017-08-02 21:48:16 +0200540 struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
Harald Weltedda21ed2017-08-12 15:07:02 +0200541 struct ippool_t *pool;
jjakoc6762cf2004-04-28 14:52:58 +0000542
Harald Welte63ebccd2017-08-02 21:10:09 +0200543 if (iph->version == 4) {
Harald Welted12eab92017-08-02 19:49:47 +0200544 if (len < sizeof(*iph) || len < 4*iph->ihl)
545 return -1;
546 dst.len = 4;
Harald Welte63ebccd2017-08-02 21:10:09 +0200547 dst.v4.s_addr = iph->daddr;
Harald Weltedda21ed2017-08-12 15:07:02 +0200548 pool = apn->v4.pool;
Harald Weltea0d281d2017-08-02 21:48:16 +0200549 } else if (iph->version == 6) {
Harald Welted4d6e092017-08-08 18:10:43 +0200550 /* Due to the fact that 3GPP requires an allocation of a
551 * /64 prefix to each MS, we must instruct
552 * ippool_getip() below to match only the leading /64
553 * prefix, i.e. the first 8 bytes of the address */
554 dst.len = 8;
Harald Weltea0d281d2017-08-02 21:48:16 +0200555 dst.v6 = ip6h->ip6_dst;
Harald Weltedda21ed2017-08-12 15:07:02 +0200556 pool = apn->v6.pool;
Harald Welted12eab92017-08-02 19:49:47 +0200557 } else {
Harald Weltedda21ed2017-08-12 15:07:02 +0200558 LOGP(DTUN, LOGL_NOTICE, "non-IPv packet received from tun\n");
Harald Welted12eab92017-08-02 19:49:47 +0200559 return -1;
560 }
jjakoc6762cf2004-04-28 14:52:58 +0000561
Harald Weltedda21ed2017-08-12 15:07:02 +0200562 /* IPv6 packet but no IPv6 pool, or IPv4 packet with no IPv4 pool */
563 if (!pool)
564 return 0;
Harald Weltebed35df2011-11-02 13:06:18 +0100565
Harald Weltedda21ed2017-08-12 15:07:02 +0200566 DEBUGP(DTUN, "Received packet from tun!\n");
567
568 if (ippool_getip(pool, &ipm, &dst)) {
569 DEBUGP(DTUN, "Received packet with no PDP contex!!\n");
Harald Weltebed35df2011-11-02 13:06:18 +0100570 return 0;
571 }
572
573 if (ipm->peer) /* Check if a peer protocol is defined */
Harald Weltedda21ed2017-08-12 15:07:02 +0200574 gtp_data_req(apn->ggsn->gsn, (struct pdp_t *)ipm->peer, pack, len);
Harald Weltebed35df2011-11-02 13:06:18 +0100575 return 0;
jjako52c24142002-12-16 13:33:51 +0000576}
577
Harald Welted46bcd22017-08-08 23:27:22 +0200578/* RFC3307 link-local scope multicast address */
579static const struct in6_addr all_router_mcast_addr = {
580 .s6_addr = { 0xff,0x02,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,2 }
581};
582
Harald Weltedda21ed2017-08-12 15:07:02 +0200583/* MS-originated GTP1-U packet, needs to be sent via TUN device */
584static int encaps_tun(struct pdp_t *pdp, void *pack, unsigned len)
Harald Weltebed35df2011-11-02 13:06:18 +0100585{
Harald Welted46bcd22017-08-08 23:27:22 +0200586 struct iphdr *iph = (struct iphdr *)pack;
587 struct ip6_hdr *ip6h = (struct ip6_hdr *)pack;
Harald Weltef85fe972017-09-24 20:00:34 +0800588 struct tun_t *tun = (struct tun_t *)pdp->ipif;
589 struct apn_ctx *apn = tun->priv;
590
591 OSMO_ASSERT(tun);
592 OSMO_ASSERT(apn);
Harald Welted46bcd22017-08-08 23:27:22 +0200593
Harald Weltedda21ed2017-08-12 15:07:02 +0200594 LOGPPDP(LOGL_DEBUG, pdp, "Packet received: forwarding to tun\n");
Harald Welted46bcd22017-08-08 23:27:22 +0200595
596 switch (iph->version) {
597 case 6:
598 /* daddr: all-routers multicast addr */
599 if (IN6_ARE_ADDR_EQUAL(&ip6h->ip6_dst, &all_router_mcast_addr))
Harald Weltef85fe972017-09-24 20:00:34 +0800600 return handle_router_mcast(pdp->gsn, pdp, &apn->v6_lladdr, pack, len);
Harald Welted46bcd22017-08-08 23:27:22 +0200601 break;
602 case 4:
603 break;
604 default:
Harald Weltedda21ed2017-08-12 15:07:02 +0200605 LOGPPDP(LOGL_ERROR, pdp, "Packet from MS is neither IPv4 nor IPv6: %s\n",
606 osmo_hexdump(pack, len));
Harald Welted46bcd22017-08-08 23:27:22 +0200607 return -1;
608 }
Harald Weltebed35df2011-11-02 13:06:18 +0100609 return tun_encaps((struct tun_t *)pdp->ipif, pack, len);
jjako52c24142002-12-16 13:33:51 +0000610}
611
Harald Welte632e8432017-09-05 18:12:14 +0200612static char *config_file = "osmo-ggsn.cfg";
Harald Weltedda21ed2017-08-12 15:07:02 +0200613
614/* callback for tun device osmocom select loop integration */
615static int ggsn_tun_fd_cb(struct osmo_fd *fd, unsigned int what)
616{
617 struct apn_ctx *apn = fd->data;
618
619 OSMO_ASSERT(what & BSC_FD_READ);
620
621 return tun_decaps(apn->tun.tun);
622}
623
624/* callback for libgtp osmocom select loop integration */
625static int ggsn_gtp_fd_cb(struct osmo_fd *fd, unsigned int what)
626{
627 struct ggsn_ctx *ggsn = fd->data;
628 int rc;
629
630 OSMO_ASSERT(what & BSC_FD_READ);
631
632 switch (fd->priv_nr) {
633 case 0:
634 rc = gtp_decaps0(ggsn->gsn);
635 break;
636 case 1:
637 rc = gtp_decaps1c(ggsn->gsn);
638 break;
639 case 2:
640 rc = gtp_decaps1u(ggsn->gsn);
641 break;
642 default:
643 OSMO_ASSERT(0);
644 break;
645 }
646 return rc;
647}
648
649static void ggsn_gtp_tmr_start(struct ggsn_ctx *ggsn)
650{
651 struct timeval next;
652
653 /* Retrieve next retransmission as timeval */
654 gtp_retranstimeout(ggsn->gsn, &next);
655
656 /* re-schedule the timer */
657 osmo_timer_schedule(&ggsn->gtp_timer, next.tv_sec, next.tv_usec/1000);
658}
659
660/* timer callback for libgtp retransmission and ping */
661static void ggsn_gtp_tmr_cb(void *data)
662{
663 struct ggsn_ctx *ggsn = data;
664
665 /* do all the retransmissions as needed */
666 gtp_retrans(ggsn->gsn);
667
668 ggsn_gtp_tmr_start(ggsn);
669}
670
671/* To exit gracefully. Used with GCC compilation flag -pg and gprof */
672static void signal_handler(int s)
673{
674 LOGP(DGGSN, LOGL_NOTICE, "signal %d received\n", s);
675 switch (s) {
676 case SIGINT:
Harald Weltee8049472017-08-20 12:44:21 +0200677 case SIGTERM:
Harald Weltedda21ed2017-08-12 15:07:02 +0200678 LOGP(DGGSN, LOGL_NOTICE, "SIGINT received, shutting down\n");
679 end = 1;
680 break;
681 case SIGABRT:
682 case SIGUSR1:
683 talloc_report(tall_vty_ctx, stderr);
684 talloc_report_full(tall_ggsn_ctx, stderr);
685 break;
686 case SIGUSR2:
687 talloc_report_full(tall_vty_ctx, stderr);
688 break;
689 default:
690 break;
691 }
692}
693
694
695/* Start a given GGSN */
696int ggsn_start(struct ggsn_ctx *ggsn)
697{
698 struct apn_ctx *apn;
699 int rc;
700
701 if (ggsn->started)
702 return 0;
703
704 LOGPGGSN(LOGL_INFO, ggsn, "Starting GGSN\n");
705
706 /* Start libgtp listener */
707 if (gtp_new(&ggsn->gsn, ggsn->cfg.state_dir, &ggsn->cfg.listen_addr.v4, GTP_MODE_GGSN)) {
708 LOGPGGSN(LOGL_ERROR, ggsn, "Failed to create GTP: %s\n", strerror(errno));
709 return -1;
710 }
711 ggsn->gsn->priv = ggsn;
712
Harald Welte98146772017-09-05 17:41:20 +0200713 /* patch in different addresses to use (in case we're behind NAT, the listen
714 * address is different from what we advertise externally) */
715 if (ggsn->cfg.gtpc_addr.v4.s_addr)
716 ggsn->gsn->gsnc = ggsn->cfg.gtpc_addr.v4;
717
718 if (ggsn->cfg.gtpu_addr.v4.s_addr)
719 ggsn->gsn->gsnu = ggsn->cfg.gtpu_addr.v4;
720
Harald Weltedda21ed2017-08-12 15:07:02 +0200721 /* Register File Descriptors */
722 osmo_fd_setup(&ggsn->gtp_fd0, ggsn->gsn->fd0, BSC_FD_READ, ggsn_gtp_fd_cb, ggsn, 0);
723 rc = osmo_fd_register(&ggsn->gtp_fd0);
724 OSMO_ASSERT(rc == 0);
725
726 osmo_fd_setup(&ggsn->gtp_fd1c, ggsn->gsn->fd1c, BSC_FD_READ, ggsn_gtp_fd_cb, ggsn, 1);
727 rc = osmo_fd_register(&ggsn->gtp_fd1c);
728 OSMO_ASSERT(rc == 0);
729
730 osmo_fd_setup(&ggsn->gtp_fd1u, ggsn->gsn->fd1u, BSC_FD_READ, ggsn_gtp_fd_cb, ggsn, 2);
731 rc = osmo_fd_register(&ggsn->gtp_fd1u);
732 OSMO_ASSERT(rc == 0);
733
734 /* Start GTP re-transmission timer */
735 osmo_timer_setup(&ggsn->gtp_timer, ggsn_gtp_tmr_cb, ggsn);
736
737 gtp_set_cb_data_ind(ggsn->gsn, encaps_tun);
738 gtp_set_cb_delete_context(ggsn->gsn, delete_context);
739 gtp_set_cb_create_context_ind(ggsn->gsn, create_context_ind);
740
741 LOGPGGSN(LOGL_NOTICE, ggsn, "Successfully started\n");
742 ggsn->started = true;
743
744 llist_for_each_entry(apn, &ggsn->apn_list, list)
745 apn_start(apn);
746
747 return 0;
748}
749
750/* Stop a given GGSN */
751int ggsn_stop(struct ggsn_ctx *ggsn)
752{
753 struct apn_ctx *apn;
754
755 if (!ggsn->started)
756 return 0;
757
758 /* iterate over all APNs and stop them */
759 llist_for_each_entry(apn, &ggsn->apn_list, list)
760 apn_stop(apn, true);
761
762 osmo_timer_del(&ggsn->gtp_timer);
763
764 osmo_fd_unregister(&ggsn->gtp_fd1u);
765 osmo_fd_unregister(&ggsn->gtp_fd1c);
766 osmo_fd_unregister(&ggsn->gtp_fd0);
767
768 if (ggsn->gsn) {
769 gtp_free(ggsn->gsn);
770 ggsn->gsn = NULL;
771 }
772
773 ggsn->started = false;
774 return 0;
775}
776
777static void print_usage()
778{
779 printf("Usage: osmo-ggsn [-h] [-D] [-c configfile] [-V]\n");
780}
781
782static void print_help()
783{
784 printf( " Some useful help...\n"
785 " -h --help This help text\n"
786 " -D --daemonize Fork the process into a background daemon\n"
787 " -c --config-file filename The config file to use\n"
788 " -V --version Print the version of OsmoGGSN\n"
789 );
790}
791
792static void handle_options(int argc, char **argv)
793{
794 while (1) {
795 int option_index = 0, c;
796 static struct option long_options[] = {
797 { "help", 0, 0, 'h' },
798 { "daemonize", 0, 0, 'D' },
799 { "config-file", 1, 0, 'c' },
800 { "version", 0, 0, 'V' },
801 { 0, 0, 0, 0 }
802 };
803
804 c = getopt_long(argc, argv, "hdc:V", long_options, &option_index);
805 if (c == -1)
806 break;
807
808 switch (c) {
809 case 'h':
810 print_usage();
811 print_help();
812 exit(0);
813 case 'D':
814 daemonize = 1;
815 break;
816 case 'c':
817 config_file = optarg;
818 break;
819 case 'V':
820 print_version(1);
821 exit(0);
822 break;
823 }
824 }
825}
826
jjako52c24142002-12-16 13:33:51 +0000827int main(int argc, char **argv)
828{
Harald Weltedda21ed2017-08-12 15:07:02 +0200829 struct ggsn_ctx *ggsn;
830 int rc;
jjako52c24142002-12-16 13:33:51 +0000831
Harald Welte632e8432017-09-05 18:12:14 +0200832 tall_ggsn_ctx = talloc_named_const(NULL, 0, "OsmoGGSN");
Harald Weltedda21ed2017-08-12 15:07:02 +0200833 msgb_talloc_ctx_init(tall_ggsn_ctx, 0);
jjako52c24142002-12-16 13:33:51 +0000834
Harald Weltee8049472017-08-20 12:44:21 +0200835 /* Handle keyboard interrupt SIGINT */
Harald Weltedda21ed2017-08-12 15:07:02 +0200836 signal(SIGINT, &signal_handler);
Harald Weltee8049472017-08-20 12:44:21 +0200837 signal(SIGTERM, &signal_handler);
Harald Weltedda21ed2017-08-12 15:07:02 +0200838 signal(SIGABRT, &signal_handler);
839 signal(SIGUSR1, &signal_handler);
840 signal(SIGUSR2, &signal_handler);
jjako52c24142002-12-16 13:33:51 +0000841
Harald Weltedda21ed2017-08-12 15:07:02 +0200842 osmo_init_ignore_signals();
Holger Hans Peter Freyther9c7fd8e2014-12-04 16:32:37 +0100843 osmo_init_logging(&log_info);
Harald Weltedda21ed2017-08-12 15:07:02 +0200844 osmo_stats_init(tall_ggsn_ctx);
jjako0141d202004-01-09 15:19:20 +0000845
Harald Weltedda21ed2017-08-12 15:07:02 +0200846 vty_init(&g_vty_info);
847 logging_vty_add_cmds(NULL);
848 osmo_stats_vty_add_cmds(&log_info);
849 ggsn_vty_init();
850 ctrl_vty_init(tall_ggsn_ctx);
851
852 handle_options(argc, argv);
853
854 rate_ctr_init(tall_ggsn_ctx);
855
856 rc = vty_read_config_file(config_file, NULL);
857 if (rc < 0) {
858 fprintf(stderr, "Failed to open config file: '%s'\n", config_file);
859 exit(2);
Harald Weltebed35df2011-11-02 13:06:18 +0100860 }
jjako52c24142002-12-16 13:33:51 +0000861
Harald Weltedda21ed2017-08-12 15:07:02 +0200862 rc = telnet_init_dynif(tall_ggsn_ctx, NULL, vty_get_bind_addr(), OSMO_VTY_PORT_GGSN);
863 if (rc < 0)
Harald Weltebed35df2011-11-02 13:06:18 +0100864 exit(1);
Holger Hans Peter Freyther9c0ff4f2014-03-23 10:07:26 +0100865
Harald Weltedda21ed2017-08-12 15:07:02 +0200866 g_ctrlh = ctrl_interface_setup(NULL, OSMO_CTRL_PORT_GGSN, NULL);
867 if (!g_ctrlh) {
868 LOGP(DGGSN, LOGL_ERROR, "Failed to create CTRL interface.\n");
Harald Weltebed35df2011-11-02 13:06:18 +0100869 exit(1);
870 }
jjako88c22162003-07-06 19:33:18 +0000871
Harald Weltedda21ed2017-08-12 15:07:02 +0200872 if (daemonize) {
873 rc = osmo_daemonize();
874 if (rc < 0) {
875 perror("Error during daemonize");
Harald Weltebed35df2011-11-02 13:06:18 +0100876 exit(1);
877 }
878 }
jjako1d3db972004-01-16 09:56:56 +0000879
Harald Weltedda21ed2017-08-12 15:07:02 +0200880#if 0
Harald Weltebed35df2011-11-02 13:06:18 +0100881 /* qos */
882 qos.l = 3;
883 qos.v[2] = (args_info.qos_arg) & 0xff;
884 qos.v[1] = ((args_info.qos_arg) >> 8) & 0xff;
885 qos.v[0] = ((args_info.qos_arg) >> 16) & 0xff;
Harald Weltedda21ed2017-08-12 15:07:02 +0200886#endif
jjakoa7cd2492003-04-11 09:40:12 +0000887
Harald Weltedda21ed2017-08-12 15:07:02 +0200888 /* Main select loop */
889 while (!end) {
890 osmo_select_main(0);
Harald Weltebed35df2011-11-02 13:06:18 +0100891 }
jjakoe0149782003-07-06 17:07:04 +0000892
Harald Weltedda21ed2017-08-12 15:07:02 +0200893 llist_for_each_entry(ggsn, &g_ggsn_list, list)
894 ggsn_stop(ggsn);
Harald Weltebed35df2011-11-02 13:06:18 +0100895
896 return 1;
jjako52c24142002-12-16 13:33:51 +0000897}