blob: c0774c4c393fbcb02ee15cfbb9457bbd279ce2d8 [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>
9
10#include "../lib/tun.h"
11#include "../lib/ippool.h"
12#include "../lib/syserr.h"
13#include "../lib/in46_addr.h"
14#include "../gtp/gtp.h"
15
16#define APN_TYPE_IPv4 0x01 /* v4-only */
17#define APN_TYPE_IPv6 0x02 /* v6-only */
18#define APN_TYPE_IPv4v6 0x04 /* v4v6 dual-stack */
19
20struct ggsn_ctx;
21
22struct apn_ctx_ip {
23 struct {
24 struct in46_prefix ifconfig_prefix;
25 struct in46_prefix static_prefix;
26 struct in46_prefix dynamic_prefix;
27 /* v4 DNS server names */
28 struct in46_addr dns[2];
29 } cfg;
30
31 /* v4 address pool */
32 struct ippool_t *pool;
33};
34
35struct apn_name {
36 struct llist_head list;
37 char *name;
38};
39
40enum apn_gtpu_mode {
41 APN_GTPU_MODE_TUN = 0, /* default */
42 APN_GTPU_MODE_KERNEL_GTP,
43};
44
45struct apn_ctx {
46 /* list of APNs inside GGSN */
47 struct llist_head list;
48 /* back-pointer to GGSN */
49 struct ggsn_ctx *ggsn;
50
51 bool started;
52
53 struct {
54 /* Primary name */
55 char *name;
56 /* Description string */
57 char *description;
58 /* List of secondary APN names */
59 struct llist_head name_list;
60 /* types supported address types on this APN */
61 uint32_t apn_type_mask;
62 /* GTP-U via TUN device or in Linux kernel */
63 enum apn_gtpu_mode gtpu_mode;
64 /* administratively shut-down (true) or not (false) */
65 bool shutdown;
Harald Welte93fed3b2017-09-24 11:43:17 +080066 /* transmit G-PDU sequeence numbers (true) or not (false) */
67 bool tx_gpdu_seq;
Harald Weltedda21ed2017-08-12 15:07:02 +020068 } cfg;
69
70 /* corresponding tun device */
71 struct {
72 struct {
73 /* name of the network device */
74 char *dev_name;
75 /* ip-up and ip-down script names/paths */
76 char *ipup_script;
77 char *ipdown_script;
78 } cfg;
79 struct tun_t *tun;
80 struct osmo_fd fd;
81 } tun;
82
Harald Weltef85fe972017-09-24 20:00:34 +080083 /* ipv6 link-local address */
84 struct in6_addr v6_lladdr;
85
Harald Weltedda21ed2017-08-12 15:07:02 +020086 struct apn_ctx_ip v4;
87 struct apn_ctx_ip v6;
88};
89
90struct ggsn_ctx {
91 /* global list of GGSNs */
92 struct llist_head list;
93
94 /* list of APNs in this GGSN */
95 struct llist_head apn_list;
96
97 bool started;
98
99 struct {
100 char *name;
101 /* Description string */
102 char *description;
103 /* an APN that shall be used as default for any non-matching APN */
104 struct apn_ctx *default_apn;
105 /* ADdress to which we listen for GTP */
106 struct in46_addr listen_addr;
Harald Welte98146772017-09-05 17:41:20 +0200107 /* Local GTP-C address advertised in GTP */
108 struct in46_addr gtpc_addr;
109 /* Local GTP-U address advertised in GTP */
110 struct in46_addr gtpu_addr;
Harald Weltedda21ed2017-08-12 15:07:02 +0200111 /* directory for state file */
112 char *state_dir;
113 /* administratively shut-down (true) or not (false) */
114 bool shutdown;
115 } cfg;
116
117 /* The libgtp (G)GSN instance, i.e. what listens to GTP */
118 struct gsn_t *gsn;
119
120 /* osmo-fd for gsn */
121 struct osmo_fd gtp_fd0;
122 struct osmo_fd gtp_fd1c;
123 struct osmo_fd gtp_fd1u;
124
125 struct osmo_timer_list gtp_timer;
126};
127
128/* ggsn_vty.c */
129extern struct llist_head g_ggsn_list;
130extern struct vty_app_info g_vty_info;
131extern int ggsn_vty_init(void);
132struct ggsn_ctx *ggsn_find(const char *name);
133struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name);
134struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name);
135struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name);
136
137/* ggsn.c */
138extern void *tall_ggsn_ctx;
139extern int ggsn_start(struct ggsn_ctx *ggsn);
140extern int ggsn_stop(struct ggsn_ctx *ggsn);
141extern int apn_start(struct apn_ctx *apn);
142extern int apn_stop(struct apn_ctx *apn, bool force);