Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 24 | #include <string.h> |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 25 | #include <time.h> |
Pau Espin Pedrol | 67f1d1e | 2018-08-16 12:11:46 +0200 | [diff] [blame] | 26 | #include <inttypes.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 27 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 28 | #include <osmocom/core/hashtable.h> |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/talloc.h> |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 30 | #include <osmocom/core/timer.h> |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 31 | #include <osmocom/core/rate_ctr.h> |
Daniel Willmann | dee0bcc | 2020-12-28 18:07:27 +0100 | [diff] [blame] | 32 | #include <osmocom/core/utils.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 33 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 34 | #include <osmocom/gprs/gprs_ns2.h> |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 35 | #include <osmocom/gprs/bssgp_bvc_fsm.h> |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 36 | |
Harald Welte | 7e82b74 | 2017-08-12 13:43:54 +0200 | [diff] [blame] | 37 | #include <osmocom/gsm/apn.h> |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 38 | #include <osmocom/gsm/gsm23236.h> |
| 39 | #include <osmocom/gsm/gsm48.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 40 | |
Neels Hofmeyr | 396f2e6 | 2017-09-04 15:13:25 +0200 | [diff] [blame] | 41 | #include <osmocom/sgsn/debug.h> |
| 42 | #include <osmocom/sgsn/gb_proxy.h> |
| 43 | #include <osmocom/sgsn/gprs_utils.h> |
| 44 | #include <osmocom/sgsn/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 45 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 46 | #include <osmocom/vty/command.h> |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 47 | #include <osmocom/vty/logging.h> |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 48 | #include <osmocom/vty/vty.h> |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 49 | #include <osmocom/vty/misc.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 50 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 51 | #define NRI_STR "Mapping of Network Resource Indicators to this SGSN, for SGSN pooling\n" |
| 52 | #define NULL_NRI_STR "Define NULL-NRI values that cause re-assignment of an MS to a different SGSN, for SGSN pooling.\n" |
| 53 | #define NRI_FIRST_LAST_STR "First value of the NRI value range, should not surpass the configured 'nri bitlen'.\n" \ |
| 54 | "Last value of the NRI value range, should not surpass the configured 'nri bitlen' and be larger than the" \ |
| 55 | " first value; if omitted, apply only the first value.\n" |
| 56 | #define NRI_ARGS_TO_STR_FMT "%s%s%s" |
| 57 | #define NRI_ARGS_TO_STR_ARGS(ARGC, ARGV) ARGV[0], (ARGC>1)? ".." : "", (ARGC>1)? ARGV[1] : "" |
| 58 | #define NRI_WARN(SGSN, FORMAT, args...) do { \ |
| 59 | vty_out(vty, "%% Warning: NSE(%05d/SGSN): " FORMAT "%s", (SGSN)->nse->nsei, ##args, VTY_NEWLINE); \ |
| 60 | LOGP(DLBSSGP, LOGL_ERROR, "NSE(%05d/SGSN): " FORMAT "\n", (SGSN)->nse->nsei, ##args); \ |
| 61 | } while (0) |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 62 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 63 | static struct gbproxy_config *g_cfg = NULL; |
| 64 | |
| 65 | /* |
Pau Espin Pedrol | 94998fa | 2018-06-20 23:55:22 +0200 | [diff] [blame] | 66 | * vty code for gbproxy below |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 67 | */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 68 | static struct cmd_node gbproxy_node = { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 69 | GBPROXY_NODE, |
Harald Welte | 570ce24 | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 70 | "%s(config-gbproxy)# ", |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 71 | 1, |
| 72 | }; |
| 73 | |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 74 | static void gbprox_vty_print_bvc(struct vty *vty, struct gbproxy_bvc *bvc) |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 75 | { |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 76 | |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 77 | if (bvc->bvci == 0) { |
| 78 | vty_out(vty, "NSEI %5u, SIG-BVCI %5u [%s]%s", bvc->nse->nsei, bvc->bvci, |
| 79 | osmo_fsm_inst_state_name(bvc->fi), VTY_NEWLINE); |
| 80 | } else { |
| 81 | struct gprs_ra_id raid; |
| 82 | gsm48_parse_ra(&raid, bvc->ra); |
| 83 | vty_out(vty, "NSEI %5u, PTP-BVCI %5u, RAI %s [%s]%s", bvc->nse->nsei, bvc->bvci, |
| 84 | osmo_rai_name(&raid), osmo_fsm_inst_state_name(bvc->fi), VTY_NEWLINE); |
| 85 | } |
| 86 | } |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 87 | |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 88 | static void gbproxy_vty_print_nse(struct vty *vty, struct gbproxy_nse *nse, bool show_stats) |
| 89 | { |
| 90 | struct gbproxy_bvc *bvc; |
| 91 | int j; |
| 92 | |
| 93 | hash_for_each(nse->bvcs, j, bvc, list) { |
| 94 | gbprox_vty_print_bvc(vty, bvc); |
| 95 | |
| 96 | if (show_stats) |
| 97 | vty_out_rate_ctr_group(vty, " ", bvc->ctrg); |
| 98 | } |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 99 | } |
| 100 | |
Harald Welte | 5a21f07 | 2020-12-12 15:16:43 +0100 | [diff] [blame] | 101 | static void gbproxy_vty_print_cell(struct vty *vty, struct gbproxy_cell *cell, bool show_stats) |
| 102 | { |
| 103 | struct gprs_ra_id raid; |
| 104 | gsm48_parse_ra(&raid, cell->ra); |
| 105 | unsigned int num_sgsn_bvc = 0; |
| 106 | unsigned int i; |
| 107 | |
| 108 | vty_out(vty, "BVCI %5u RAI %s: ", cell->bvci, osmo_rai_name(&raid)); |
| 109 | if (cell->bss_bvc) |
| 110 | vty_out(vty, "BSS NSEI %5u, SGSN NSEI ", cell->bss_bvc->nse->nsei); |
| 111 | else |
| 112 | vty_out(vty, "BSS NSEI <none>, SGSN NSEI "); |
| 113 | |
| 114 | for (i = 0; i < ARRAY_SIZE(cell->sgsn_bvc); i++) { |
| 115 | struct gbproxy_bvc *sgsn_bvc = cell->sgsn_bvc[i]; |
| 116 | if (sgsn_bvc) { |
| 117 | vty_out(vty, "%5u ", sgsn_bvc->nse->nsei); |
| 118 | num_sgsn_bvc++; |
| 119 | } |
| 120 | } |
| 121 | if (num_sgsn_bvc) |
| 122 | vty_out(vty, "%s", VTY_NEWLINE); |
| 123 | else |
| 124 | vty_out(vty, "<none>%s", VTY_NEWLINE); |
| 125 | } |
| 126 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 127 | static int config_write_gbproxy(struct vty *vty) |
| 128 | { |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 129 | struct osmo_nri_range *r; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 130 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 131 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 132 | |
Harald Welte | 9e91764 | 2020-12-12 19:02:16 +0100 | [diff] [blame] | 133 | if (g_cfg->pool.bvc_fc_ratio != 100) |
| 134 | vty_out(vty, " pool bvc-flow-control-ratio %u%s", g_cfg->pool.bvc_fc_ratio, VTY_NEWLINE); |
| 135 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 136 | if (g_cfg->pool.nri_bitlen != OSMO_NRI_BITLEN_DEFAULT) |
| 137 | vty_out(vty, " nri bitlen %u%s", g_cfg->pool.nri_bitlen, VTY_NEWLINE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 138 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 139 | llist_for_each_entry(r, &g_cfg->pool.null_nri_ranges->entries, entry) { |
| 140 | vty_out(vty, " nri null add %d", r->first); |
| 141 | if (r->first != r->last) |
| 142 | vty_out(vty, " %d", r->last); |
| 143 | vty_out(vty, "%s", VTY_NEWLINE); |
| 144 | } |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 145 | return CMD_SUCCESS; |
| 146 | } |
| 147 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 148 | DEFUN(cfg_gbproxy, |
| 149 | cfg_gbproxy_cmd, |
| 150 | "gbproxy", |
| 151 | "Configure the Gb proxy") |
| 152 | { |
| 153 | vty->node = GBPROXY_NODE; |
| 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 157 | /* VTY code for SGSN (pool) configuration */ |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 158 | extern const struct bssgp_bvc_fsm_ops sgsn_sig_bvc_fsm_ops; |
| 159 | #include <osmocom/gprs/protocol/gsm_08_18.h> |
| 160 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 161 | static struct cmd_node sgsn_node = { |
| 162 | SGSN_NODE, |
| 163 | "%s(config-sgsn)# ", |
| 164 | 1, |
| 165 | }; |
| 166 | |
| 167 | static void sgsn_write_nri(struct vty *vty, struct gbproxy_sgsn *sgsn, bool verbose) |
| 168 | { |
| 169 | struct osmo_nri_range *r; |
| 170 | |
| 171 | if (verbose) { |
| 172 | vty_out(vty, "sgsn nsei %d%s", sgsn->nse->nsei, VTY_NEWLINE); |
| 173 | if (llist_empty(&sgsn->pool.nri_ranges->entries)) { |
| 174 | vty_out(vty, " %% no NRI mappings%s", VTY_NEWLINE); |
| 175 | return; |
| 176 | } |
| 177 | } |
| 178 | |
| 179 | llist_for_each_entry(r, &sgsn->pool.nri_ranges->entries, entry) { |
| 180 | if (osmo_nri_range_validate(r, 255)) |
| 181 | vty_out(vty, " %% INVALID RANGE:"); |
| 182 | vty_out(vty, " nri add %d", r->first); |
| 183 | if (r->first != r->last) |
| 184 | vty_out(vty, " %d", r->last); |
| 185 | vty_out(vty, "%s", VTY_NEWLINE); |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | static void write_sgsn(struct vty *vty, struct gbproxy_sgsn *sgsn) |
| 190 | { |
| 191 | vty_out(vty, "sgsn nsei %u%s", sgsn->nse->nsei, VTY_NEWLINE); |
Daniel Willmann | dee0bcc | 2020-12-28 18:07:27 +0100 | [diff] [blame] | 192 | vty_out(vty, " name %s%s", sgsn->name, VTY_NEWLINE); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 193 | vty_out(vty, " %sallow-attach%s", sgsn->pool.allow_attach ? "" : "no ", VTY_NEWLINE); |
| 194 | sgsn_write_nri(vty, sgsn, false); |
| 195 | } |
| 196 | |
| 197 | static int config_write_sgsn(struct vty *vty) |
| 198 | { |
| 199 | struct gbproxy_sgsn *sgsn; |
| 200 | |
| 201 | llist_for_each_entry(sgsn, &g_cfg->sgsns, list) |
| 202 | write_sgsn(vty, sgsn); |
| 203 | |
| 204 | return CMD_SUCCESS; |
| 205 | } |
| 206 | |
| 207 | DEFUN(cfg_sgsn_nsei, |
| 208 | cfg_sgsn_nsei_cmd, |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 209 | "sgsn nsei <0-65534>", |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 210 | "Configure the SGSN\n" |
Holger Hans Peter Freyther | 2eb6e2c | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 211 | "NSEI to be used in the connection with the SGSN\n" |
| 212 | "The NSEI\n") |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 213 | { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 214 | uint32_t features = 0; // FIXME: make configurable |
Jacob Erlbeck | cc8856f | 2014-10-08 13:37:28 +0200 | [diff] [blame] | 215 | unsigned int nsei = atoi(argv[0]); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 216 | unsigned int num_sgsn = llist_count(&g_cfg->sgsns); |
| 217 | struct gbproxy_sgsn *sgsn; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 218 | struct gbproxy_nse *nse; |
| 219 | struct gbproxy_bvc *bvc; |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 220 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 221 | if (num_sgsn >= GBPROXY_MAX_NR_SGSN) { |
| 222 | vty_out(vty, "%% Too many SGSN NSE defined (%d), increase GBPROXY_MAX_NR_SGSN%s", |
| 223 | num_sgsn, VTY_NEWLINE); |
| 224 | return CMD_WARNING; |
| 225 | } |
| 226 | |
| 227 | /* This will have created the gbproxy_nse as well */ |
| 228 | sgsn = gbproxy_sgsn_by_nsei_or_new(g_cfg, nsei); |
| 229 | if (!sgsn) |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 230 | goto free_nothing; |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 231 | nse = sgsn->nse; |
| 232 | if (num_sgsn > 1 && g_cfg->pool.nri_bitlen == 0) |
| 233 | vty_out(vty, "%% Multiple SGSNs defined, but no pooling enabled%s", VTY_NEWLINE); |
| 234 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 235 | |
| 236 | if (!gbproxy_bvc_by_bvci(nse, 0)) { |
| 237 | uint8_t cause = BSSGP_CAUSE_OML_INTERV; |
| 238 | bvc = gbproxy_bvc_alloc(nse, 0); |
| 239 | if (!bvc) |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 240 | goto free_sgsn; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 241 | bvc->fi = bssgp_bvc_fsm_alloc_sig_bss(bvc, nse->cfg->nsi, nsei, features); |
| 242 | if (!bvc->fi) |
| 243 | goto free_bvc; |
| 244 | bssgp_bvc_fsm_set_ops(bvc->fi, &sgsn_sig_bvc_fsm_ops, bvc); |
| 245 | osmo_fsm_inst_dispatch(bvc->fi, BSSGP_BVCFSM_E_REQ_RESET, &cause); |
| 246 | } |
| 247 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 248 | vty->node = SGSN_NODE; |
| 249 | vty->index = sgsn; |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 250 | return CMD_SUCCESS; |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 251 | |
| 252 | free_bvc: |
| 253 | gbproxy_bvc_free(bvc); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 254 | free_sgsn: |
| 255 | gbproxy_sgsn_free(sgsn); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 256 | free_nothing: |
| 257 | vty_out(vty, "%% Unable to create NSE for NSEI=%05u%s", nsei, VTY_NEWLINE); |
| 258 | return CMD_WARNING; |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 259 | } |
| 260 | |
Daniel Willmann | dee0bcc | 2020-12-28 18:07:27 +0100 | [diff] [blame] | 261 | DEFUN(cfg_sgsn_name, |
| 262 | cfg_sgsn_name_cmd, |
| 263 | "name NAME", |
| 264 | "Configure the SGSN\n" |
| 265 | "Name the SGSN\n" |
| 266 | "The name\n") |
| 267 | { |
| 268 | struct gbproxy_sgsn *sgsn = vty->index; |
| 269 | const char *name = argv[0]; |
| 270 | |
| 271 | |
| 272 | osmo_talloc_replace_string(sgsn, &sgsn->name, name); |
| 273 | if (!sgsn->name) { |
| 274 | vty_out(vty, "%% Unable to set name for SGSN with nsei %05u%s", sgsn->nse->nsei, VTY_NEWLINE); |
| 275 | return CMD_WARNING; |
| 276 | } |
| 277 | |
| 278 | return CMD_SUCCESS; |
| 279 | } |
| 280 | |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 281 | DEFUN_ATTR(cfg_sgsn_nri_add, cfg_sgsn_nri_add_cmd, |
| 282 | "nri add <0-32767> [<0-32767>]", |
| 283 | NRI_STR "Add NRI value or range to the NRI mapping for this MSC\n" |
| 284 | NRI_FIRST_LAST_STR, |
| 285 | CMD_ATTR_IMMEDIATE) |
| 286 | { |
| 287 | struct gbproxy_sgsn *sgsn = vty->index; |
| 288 | struct gbproxy_sgsn *other_sgsn; |
| 289 | bool before; |
| 290 | int rc; |
| 291 | const char *message; |
| 292 | struct osmo_nri_range add_range; |
| 293 | |
| 294 | rc = osmo_nri_ranges_vty_add(&message, &add_range, sgsn->pool.nri_ranges, argc, argv, g_cfg->pool.nri_bitlen); |
| 295 | if (message) { |
| 296 | NRI_WARN(sgsn, "%s: " NRI_ARGS_TO_STR_FMT, message, NRI_ARGS_TO_STR_ARGS(argc, argv)); |
| 297 | } |
| 298 | if (rc < 0) |
| 299 | return CMD_WARNING; |
| 300 | |
| 301 | /* Issue a warning about NRI range overlaps (but still allow them). |
| 302 | * Overlapping ranges will map to whichever SGSN comes fist in the gbproxy_config->sgsns llist, |
| 303 | * which should be the first one defined in the config */ |
| 304 | before = true; |
| 305 | |
| 306 | llist_for_each_entry(other_sgsn, &g_cfg->sgsns, list) { |
| 307 | if (other_sgsn == sgsn) { |
| 308 | before = false; |
| 309 | continue; |
| 310 | } |
| 311 | if (osmo_nri_range_overlaps_ranges(&add_range, other_sgsn->pool.nri_ranges)) { |
| 312 | uint16_t nsei = sgsn->nse->nsei; |
| 313 | uint16_t other_nsei = other_sgsn->nse->nsei; |
| 314 | NRI_WARN(sgsn, "NRI range [%d..%d] overlaps between NSE %05d and NSE %05d." |
| 315 | " For overlaps, NSE %05d has higher priority than NSE %05d", |
| 316 | add_range.first, add_range.last, nsei, other_nsei, |
| 317 | before ? other_nsei : nsei, before ? nsei : other_nsei); |
| 318 | } |
| 319 | } |
| 320 | return CMD_SUCCESS; |
| 321 | } |
| 322 | |
| 323 | DEFUN_ATTR(cfg_sgsn_nri_del, cfg_sgsn_nri_del_cmd, |
| 324 | "nri del <0-32767> [<0-32767>]", |
| 325 | NRI_STR "Remove NRI value or range from the NRI mapping for this MSC\n" |
| 326 | NRI_FIRST_LAST_STR, |
| 327 | CMD_ATTR_IMMEDIATE) |
| 328 | { |
| 329 | struct gbproxy_sgsn *sgsn = vty->index; |
| 330 | int rc; |
| 331 | const char *message; |
| 332 | |
| 333 | rc = osmo_nri_ranges_vty_del(&message, NULL, sgsn->pool.nri_ranges, argc, argv); |
| 334 | if (message) { |
| 335 | NRI_WARN(sgsn, "%s: " NRI_ARGS_TO_STR_FMT, message, NRI_ARGS_TO_STR_ARGS(argc, argv)); |
| 336 | } |
| 337 | if (rc < 0) |
| 338 | return CMD_WARNING; |
| 339 | return CMD_SUCCESS; |
| 340 | } |
| 341 | |
| 342 | DEFUN_ATTR(cfg_sgsn_allow_attach, cfg_sgsn_allow_attach_cmd, |
| 343 | "allow-attach", |
| 344 | "Allow this SGSN to attach new subscribers (default).\n", |
| 345 | CMD_ATTR_IMMEDIATE) |
| 346 | { |
| 347 | struct gbproxy_sgsn *sgsn = vty->index; |
| 348 | sgsn->pool.allow_attach = true; |
| 349 | return CMD_SUCCESS; |
| 350 | } |
| 351 | |
| 352 | DEFUN_ATTR(cfg_sgsn_no_allow_attach, cfg_sgsn_no_allow_attach_cmd, |
| 353 | "no allow-attach", |
| 354 | NO_STR |
| 355 | "Do not assign new subscribers to this MSC." |
| 356 | " Useful if an MSC in an MSC pool is configured to off-load subscribers." |
| 357 | " The MSC will still be operational for already IMSI-Attached subscribers," |
| 358 | " but the NAS node selection function will skip this MSC for new subscribers\n", |
| 359 | CMD_ATTR_IMMEDIATE) |
| 360 | { |
| 361 | struct gbproxy_sgsn *sgsn = vty->index; |
| 362 | sgsn->pool.allow_attach = false; |
| 363 | return CMD_SUCCESS; |
| 364 | } |
| 365 | |
| 366 | DEFUN(cfg_sgsn_show_nri_all, show_nri_all_cmd, |
| 367 | "show nri all", |
| 368 | SHOW_STR NRI_STR "Show all SGSNs\n") |
| 369 | { |
| 370 | struct gbproxy_sgsn *sgsn; |
| 371 | |
| 372 | llist_for_each_entry(sgsn, &g_cfg->sgsns, list) |
| 373 | sgsn_write_nri(vty, sgsn, true); |
| 374 | |
| 375 | return CMD_SUCCESS; |
| 376 | } |
| 377 | |
| 378 | DEFUN(show_nri, show_nri_nsei_cmd, |
| 379 | "show nri nsei <0-65535>", |
| 380 | SHOW_STR NRI_STR "Identify SGSN by NSEI\n" |
| 381 | "NSEI of the SGSN\n") |
| 382 | { |
| 383 | struct gbproxy_sgsn *sgsn; |
| 384 | int nsei = atoi(argv[0]); |
| 385 | |
| 386 | sgsn = gbproxy_sgsn_by_nsei(g_cfg, nsei); |
| 387 | if (!sgsn) { |
| 388 | vty_out(vty, "%% No SGSN with found for NSEI %05d%s", nsei, VTY_NEWLINE); |
| 389 | return CMD_SUCCESS; |
| 390 | } |
| 391 | sgsn_write_nri(vty, sgsn, true); |
| 392 | |
| 393 | return CMD_SUCCESS; |
| 394 | } |
| 395 | |
Harald Welte | 9e91764 | 2020-12-12 19:02:16 +0100 | [diff] [blame] | 396 | DEFUN(cfg_pool_bvc_fc_ratio, |
| 397 | cfg_pool_bvc_fc_ratio_cmd, |
| 398 | "pool bvc-flow-control-ratio <1-100>", |
| 399 | "SGSN Pool related configuration\n" |
| 400 | "Ratio of BSS-advertised bucket size + leak rate advertised to each SGSN\n" |
| 401 | "Ratio of BSS-advertised bucket size + leak rate advertised to each SGSN (Percent)\n") |
| 402 | { |
| 403 | g_cfg->pool.bvc_fc_ratio = atoi(argv[0]); |
| 404 | return CMD_SUCCESS; |
| 405 | } |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 406 | DEFUN_ATTR(cfg_gbproxy_nri_bitlen, |
| 407 | cfg_gbproxy_nri_bitlen_cmd, |
| 408 | "nri bitlen <0-15>", |
| 409 | NRI_STR |
| 410 | "Set number of bits that an NRI has, to extract from TMSI identities (always starting just after the TMSI's most significant octet).\n" |
| 411 | "bit count (0 disables) pooling)\n", |
| 412 | CMD_ATTR_IMMEDIATE) |
| 413 | { |
| 414 | g_cfg->pool.nri_bitlen = atoi(argv[0]); |
| 415 | |
| 416 | if (llist_count(&g_cfg->sgsns) > 1 && g_cfg->pool.nri_bitlen == 0) |
| 417 | vty_out(vty, "%% Pooling disabled, but multiple SGSNs defined%s", VTY_NEWLINE); |
| 418 | |
| 419 | /* TODO: Verify all nri ranges and warn on mismatch */ |
| 420 | |
| 421 | return CMD_SUCCESS; |
| 422 | } |
| 423 | |
| 424 | DEFUN_ATTR(cfg_gbproxy_nri_null_add, |
| 425 | cfg_gbproxy_nri_null_add_cmd, |
| 426 | "nri null add <0-32767> [<0-32767>]", |
| 427 | NRI_STR NULL_NRI_STR "Add NULL-NRI value (or range)\n" |
| 428 | NRI_FIRST_LAST_STR, |
| 429 | CMD_ATTR_IMMEDIATE) |
| 430 | { |
| 431 | int rc; |
| 432 | const char *message; |
| 433 | |
| 434 | rc = osmo_nri_ranges_vty_add(&message, NULL, g_cfg->pool.null_nri_ranges, argc, argv, |
| 435 | g_cfg->pool.nri_bitlen); |
| 436 | if (message) { |
| 437 | vty_out(vty, "%% nri null add: %s: " NRI_ARGS_TO_STR_FMT "%s", message, NRI_ARGS_TO_STR_ARGS(argc, argv), |
| 438 | VTY_NEWLINE); |
| 439 | vty_out(vty, "%s: \n" NRI_ARGS_TO_STR_FMT, message, NRI_ARGS_TO_STR_ARGS(argc, argv)); |
| 440 | } |
| 441 | if (rc < 0) |
| 442 | return CMD_WARNING; |
| 443 | return CMD_SUCCESS; |
| 444 | } |
| 445 | |
| 446 | DEFUN_ATTR(cfg_gbproxy_nri_null_del, |
| 447 | cfg_gbproxy_nri_null_del_cmd, |
| 448 | "nri null del <0-32767> [<0-32767>]", |
| 449 | NRI_STR NULL_NRI_STR "Remove NRI value or range from the NRI mapping for this MSC\n" |
| 450 | NRI_FIRST_LAST_STR, |
| 451 | CMD_ATTR_IMMEDIATE) |
| 452 | { |
| 453 | int rc; |
| 454 | const char *message; |
| 455 | rc = osmo_nri_ranges_vty_del(&message, NULL, g_cfg->pool.null_nri_ranges, argc, argv); |
| 456 | if (message) { |
| 457 | vty_out(vty, "%% %s: " NRI_ARGS_TO_STR_FMT "%s", message, NRI_ARGS_TO_STR_ARGS(argc, argv), |
| 458 | VTY_NEWLINE); |
| 459 | } |
| 460 | if (rc < 0) |
| 461 | return CMD_WARNING; |
| 462 | return CMD_SUCCESS; |
| 463 | } |
Harald Welte | 9e91764 | 2020-12-12 19:02:16 +0100 | [diff] [blame] | 464 | |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 465 | static void log_set_bvc_filter(struct log_target *target, |
| 466 | const uint16_t *bvci) |
| 467 | { |
| 468 | if (bvci) { |
| 469 | uintptr_t bvci_filter = *bvci | BVC_LOG_CTX_FLAG; |
| 470 | target->filter_map |= (1 << LOG_FLT_GB_BVC); |
| 471 | target->filter_data[LOG_FLT_GB_BVC] = (void *)bvci_filter; |
| 472 | } else if (target->filter_data[LOG_FLT_GB_BVC]) { |
| 473 | target->filter_map = ~(1 << LOG_FLT_GB_BVC); |
| 474 | target->filter_data[LOG_FLT_GB_BVC] = NULL; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | DEFUN(logging_fltr_bvc, |
| 479 | logging_fltr_bvc_cmd, |
| 480 | "logging filter bvc bvci <0-65535>", |
| 481 | LOGGING_STR FILTER_STR |
| 482 | "Filter based on BSSGP VC\n" |
| 483 | "Identify BVC by BVCI\n" |
| 484 | "Numeric identifier\n") |
| 485 | { |
| 486 | struct log_target *tgt; |
| 487 | uint16_t id = atoi(argv[0]); |
| 488 | |
| 489 | log_tgt_mutex_lock(); |
| 490 | tgt = osmo_log_vty2tgt(vty); |
| 491 | if (!tgt) { |
| 492 | log_tgt_mutex_unlock(); |
| 493 | return CMD_WARNING; |
| 494 | } |
| 495 | |
| 496 | log_set_bvc_filter(tgt, &id); |
| 497 | log_tgt_mutex_unlock(); |
| 498 | return CMD_SUCCESS; |
| 499 | } |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 500 | |
Harald Welte | b6b2f14 | 2020-12-12 15:15:34 +0100 | [diff] [blame] | 501 | DEFUN(show_gbproxy_bvc, show_gbproxy_bvc_cmd, "show gbproxy bvc (bss|sgsn) [stats]", |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 502 | SHOW_STR "Display information about the Gb proxy\n" |
Harald Welte | b6b2f14 | 2020-12-12 15:15:34 +0100 | [diff] [blame] | 503 | "Show BSSGP Virtual Connections\n" |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 504 | "Display BSS-side BVCs\n" |
| 505 | "Display SGSN-side BVCs\n" |
| 506 | "Show statistics\n") |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 507 | { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 508 | struct gbproxy_nse *nse; |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 509 | bool show_stats = argc >= 2; |
| 510 | int i; |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 511 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 512 | if (show_stats) |
Holger Hans Peter Freyther | eece627 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 513 | vty_out_rate_ctr_group(vty, "", g_cfg->ctrg); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 514 | |
Harald Welte | 959f77e | 2020-12-12 14:17:51 +0100 | [diff] [blame] | 515 | if (!strcmp(argv[0], "bss")) { |
| 516 | hash_for_each(g_cfg->bss_nses, i, nse, list) |
| 517 | gbproxy_vty_print_nse(vty, nse, show_stats); |
| 518 | } else { |
| 519 | hash_for_each(g_cfg->sgsn_nses, i, nse, list) |
| 520 | gbproxy_vty_print_nse(vty, nse, show_stats); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 521 | } |
| 522 | return CMD_SUCCESS; |
| 523 | } |
| 524 | |
Harald Welte | 5a21f07 | 2020-12-12 15:16:43 +0100 | [diff] [blame] | 525 | DEFUN(show_gbproxy_cell, show_gbproxy_cell_cmd, "show gbproxy cell [stats]", |
| 526 | SHOW_STR "Display information about the Gb proxy\n" |
| 527 | "Show GPRS Cell Information\n" |
| 528 | "Show statistics\n") |
| 529 | { |
| 530 | struct gbproxy_cell *cell; |
| 531 | bool show_stats = argc >= 1; |
| 532 | int i; |
| 533 | |
| 534 | hash_for_each(g_cfg->cells, i, cell, list) |
| 535 | gbproxy_vty_print_cell(vty, cell, show_stats); |
| 536 | |
| 537 | return CMD_SUCCESS; |
| 538 | } |
| 539 | |
Jacob Erlbeck | d4c79a4 | 2014-09-19 15:36:44 +0200 | [diff] [blame] | 540 | DEFUN(show_gbproxy_links, show_gbproxy_links_cmd, "show gbproxy links", |
| 541 | SHOW_STR "Display information about the Gb proxy\n" "Show logical links\n") |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 542 | { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 543 | struct gbproxy_nse *nse; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 544 | int i, j; |
Jacob Erlbeck | c6807c4 | 2014-09-19 16:34:01 +0200 | [diff] [blame] | 545 | |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 546 | hash_for_each(g_cfg->bss_nses, i, nse, list) { |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 547 | struct gbproxy_bvc *bvc; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 548 | hash_for_each(nse->bvcs, j, bvc, list) { |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 549 | gbprox_vty_print_bvc(vty, bvc); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 550 | } |
| 551 | } |
| 552 | return CMD_SUCCESS; |
| 553 | } |
| 554 | |
| 555 | DEFUN(delete_gb_bvci, delete_gb_bvci_cmd, |
| 556 | "delete-gbproxy-peer <0-65534> bvci <2-65534>", |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 557 | "Delete a GBProxy bvc by NSEI and optionally BVCI\n" |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 558 | "NSEI number\n" |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 559 | "Only delete bvc with a matching BVCI\n" |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 560 | "BVCI number\n") |
| 561 | { |
| 562 | const uint16_t nsei = atoi(argv[0]); |
| 563 | const uint16_t bvci = atoi(argv[1]); |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 564 | struct gbproxy_nse *nse = gbproxy_nse_by_nsei(g_cfg, nsei, NSE_F_BSS); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 565 | int counter; |
| 566 | |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 567 | if (!nse) { |
| 568 | vty_out(vty, "NSE not found%s", VTY_NEWLINE); |
| 569 | return CMD_WARNING; |
| 570 | } |
| 571 | |
| 572 | counter = gbproxy_cleanup_bvcs(nse, bvci); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 573 | |
| 574 | if (counter == 0) { |
| 575 | vty_out(vty, "BVC not found%s", VTY_NEWLINE); |
| 576 | return CMD_WARNING; |
| 577 | } |
| 578 | |
| 579 | return CMD_SUCCESS; |
| 580 | } |
| 581 | |
| 582 | DEFUN(delete_gb_nsei, delete_gb_nsei_cmd, |
| 583 | "delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]", |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 584 | "Delete a GBProxy bvc by NSEI and optionally BVCI\n" |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 585 | "NSEI number\n" |
| 586 | "Only delete BSSGP connections (BVC)\n" |
| 587 | "Only delete dynamic NS connections (NS-VC)\n" |
| 588 | "Delete BVC and dynamic NS connections\n" |
| 589 | "Show what would be deleted instead of actually deleting\n" |
| 590 | ) |
| 591 | { |
| 592 | const uint16_t nsei = atoi(argv[0]); |
| 593 | const char *mode = argv[1]; |
| 594 | int dry_run = argc > 2; |
| 595 | int delete_bvc = 0; |
| 596 | int delete_nsvc = 0; |
| 597 | int counter; |
| 598 | |
| 599 | if (strcmp(mode, "only-bvc") == 0) |
| 600 | delete_bvc = 1; |
| 601 | else if (strcmp(mode, "only-nsvc") == 0) |
| 602 | delete_nsvc = 1; |
| 603 | else |
| 604 | delete_bvc = delete_nsvc = 1; |
| 605 | |
| 606 | if (delete_bvc) { |
Daniel Willmann | 9a2fc90 | 2020-12-04 17:43:27 +0100 | [diff] [blame] | 607 | if (!dry_run) { |
Harald Welte | 5687ae6 | 2020-12-05 19:59:45 +0100 | [diff] [blame] | 608 | struct gbproxy_nse *nse = gbproxy_nse_by_nsei(g_cfg, nsei, NSE_F_BSS); |
| 609 | counter = gbproxy_cleanup_bvcs(nse, 0); |
Daniel Willmann | 9a2fc90 | 2020-12-04 17:43:27 +0100 | [diff] [blame] | 610 | gbproxy_nse_free(nse); |
| 611 | } else { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 612 | struct gbproxy_nse *nse; |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 613 | struct gbproxy_bvc *bvc; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 614 | int i, j; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 615 | counter = 0; |
Harald Welte | 78db244 | 2020-12-05 00:31:07 +0100 | [diff] [blame] | 616 | hash_for_each(g_cfg->bss_nses, i, nse, list) { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 617 | if (nse->nsei != nsei) |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 618 | continue; |
Harald Welte | 993d3f4 | 2020-12-05 10:14:49 +0100 | [diff] [blame] | 619 | hash_for_each(nse->bvcs, j, bvc, list) { |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 620 | vty_out(vty, "BVC: "); |
Harald Welte | 8cd7440 | 2020-12-04 22:24:47 +0100 | [diff] [blame] | 621 | gbprox_vty_print_bvc(vty, bvc); |
Daniel Willmann | 447ad44 | 2020-11-26 18:19:21 +0100 | [diff] [blame] | 622 | counter += 1; |
| 623 | } |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 624 | } |
| 625 | } |
| 626 | vty_out(vty, "%sDeleted %d BVC%s", |
| 627 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 628 | } |
| 629 | |
| 630 | if (delete_nsvc) { |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 631 | struct gprs_ns2_inst *nsi = g_cfg->nsi; |
| 632 | struct gprs_ns2_nse *nse; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 633 | |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 634 | nse = gprs_ns2_nse_by_nsei(nsi, nsei); |
| 635 | if (!nse) { |
| 636 | vty_out(vty, "NSEI not found%s", VTY_NEWLINE); |
| 637 | return CMD_WARNING; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 638 | } |
Alexander Couzens | 82182d0 | 2020-09-22 13:21:46 +0200 | [diff] [blame] | 639 | |
| 640 | /* TODO: We should NOT delete a persistent NSEI/NSVC as soon as we can check for these */ |
| 641 | if (!dry_run) |
| 642 | gprs_ns2_free_nse(nse); |
| 643 | |
| 644 | vty_out(vty, "%sDeleted NS-VCs for NSEI %d%s", |
| 645 | dry_run ? "Not " : "", nsei, VTY_NEWLINE); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | return CMD_SUCCESS; |
| 649 | } |
| 650 | |
Daniel Willmann | 3844da9 | 2020-12-27 18:14:39 +0100 | [diff] [blame] | 651 | /* Only for ttcn3 testing */ |
| 652 | DEFUN_HIDDEN(sgsn_pool_nsf_fixed, sgsn_pool_nsf_fixed_cmd, |
| 653 | "sgsn-pool nsf fixed NAME", |
| 654 | "SGSN pooling: load balancing across multiple SGSNs.\n" |
| 655 | "Customize the Network Selection Function.\n" |
| 656 | "Set a fixed SGSN to use (for testing).\n" |
| 657 | "The name of the SGSN to use.\n") |
| 658 | { |
| 659 | const char *name = argv[0]; |
| 660 | struct gbproxy_sgsn *sgsn = gbproxy_sgsn_by_name(g_cfg, name); |
| 661 | |
| 662 | if (!sgsn) { |
| 663 | vty_out(vty, "%% Could not find SGSN with name %s%s", name, VTY_NEWLINE); |
| 664 | return CMD_WARNING; |
| 665 | } |
| 666 | |
| 667 | g_cfg->pool.nsf_override = sgsn; |
| 668 | return CMD_SUCCESS; |
| 669 | } |
| 670 | |
| 671 | DEFUN_HIDDEN(sgsn_pool_nsf_normal, sgsn_pool_nsf_normal_cmd, |
| 672 | "sgsn-pool nsf normal", |
| 673 | "SGSN pooling: load balancing across multiple SGSNs.\n" |
| 674 | "Customize the Network Selection Function.\n" |
| 675 | "Reset the NSF back to regular operation (for testing).\n") |
| 676 | { |
| 677 | g_cfg->pool.nsf_override = NULL; |
| 678 | return CMD_SUCCESS; |
| 679 | } |
| 680 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 681 | int gbproxy_vty_init(void) |
| 682 | { |
Harald Welte | b6b2f14 | 2020-12-12 15:15:34 +0100 | [diff] [blame] | 683 | install_element_ve(&show_gbproxy_bvc_cmd); |
Harald Welte | 5a21f07 | 2020-12-12 15:16:43 +0100 | [diff] [blame] | 684 | install_element_ve(&show_gbproxy_cell_cmd); |
Jacob Erlbeck | d4c79a4 | 2014-09-19 15:36:44 +0200 | [diff] [blame] | 685 | install_element_ve(&show_gbproxy_links_cmd); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 686 | install_element_ve(&show_nri_all_cmd); |
| 687 | install_element_ve(&show_nri_nsei_cmd); |
Daniel Willmann | e8c8ec9 | 2020-12-02 19:33:50 +0100 | [diff] [blame] | 688 | install_element_ve(&logging_fltr_bvc_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 689 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 690 | install_element(ENABLE_NODE, &delete_gb_bvci_cmd); |
| 691 | install_element(ENABLE_NODE, &delete_gb_nsei_cmd); |
Daniel Willmann | 3844da9 | 2020-12-27 18:14:39 +0100 | [diff] [blame] | 692 | install_element(ENABLE_NODE, &sgsn_pool_nsf_fixed_cmd); |
| 693 | install_element(ENABLE_NODE, &sgsn_pool_nsf_normal_cmd); |
Holger Hans Peter Freyther | 90267a9 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 694 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 695 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 696 | install_node(&gbproxy_node, config_write_gbproxy); |
Harald Welte | 9e91764 | 2020-12-12 19:02:16 +0100 | [diff] [blame] | 697 | install_element(GBPROXY_NODE, &cfg_pool_bvc_fc_ratio_cmd); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 698 | install_element(GBPROXY_NODE, &cfg_gbproxy_nri_bitlen_cmd); |
| 699 | install_element(GBPROXY_NODE, &cfg_gbproxy_nri_null_add_cmd); |
| 700 | install_element(GBPROXY_NODE, &cfg_gbproxy_nri_null_del_cmd); |
| 701 | |
| 702 | install_element(CONFIG_NODE, &cfg_sgsn_nsei_cmd); |
| 703 | install_node(&sgsn_node, config_write_sgsn); |
Daniel Willmann | dee0bcc | 2020-12-28 18:07:27 +0100 | [diff] [blame] | 704 | install_element(SGSN_NODE, &cfg_sgsn_name_cmd); |
Daniel Willmann | ef3c9af | 2020-12-14 16:22:39 +0100 | [diff] [blame] | 705 | install_element(SGSN_NODE, &cfg_sgsn_allow_attach_cmd); |
| 706 | install_element(SGSN_NODE, &cfg_sgsn_no_allow_attach_cmd); |
| 707 | install_element(SGSN_NODE, &cfg_sgsn_nri_add_cmd); |
| 708 | install_element(SGSN_NODE, &cfg_sgsn_nri_del_cmd); |
| 709 | |
Holger Hans Peter Freyther | 925504b | 2015-09-24 10:21:40 +0200 | [diff] [blame] | 710 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 711 | return 0; |
| 712 | } |
| 713 | |
| 714 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 715 | { |
| 716 | int rc; |
| 717 | |
| 718 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 719 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 720 | if (rc < 0) { |
| 721 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 722 | return rc; |
| 723 | } |
| 724 | |
| 725 | return 0; |
| 726 | } |