Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 1 | /* Gb proxy peer handling */ |
| 2 | |
| 3 | /* (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * (C) 2010-2013 by On-Waves |
| 5 | * (C) 2013 by Holger Hans Peter Freyther |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU Affero General Public License as published by |
| 10 | * the Free Software Foundation; either version 3 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU Affero General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Affero General Public License |
| 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <osmocom/sgsn/gb_proxy.h> |
| 24 | |
| 25 | #include <osmocom/sgsn/debug.h> |
| 26 | |
| 27 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
Daniel Willmann | 8f407b1 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 28 | #include <osmocom/core/logging.h> |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 29 | #include <osmocom/core/rate_ctr.h> |
| 30 | #include <osmocom/core/stats.h> |
| 31 | #include <osmocom/core/talloc.h> |
| 32 | #include <osmocom/gsm/tlv.h> |
| 33 | |
| 34 | #include <string.h> |
| 35 | |
| 36 | extern void *tall_sgsn_ctx; |
| 37 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 38 | static const struct rate_ctr_desc bvc_ctr_description[] = { |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 39 | { "blocked", "BVC Block " }, |
| 40 | { "unblocked", "BVC Unblock " }, |
| 41 | { "dropped", "BVC blocked, dropped packet " }, |
| 42 | { "inv-nsei", "NSEI mismatch " }, |
| 43 | { "tx-err", "NS Transmission error " }, |
| 44 | { "raid-mod:bss", "RAID patched (BSS )" }, |
| 45 | { "raid-mod:sgsn", "RAID patched (SGSN)" }, |
| 46 | { "apn-mod:sgsn", "APN patched " }, |
| 47 | { "tlli-mod:bss", "TLLI patched (BSS )" }, |
| 48 | { "tlli-mod:sgsn", "TLLI patched (SGSN)" }, |
| 49 | { "ptmsi-mod:bss", "P-TMSI patched (BSS )" }, |
| 50 | { "ptmsi-mod:sgsn","P-TMSI patched (SGSN)" }, |
| 51 | { "mod-crypt-err", "Patch error: encrypted " }, |
| 52 | { "mod-err", "Patch error: other " }, |
| 53 | { "attach-reqs", "Attach Request count " }, |
| 54 | { "attach-rejs", "Attach Reject count " }, |
| 55 | { "attach-acks", "Attach Accept count " }, |
| 56 | { "attach-cpls", "Attach Completed count " }, |
| 57 | { "ra-upd-reqs", "RoutingArea Update Request count" }, |
| 58 | { "ra-upd-rejs", "RoutingArea Update Reject count " }, |
| 59 | { "ra-upd-acks", "RoutingArea Update Accept count " }, |
| 60 | { "ra-upd-cpls", "RoutingArea Update Compltd count" }, |
| 61 | { "gmm-status", "GMM Status count (BSS)" }, |
| 62 | { "gmm-status", "GMM Status count (SGSN)" }, |
| 63 | { "detach-reqs", "Detach Request count " }, |
| 64 | { "detach-acks", "Detach Accept count " }, |
| 65 | { "pdp-act-reqs", "PDP Activation Request count " }, |
| 66 | { "pdp-act-rejs", "PDP Activation Reject count " }, |
| 67 | { "pdp-act-acks", "PDP Activation Accept count " }, |
| 68 | { "pdp-deact-reqs","PDP Deactivation Request count " }, |
| 69 | { "pdp-deact-acks","PDP Deactivation Accept count " }, |
| 70 | { "tlli-unknown", "TLLI from SGSN unknown " }, |
| 71 | { "tlli-cache", "TLLI cache size " }, |
| 72 | }; |
| 73 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 74 | osmo_static_assert(ARRAY_SIZE(bvc_ctr_description) == GBPROX_PEER_CTR_LAST, everything_described); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 75 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 76 | static const struct rate_ctr_group_desc bvc_ctrg_desc = { |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 77 | .group_name_prefix = "gbproxy:peer", |
| 78 | .group_description = "GBProxy Peer Statistics", |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 79 | .num_ctr = ARRAY_SIZE(bvc_ctr_description), |
| 80 | .ctr_desc = bvc_ctr_description, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 81 | .class_id = OSMO_STATS_CLASS_PEER, |
| 82 | }; |
| 83 | |
| 84 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 85 | /* Find the gbproxy_bvc by its BVCI. There can only be one match */ |
| 86 | struct gbproxy_bvc *gbproxy_bvc_by_bvci(struct gbproxy_config *cfg, uint16_t bvci) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 87 | { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 88 | struct gbproxy_nse *nse; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 89 | int i; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 90 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 91 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 92 | struct gbproxy_bvc *bvc; |
| 93 | llist_for_each_entry(bvc, &nse->bvcs, list) { |
| 94 | if (bvc->bvci == bvci) |
| 95 | return bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 96 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 97 | } |
| 98 | return NULL; |
| 99 | } |
| 100 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 101 | /* Find the gbproxy_bvc by its NSEI */ |
| 102 | /* FIXME: Only returns the first bvc, but we could have multiple on this nsei */ |
| 103 | struct gbproxy_bvc *gbproxy_bvc_by_nsei(struct gbproxy_config *cfg, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 104 | uint16_t nsei) |
| 105 | { |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 106 | struct gbproxy_nse *nse = gbproxy_nse_by_nsei(cfg, nsei); |
| 107 | |
| 108 | if (nse && !llist_empty(&nse->bvcs)) |
| 109 | return llist_first_entry(&nse->bvcs, struct gbproxy_bvc, list); |
| 110 | |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 111 | return NULL; |
| 112 | } |
| 113 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 114 | /* look-up a bvc by its Routeing Area Identification (RAI) */ |
| 115 | /* FIXME: this doesn't make sense, as RA can span multiple bvcs! */ |
| 116 | struct gbproxy_bvc *gbproxy_bvc_by_rai(struct gbproxy_config *cfg, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 117 | const uint8_t *ra) |
| 118 | { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 119 | struct gbproxy_nse *nse; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 120 | int i; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 121 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 122 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 123 | struct gbproxy_bvc *bvc; |
| 124 | llist_for_each_entry(bvc, &nse->bvcs, list) { |
| 125 | if (!memcmp(bvc->ra, ra, 6)) |
| 126 | return bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 127 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 128 | } |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 129 | |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 130 | return NULL; |
| 131 | } |
| 132 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 133 | /* look-up a bvc by its Location Area Identification (LAI) */ |
| 134 | /* FIXME: this doesn't make sense, as LA can span multiple bvcs! */ |
| 135 | struct gbproxy_bvc *gbproxy_bvc_by_lai(struct gbproxy_config *cfg, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 136 | const uint8_t *la) |
| 137 | { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 138 | struct gbproxy_nse *nse; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 139 | int i; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 140 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 141 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 142 | struct gbproxy_bvc *bvc; |
| 143 | llist_for_each_entry(bvc, &nse->bvcs, list) { |
| 144 | if (!memcmp(bvc->ra, la, 5)) |
| 145 | return bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 146 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 147 | } |
| 148 | return NULL; |
| 149 | } |
| 150 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 151 | /* look-up a bvc by its Location Area Code (LAC) */ |
| 152 | /* FIXME: this doesn't make sense, as LAC can span multiple bvcs! */ |
| 153 | struct gbproxy_bvc *gbproxy_bvc_by_lac(struct gbproxy_config *cfg, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 154 | const uint8_t *la) |
| 155 | { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 156 | struct gbproxy_nse *nse; |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 157 | int i; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 158 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 159 | hash_for_each(cfg->bss_nses, i, nse, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 160 | struct gbproxy_bvc *bvc; |
| 161 | llist_for_each_entry(bvc, &nse->bvcs, list) { |
| 162 | if (!memcmp(bvc->ra + 3, la + 3, 2)) |
| 163 | return bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 164 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 165 | } |
| 166 | return NULL; |
| 167 | } |
| 168 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 169 | struct gbproxy_bvc *gbproxy_bvc_by_bssgp_tlv(struct gbproxy_config *cfg, |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 170 | struct tlv_parsed *tp) |
| 171 | { |
Harald Welte | 173a182 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 172 | if (TLVP_PRES_LEN(tp, BSSGP_IE_BVCI, 2)) { |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 173 | uint16_t bvci; |
| 174 | |
| 175 | bvci = ntohs(tlvp_val16_unal(tp, BSSGP_IE_BVCI)); |
| 176 | if (bvci >= 2) |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 177 | return gbproxy_bvc_by_bvci(cfg, bvci); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 180 | /* FIXME: this doesn't make sense, as RA can span multiple bvcs! */ |
Harald Welte | 173a182 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 181 | if (TLVP_PRES_LEN(tp, BSSGP_IE_ROUTEING_AREA, 6)) { |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 182 | uint8_t *rai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_ROUTEING_AREA); |
| 183 | /* Only compare LAC part, since MCC/MNC are possibly patched. |
| 184 | * Since the LAC of different BSS must be different when |
| 185 | * MCC/MNC are patched, collisions shouldn't happen. */ |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 186 | return gbproxy_bvc_by_lac(cfg, rai); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 187 | } |
| 188 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 189 | /* FIXME: this doesn't make sense, as LA can span multiple bvcs! */ |
Harald Welte | 173a182 | 2020-12-03 15:36:59 +0100 | [diff] [blame] | 190 | if (TLVP_PRES_LEN(tp, BSSGP_IE_LOCATION_AREA, 5)) { |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 191 | uint8_t *lai = (uint8_t *)TLVP_VAL(tp, BSSGP_IE_LOCATION_AREA); |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 192 | return gbproxy_bvc_by_lac(cfg, lai); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 193 | } |
| 194 | |
| 195 | return NULL; |
| 196 | } |
| 197 | |
| 198 | static void clean_stale_timer_cb(void *data) |
| 199 | { |
| 200 | time_t now; |
| 201 | struct timespec ts = {0,}; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 202 | struct gbproxy_bvc *bvc = (struct gbproxy_bvc *) data; |
| 203 | OSMO_ASSERT(bvc); |
| 204 | OSMO_ASSERT(bvc->nse); |
| 205 | struct gbproxy_config *cfg = bvc->nse->cfg; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 206 | OSMO_ASSERT(cfg); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 207 | |
| 208 | osmo_clock_gettime(CLOCK_MONOTONIC, &ts); |
| 209 | now = ts.tv_sec; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 210 | gbproxy_remove_stale_link_infos(bvc, now); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 211 | if (cfg->clean_stale_timer_freq != 0) |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 212 | osmo_timer_schedule(&bvc->clean_stale_timer, |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 213 | cfg->clean_stale_timer_freq, 0); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 214 | } |
| 215 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 216 | struct gbproxy_bvc *gbproxy_bvc_alloc(struct gbproxy_nse *nse, uint16_t bvci) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 217 | { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 218 | struct gbproxy_bvc *bvc; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 219 | OSMO_ASSERT(nse); |
| 220 | struct gbproxy_config *cfg = nse->cfg; |
| 221 | OSMO_ASSERT(cfg); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 222 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 223 | bvc = talloc_zero(tall_sgsn_ctx, struct gbproxy_bvc); |
| 224 | if (!bvc) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 225 | return NULL; |
| 226 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 227 | bvc->bvci = bvci; |
| 228 | bvc->ctrg = rate_ctr_group_alloc(bvc, &bvc_ctrg_desc, bvci); |
| 229 | if (!bvc->ctrg) { |
| 230 | talloc_free(bvc); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 231 | return NULL; |
| 232 | } |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 233 | bvc->nse = nse; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 234 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 235 | llist_add(&bvc->list, &nse->bvcs); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 236 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 237 | INIT_LLIST_HEAD(&bvc->patch_state.logical_links); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 238 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 239 | osmo_timer_setup(&bvc->clean_stale_timer, clean_stale_timer_cb, bvc); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 240 | if (cfg->clean_stale_timer_freq != 0) |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 241 | osmo_timer_schedule(&bvc->clean_stale_timer, |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 242 | cfg->clean_stale_timer_freq, 0); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 243 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 244 | return bvc; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 245 | } |
| 246 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 247 | void gbproxy_bvc_free(struct gbproxy_bvc *bvc) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 248 | { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 249 | if (!bvc) |
Daniel Willmann | f6a36cc | 2020-12-04 17:38:46 +0100 | [diff] [blame] | 250 | return; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 251 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 252 | llist_del(&bvc->list); |
| 253 | osmo_timer_del(&bvc->clean_stale_timer); |
| 254 | gbproxy_delete_link_infos(bvc); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 255 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 256 | rate_ctr_group_free(bvc->ctrg); |
| 257 | bvc->ctrg = NULL; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 258 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 259 | talloc_free(bvc); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 260 | } |
| 261 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 262 | void gbproxy_bvc_move(struct gbproxy_bvc *bvc, struct gbproxy_nse *nse) |
Daniel Willmann | 559edac | 2020-11-30 17:14:24 +0100 | [diff] [blame] | 263 | { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 264 | llist_del(&bvc->list); |
| 265 | llist_add(&bvc->list, &nse->bvcs); |
| 266 | bvc->nse = nse; |
Daniel Willmann | 559edac | 2020-11-30 17:14:24 +0100 | [diff] [blame] | 267 | } |
| 268 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 269 | /*! remove bvcs (BVCs) on NSE specified by NSEI. |
| 270 | * \param[in] cfg proxy in which we operate |
| 271 | * \param[in] nsei NS entity in which we should clean up |
| 272 | * \param[in] bvci if 0: remove all BVCs; if != 0: BVCI of the single BVC to clean up */ |
| 273 | int gbproxy_cleanup_bvcs(struct gbproxy_config *cfg, uint16_t nsei, uint16_t bvci) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 274 | { |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 275 | int i, counter = 0; |
| 276 | struct gbproxy_nse *nse; |
| 277 | struct hlist_node *ntmp; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 278 | OSMO_ASSERT(cfg); |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 279 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 280 | hash_for_each_safe(cfg->bss_nses, i, ntmp, nse, list) { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 281 | struct gbproxy_bvc *bvc, *tmp; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 282 | if (nse->nsei != nsei) |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 283 | continue; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 284 | llist_for_each_entry_safe(bvc, tmp, &nse->bvcs, list) { |
| 285 | if (bvci && bvc->bvci != bvci) |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 286 | continue; |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 287 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 288 | gbproxy_bvc_free(bvc); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 289 | counter += 1; |
| 290 | } |
Pau Espin Pedrol | 1ddefb1 | 2019-08-30 19:48:34 +0200 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | return counter; |
| 294 | } |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 295 | |
| 296 | struct gbproxy_nse *gbproxy_nse_alloc(struct gbproxy_config *cfg, uint16_t nsei) |
| 297 | { |
| 298 | struct gbproxy_nse *nse; |
| 299 | OSMO_ASSERT(cfg); |
| 300 | |
| 301 | nse = talloc_zero(tall_sgsn_ctx, struct gbproxy_nse); |
| 302 | if (!nse) |
| 303 | return NULL; |
| 304 | |
| 305 | nse->nsei = nsei; |
| 306 | nse->cfg = cfg; |
| 307 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 308 | hash_add(cfg->bss_nses, &nse->list, nsei); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 309 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 310 | INIT_LLIST_HEAD(&nse->bvcs); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 311 | |
| 312 | return nse; |
| 313 | } |
| 314 | |
| 315 | void gbproxy_nse_free(struct gbproxy_nse *nse) |
| 316 | { |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 317 | struct gbproxy_bvc *bvc, *tmp; |
Daniel Willmann | f6a36cc | 2020-12-04 17:38:46 +0100 | [diff] [blame] | 318 | if (!nse) |
| 319 | return; |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 320 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 321 | hash_del(&nse->list); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 322 | |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 323 | llist_for_each_entry_safe(bvc, tmp, &nse->bvcs, list) |
| 324 | gbproxy_bvc_free(bvc); |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 325 | |
| 326 | talloc_free(nse); |
| 327 | } |
| 328 | |
| 329 | struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei) |
| 330 | { |
| 331 | struct gbproxy_nse *nse; |
| 332 | OSMO_ASSERT(cfg); |
| 333 | |
Harald Welte | d2fef95 | 2020-12-05 00:31:07 +0100 | [diff] [blame^] | 334 | hash_for_each_possible(cfg->bss_nses, nse, list, nsei) { |
Daniel Willmann | e50550e | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 335 | if (nse->nsei == nsei) |
| 336 | return nse; |
| 337 | } |
| 338 | |
| 339 | return NULL; |
| 340 | } |
| 341 | |
| 342 | struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei) |
| 343 | { |
| 344 | struct gbproxy_nse *nse; |
| 345 | OSMO_ASSERT(cfg); |
| 346 | |
| 347 | nse = gbproxy_nse_by_nsei(cfg, nsei); |
| 348 | if (!nse) |
| 349 | nse = gbproxy_nse_alloc(cfg, nsei); |
| 350 | |
| 351 | return nse; |
Harald Welte | 560bdb3 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 352 | } |