blob: 42f8e1c35a5d292c74a7ff8f3e668d7fd07cbec1 [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;
66 } cfg;
67
68 /* corresponding tun device */
69 struct {
70 struct {
71 /* name of the network device */
72 char *dev_name;
73 /* ip-up and ip-down script names/paths */
74 char *ipup_script;
75 char *ipdown_script;
76 } cfg;
77 struct tun_t *tun;
78 struct osmo_fd fd;
79 } tun;
80
Harald Weltef85fe972017-09-24 20:00:34 +080081 /* ipv6 link-local address */
82 struct in6_addr v6_lladdr;
83
Harald Weltedda21ed2017-08-12 15:07:02 +020084 struct apn_ctx_ip v4;
85 struct apn_ctx_ip v6;
86};
87
88struct ggsn_ctx {
89 /* global list of GGSNs */
90 struct llist_head list;
91
92 /* list of APNs in this GGSN */
93 struct llist_head apn_list;
94
95 bool started;
96
97 struct {
98 char *name;
99 /* Description string */
100 char *description;
101 /* an APN that shall be used as default for any non-matching APN */
102 struct apn_ctx *default_apn;
103 /* ADdress to which we listen for GTP */
104 struct in46_addr listen_addr;
Harald Welte98146772017-09-05 17:41:20 +0200105 /* Local GTP-C address advertised in GTP */
106 struct in46_addr gtpc_addr;
107 /* Local GTP-U address advertised in GTP */
108 struct in46_addr gtpu_addr;
Harald Weltedda21ed2017-08-12 15:07:02 +0200109 /* directory for state file */
110 char *state_dir;
111 /* administratively shut-down (true) or not (false) */
112 bool shutdown;
113 } cfg;
114
115 /* The libgtp (G)GSN instance, i.e. what listens to GTP */
116 struct gsn_t *gsn;
117
118 /* osmo-fd for gsn */
119 struct osmo_fd gtp_fd0;
120 struct osmo_fd gtp_fd1c;
121 struct osmo_fd gtp_fd1u;
122
123 struct osmo_timer_list gtp_timer;
124};
125
126/* ggsn_vty.c */
127extern struct llist_head g_ggsn_list;
128extern struct vty_app_info g_vty_info;
129extern int ggsn_vty_init(void);
130struct ggsn_ctx *ggsn_find(const char *name);
131struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name);
132struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name);
133struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name);
134
135/* ggsn.c */
136extern void *tall_ggsn_ctx;
137extern int ggsn_start(struct ggsn_ctx *ggsn);
138extern int ggsn_stop(struct ggsn_ctx *ggsn);
139extern int apn_start(struct apn_ctx *apn);
140extern int apn_stop(struct apn_ctx *apn, bool force);