blob: bab6cf7479657667cbf218ce8cb55b391a4ea3e8 [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
81 struct apn_ctx_ip v4;
82 struct apn_ctx_ip v6;
83};
84
85struct ggsn_ctx {
86 /* global list of GGSNs */
87 struct llist_head list;
88
89 /* list of APNs in this GGSN */
90 struct llist_head apn_list;
91
92 bool started;
93
94 struct {
95 char *name;
96 /* Description string */
97 char *description;
98 /* an APN that shall be used as default for any non-matching APN */
99 struct apn_ctx *default_apn;
100 /* ADdress to which we listen for GTP */
101 struct in46_addr listen_addr;
102 /* directory for state file */
103 char *state_dir;
104 /* administratively shut-down (true) or not (false) */
105 bool shutdown;
106 } cfg;
107
108 /* The libgtp (G)GSN instance, i.e. what listens to GTP */
109 struct gsn_t *gsn;
110
111 /* osmo-fd for gsn */
112 struct osmo_fd gtp_fd0;
113 struct osmo_fd gtp_fd1c;
114 struct osmo_fd gtp_fd1u;
115
116 struct osmo_timer_list gtp_timer;
117};
118
119/* ggsn_vty.c */
120extern struct llist_head g_ggsn_list;
121extern struct vty_app_info g_vty_info;
122extern int ggsn_vty_init(void);
123struct ggsn_ctx *ggsn_find(const char *name);
124struct ggsn_ctx *ggsn_find_or_create(void *ctx, const char *name);
125struct apn_ctx *ggsn_find_apn(struct ggsn_ctx *ggsn, const char *name);
126struct apn_ctx *ggsn_find_or_create_apn(struct ggsn_ctx *ggsn, const char *name);
127
128/* ggsn.c */
129extern void *tall_ggsn_ctx;
130extern int ggsn_start(struct ggsn_ctx *ggsn);
131extern int ggsn_stop(struct ggsn_ctx *ggsn);
132extern int apn_start(struct apn_ctx *apn);
133extern int apn_stop(struct apn_ctx *apn, bool force);