Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 1 | #ifndef _GB_PROXY_H |
| 2 | #define _GB_PROXY_H |
| 3 | |
| 4 | |
| 5 | #include <osmocom/core/msgb.h> |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 6 | #include <osmocom/core/timer.h> |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 7 | #include <osmocom/core/hashtable.h> |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 8 | #include <osmocom/gsm/gsm23003.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 9 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 10 | #include <osmocom/gprs/gprs_ns2.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 11 | #include <osmocom/vty/command.h> |
| 12 | |
| 13 | #include <sys/types.h> |
| 14 | #include <regex.h> |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 15 | #include <stdbool.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 16 | |
| 17 | #define GBPROXY_INIT_VU_GEN_TX 256 |
| 18 | |
Daniel Willmann | 8f407b1 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 19 | /* BVCI uses 16 bits */ |
| 20 | #define BVC_LOG_CTX_FLAG (1<<17) |
| 21 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 22 | struct rate_ctr_group; |
| 23 | struct gprs_gb_parse_context; |
| 24 | struct tlv_parsed; |
| 25 | |
| 26 | enum gbproxy_global_ctr { |
| 27 | GBPROX_GLOB_CTR_INV_BVCI, |
| 28 | GBPROX_GLOB_CTR_INV_LAI, |
| 29 | GBPROX_GLOB_CTR_INV_RAI, |
| 30 | GBPROX_GLOB_CTR_INV_NSEI, |
| 31 | GBPROX_GLOB_CTR_PROTO_ERR_BSS, |
| 32 | GBPROX_GLOB_CTR_PROTO_ERR_SGSN, |
| 33 | GBPROX_GLOB_CTR_NOT_SUPPORTED_BSS, |
| 34 | GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN, |
| 35 | GBPROX_GLOB_CTR_RESTART_RESET_SGSN, |
| 36 | GBPROX_GLOB_CTR_TX_ERR_SGSN, |
| 37 | GBPROX_GLOB_CTR_OTHER_ERR, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 38 | }; |
| 39 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 40 | enum gbproxy_bvc_ctr { |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 41 | GBPROX_PEER_CTR_BLOCKED, |
| 42 | GBPROX_PEER_CTR_UNBLOCKED, |
| 43 | GBPROX_PEER_CTR_DROPPED, |
| 44 | GBPROX_PEER_CTR_INV_NSEI, |
| 45 | GBPROX_PEER_CTR_TX_ERR, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 46 | GBPROX_PEER_CTR_LAST, |
| 47 | }; |
| 48 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 49 | /* global gb-proxy configuration */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 50 | struct gbproxy_config { |
| 51 | /* parsed from config file */ |
| 52 | uint16_t nsip_sgsn_nsei; |
| 53 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 54 | /* NS instance of libosmogb */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 55 | struct gprs_ns2_inst *nsi; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 56 | |
Harald Welte | 2b7b1bb | 2020-12-04 23:58:20 +0100 | [diff] [blame] | 57 | /* Linked list of all BSS side Gb peers */ |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 58 | DECLARE_HASHTABLE(bss_nses, 8); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 59 | |
| 60 | /* Counter */ |
| 61 | struct rate_ctr_group *ctrg; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 64 | /* One BVC inside an NSE */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 65 | struct gbproxy_bvc { |
| 66 | /* linked to gbproxy_nse.bvcs */ |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 67 | struct hlist_node list; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 68 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 69 | /* The NSE this BVC belongs to */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 70 | struct gbproxy_nse *nse; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 71 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 72 | /* PTP BVCI of this BVC */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 73 | uint16_t bvci; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 74 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 75 | /* Routing Area that this BVC is part of (raw 04.08 encoding) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 76 | uint8_t ra[6]; |
| 77 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 78 | /* true if this BVC is blocked */ |
| 79 | bool blocked; |
| 80 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 81 | /* Counter */ |
| 82 | struct rate_ctr_group *ctrg; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 85 | /* one NS Entity that we interact with (BSS/PCU) */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 86 | struct gbproxy_nse { |
Harald Welte | 2b7b1bb | 2020-12-04 23:58:20 +0100 | [diff] [blame] | 87 | /* linked to gbproxy_config.bss_nses */ |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 88 | struct hlist_node list; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 89 | |
| 90 | /* point back to the config */ |
| 91 | struct gbproxy_config *cfg; |
| 92 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 93 | /* NSEI of the NSE */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 94 | uint16_t nsei; |
| 95 | |
| 96 | /* List of all BVCs in this NSE */ |
Harald Welte | 8b4c794 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 97 | DECLARE_HASHTABLE(bvcs, 10); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 98 | }; |
| 99 | |
Daniel Willmann | 066c4cb | 2020-12-01 16:36:29 +0100 | [diff] [blame] | 100 | /* Convenience logging macros for NSE/BVC */ |
| 101 | #define LOGPNSE_CAT(NSE, SUBSYS, LEVEL, FMT, ARGS...) \ |
| 102 | LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS) " FMT, (NSE)->nsei, ## ARGS) |
| 103 | #define LOGPNSE(NSE, LEVEL, FMT, ARGS...) \ |
| 104 | LOGPNSE_CAT(NSE, DGPRS, LEVEL, FMT, ## ARGS) |
| 105 | |
| 106 | #define LOGPBVC_CAT(BVC, SUBSYS, LEVEL, FMT, ARGS...) \ |
| 107 | LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS)-BVC(%05u/%s) " FMT, (BVC)->nse->nsei, (BVC)->bvci, \ |
| 108 | (BVC)->blocked ? "BLOCKED" : "UNBLOCKED", ## ARGS) |
| 109 | #define LOGPBVC(BVC, LEVEL, FMT, ARGS...) \ |
| 110 | LOGPBVC_CAT(BVC, DGPRS, LEVEL, FMT, ## ARGS) |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 111 | |
| 112 | /* gb_proxy_vty .c */ |
| 113 | |
| 114 | int gbproxy_vty_init(void); |
| 115 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg); |
| 116 | |
Daniel Willmann | 13404b7 | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 117 | /* gb_proxy_ctrl.c */ |
| 118 | int gb_ctrl_cmds_install(void); |
| 119 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 120 | |
| 121 | /* gb_proxy.c */ |
| 122 | int gbproxy_init_config(struct gbproxy_config *cfg); |
| 123 | |
| 124 | /* Main input function for Gb proxy */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 125 | int gbprox_rcvmsg(void *ctx, struct msgb *msg); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 126 | |
| 127 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 128 | void *handler_data, void *signal_data); |
| 129 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 130 | |
| 131 | int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 132 | |
| 133 | void gbprox_reset(struct gbproxy_config *cfg); |
| 134 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 135 | /* Peer handling */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 136 | struct gbproxy_bvc *gbproxy_bvc_by_bvci( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 137 | struct gbproxy_config *cfg, uint16_t bvci); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 138 | struct gbproxy_bvc *gbproxy_bvc_by_nsei( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 139 | struct gbproxy_config *cfg, uint16_t nsei); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 140 | struct gbproxy_bvc *gbproxy_bvc_by_rai( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 141 | struct gbproxy_config *cfg, const uint8_t *ra); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 142 | struct gbproxy_bvc *gbproxy_bvc_alloc(struct gbproxy_nse *nse, uint16_t bvci); |
| 143 | void gbproxy_bvc_free(struct gbproxy_bvc *bvc); |
| 144 | void gbproxy_bvc_move(struct gbproxy_bvc *bvc, struct gbproxy_nse *nse); |
| 145 | int gbproxy_cleanup_bvcs(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 146 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 147 | /* NSE handling */ |
| 148 | struct gbproxy_nse *gbproxy_nse_alloc(struct gbproxy_config *cfg, uint16_t nsei); |
| 149 | void gbproxy_nse_free(struct gbproxy_nse *nse); |
| 150 | struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei); |
| 151 | struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei); |
| 152 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 153 | #endif |