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> |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 7 | #include <osmocom/gsm/gsm23003.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 8 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 9 | #include <osmocom/gprs/gprs_ns2.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 10 | #include <osmocom/vty/command.h> |
| 11 | |
| 12 | #include <sys/types.h> |
| 13 | #include <regex.h> |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 14 | #include <stdbool.h> |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 15 | |
| 16 | #define GBPROXY_INIT_VU_GEN_TX 256 |
| 17 | |
Daniel Willmann | 8f407b1 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 18 | /* BVCI uses 16 bits */ |
| 19 | #define BVC_LOG_CTX_FLAG (1<<17) |
| 20 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 21 | struct rate_ctr_group; |
| 22 | struct gprs_gb_parse_context; |
| 23 | struct tlv_parsed; |
| 24 | |
| 25 | enum gbproxy_global_ctr { |
| 26 | GBPROX_GLOB_CTR_INV_BVCI, |
| 27 | GBPROX_GLOB_CTR_INV_LAI, |
| 28 | GBPROX_GLOB_CTR_INV_RAI, |
| 29 | GBPROX_GLOB_CTR_INV_NSEI, |
| 30 | GBPROX_GLOB_CTR_PROTO_ERR_BSS, |
| 31 | GBPROX_GLOB_CTR_PROTO_ERR_SGSN, |
| 32 | GBPROX_GLOB_CTR_NOT_SUPPORTED_BSS, |
| 33 | GBPROX_GLOB_CTR_NOT_SUPPORTED_SGSN, |
| 34 | GBPROX_GLOB_CTR_RESTART_RESET_SGSN, |
| 35 | GBPROX_GLOB_CTR_TX_ERR_SGSN, |
| 36 | GBPROX_GLOB_CTR_OTHER_ERR, |
| 37 | GBPROX_GLOB_CTR_PATCH_PEER_ERR, |
| 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, |
| 46 | GBPROX_PEER_CTR_RAID_PATCHED_BSS, |
| 47 | GBPROX_PEER_CTR_RAID_PATCHED_SGSN, |
| 48 | GBPROX_PEER_CTR_APN_PATCHED, |
| 49 | GBPROX_PEER_CTR_TLLI_PATCHED_BSS, |
| 50 | GBPROX_PEER_CTR_TLLI_PATCHED_SGSN, |
| 51 | GBPROX_PEER_CTR_PTMSI_PATCHED_BSS, |
| 52 | GBPROX_PEER_CTR_PTMSI_PATCHED_SGSN, |
| 53 | GBPROX_PEER_CTR_PATCH_CRYPT_ERR, |
| 54 | GBPROX_PEER_CTR_PATCH_ERR, |
| 55 | GBPROX_PEER_CTR_ATTACH_REQS, |
| 56 | GBPROX_PEER_CTR_ATTACH_REJS, |
| 57 | GBPROX_PEER_CTR_ATTACH_ACKS, |
| 58 | GBPROX_PEER_CTR_ATTACH_COMPLS, |
| 59 | GBPROX_PEER_CTR_RA_UPD_REQS, |
| 60 | GBPROX_PEER_CTR_RA_UPD_REJS, |
| 61 | GBPROX_PEER_CTR_RA_UPD_ACKS, |
| 62 | GBPROX_PEER_CTR_RA_UPD_COMPLS, |
| 63 | GBPROX_PEER_CTR_GMM_STATUS_BSS, |
| 64 | GBPROX_PEER_CTR_GMM_STATUS_SGSN, |
| 65 | GBPROX_PEER_CTR_DETACH_REQS, |
| 66 | GBPROX_PEER_CTR_DETACH_ACKS, |
| 67 | GBPROX_PEER_CTR_PDP_ACT_REQS, |
| 68 | GBPROX_PEER_CTR_PDP_ACT_REJS, |
| 69 | GBPROX_PEER_CTR_PDP_ACT_ACKS, |
| 70 | GBPROX_PEER_CTR_PDP_DEACT_REQS, |
| 71 | GBPROX_PEER_CTR_PDP_DEACT_ACKS, |
| 72 | GBPROX_PEER_CTR_TLLI_UNKNOWN, |
| 73 | GBPROX_PEER_CTR_TLLI_CACHE_SIZE, |
| 74 | GBPROX_PEER_CTR_LAST, |
| 75 | }; |
| 76 | |
| 77 | enum gbproxy_keep_mode { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 78 | GBPROX_KEEP_NEVER, /* don't ever keep TLLI/IMSI state of de-registered subscribers */ |
| 79 | GBPROX_KEEP_REATTACH, /* keep if re-attach has been requested by SGSN */ |
| 80 | GBPROX_KEEP_IDENTIFIED, /* keep if we had resolved an IMSI */ |
| 81 | GBPROX_KEEP_ALWAYS, /* always keep */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | enum gbproxy_match_id { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 85 | GBPROX_MATCH_PATCHING, /* match rule on whether or not we should patch */ |
| 86 | GBPROX_MATCH_ROUTING, /* match rule on whether or not we should route (2-SGSN) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 87 | GBPROX_MATCH_LAST |
| 88 | }; |
| 89 | |
| 90 | struct gbproxy_match { |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 91 | bool enable; /* is this match enabled? */ |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 92 | char *re_str; /* regular expression (for IMSI) in string format */ |
| 93 | regex_t re_comp; /* compiled regular expression (for IMSI) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 94 | }; |
| 95 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 96 | /* global gb-proxy configuration */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 97 | struct gbproxy_config { |
| 98 | /* parsed from config file */ |
| 99 | uint16_t nsip_sgsn_nsei; |
| 100 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 101 | /* NS instance of libosmogb */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 102 | struct gprs_ns2_inst *nsi; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 103 | |
| 104 | /* Linked list of all Gb peers (except SGSN) */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 105 | struct llist_head nses; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 106 | |
| 107 | /* Counter */ |
| 108 | struct rate_ctr_group *ctrg; |
| 109 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 110 | /* MCC/MNC to be patched into RA-ID on the way from BSS to SGSN? */ |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 111 | struct osmo_plmn_id core_plmn; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 112 | |
| 113 | /* APN to be patched into PDP CTX ACT REQ on the way from BSS to SGSN */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 114 | uint8_t* core_apn; |
| 115 | size_t core_apn_size; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 116 | |
Pau Espin Pedrol | e0d647f | 2018-08-17 13:13:27 +0200 | [diff] [blame] | 117 | /* Frequency (sec) at which timer to clean stale links is fired (0 disabled) */ |
| 118 | unsigned int clean_stale_timer_freq; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 119 | /* If !0, Max age to consider a struct gbproxy_link_info as stale */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 120 | int tlli_max_age; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 121 | /* If !0, Max len of gbproxy_bvc->list (list of struct gbproxy_link_info) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 122 | int tlli_max_len; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 123 | /* If !0, Max len of gbproxy_link_info->stored_msgs (list of msgb) */ |
| 124 | uint32_t stored_msgs_max_len; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 125 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 126 | /* Should the P-TMSI be patched on the fly (required for 2-SGSN config) */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 127 | bool patch_ptmsi; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 128 | /* Should the IMSI be acquired by the proxy (required for 2-SGSN config) */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 129 | bool acquire_imsi; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 130 | /* Should we route subscribers to two different SGSNs? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 131 | bool route_to_sgsn2; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 132 | /* NSEI of the second SGSN */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 133 | uint16_t nsip_sgsn2_nsei; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 134 | /* should we keep a cache of per-subscriber state even after de-registration? */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 135 | enum gbproxy_keep_mode keep_link_infos; |
| 136 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 137 | /* IMSI checking/matching for 2-SGSN routing and patching */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 138 | struct gbproxy_match matches[GBPROX_MATCH_LAST]; |
| 139 | }; |
| 140 | |
| 141 | struct gbproxy_patch_state { |
Neels Hofmeyr | 6179f0c | 2018-02-21 00:39:36 +0100 | [diff] [blame] | 142 | struct osmo_plmn_id local_plmn; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 143 | |
| 144 | /* List of TLLIs for which patching is enabled */ |
| 145 | struct llist_head logical_links; |
| 146 | int logical_link_count; |
| 147 | }; |
| 148 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 149 | /* One BVC inside an NSE */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 150 | struct gbproxy_bvc { |
| 151 | /* linked to gbproxy_nse.bvcs */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 152 | struct llist_head list; |
| 153 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 154 | /* The NSE this BVC belongs to */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 155 | struct gbproxy_nse *nse; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 156 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 157 | /* PTP BVCI of this BVC */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 158 | uint16_t bvci; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 159 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 160 | /* Routing Area that this BVC is part of (raw 04.08 encoding) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 161 | uint8_t ra[6]; |
| 162 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 163 | /* true if this BVC is blocked */ |
| 164 | bool blocked; |
| 165 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 166 | /* Counter */ |
| 167 | struct rate_ctr_group *ctrg; |
| 168 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 169 | /* State related to on-the-fly patching of certain messages */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 170 | struct gbproxy_patch_state patch_state; |
Pau Espin Pedrol | e0d647f | 2018-08-17 13:13:27 +0200 | [diff] [blame] | 171 | |
| 172 | /* Fired periodically to clean up stale links from list */ |
| 173 | struct osmo_timer_list clean_stale_timer; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 174 | }; |
| 175 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 176 | /* one NS Entity that we interact with (BSS/PCU) */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 177 | struct gbproxy_nse { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 178 | /* linked to gbproxy_config.nses */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 179 | struct llist_head list; |
| 180 | |
| 181 | /* point back to the config */ |
| 182 | struct gbproxy_config *cfg; |
| 183 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 184 | /* NSEI of the NSE */ |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 185 | uint16_t nsei; |
| 186 | |
| 187 | /* List of all BVCs in this NSE */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 188 | struct llist_head bvcs; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 189 | }; |
| 190 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 191 | struct gbproxy_tlli_state { |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 192 | /* currently active TLLI */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 193 | uint32_t current; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 194 | /* newly-assigned TLLI (e.g. during P-TMSI allocation procedure) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 195 | uint32_t assigned; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 196 | /* has the BSS side validated (confirmed) the new TLLI? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 197 | bool bss_validated; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 198 | /* has the SGSN side validated (confirmed) the new TLLI? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 199 | bool net_validated; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 200 | /* NOTE: once both are validated, we set current = assigned and assigned = 0 */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 201 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 202 | /* The P-TMSI for this subscriber */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 203 | uint32_t ptmsi; |
| 204 | }; |
| 205 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 206 | /* One TLLI (= UE, = Subscriber) served via this proxy */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 207 | struct gbproxy_link_info { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 208 | /* link to gbproxy_bvc.patch_state.logical_links */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 209 | struct llist_head list; |
| 210 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 211 | /* TLLI on the BSS/PCU side */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 212 | struct gbproxy_tlli_state tlli; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 213 | /* TLLI on the SGSN side (can be different in case of P-TMSI patching) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 214 | struct gbproxy_tlli_state sgsn_tlli; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 215 | /* NSEI of the SGSN serving this link */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 216 | uint32_t sgsn_nsei; |
| 217 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 218 | /* timestamp when we last had any contact with this UE */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 219 | time_t timestamp; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 220 | |
| 221 | /* IMSI of the subscriber (if/once known) */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 222 | uint8_t *imsi; |
| 223 | size_t imsi_len; |
| 224 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 225 | /* is the IMSI acquisition still pending? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 226 | bool imsi_acq_pending; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 227 | |
| 228 | /* queue of stored UL messages (until IMSI acquisition completes and we can |
| 229 | * determine which of the SGSNs we should route this to */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 230 | struct llist_head stored_msgs; |
Pau Espin Pedrol | 0248524 | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 231 | uint32_t stored_msgs_len; |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 232 | |
| 233 | /* generated N(U) we use (required due to IMSI acquisition */ |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 234 | unsigned vu_gen_tx_bss; |
| 235 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 236 | /* is this subscriber deregistered (TLLI invalidated)? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 237 | bool is_deregistered; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 238 | |
Harald Welte | 4a8769a | 2019-03-22 08:26:45 +0100 | [diff] [blame] | 239 | /* does this link match either the (2-SGSN) routing or the patching rule? */ |
Harald Welte | bec7041 | 2019-03-22 09:44:42 +0100 | [diff] [blame] | 240 | bool is_matching[GBPROX_MATCH_LAST]; |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 241 | }; |
| 242 | |
Daniel Willmann | 066c4cb | 2020-12-01 16:36:29 +0100 | [diff] [blame] | 243 | /* Convenience logging macros for NSE/BVC */ |
| 244 | #define LOGPNSE_CAT(NSE, SUBSYS, LEVEL, FMT, ARGS...) \ |
| 245 | LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS) " FMT, (NSE)->nsei, ## ARGS) |
| 246 | #define LOGPNSE(NSE, LEVEL, FMT, ARGS...) \ |
| 247 | LOGPNSE_CAT(NSE, DGPRS, LEVEL, FMT, ## ARGS) |
| 248 | |
| 249 | #define LOGPBVC_CAT(BVC, SUBSYS, LEVEL, FMT, ARGS...) \ |
| 250 | LOGP(SUBSYS, LEVEL, "NSE(%05u/BSS)-BVC(%05u/%s) " FMT, (BVC)->nse->nsei, (BVC)->bvci, \ |
| 251 | (BVC)->blocked ? "BLOCKED" : "UNBLOCKED", ## ARGS) |
| 252 | #define LOGPBVC(BVC, LEVEL, FMT, ARGS...) \ |
| 253 | LOGPBVC_CAT(BVC, DGPRS, LEVEL, FMT, ## ARGS) |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 254 | |
| 255 | /* gb_proxy_vty .c */ |
| 256 | |
| 257 | int gbproxy_vty_init(void); |
| 258 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg); |
| 259 | |
Daniel Willmann | 13404b7 | 2018-06-01 07:21:20 +0200 | [diff] [blame] | 260 | /* gb_proxy_ctrl.c */ |
| 261 | int gb_ctrl_cmds_install(void); |
| 262 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 263 | |
| 264 | /* gb_proxy.c */ |
| 265 | int gbproxy_init_config(struct gbproxy_config *cfg); |
| 266 | |
| 267 | /* Main input function for Gb proxy */ |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 268 | int gbprox_rcvmsg(void *ctx, struct msgb *msg); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 269 | |
| 270 | int gbprox_signal(unsigned int subsys, unsigned int signal, |
| 271 | void *handler_data, void *signal_data); |
| 272 | |
Alexander Couzens | 951e133 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 273 | |
| 274 | int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 275 | |
| 276 | void gbprox_reset(struct gbproxy_config *cfg); |
| 277 | |
| 278 | /* TLLI info handling */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 279 | void gbproxy_delete_link_infos(struct gbproxy_bvc *bvc); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 280 | struct gbproxy_link_info *gbproxy_update_link_state_ul( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 281 | struct gbproxy_bvc *bvc, time_t now, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 282 | struct gprs_gb_parse_context *parse_ctx); |
| 283 | struct gbproxy_link_info *gbproxy_update_link_state_dl( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 284 | struct gbproxy_bvc *bvc, time_t now, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 285 | struct gprs_gb_parse_context *parse_ctx); |
| 286 | int gbproxy_update_link_state_after( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 287 | struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 288 | time_t now, struct gprs_gb_parse_context *parse_ctx); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 289 | int gbproxy_remove_stale_link_infos(struct gbproxy_bvc *bvc, time_t now); |
| 290 | void gbproxy_delete_link_info(struct gbproxy_bvc *bvc, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 291 | struct gbproxy_link_info *link_info); |
| 292 | void gbproxy_link_info_discard_messages(struct gbproxy_link_info *link_info); |
| 293 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 294 | void gbproxy_attach_link_info(struct gbproxy_bvc *bvc, time_t now, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 295 | struct gbproxy_link_info *link_info); |
| 296 | void gbproxy_update_link_info(struct gbproxy_link_info *link_info, |
| 297 | const uint8_t *imsi, size_t imsi_len); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 298 | void gbproxy_detach_link_info(struct gbproxy_bvc *bvc, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 299 | struct gbproxy_link_info *link_info); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 300 | struct gbproxy_link_info *gbproxy_link_info_alloc( struct gbproxy_bvc *bvc); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 301 | |
| 302 | struct gbproxy_link_info *gbproxy_link_info_by_tlli( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 303 | struct gbproxy_bvc *bvc, uint32_t tlli); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 304 | struct gbproxy_link_info *gbproxy_link_info_by_imsi( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 305 | struct gbproxy_bvc *bvc, const uint8_t *imsi, size_t imsi_len); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 306 | struct gbproxy_link_info *gbproxy_link_info_by_any_sgsn_tlli( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 307 | struct gbproxy_bvc *bvc, uint32_t tlli); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 308 | struct gbproxy_link_info *gbproxy_link_info_by_sgsn_tlli( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 309 | struct gbproxy_bvc *bvc, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 310 | uint32_t tlli, uint32_t sgsn_nsei); |
| 311 | struct gbproxy_link_info *gbproxy_link_info_by_ptmsi( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 312 | struct gbproxy_bvc *bvc, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 313 | uint32_t ptmsi); |
| 314 | |
| 315 | int gbproxy_imsi_matches( |
| 316 | struct gbproxy_config *cfg, |
| 317 | enum gbproxy_match_id match_id, |
| 318 | struct gbproxy_link_info *link_info); |
| 319 | uint32_t gbproxy_map_tlli( |
| 320 | uint32_t other_tlli, struct gbproxy_link_info *link_info, int to_bss); |
| 321 | |
| 322 | /* needed by gb_proxy_tlli.h */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 323 | uint32_t gbproxy_make_bss_ptmsi(struct gbproxy_bvc *bvc, uint32_t sgsn_ptmsi); |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 324 | uint32_t gbproxy_make_sgsn_tlli( |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 325 | struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 326 | uint32_t bss_tlli); |
| 327 | void gbproxy_reset_link(struct gbproxy_link_info *link_info); |
| 328 | int gbproxy_check_imsi( |
| 329 | struct gbproxy_match *match, const uint8_t *imsi, size_t imsi_len); |
| 330 | |
| 331 | /* Message patching */ |
| 332 | void gbproxy_patch_bssgp( |
| 333 | struct msgb *msg, uint8_t *bssgp, size_t bssgp_len, |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 334 | struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 335 | int *len_change, struct gprs_gb_parse_context *parse_ctx); |
| 336 | |
| 337 | int gbproxy_patch_llc( |
| 338 | struct msgb *msg, uint8_t *llc, size_t llc_len, |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 339 | struct gbproxy_bvc *bvc, struct gbproxy_link_info *link_info, |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 340 | int *len_change, struct gprs_gb_parse_context *parse_ctx); |
| 341 | |
| 342 | int gbproxy_set_patch_filter( |
| 343 | struct gbproxy_match *match, const char *filter, const char **err_msg); |
| 344 | void gbproxy_clear_patch_filter(struct gbproxy_match *match); |
| 345 | |
| 346 | /* Peer handling */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 347 | struct gbproxy_bvc *gbproxy_bvc_by_bvci( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 348 | struct gbproxy_config *cfg, uint16_t bvci); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 349 | struct gbproxy_bvc *gbproxy_bvc_by_nsei( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 350 | struct gbproxy_config *cfg, uint16_t nsei); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 351 | struct gbproxy_bvc *gbproxy_bvc_by_rai( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 352 | struct gbproxy_config *cfg, const uint8_t *ra); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 353 | struct gbproxy_bvc *gbproxy_bvc_by_lai( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 354 | struct gbproxy_config *cfg, const uint8_t *la); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 355 | struct gbproxy_bvc *gbproxy_bvc_by_lac( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 356 | struct gbproxy_config *cfg, const uint8_t *la); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 357 | struct gbproxy_bvc *gbproxy_bvc_by_bssgp_tlv( |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 358 | struct gbproxy_config *cfg, struct tlv_parsed *tp); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame^] | 359 | struct gbproxy_bvc *gbproxy_bvc_alloc(struct gbproxy_nse *nse, uint16_t bvci); |
| 360 | void gbproxy_bvc_free(struct gbproxy_bvc *bvc); |
| 361 | void gbproxy_bvc_move(struct gbproxy_bvc *bvc, struct gbproxy_nse *nse); |
| 362 | 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] | 363 | |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 364 | /* NSE handling */ |
| 365 | struct gbproxy_nse *gbproxy_nse_alloc(struct gbproxy_config *cfg, uint16_t nsei); |
| 366 | void gbproxy_nse_free(struct gbproxy_nse *nse); |
| 367 | struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei); |
| 368 | struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei); |
| 369 | |
Neels Hofmeyr | 4b4c586 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 370 | #endif |