Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1 | /*! \file gprs_ns2_internal.h */ |
| 2 | |
| 3 | #pragma once |
| 4 | |
| 5 | #include <stdbool.h> |
| 6 | #include <stdint.h> |
| 7 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 8 | #include <osmocom/core/logging.h> |
Daniel Willmann | fa3a9ce | 2022-11-21 19:27:18 +0100 | [diff] [blame] | 9 | #include <osmocom/core/rate_ctr.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 10 | #include <osmocom/gprs/protocol/gsm_08_16.h> |
| 11 | #include <osmocom/gprs/gprs_ns2.h> |
| 12 | |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 13 | #define LOGNSE(nse, lvl, fmt, args ...) \ |
| 14 | LOGP(DLNS, lvl, "NSE(%05u) " fmt, (nse)->nsei, ## args) |
| 15 | |
| 16 | #define LOGBIND(bind, lvl, fmt, args ...) \ |
| 17 | LOGP(DLNS, lvl, "BIND(%s) " fmt, (bind)->name, ## args) |
| 18 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 19 | #define LOGNSVC_SS(ss, nsvc, lvl, fmt, args ...) \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 20 | do { \ |
| 21 | if ((nsvc)->nsvci_is_valid) { \ |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 22 | LOGP(ss, lvl, "NSE(%05u)-NSVC(%05u) " fmt, \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 23 | (nsvc)->nse->nsei, (nsvc)->nsvci, ## args); \ |
| 24 | } else { \ |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 25 | LOGP(ss, lvl, "NSE(%05u)-NSVC(none) " fmt, \ |
Harald Welte | f294974 | 2021-01-20 14:54:14 +0100 | [diff] [blame] | 26 | (nsvc)->nse->nsei, ## args); \ |
| 27 | } \ |
| 28 | } while (0) |
| 29 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 30 | #define LOGNSVC(nsvc, lvl, fmt, args ...) \ |
| 31 | LOGNSVC_SS(DLNS, nsvc, lvl, fmt, ## args) |
| 32 | |
| 33 | #define LOG_NS_SIGNAL(nsvc, direction, pdu_type, lvl, fmt, args ...) \ |
| 34 | LOGNSVC_SS(DLNSSIGNAL, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args) |
| 35 | |
| 36 | #define LOG_NS_DATA(nsvc, direction, pdu_type, lvl, fmt, args ...) \ |
| 37 | LOGNSVC_SS(DLNSDATA, nsvc, lvl, "%s %s" fmt, direction, get_value_string(gprs_ns_pdu_strings, pdu_type), ## args) |
| 38 | |
| 39 | #define LOG_NS_RX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Rx", pdu_type, LOGL_INFO, "\n") |
| 40 | #define LOG_NS_TX_SIGNAL(nsvc, pdu_type) LOG_NS_SIGNAL(nsvc, "Tx", pdu_type, LOGL_INFO, "\n") |
| 41 | |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 42 | #define RATE_CTR_INC_NS(nsvc, ctr) \ |
| 43 | do { \ |
| 44 | struct gprs_ns2_vc *_nsvc = (nsvc); \ |
| 45 | rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr)); \ |
| 46 | rate_ctr_inc(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr)); \ |
| 47 | } while (0) |
| 48 | |
| 49 | #define RATE_CTR_ADD_NS(nsvc, ctr, val) \ |
| 50 | do { \ |
| 51 | struct gprs_ns2_vc *_nsvc = (nsvc); \ |
| 52 | rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->ctrg, ctr), val); \ |
| 53 | rate_ctr_add(rate_ctr_group_get_ctr(_nsvc->nse->ctrg, ctr), val); \ |
| 54 | } while (0) |
| 55 | |
Alexander Couzens | 6cf65d9 | 2021-01-18 17:55:35 +0100 | [diff] [blame] | 56 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 57 | struct osmo_fsm_inst; |
| 58 | struct tlv_parsed; |
| 59 | struct vty; |
| 60 | |
| 61 | struct gprs_ns2_vc_driver; |
| 62 | struct gprs_ns2_vc_bind; |
| 63 | |
Alexander Couzens | 1f3193d | 2021-06-05 22:08:11 +0200 | [diff] [blame] | 64 | #define NS_TIMERS_COUNT 11 |
arehbein | 8000647 | 2023-12-10 20:52:42 +0100 | [diff] [blame^] | 65 | |
| 66 | #define TNS_BLOCK_STR "tns-block" |
| 67 | #define TNS_BLOCK_RETRIES_STR "tns-block-retries" |
| 68 | #define TNS_RESET_STR "tns-reset" |
| 69 | #define TNS_RESET_RETRIES_STR "tns-reset-retries" |
| 70 | #define TNS_TEST_STR "tns-test" |
| 71 | #define TNS_ALIVE_STR "tns-alive" |
| 72 | #define TNS_ALIVE_RETRIES_STR "tns-alive-retries" |
| 73 | #define TSNS_PROV_STR "tsns-prov" |
| 74 | #define TSNS_SIZE_RETRIES_STR "tsns-size-retries" |
| 75 | #define TSNS_CONFIG_RETRIES_STR "tsns-config-retries" |
| 76 | #define TSNS_PROCEDURES_RETRIES_STR "tsns-procedures-retries" |
| 77 | #define NS_TIMERS "(" TNS_BLOCK_STR "|" TNS_BLOCK_RETRIES_STR "|" TNS_RESET_STR "|" TNS_RESET_RETRIES_STR "|" TNS_TEST_STR "|"\ |
| 78 | TNS_ALIVE_STR "|" TNS_ALIVE_RETRIES_STR "|" TSNS_PROV_STR "|" TSNS_SIZE_RETRIES_STR "|" TSNS_CONFIG_RETRIES_STR "|"\ |
| 79 | TSNS_PROCEDURES_RETRIES_STR ")" |
| 80 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 81 | #define NS_TIMERS_HELP \ |
| 82 | "(un)blocking Timer (Tns-block) timeout\n" \ |
| 83 | "(un)blocking Timer (Tns-block) number of retries\n" \ |
| 84 | "Reset Timer (Tns-reset) timeout\n" \ |
| 85 | "Reset Timer (Tns-reset) number of retries\n" \ |
| 86 | "Test Timer (Tns-test) timeout\n" \ |
| 87 | "Alive Timer (Tns-alive) timeout\n" \ |
| 88 | "Alive Timer (Tns-alive) number of retries\n" \ |
Alexander Couzens | 90ee963 | 2020-12-07 06:18:32 +0100 | [diff] [blame] | 89 | "SNS Provision Timer (Tsns-prov) timeout\n" \ |
| 90 | "SNS Size number of retries\n" \ |
| 91 | "SNS Config number of retries\n" \ |
Alexander Couzens | 1f3193d | 2021-06-05 22:08:11 +0200 | [diff] [blame] | 92 | "SNS Procedures number of retries\n" \ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 93 | |
| 94 | /* Educated guess - LLC user payload is 1500 bytes plus possible headers */ |
| 95 | #define NS_ALLOC_SIZE 3072 |
| 96 | #define NS_ALLOC_HEADROOM 20 |
| 97 | |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 98 | #define NS_DEFAULT_TXQUEUE_MAX_LENGTH 128 |
| 99 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 100 | enum ns2_timeout { |
| 101 | NS_TOUT_TNS_BLOCK, |
| 102 | NS_TOUT_TNS_BLOCK_RETRIES, |
| 103 | NS_TOUT_TNS_RESET, |
| 104 | NS_TOUT_TNS_RESET_RETRIES, |
| 105 | NS_TOUT_TNS_TEST, |
| 106 | NS_TOUT_TNS_ALIVE, |
| 107 | NS_TOUT_TNS_ALIVE_RETRIES, |
| 108 | NS_TOUT_TSNS_PROV, |
Alexander Couzens | 90ee963 | 2020-12-07 06:18:32 +0100 | [diff] [blame] | 109 | NS_TOUT_TSNS_SIZE_RETRIES, |
| 110 | NS_TOUT_TSNS_CONFIG_RETRIES, |
Alexander Couzens | 1f3193d | 2021-06-05 22:08:11 +0200 | [diff] [blame] | 111 | NS_TOUT_TSNS_PROCEDURES_RETRIES, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | enum nsvc_timer_mode { |
| 115 | /* standard timers */ |
| 116 | NSVC_TIMER_TNS_TEST, |
| 117 | NSVC_TIMER_TNS_ALIVE, |
| 118 | NSVC_TIMER_TNS_RESET, |
| 119 | _NSVC_TIMER_NR, |
| 120 | }; |
| 121 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 122 | enum ns2_vc_stat { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 123 | NS_STAT_ALIVE_DELAY, |
| 124 | }; |
| 125 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 126 | enum ns2_bind_stat { |
| 127 | NS2_BIND_STAT_BACKLOG_LEN, |
| 128 | }; |
| 129 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 130 | /*! Osmocom NS2 VC create status */ |
Alexander Couzens | ba5a992 | 2021-01-25 16:03:23 +0100 | [diff] [blame] | 131 | enum ns2_cs { |
| 132 | NS2_CS_CREATED, /*!< A NSVC object has been created */ |
| 133 | NS2_CS_FOUND, /*!< A NSVC object has been found */ |
| 134 | NS2_CS_REJECTED, /*!< Rejected and answered message */ |
| 135 | NS2_CS_SKIPPED, /*!< Skipped message */ |
| 136 | NS2_CS_ERROR, /*!< Failed to process message */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 137 | }; |
| 138 | |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 139 | enum ns_ctr { |
| 140 | NS_CTR_PKTS_IN, |
| 141 | NS_CTR_PKTS_OUT, |
Harald Welte | f22ae5a | 2021-01-30 22:01:28 +0100 | [diff] [blame] | 142 | NS_CTR_PKTS_OUT_DROP, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 143 | NS_CTR_BYTES_IN, |
| 144 | NS_CTR_BYTES_OUT, |
Harald Welte | f22ae5a | 2021-01-30 22:01:28 +0100 | [diff] [blame] | 145 | NS_CTR_BYTES_OUT_DROP, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 146 | NS_CTR_BLOCKED, |
Harald Welte | b40bf8b | 2021-01-30 22:43:01 +0100 | [diff] [blame] | 147 | NS_CTR_UNBLOCKED, |
Harald Welte | 3d5eaee | 2021-01-30 21:33:02 +0100 | [diff] [blame] | 148 | NS_CTR_DEAD, |
| 149 | NS_CTR_REPLACED, |
| 150 | NS_CTR_NSEI_CHG, |
| 151 | NS_CTR_INV_VCI, |
| 152 | NS_CTR_INV_NSEI, |
| 153 | NS_CTR_LOST_ALIVE, |
| 154 | NS_CTR_LOST_RESET, |
| 155 | }; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 156 | |
| 157 | #define NSE_S_BLOCKED 0x0001 |
| 158 | #define NSE_S_ALIVE 0x0002 |
| 159 | #define NSE_S_RESET 0x0004 |
| 160 | |
| 161 | #define NS_DESC_B(st) ((st) & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED") |
| 162 | #define NS_DESC_A(st) ((st) & NSE_S_ALIVE ? "ALIVE" : "DEAD") |
| 163 | #define NS_DESC_R(st) ((st) & NSE_S_RESET ? "RESET" : "UNRESET") |
| 164 | |
| 165 | /*! An instance of the NS protocol stack */ |
| 166 | struct gprs_ns2_inst { |
| 167 | /*! callback to the user for incoming UNIT DATA IND */ |
| 168 | osmo_prim_cb cb; |
| 169 | |
| 170 | /*! callback data */ |
| 171 | void *cb_data; |
| 172 | |
| 173 | /*! linked lists of all NSVC binds (e.g. IPv4 bind, but could be also E1 */ |
| 174 | struct llist_head binding; |
| 175 | |
| 176 | /*! linked lists of all NSVC in this instance */ |
| 177 | struct llist_head nse; |
| 178 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 179 | uint16_t timeout[NS_TIMERS_COUNT]; |
| 180 | |
| 181 | /*! workaround for rate counter until rate counter accepts char str as index */ |
Harald Welte | 97ccbf7 | 2021-01-31 11:49:19 +0100 | [diff] [blame] | 182 | uint32_t nsvc_rate_ctr_idx; |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 183 | uint32_t bind_rate_ctr_idx; |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 184 | |
| 185 | uint32_t txqueue_max_length; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 186 | }; |
| 187 | |
Harald Welte | 53a2fde | 2020-12-01 22:21:14 +0100 | [diff] [blame] | 188 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 189 | /*! Structure repesenting a NSE. The BSS/PCU will only have a single NSE, while SGSN has one for each BSS/PCU */ |
| 190 | struct gprs_ns2_nse { |
| 191 | uint16_t nsei; |
| 192 | |
| 193 | /*! entry back to ns2_inst */ |
| 194 | struct gprs_ns2_inst *nsi; |
| 195 | |
| 196 | /*! llist entry for gprs_ns2_inst */ |
| 197 | struct llist_head list; |
| 198 | |
| 199 | /*! llist head to hold all nsvc */ |
| 200 | struct llist_head nsvc; |
| 201 | |
Alexander Couzens | 8a2a1a4 | 2020-12-26 18:00:17 +0100 | [diff] [blame] | 202 | /*! count all active NSVCs */ |
| 203 | int nsvc_count; |
Alexander Couzens | fc3dd1f | 2020-11-19 00:41:47 +0100 | [diff] [blame] | 204 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 205 | /*! true if this NSE was created by VTY or pcu socket) */ |
| 206 | bool persistent; |
| 207 | |
Alexander Couzens | da0a285 | 2020-10-01 23:24:07 +0200 | [diff] [blame] | 208 | /*! true if this NSE wasn't yet alive at all. |
| 209 | * Will be true after the first status ind with NS_AFF_CAUSE_RECOVERY */ |
| 210 | bool first; |
| 211 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 212 | /*! true if this NSE has at least one alive VC */ |
| 213 | bool alive; |
| 214 | |
Alexander Couzens | aac9016 | 2020-11-19 02:44:04 +0100 | [diff] [blame] | 215 | /*! which link-layer are we based on? */ |
| 216 | enum gprs_ns2_ll ll; |
| 217 | |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 218 | /*! which dialect does this NSE speaks? */ |
| 219 | enum gprs_ns2_dialect dialect; |
| 220 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 221 | struct osmo_fsm_inst *bss_sns_fi; |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 222 | |
Alexander Couzens | e052c41 | 2021-02-15 02:10:57 +0100 | [diff] [blame] | 223 | /*! sum of all the data weight of _alive_ NS-VCs */ |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 224 | uint32_t sum_data_weight; |
| 225 | |
Alexander Couzens | e052c41 | 2021-02-15 02:10:57 +0100 | [diff] [blame] | 226 | /*! sum of all the signalling weight of _alive_ NS-VCs */ |
Harald Welte | 3221f87 | 2021-01-18 14:58:51 +0100 | [diff] [blame] | 227 | uint32_t sum_sig_weight; |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 228 | |
| 229 | /*! MTU of a NS PDU. This is the lowest MTU of all NSVCs */ |
| 230 | uint16_t mtu; |
Harald Welte | 5b034fb | 2021-03-04 14:16:49 +0100 | [diff] [blame] | 231 | |
| 232 | /*! are we implementing the SGSN role? */ |
| 233 | bool ip_sns_role_sgsn; |
Daniel Willmann | efa64f9 | 2021-07-09 20:35:00 +0200 | [diff] [blame] | 234 | |
| 235 | /*! NSE-wide statistics */ |
| 236 | struct rate_ctr_group *ctrg; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 237 | |
| 238 | /*! recursive anchor */ |
| 239 | bool freed; |
Alexander Couzens | 2c64c25 | 2021-09-05 23:15:29 +0200 | [diff] [blame] | 240 | |
| 241 | /*! when the NSE became alive or dead */ |
| 242 | struct timespec ts_alive_change; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 243 | }; |
| 244 | |
| 245 | /*! Structure representing a single NS-VC */ |
| 246 | struct gprs_ns2_vc { |
| 247 | /*! list of NS-VCs within NSE */ |
| 248 | struct llist_head list; |
| 249 | |
| 250 | /*! list of NS-VCs within bind, bind is the owner! */ |
| 251 | struct llist_head blist; |
| 252 | |
| 253 | /*! pointer to NS Instance */ |
| 254 | struct gprs_ns2_nse *nse; |
| 255 | |
| 256 | /*! pointer to NS VL bind. bind own the memory of this instance */ |
| 257 | struct gprs_ns2_vc_bind *bind; |
| 258 | |
| 259 | /*! true if this NS was created by VTY or pcu socket) */ |
| 260 | bool persistent; |
| 261 | |
| 262 | /*! uniquely identifies NS-VC if VC contains nsvci */ |
| 263 | uint16_t nsvci; |
| 264 | |
| 265 | /*! signalling weight. 0 = don't use for signalling (BVCI == 0)*/ |
| 266 | uint8_t sig_weight; |
| 267 | |
Alexander Couzens | fc3dd1f | 2020-11-19 00:41:47 +0100 | [diff] [blame] | 268 | /*! signalling packet counter for the load sharing function */ |
| 269 | uint8_t sig_counter; |
| 270 | |
| 271 | /*! data weight. 0 = don't use for user data (BVCI != 0) */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 272 | uint8_t data_weight; |
| 273 | |
| 274 | /*! can be used by the bind/driver of the virtual circuit. e.g. ipv4/ipv6/frgre/e1 */ |
| 275 | void *priv; |
| 276 | |
| 277 | bool nsvci_is_valid; |
Harald Welte | c962a2e | 2021-03-05 08:09:08 +0100 | [diff] [blame] | 278 | /*! should this NS-VC only be used for SNS-SIZE and SNS-CONFIG? */ |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 279 | bool sns_only; |
| 280 | |
| 281 | struct rate_ctr_group *ctrg; |
| 282 | struct osmo_stat_item_group *statg; |
| 283 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 284 | enum gprs_ns2_vc_mode mode; |
| 285 | |
| 286 | struct osmo_fsm_inst *fi; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 287 | |
| 288 | /*! recursive anchor */ |
| 289 | bool freed; |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 290 | |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 291 | /*! if blocked by O&M/vty */ |
| 292 | bool om_blocked; |
| 293 | |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 294 | /*! when the NSVC became alive or dead */ |
| 295 | struct timespec ts_alive_change; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 296 | }; |
| 297 | |
| 298 | /*! Structure repesenting a bind instance. E.g. IPv4 listen port. */ |
| 299 | struct gprs_ns2_vc_bind { |
Alexander Couzens | aaa55a6 | 2020-12-03 06:02:03 +0100 | [diff] [blame] | 300 | /*! unique name */ |
| 301 | const char *name; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 302 | /*! list entry in nsi */ |
| 303 | struct llist_head list; |
| 304 | /*! list of all VC */ |
| 305 | struct llist_head nsvc; |
| 306 | /*! driver private structure */ |
| 307 | void *priv; |
| 308 | /*! a pointer back to the nsi */ |
| 309 | struct gprs_ns2_inst *nsi; |
| 310 | struct gprs_ns2_vc_driver *driver; |
| 311 | |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 312 | bool accept_ipaccess; |
| 313 | bool accept_sns; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 314 | |
Alexander Couzens | 1c8785d | 2020-12-17 06:58:53 +0100 | [diff] [blame] | 315 | /*! transfer capability in mbit */ |
| 316 | int transfer_capability; |
| 317 | |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 318 | /*! MTU of a NS PDU on this bind. */ |
| 319 | uint16_t mtu; |
| 320 | |
Alexander Couzens | aac9016 | 2020-11-19 02:44:04 +0100 | [diff] [blame] | 321 | /*! which link-layer are we based on? */ |
| 322 | enum gprs_ns2_ll ll; |
| 323 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 324 | /*! send a msg over a VC */ |
| 325 | int (*send_vc)(struct gprs_ns2_vc *nsvc, struct msgb *msg); |
| 326 | |
| 327 | /*! free the vc priv data */ |
| 328 | void (*free_vc)(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 329 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 330 | /*! allow to show information for the vty */ |
| 331 | void (*dump_vty)(const struct gprs_ns2_vc_bind *bind, |
| 332 | struct vty *vty, bool stats); |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 333 | |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 334 | /*! the IP-SNS signalling weight when doing dynamic configuration */ |
| 335 | uint8_t sns_sig_weight; |
| 336 | /*! the IP-SNS data weight when doing dynamic configuration */ |
| 337 | uint8_t sns_data_weight; |
| 338 | |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 339 | struct osmo_stat_item_group *statg; |
Alexander Couzens | 41589a3 | 2021-07-19 03:40:02 +0200 | [diff] [blame] | 340 | |
| 341 | /*! recursive anchor */ |
| 342 | bool freed; |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 343 | }; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 344 | |
| 345 | struct gprs_ns2_vc_driver { |
| 346 | const char *name; |
| 347 | void *priv; |
| 348 | void (*free_bind)(struct gprs_ns2_vc_bind *driver); |
| 349 | }; |
| 350 | |
Alexander Couzens | 175eb7b | 2021-07-20 18:41:14 +0200 | [diff] [blame] | 351 | enum ns2_sns_event { |
| 352 | NS2_SNS_EV_REQ_SELECT_ENDPOINT, /*!< Select a SNS endpoint from the list */ |
| 353 | NS2_SNS_EV_RX_SIZE, |
| 354 | NS2_SNS_EV_RX_SIZE_ACK, |
| 355 | NS2_SNS_EV_RX_CONFIG, |
| 356 | NS2_SNS_EV_RX_CONFIG_END, /*!< SNS-CONFIG with end flag received */ |
| 357 | NS2_SNS_EV_RX_CONFIG_ACK, |
| 358 | NS2_SNS_EV_RX_ADD, |
| 359 | NS2_SNS_EV_RX_DELETE, |
| 360 | NS2_SNS_EV_RX_CHANGE_WEIGHT, |
| 361 | NS2_SNS_EV_RX_ACK, /*!< Rx of SNS-ACK (response to ADD/DELETE/CHG_WEIGHT */ |
| 362 | NS2_SNS_EV_REQ_NO_NSVC, /*!< no more NS-VC remaining (all dead) */ |
Alexander Couzens | 83f06ce | 2021-08-06 19:50:09 +0200 | [diff] [blame] | 363 | NS2_SNS_EV_REQ_FREE_NSVCS, /*!< free all NS-VCs */ |
Alexander Couzens | 175eb7b | 2021-07-20 18:41:14 +0200 | [diff] [blame] | 364 | NS2_SNS_EV_REQ_NSVC_ALIVE, /*!< a NS-VC became alive */ |
| 365 | NS2_SNS_EV_REQ_ADD_BIND, /*!< add a new local bind to this NSE */ |
| 366 | NS2_SNS_EV_REQ_DELETE_BIND, /*!< remove a local bind from this NSE */ |
Alexander Couzens | 1f3193d | 2021-06-05 22:08:11 +0200 | [diff] [blame] | 367 | NS2_SNS_EV_REQ_CHANGE_WEIGHT, /*!< a bind changed its weight */ |
Alexander Couzens | 175eb7b | 2021-07-20 18:41:14 +0200 | [diff] [blame] | 368 | }; |
| 369 | |
Alexander Couzens | ba5a992 | 2021-01-25 16:03:23 +0100 | [diff] [blame] | 370 | enum ns2_cs ns2_create_vc(struct gprs_ns2_vc_bind *bind, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 371 | struct msgb *msg, |
Harald Welte | 7d0daac | 2021-03-02 23:08:43 +0100 | [diff] [blame] | 372 | const struct osmo_sockaddr *remote, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 373 | const char *logname, |
| 374 | struct msgb **reject, |
| 375 | struct gprs_ns2_vc **success); |
| 376 | |
Alexander Couzens | ffd49d0 | 2020-09-24 00:47:17 +0200 | [diff] [blame] | 377 | int ns2_recv_vc(struct gprs_ns2_vc *nsvc, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 378 | struct msgb *msg); |
| 379 | |
| 380 | struct gprs_ns2_vc *ns2_vc_alloc(struct gprs_ns2_vc_bind *bind, |
| 381 | struct gprs_ns2_nse *nse, |
Alexander Couzens | d923cff | 2020-12-01 01:03:52 +0100 | [diff] [blame] | 382 | bool initiater, |
Harald Welte | 603f404 | 2020-11-29 17:39:19 +0100 | [diff] [blame] | 383 | enum gprs_ns2_vc_mode vc_mode, |
| 384 | const char *id); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 385 | |
Alexander Couzens | f074659 | 2021-07-20 19:05:45 +0200 | [diff] [blame] | 386 | void ns2_free_nsvcs(struct gprs_ns2_nse *nse); |
Harald Welte | c3aa8f9 | 2021-01-31 11:41:34 +0100 | [diff] [blame] | 387 | int ns2_bind_alloc(struct gprs_ns2_inst *nsi, const char *name, |
| 388 | struct gprs_ns2_vc_bind **result); |
| 389 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 390 | struct msgb *ns2_msgb_alloc(void); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 391 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 392 | void ns2_sns_write_vty(struct vty *vty, const struct gprs_ns2_nse *nse); |
| 393 | void ns2_sns_dump_vty(struct vty *vty, const char *prefix, const struct gprs_ns2_nse *nse, bool stats); |
Alexander Couzens | bf95f0f | 2020-10-01 22:56:03 +0200 | [diff] [blame] | 394 | void ns2_prim_status_ind(struct gprs_ns2_nse *nse, |
Daniel Willmann | 15c09a8 | 2020-11-03 23:05:43 +0100 | [diff] [blame] | 395 | struct gprs_ns2_vc *nsvc, |
Alexander Couzens | bf95f0f | 2020-10-01 22:56:03 +0200 | [diff] [blame] | 396 | uint16_t bvci, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 397 | enum gprs_ns2_affecting_cause cause); |
| 398 | void ns2_nse_notify_alive(struct gprs_ns2_vc *nsvc, bool alive); |
Alexander Couzens | 4f1128f | 2021-01-20 17:42:48 +0100 | [diff] [blame] | 399 | void ns2_nse_update_mtu(struct gprs_ns2_nse *nse); |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 400 | int ns2_nse_set_dialect(struct gprs_ns2_nse *nse, enum gprs_ns2_dialect dialect); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 401 | |
| 402 | /* message */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 403 | int ns2_validate(struct gprs_ns2_vc *nsvc, |
| 404 | uint8_t pdu_type, |
| 405 | struct msgb *msg, |
| 406 | struct tlv_parsed *tp, |
| 407 | uint8_t *cause); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 408 | |
| 409 | /* SNS messages */ |
| 410 | int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause, |
| 411 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 412 | unsigned int num_ip4_elems, |
| 413 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 414 | unsigned int num_ip6_elems); |
| 415 | int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag, |
| 416 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 417 | unsigned int num_ip4_elems, |
| 418 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 419 | unsigned int num_ip6_elems); |
| 420 | int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause); |
| 421 | int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_nsvc, |
| 422 | int ip4_ep_nr, int ip6_ep_nr); |
| 423 | int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause); |
| 424 | |
Alexander Couzens | 27a5592 | 2021-02-27 01:08:35 +0100 | [diff] [blame] | 425 | int ns2_tx_sns_add(struct gprs_ns2_vc *nsvc, |
| 426 | uint8_t trans_id, |
| 427 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 428 | unsigned int num_ip4_elems, |
| 429 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 430 | unsigned int num_ip6_elems); |
| 431 | int ns2_tx_sns_change_weight(struct gprs_ns2_vc *nsvc, |
| 432 | uint8_t trans_id, |
| 433 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 434 | unsigned int num_ip4_elems, |
| 435 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 436 | unsigned int num_ip6_elems); |
| 437 | int ns2_tx_sns_del(struct gprs_ns2_vc *nsvc, |
| 438 | uint8_t trans_id, |
| 439 | const struct gprs_ns_ie_ip4_elem *ip4_elems, |
| 440 | unsigned int num_ip4_elems, |
| 441 | const struct gprs_ns_ie_ip6_elem *ip6_elems, |
| 442 | unsigned int num_ip6_elems); |
| 443 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 444 | /* transmit message over a VC */ |
Alexander Couzens | 67cfc5d | 2021-09-07 01:10:38 +0200 | [diff] [blame] | 445 | int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause, uint16_t *nsvci); |
| 446 | int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc, uint16_t *nsvci); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 447 | |
| 448 | int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause); |
| 449 | int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc); |
| 450 | |
| 451 | int ns2_tx_unblock(struct gprs_ns2_vc *nsvc); |
| 452 | int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc); |
| 453 | |
| 454 | int ns2_tx_alive(struct gprs_ns2_vc *nsvc); |
| 455 | int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc); |
| 456 | |
| 457 | int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc, |
| 458 | uint16_t bvci, uint8_t sducontrol, |
| 459 | struct msgb *msg); |
| 460 | |
| 461 | int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause, |
Alexander Couzens | d802f9a | 2021-09-23 16:19:32 +0200 | [diff] [blame] | 462 | uint16_t bvci, struct msgb *orig_msg, uint16_t *nsvci); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 463 | |
| 464 | /* driver */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 465 | struct gprs_ns2_vc *ns2_ip_bind_connect(struct gprs_ns2_vc_bind *bind, |
| 466 | struct gprs_ns2_nse *nse, |
| 467 | const struct osmo_sockaddr *remote); |
Alexander Couzens | e769f52 | 2020-12-07 07:37:07 +0100 | [diff] [blame] | 468 | int ns2_ip_count_bind(struct gprs_ns2_inst *nsi, struct osmo_sockaddr *remote); |
| 469 | struct gprs_ns2_vc_bind *ns2_ip_get_bind_by_index(struct gprs_ns2_inst *nsi, |
| 470 | struct osmo_sockaddr *remote, |
| 471 | int index); |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 472 | void ns2_ip_set_txqueue_max_length(struct gprs_ns2_vc_bind *bind, unsigned int max_length); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 473 | |
| 474 | /* sns */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 475 | int ns2_sns_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 476 | struct osmo_fsm_inst *ns2_sns_bss_fsm_alloc(struct gprs_ns2_nse *nse, |
| 477 | const char *id); |
Harald Welte | 4f12746 | 2021-03-02 20:49:10 +0100 | [diff] [blame] | 478 | struct osmo_fsm_inst *ns2_sns_sgsn_fsm_alloc(struct gprs_ns2_nse *nse, const char *id); |
Alexander Couzens | be7cecc | 2021-02-03 18:25:27 +0100 | [diff] [blame] | 479 | void ns2_sns_replace_nsvc(struct gprs_ns2_vc *nsvc); |
| 480 | void ns2_sns_notify_alive(struct gprs_ns2_nse *nse, struct gprs_ns2_vc *nsvc, bool alive); |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 481 | void ns2_sns_update_weights(struct gprs_ns2_vc_bind *bind); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 482 | |
| 483 | /* vc */ |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 484 | struct osmo_fsm_inst *ns2_vc_fsm_alloc(struct gprs_ns2_vc *nsvc, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 485 | const char *id, bool initiate); |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 486 | int ns2_vc_fsm_start(struct gprs_ns2_vc *nsvc); |
| 487 | int ns2_vc_force_unconfigured(struct gprs_ns2_vc *nsvc); |
| 488 | int ns2_vc_rx(struct gprs_ns2_vc *nsvc, struct msgb *msg, struct tlv_parsed *tp); |
| 489 | int ns2_vc_is_alive(struct gprs_ns2_vc *nsvc); |
| 490 | int ns2_vc_is_unblocked(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 491 | int ns2_vc_block(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 492 | int ns2_vc_reset(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 47afc42 | 2021-01-17 20:12:46 +0100 | [diff] [blame] | 493 | int ns2_vc_unblock(struct gprs_ns2_vc *nsvc); |
Alexander Couzens | 75b6188 | 2021-03-21 16:18:17 +0100 | [diff] [blame] | 494 | void ns2_vty_dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 495 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 496 | /* nse */ |
| 497 | void ns2_nse_notify_unblocked(struct gprs_ns2_vc *nsvc, bool unblocked); |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 498 | enum gprs_ns2_vc_mode ns2_dialect_to_vc_mode(enum gprs_ns2_dialect dialect); |
Alexander Couzens | 1c8785d | 2020-12-17 06:58:53 +0100 | [diff] [blame] | 499 | int ns2_count_transfer_cap(struct gprs_ns2_nse *nse, |
| 500 | uint16_t bvci); |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 501 | |
| 502 | /* vty */ |
| 503 | int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse); |