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