blob: 51f4ec1c66b2efd1e58416a26143132c5889ee54 [file] [log] [blame]
Harald Weltedda21ed2017-08-12 15:07:02 +02001#pragma once
2
3#include <stdint.h>
4#include <stdbool.h>
5#include <osmocom/core/utils.h>
6#include <osmocom/core/linuxlist.h>
7#include <osmocom/core/select.h>
8#include <osmocom/core/timer.h>
Pau Espin Pedrol421f22e2019-08-20 12:52:13 +02009#include <osmocom/ctrl/control_if.h>
Harald Weltedda21ed2017-08-12 15:07:02 +020010
11#include "../lib/tun.h"
12#include "../lib/ippool.h"
13#include "../lib/syserr.h"
14#include "../lib/in46_addr.h"
15#include "../gtp/gtp.h"
16
Pau Espin Pedrolf5fbb412019-08-21 18:49:44 +020017#include "sgsn.h"
18
Harald Weltedda21ed2017-08-12 15:07:02 +020019#define APN_TYPE_IPv4 0x01 /* v4-only */
20#define APN_TYPE_IPv6 0x02 /* v6-only */
21#define APN_TYPE_IPv4v6 0x04 /* v4v6 dual-stack */
22
23struct ggsn_ctx;
24
25struct apn_ctx_ip {
26 struct {
27 struct in46_prefix ifconfig_prefix;
Pau Espin Pedrol37c45e32017-12-14 14:09:13 +010028 struct in46_prefix ll_prefix;
Harald Weltedda21ed2017-08-12 15:07:02 +020029 struct in46_prefix static_prefix;
30 struct in46_prefix dynamic_prefix;
31 /* v4 DNS server names */
32 struct in46_addr dns[2];
33 } cfg;
34
35 /* v4 address pool */
36 struct ippool_t *pool;
37};
38
39struct apn_name {
40 struct llist_head list;
41 char *name;
42};
43
44enum apn_gtpu_mode {
45 APN_GTPU_MODE_TUN = 0, /* default */
46 APN_GTPU_MODE_KERNEL_GTP,
47};
48
49struct apn_ctx {
50 /* list of APNs inside GGSN */
51 struct llist_head list;
52 /* back-pointer to GGSN */
53 struct ggsn_ctx *ggsn;
54
55 bool started;
56
57 struct {
58 /* Primary name */
59 char *name;
60 /* Description string */
61 char *description;
62 /* List of secondary APN names */
63 struct llist_head name_list;
64 /* types supported address types on this APN */
65 uint32_t apn_type_mask;
66 /* GTP-U via TUN device or in Linux kernel */
67 enum apn_gtpu_mode gtpu_mode;
68 /* administratively shut-down (true) or not (false) */
69 bool shutdown;
Harald Welte93fed3b2017-09-24 11:43:17 +080070 /* transmit G-PDU sequeence numbers (true) or not (false) */
71 bool tx_gpdu_seq;
Harald Weltedda21ed2017-08-12 15:07:02 +020072 } cfg;
73
74 /* corresponding tun device */
75 struct {
76 struct {
77 /* name of the network device */
78 char *dev_name;
79 /* ip-up and ip-down script names/paths */
80 char *ipup_script;
81 char *ipdown_script;
82 } cfg;
83 struct tun_t *tun;
84 struct osmo_fd fd;
85 } tun;
86
Harald Weltef85fe972017-09-24 20:00:34 +080087 /* ipv6 link-local address */
88 struct in6_addr v6_lladdr;
89
Harald Weltedda21ed2017-08-12 15:07:02 +020090 struct apn_ctx_ip v4;
91 struct apn_ctx_ip v6;
92};
93
Pau Espin Pedrolf5fbb412019-08-21 18:49:44 +020094struct pdp_priv_t {
95 struct pdp_t *lib; /* pointer to libgtp associated pdp_t instance */
96 struct sgsn_peer *sgsn;
97 struct apn_ctx *apn;
98 struct llist_head entry; /* to be included into sgsn_peer */
99 /* struct ggsn_ctx can be reached through lib->gsn->priv, or through sgsn->ggsn */
100};
101
Harald Weltedda21ed2017-08-12 15:07:02 +0200102struct ggsn_ctx {
103 /* global list of GGSNs */
104 struct llist_head list;
105
106 /* list of APNs in this GGSN */
107 struct llist_head apn_list;
108
Pau Espin Pedrolf5fbb412019-08-21 18:49:44 +0200109 /* list of SGSN peers (struct sgsn_peer) in this GGSN. TODO: hash table with key <ip+port>? */
110 struct llist_head sgsn_list;
111
Harald Weltedda21ed2017-08-12 15:07:02 +0200112 bool started;
113
114 struct {
115 char *name;
116 /* Description string */
117 char *description;
Keitha6a8cc12020-04-25 05:39:21 +0200118 /* APNs that shall be used as default for any non-matching APN */
119 struct apn_ctx *default_apn_v4;
120 struct apn_ctx *default_apn_v6;
121 struct apn_ctx *default_apn_v4v6;
Harald Weltedda21ed2017-08-12 15:07:02 +0200122 /* ADdress to which we listen for GTP */
123 struct in46_addr listen_addr;
Harald Welte98146772017-09-05 17:41:20 +0200124 /* Local GTP-C address advertised in GTP */
125 struct in46_addr gtpc_addr;
126 /* Local GTP-U address advertised in GTP */
127 struct in46_addr gtpu_addr;
Harald Weltedda21ed2017-08-12 15:07:02 +0200128 /* directory for state file */
129 char *state_dir;
Pau Espin Pedrolf5fbb412019-08-21 18:49:44 +0200130 /* Time between Echo requests on each SGSN */
131 unsigned int echo_interval;
Harald Weltedda21ed2017-08-12 15:07:02 +0200132 /* administratively shut-down (true) or not (false) */
133 bool shutdown;
134 } cfg;
135
136 /* The libgtp (G)GSN instance, i.e. what listens to GTP */
137 struct gsn_t *gsn;
138
139 /* osmo-fd for gsn */
140 struct osmo_fd gtp_fd0;
141 struct osmo_fd gtp_fd1c;
142 struct osmo_fd gtp_fd1u;
Harald Weltedda21ed2017-08-12 15:07:02 +0200143};
144
145/* ggsn_vty.c */
146extern struct llist_head g_ggsn_list;
147extern struct vty_app_info g_vty_info;
148extern int ggsn_vty_init(void);
149struct ggsn_ctx *ggsn_find(const char *name);
150struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name);
151struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name);
152struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name);
153
Pau Espin Pedrol421f22e2019-08-20 12:52:13 +0200154/* ggsn_main.c */
155extern struct ctrl_handle *g_ctrlh;
Harald Weltedda21ed2017-08-12 15:07:02 +0200156extern void *tall_ggsn_ctx;
Pau Espin Pedrol421f22e2019-08-20 12:52:13 +0200157
158/* ggsn.c */
Harald Weltedda21ed2017-08-12 15:07:02 +0200159extern int ggsn_start(struct ggsn_ctx *ggsn);
160extern int ggsn_stop(struct ggsn_ctx *ggsn);
161extern int apn_start(struct apn_ctx *apn);
Pau Espin Pedrol72ab4bc2019-05-29 19:08:26 +0200162extern int apn_stop(struct apn_ctx *apn);
Pau Espin Pedrolf5fbb412019-08-21 18:49:44 +0200163void ggsn_close_one_pdp(struct pdp_t *pdp);
Pau Espin Pedrolf7884e82019-08-20 12:06:13 +0200164
165#define LOGPAPN(level, apn, fmt, args...) \
166 LOGP(DGGSN, level, "APN(%s): " fmt, (apn)->cfg.name, ## args)
167
168#define LOGPGGSN(level, ggsn, fmt, args...) \
169 LOGP(DGGSN, level, "GGSN(%s): " fmt, (ggsn)->cfg.name, ## args)
170
171#define LOGPPDP(level, pdp, fmt, args...) LOGPDPX(DGGSN, level, pdp, fmt, ## args)
Pau Espin Pedrol012d51e2019-08-20 13:43:38 +0200172
173#define LOGTUN(level, tun, fmt, args...) \
174 LOGP(DTUN, level, "TUN(%s): " fmt, (tun)->devname, ## args)