Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1 | /*! \file gprs_ns2_vty.c |
| 2 | * VTY interface for our GPRS Networks Service (NS) implementation. */ |
| 3 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 4 | /* (C) 2020 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 5 | * Author: Alexander Couzens <lynxis@fe80.eu> |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 6 | * (C) 2021 by Harald Welte <laforge@osmocom.org> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 7 | * |
| 8 | * All Rights Reserved |
| 9 | * |
| 10 | * SPDX-License-Identifier: GPL-2.0+ |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 24 | * |
| 25 | */ |
| 26 | |
| 27 | #include <stdlib.h> |
| 28 | #include <unistd.h> |
| 29 | #include <errno.h> |
| 30 | #include <stdint.h> |
| 31 | |
| 32 | #include <arpa/inet.h> |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 33 | #include <net/if.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 34 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 35 | #include <osmocom/core/byteswap.h> |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 36 | #include <osmocom/core/fsm.h> |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 37 | #include <osmocom/core/linuxlist.h> |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 38 | #include <osmocom/core/msgb.h> |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 39 | #include <osmocom/core/osmo_io.h> |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 40 | #include <osmocom/core/rate_ctr.h> |
| 41 | #include <osmocom/core/select.h> |
| 42 | #include <osmocom/core/talloc.h> |
| 43 | #include <osmocom/core/sockaddr_str.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 44 | #include <osmocom/core/socket.h> |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 45 | #include <osmocom/gprs/frame_relay.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 46 | #include <osmocom/gprs/gprs_ns2.h> |
| 47 | #include <osmocom/gsm/tlv.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 48 | #include <osmocom/vty/command.h> |
| 49 | #include <osmocom/vty/logging.h> |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 50 | #include <osmocom/vty/misc.h> |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 51 | #include <osmocom/vty/telnet_interface.h> |
| 52 | #include <osmocom/vty/vty.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 53 | |
| 54 | #include "gprs_ns2_internal.h" |
| 55 | |
Daniel Willmann | cb3e9b5 | 2020-12-02 15:50:22 +0100 | [diff] [blame] | 56 | #define SHOW_NS_STR "Display information about the NS protocol\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 57 | #define NSVCI_STR "NS Virtual Connection ID (NS-VCI)\n" |
| 58 | #define DLCI_STR "Data Link connection identifier\n" |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 59 | |
| 60 | static struct gprs_ns2_inst *vty_nsi = NULL; |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 61 | static struct osmo_fr_network *vty_fr_network = NULL; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 62 | static struct llist_head binds; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 63 | static struct llist_head nses; |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 64 | static struct llist_head ip_sns_default_binds; |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 65 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 66 | struct vty_bind { |
| 67 | struct llist_head list; |
| 68 | const char *name; |
| 69 | enum gprs_ns2_ll ll; |
| 70 | int dscp; |
Harald Welte | d99e4ee | 2021-04-28 19:57:12 +0200 | [diff] [blame] | 71 | uint8_t priority; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 72 | bool accept_ipaccess; |
| 73 | bool accept_sns; |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 74 | uint8_t ip_sns_sig_weight; |
| 75 | uint8_t ip_sns_data_weight; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 76 | }; |
| 77 | |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 78 | struct vty_nse { |
| 79 | struct llist_head list; |
| 80 | uint16_t nsei; |
| 81 | /* list of binds which are valid for this nse. Only IP-SNS uses this |
| 82 | * to allow `no listen ..` in the bind context. So "half" created binds are valid for |
| 83 | * IP-SNS. This allows changing the bind ip without modifying all NSEs afterwards */ |
| 84 | struct llist_head binds; |
| 85 | }; |
| 86 | |
| 87 | /* used by IP-SNS to connect multiple vty_nse_bind to a vty_nse */ |
| 88 | struct vty_nse_bind { |
| 89 | struct llist_head list; |
| 90 | struct vty_bind *vbind; |
| 91 | }; |
| 92 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 93 | /* TODO: this should into osmo timer */ |
arehbein | 8000647 | 2023-12-10 20:52:42 +0100 | [diff] [blame] | 94 | const struct value_string gprs_ns_timer_strs[] = { |
| 95 | { NS_TOUT_TNS_BLOCK, TNS_BLOCK_STR }, |
| 96 | { NS_TOUT_TNS_BLOCK_RETRIES, TNS_BLOCK_RETRIES_STR }, |
| 97 | { NS_TOUT_TNS_RESET, TNS_RESET_STR }, |
| 98 | { NS_TOUT_TNS_RESET_RETRIES, TNS_RESET_RETRIES_STR }, |
| 99 | { NS_TOUT_TNS_TEST, TNS_TEST_STR }, |
| 100 | { NS_TOUT_TNS_ALIVE, TNS_ALIVE_STR }, |
| 101 | { NS_TOUT_TNS_ALIVE_RETRIES, TNS_ALIVE_RETRIES_STR }, |
| 102 | { NS_TOUT_TSNS_PROV, TSNS_PROV_STR }, |
| 103 | { NS_TOUT_TSNS_SIZE_RETRIES, TSNS_SIZE_RETRIES_STR }, |
| 104 | { NS_TOUT_TSNS_CONFIG_RETRIES, TSNS_CONFIG_RETRIES_STR }, |
| 105 | { NS_TOUT_TSNS_PROCEDURES_RETRIES, TSNS_PROCEDURES_RETRIES_STR }, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 106 | { 0, NULL } |
| 107 | }; |
| 108 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 109 | const struct value_string vty_fr_role_names[] = { |
| 110 | { FR_ROLE_USER_EQUIPMENT, "fr" }, |
| 111 | { FR_ROLE_NETWORK_EQUIPMENT, "frnet" }, |
| 112 | { 0, NULL } |
| 113 | }; |
| 114 | |
| 115 | const struct value_string vty_ll_names[] = { |
| 116 | { GPRS_NS2_LL_FR, "fr" }, |
| 117 | { GPRS_NS2_LL_FR_GRE, "frgre" }, |
| 118 | { GPRS_NS2_LL_UDP, "udp" }, |
| 119 | { 0, NULL } |
| 120 | }; |
| 121 | |
| 122 | static struct vty_bind *vty_bind_by_name(const char *name) |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 123 | { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 124 | struct vty_bind *vbind; |
| 125 | llist_for_each_entry(vbind, &binds, list) { |
Alexander Couzens | b792173 | 2021-02-12 03:08:42 +0100 | [diff] [blame] | 126 | if (!strcmp(vbind->name, name)) |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 127 | return vbind; |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 128 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 129 | return NULL; |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 132 | static struct vty_bind *vty_bind_alloc(const char *name) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 133 | { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 134 | struct vty_bind *vbind = talloc_zero(vty_nsi, struct vty_bind); |
| 135 | if (!vbind) |
| 136 | return NULL; |
| 137 | |
| 138 | vbind->name = talloc_strdup(vty_nsi, name); |
| 139 | if (!vbind->name) { |
| 140 | talloc_free(vbind); |
| 141 | return NULL; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 142 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 143 | |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 144 | vbind->ip_sns_sig_weight = 1; |
| 145 | vbind->ip_sns_data_weight = 1; |
Alexander Couzens | d5cd8c6 | 2021-06-15 20:59:03 +0200 | [diff] [blame] | 146 | llist_add_tail(&vbind->list, &binds); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 147 | return vbind; |
| 148 | } |
| 149 | |
| 150 | static void vty_bind_free(struct vty_bind *vbind) |
| 151 | { |
| 152 | if (!vbind) |
| 153 | return; |
| 154 | |
| 155 | llist_del(&vbind->list); |
Alexander Couzens | 3e2e4a0 | 2021-02-09 16:15:06 +0100 | [diff] [blame] | 156 | talloc_free(vbind); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 157 | } |
| 158 | |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 159 | static struct vty_nse *vty_nse_by_nsei(uint16_t nsei) |
| 160 | { |
| 161 | struct vty_nse *vnse; |
| 162 | llist_for_each_entry(vnse, &nses, list) { |
| 163 | if (vnse->nsei == nsei) |
| 164 | return vnse; |
| 165 | } |
| 166 | return NULL; |
| 167 | } |
| 168 | |
| 169 | static struct vty_nse *vty_nse_alloc(uint16_t nsei) |
| 170 | { |
| 171 | struct vty_nse *vnse = talloc_zero(vty_nsi, struct vty_nse); |
| 172 | if (!vnse) |
| 173 | return NULL; |
| 174 | |
| 175 | vnse->nsei = nsei; |
| 176 | INIT_LLIST_HEAD(&vnse->binds); |
Alexander Couzens | d5cd8c6 | 2021-06-15 20:59:03 +0200 | [diff] [blame] | 177 | llist_add_tail(&vnse->list, &nses); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 178 | return vnse; |
| 179 | } |
| 180 | |
| 181 | static void vty_nse_free(struct vty_nse *vnse) |
| 182 | { |
| 183 | if (!vnse) |
| 184 | return; |
| 185 | |
| 186 | llist_del(&vnse->list); |
| 187 | /* all vbind of the nse will be freed by talloc */ |
| 188 | talloc_free(vnse); |
| 189 | } |
| 190 | |
| 191 | static int vty_nse_add_vbind(struct vty_nse *vnse, struct vty_bind *vbind) |
| 192 | { |
| 193 | struct vty_nse_bind *vnse_bind; |
| 194 | |
| 195 | if (vbind->ll != GPRS_NS2_LL_UDP) |
| 196 | return -EINVAL; |
| 197 | |
| 198 | llist_for_each_entry(vnse_bind, &vnse->binds, list) { |
| 199 | if (vnse_bind->vbind == vbind) |
| 200 | return -EALREADY; |
| 201 | } |
| 202 | |
| 203 | vnse_bind = talloc(vnse, struct vty_nse_bind); |
| 204 | if (!vnse_bind) |
| 205 | return -ENOMEM; |
| 206 | vnse_bind->vbind = vbind; |
| 207 | |
| 208 | llist_add_tail(&vnse_bind->list, &vnse->binds); |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static int vty_nse_remove_vbind(struct vty_nse *vnse, struct vty_bind *vbind) |
| 213 | { |
| 214 | struct vty_nse_bind *vnse_bind, *tmp; |
| 215 | if (vbind->ll != GPRS_NS2_LL_UDP) |
| 216 | return -EINVAL; |
| 217 | |
| 218 | llist_for_each_entry_safe(vnse_bind, tmp, &vnse->binds, list) { |
| 219 | if (vnse_bind->vbind == vbind) { |
| 220 | llist_del(&vnse_bind->list); |
| 221 | talloc_free(vnse_bind); |
Alexander Couzens | 1559689 | 2021-04-19 03:31:05 +0200 | [diff] [blame] | 222 | return 0; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 223 | } |
| 224 | } |
| 225 | |
| 226 | return -ENOENT; |
| 227 | } |
| 228 | |
| 229 | /* check if the NSE still has SNS configuration */ |
| 230 | static bool vty_nse_check_sns(struct gprs_ns2_nse *nse) { |
| 231 | struct vty_nse *vnse = vty_nse_by_nsei(nse->nsei); |
| 232 | |
| 233 | int count = gprs_ns2_sns_count(nse); |
| 234 | if (count > 0) { |
| 235 | /* there are other sns endpoints */ |
| 236 | return true; |
| 237 | } |
| 238 | |
| 239 | if (!vnse) |
| 240 | return false; |
| 241 | |
| 242 | if (llist_empty(&vnse->binds)) |
| 243 | return false; |
| 244 | |
| 245 | return true; |
| 246 | } |
| 247 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 248 | static struct cmd_node ns_node = { |
| 249 | L_NS_NODE, |
| 250 | "%s(config-ns)# ", |
| 251 | 1, |
| 252 | }; |
| 253 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 254 | DEFUN(cfg_ns, cfg_ns_cmd, |
| 255 | "ns", |
| 256 | "Configure the GPRS Network Service") |
| 257 | { |
| 258 | vty->node = L_NS_NODE; |
| 259 | return CMD_SUCCESS; |
| 260 | } |
| 261 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 262 | DEFUN(cfg_ns_timer, cfg_ns_timer_cmd, |
| 263 | "timer " NS_TIMERS " <0-65535>", |
| 264 | "Network Service Timer\n" |
| 265 | NS_TIMERS_HELP "Timer Value\n") |
| 266 | { |
| 267 | int idx = get_string_value(gprs_ns_timer_strs, argv[0]); |
| 268 | int val = atoi(argv[1]); |
| 269 | |
| 270 | if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout)) |
| 271 | return CMD_WARNING; |
| 272 | |
| 273 | vty_nsi->timeout[idx] = val; |
| 274 | |
| 275 | return CMD_SUCCESS; |
| 276 | } |
| 277 | |
| 278 | DEFUN(cfg_ns_nsei, cfg_ns_nsei_cmd, |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 279 | "nse <0-65535> [ip-sns-role-sgsn]", |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 280 | "Persistent NS Entity\n" |
| 281 | "NS Entity ID (NSEI)\n" |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 282 | "Create NSE in SGSN role (default: BSS)\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 283 | ) |
| 284 | { |
| 285 | struct gprs_ns2_nse *nse; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 286 | struct vty_nse *vnse; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 287 | uint16_t nsei = atoi(argv[0]); |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 288 | bool sgsn_role = false; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 289 | bool free_vnse = false; |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 290 | if (argc > 1 && !strcmp(argv[1], "ip-sns-role-sgsn")) |
| 291 | sgsn_role = true; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 292 | |
| 293 | vnse = vty_nse_by_nsei(nsei); |
| 294 | if (!vnse) { |
| 295 | vnse = vty_nse_alloc(nsei); |
| 296 | if (!vnse) { |
| 297 | vty_out(vty, "Failed to create vty NSE!%s", VTY_NEWLINE); |
| 298 | return CMD_ERR_INCOMPLETE; |
| 299 | } |
| 300 | free_vnse = true; |
| 301 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 302 | |
| 303 | nse = gprs_ns2_nse_by_nsei(vty_nsi, nsei); |
| 304 | if (!nse) { |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 305 | nse = gprs_ns2_create_nse2(vty_nsi, nsei, GPRS_NS2_LL_UNDEF, GPRS_NS2_DIALECT_UNDEF, |
| 306 | sgsn_role); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 307 | if (!nse) { |
| 308 | vty_out(vty, "Failed to create NSE!%s", VTY_NEWLINE); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 309 | goto err; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 310 | } |
| 311 | nse->persistent = true; |
| 312 | } |
| 313 | |
| 314 | if (!nse->persistent) { |
| 315 | /* TODO: should the dynamic NSE removed? */ |
| 316 | vty_out(vty, "A dynamic NSE with the specified NSEI already exists%s", VTY_NEWLINE); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 317 | goto err; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | vty->node = L_NS_NSE_NODE; |
| 321 | vty->index = nse; |
| 322 | |
| 323 | return CMD_SUCCESS; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 324 | |
| 325 | err: |
| 326 | if (free_vnse) |
| 327 | talloc_free(vnse); |
| 328 | |
| 329 | return CMD_ERR_INCOMPLETE; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 330 | } |
| 331 | |
| 332 | DEFUN(cfg_no_ns_nsei, cfg_no_ns_nsei_cmd, |
| 333 | "no nse <0-65535>", |
| 334 | NO_STR |
| 335 | "Delete a Persistent NS Entity\n" |
| 336 | "NS Entity ID (NSEI)\n" |
| 337 | ) |
| 338 | { |
| 339 | struct gprs_ns2_nse *nse; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 340 | struct vty_nse *vnse; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 341 | uint16_t nsei = atoi(argv[0]); |
| 342 | |
| 343 | nse = gprs_ns2_nse_by_nsei(vty_nsi, nsei); |
| 344 | if (!nse) { |
| 345 | vty_out(vty, "Can not find NS Entity %s%s", argv[0], VTY_NEWLINE); |
| 346 | return CMD_ERR_NOTHING_TODO; |
| 347 | } |
| 348 | |
| 349 | if (!nse->persistent) { |
| 350 | vty_out(vty, "Ignoring non-persistent NS Entity%s", VTY_NEWLINE); |
| 351 | return CMD_WARNING; |
| 352 | } |
| 353 | |
| 354 | vty_out(vty, "Deleting NS Entity %u%s", nse->nsei, VTY_NEWLINE); |
| 355 | gprs_ns2_free_nse(nse); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 356 | |
| 357 | vnse = vty_nse_by_nsei(nsei); |
| 358 | vty_nse_free(vnse); |
| 359 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 360 | return CMD_SUCCESS; |
| 361 | } |
| 362 | |
| 363 | /* TODO: add fr/gre */ |
| 364 | DEFUN(cfg_ns_bind, cfg_ns_bind_cmd, |
| 365 | "bind (fr|udp) ID", |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 366 | "Configure local Bind\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 367 | "Frame Relay\n" "UDP/IP\n" |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 368 | "Unique identifier for this bind (to reference from NS-VCs, NSEs, ...)\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 369 | ) |
| 370 | { |
| 371 | const char *nstype = argv[0]; |
| 372 | const char *name = argv[1]; |
| 373 | struct vty_bind *vbind; |
| 374 | enum gprs_ns2_ll ll; |
| 375 | int rc; |
| 376 | |
| 377 | rc = get_string_value(vty_ll_names, nstype); |
| 378 | if (rc < 0) |
| 379 | return CMD_WARNING; |
| 380 | ll = (enum gprs_ns2_ll) rc; |
| 381 | |
| 382 | if (!osmo_identifier_valid(name)) { |
| 383 | vty_out(vty, "Invalid ID. The ID should be only alphanumeric.%s", VTY_NEWLINE); |
| 384 | return CMD_WARNING; |
| 385 | } |
| 386 | |
| 387 | vbind = vty_bind_by_name(name); |
| 388 | if (vbind) { |
| 389 | if (vbind->ll != ll) { |
| 390 | vty_out(vty, "A bind with the specified ID already exists with a different type (fr|frgre|udp)!%s", |
| 391 | VTY_NEWLINE); |
| 392 | return CMD_WARNING; |
| 393 | } |
| 394 | } else { |
| 395 | vbind = vty_bind_alloc(name); |
| 396 | if (!vbind) { |
| 397 | vty_out(vty, "Can not create bind - out of memory%s", VTY_NEWLINE); |
| 398 | return CMD_WARNING; |
| 399 | } |
| 400 | vbind->ll = ll; |
| 401 | } |
| 402 | |
| 403 | vty->index = vbind; |
| 404 | vty->node = L_NS_BIND_NODE; |
| 405 | |
| 406 | return CMD_SUCCESS; |
| 407 | } |
| 408 | |
| 409 | DEFUN(cfg_no_ns_bind, cfg_no_ns_bind_cmd, |
| 410 | "no bind ID", |
| 411 | NO_STR |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 412 | "Delete a bind\n" |
| 413 | "Unique identifier for this bind\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 414 | ) |
| 415 | { |
| 416 | struct vty_bind *vbind; |
| 417 | struct gprs_ns2_vc_bind *bind; |
| 418 | const char *name = argv[0]; |
| 419 | |
| 420 | vbind = vty_bind_by_name(name); |
| 421 | if (!vbind) { |
| 422 | vty_out(vty, "bind %s does not exist!%s", name, VTY_NEWLINE); |
| 423 | return CMD_WARNING; |
| 424 | } |
| 425 | vty_bind_free(vbind); |
| 426 | bind = gprs_ns2_bind_by_name(vty_nsi, name); |
| 427 | if (bind) |
Alexander Couzens | 56287d2 | 2021-07-06 10:56:55 +0200 | [diff] [blame] | 428 | gprs_ns2_free_bind(bind); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 429 | return CMD_SUCCESS; |
| 430 | } |
| 431 | |
| 432 | |
| 433 | static void config_write_vbind(struct vty *vty, struct vty_bind *vbind) |
| 434 | { |
| 435 | struct gprs_ns2_vc_bind *bind; |
| 436 | const struct osmo_sockaddr *addr; |
| 437 | struct osmo_sockaddr_str addr_str; |
| 438 | const char *netif, *frrole_str, *llstr; |
| 439 | enum osmo_fr_role frrole; |
| 440 | |
| 441 | llstr = get_value_string_or_null(vty_ll_names, vbind->ll); |
| 442 | if (!llstr) |
| 443 | return; |
| 444 | vty_out(vty, " bind %s %s%s", llstr, vbind->name, VTY_NEWLINE); |
| 445 | |
| 446 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 447 | switch (vbind->ll) { |
| 448 | case GPRS_NS2_LL_FR: |
| 449 | if (bind) { |
| 450 | netif = gprs_ns2_fr_bind_netif(bind); |
| 451 | if (!netif) |
| 452 | return; |
| 453 | frrole = gprs_ns2_fr_bind_role(bind); |
| 454 | if ((int) frrole == -1) |
| 455 | return; |
| 456 | frrole_str = get_value_string_or_null(vty_fr_role_names, frrole); |
| 457 | if (netif && frrole_str) |
| 458 | vty_out(vty, " fr %s %s%s", netif, frrole_str, VTY_NEWLINE); |
| 459 | } |
| 460 | break; |
| 461 | case GPRS_NS2_LL_UDP: |
| 462 | if (bind) { |
| 463 | addr = gprs_ns2_ip_bind_sockaddr(bind); |
| 464 | if (!osmo_sockaddr_str_from_sockaddr(&addr_str, &addr->u.sas)) { |
| 465 | vty_out(vty, " listen %s %u%s", addr_str.ip, addr_str.port, |
| 466 | VTY_NEWLINE); |
| 467 | } |
| 468 | } |
| 469 | if (vbind->accept_ipaccess) |
| 470 | vty_out(vty, " accept-ipaccess%s", VTY_NEWLINE); |
Harald Welte | 42e3646 | 2021-03-03 18:12:09 +0100 | [diff] [blame] | 471 | if (vbind->accept_sns) |
| 472 | vty_out(vty, " accept-dynamic-ip-sns%s", VTY_NEWLINE); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 473 | if (vbind->dscp) |
| 474 | vty_out(vty, " dscp %u%s", vbind->dscp, VTY_NEWLINE); |
Harald Welte | d99e4ee | 2021-04-28 19:57:12 +0200 | [diff] [blame] | 475 | if (vbind->priority) |
Harald Welte | 5782fec | 2021-04-29 21:28:53 +0200 | [diff] [blame] | 476 | vty_out(vty, " socket-priority %u%s", vbind->priority, VTY_NEWLINE); |
Daniel Willmann | 64db636 | 2021-02-12 12:21:45 +0100 | [diff] [blame] | 477 | vty_out(vty, " ip-sns signalling-weight %u data-weight %u%s", |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 478 | vbind->ip_sns_sig_weight, vbind->ip_sns_data_weight, VTY_NEWLINE); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 479 | break; |
| 480 | default: |
| 481 | return; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | static void config_write_nsvc(struct vty *vty, const struct gprs_ns2_vc *nsvc) |
| 486 | { |
| 487 | const char *netif; |
| 488 | uint16_t dlci; |
| 489 | const struct osmo_sockaddr *addr; |
| 490 | struct osmo_sockaddr_str addr_str; |
| 491 | |
| 492 | switch (nsvc->nse->ll) { |
| 493 | case GPRS_NS2_LL_UNDEF: |
| 494 | break; |
| 495 | case GPRS_NS2_LL_UDP: |
| 496 | switch (nsvc->nse->dialect) { |
| 497 | case GPRS_NS2_DIALECT_IPACCESS: |
| 498 | addr = gprs_ns2_ip_vc_remote(nsvc); |
| 499 | if (!addr) |
| 500 | break; |
| 501 | if (osmo_sockaddr_str_from_sockaddr(&addr_str, &addr->u.sas)) |
| 502 | break; |
| 503 | vty_out(vty, " nsvc ipa %s %s %u nsvci %u%s", |
| 504 | nsvc->bind->name, addr_str.ip, addr_str.port, |
| 505 | nsvc->nsvci, VTY_NEWLINE); |
| 506 | break; |
| 507 | case GPRS_NS2_DIALECT_STATIC_ALIVE: |
| 508 | addr = gprs_ns2_ip_vc_remote(nsvc); |
| 509 | if (!addr) |
| 510 | break; |
| 511 | if (osmo_sockaddr_str_from_sockaddr(&addr_str, &addr->u.sas)) |
| 512 | break; |
| 513 | vty_out(vty, " nsvc udp %s %s %u%s", |
| 514 | nsvc->bind->name, addr_str.ip, addr_str.port, VTY_NEWLINE); |
| 515 | break; |
| 516 | default: |
| 517 | break; |
| 518 | } |
| 519 | break; |
| 520 | case GPRS_NS2_LL_FR: |
| 521 | netif = gprs_ns2_fr_bind_netif(nsvc->bind); |
| 522 | if (!netif) |
| 523 | break; |
| 524 | dlci = gprs_ns2_fr_nsvc_dlci(nsvc); |
| 525 | if (!dlci) |
| 526 | break; |
| 527 | OSMO_ASSERT(nsvc->nsvci_is_valid); |
| 528 | vty_out(vty, " nsvc fr %s dlci %u nsvci %u%s", |
| 529 | netif, dlci, nsvc->nsvci, VTY_NEWLINE); |
| 530 | break; |
| 531 | case GPRS_NS2_LL_FR_GRE: |
| 532 | break; |
| 533 | } |
| 534 | } |
| 535 | |
| 536 | static void _config_write_ns_nse(struct vty *vty, struct gprs_ns2_nse *nse) |
| 537 | { |
| 538 | struct gprs_ns2_vc *nsvc; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 539 | struct vty_nse *vnse = vty_nse_by_nsei(nse->nsei); |
| 540 | struct vty_nse_bind *vbind; |
| 541 | |
| 542 | OSMO_ASSERT(vnse); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 543 | |
Harald Welte | 579699b | 2021-03-05 10:22:23 +0100 | [diff] [blame] | 544 | vty_out(vty, " nse %u%s%s", nse->nsei, |
| 545 | nse->ip_sns_role_sgsn ? " ip-sns-role-sgsn" : "", VTY_NEWLINE); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 546 | switch (nse->dialect) { |
| 547 | case GPRS_NS2_DIALECT_SNS: |
| 548 | ns2_sns_write_vty(vty, nse); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 549 | llist_for_each_entry(vbind, &vnse->binds, list) { |
| 550 | vty_out(vty, " ip-sns-bind %s%s", vbind->vbind->name, VTY_NEWLINE); |
| 551 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 552 | break; |
| 553 | default: |
| 554 | llist_for_each_entry(nsvc, &nse->nsvc, list) { |
| 555 | config_write_nsvc(vty, nsvc); |
| 556 | } |
| 557 | break; |
| 558 | } |
| 559 | } |
| 560 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 561 | static int config_write_ns_nse(struct vty *vty) |
| 562 | { |
| 563 | struct gprs_ns2_nse *nse; |
| 564 | |
| 565 | llist_for_each_entry(nse, &vty_nsi->nse, list) { |
| 566 | if (!nse->persistent) |
| 567 | continue; |
| 568 | |
| 569 | _config_write_ns_nse(vty, nse); |
| 570 | } |
| 571 | |
| 572 | return 0; |
| 573 | } |
| 574 | |
| 575 | static int config_write_ns_bind(struct vty *vty) |
| 576 | { |
| 577 | struct vty_bind *vbind; |
| 578 | |
| 579 | llist_for_each_entry(vbind, &binds, list) { |
| 580 | config_write_vbind(vty, vbind); |
| 581 | } |
| 582 | |
| 583 | return 0; |
| 584 | } |
| 585 | |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 586 | static int config_write_ns(struct vty *vty) |
| 587 | { |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 588 | struct vty_nse_bind *vbind; |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 589 | unsigned int i; |
| 590 | int ret; |
| 591 | |
| 592 | vty_out(vty, "ns%s", VTY_NEWLINE); |
| 593 | |
| 594 | for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++) |
| 595 | vty_out(vty, " timer %s %u%s", |
| 596 | get_value_string(gprs_ns_timer_strs, i), |
| 597 | vty_nsi->timeout[i], VTY_NEWLINE); |
| 598 | |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 599 | if (vty_nsi->txqueue_max_length != NS_DEFAULT_TXQUEUE_MAX_LENGTH) |
| 600 | vty_out(vty, " txqueue-max-length %u%s", vty_nsi->txqueue_max_length, VTY_NEWLINE); |
| 601 | |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 602 | ret = config_write_ns_bind(vty); |
| 603 | if (ret) |
| 604 | return ret; |
| 605 | |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 606 | llist_for_each_entry(vbind, &ip_sns_default_binds, list) { |
| 607 | vty_out(vty, " ip-sns-default bind %s%s", vbind->vbind->name, VTY_NEWLINE); |
| 608 | } |
| 609 | |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 610 | ret = config_write_ns_nse(vty); |
| 611 | if (ret) |
| 612 | return ret; |
| 613 | |
| 614 | return 0; |
| 615 | } |
| 616 | |
| 617 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 618 | static struct cmd_node ns_bind_node = { |
| 619 | L_NS_BIND_NODE, |
| 620 | "%s(config-ns-bind)# ", |
| 621 | 1, |
| 622 | }; |
| 623 | |
| 624 | DEFUN(cfg_ns_bind_listen, cfg_ns_bind_listen_cmd, |
| 625 | "listen " VTY_IPV46_CMD " <1-65535>", |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 626 | "Configure local IP + Port of this bind\n" |
| 627 | "Local IPv4 Address\n" "Local IPv6 Address\n" |
| 628 | "Local UDP Port\n" |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 629 | ) |
| 630 | { |
| 631 | struct vty_bind *vbind = vty->index; |
| 632 | struct gprs_ns2_vc_bind *bind; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 633 | int rc; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 634 | const char *addr_str = argv[0]; |
| 635 | unsigned int port = atoi(argv[1]); |
| 636 | struct osmo_sockaddr_str sockaddr_str; |
| 637 | struct osmo_sockaddr sockaddr; |
| 638 | |
| 639 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 640 | vty_out(vty, "listen can be only used with UDP bind%s", |
| 641 | VTY_NEWLINE); |
| 642 | return CMD_WARNING; |
| 643 | } |
| 644 | |
| 645 | if (osmo_sockaddr_str_from_str(&sockaddr_str, addr_str, port)) { |
| 646 | vty_out(vty, "Can not parse the Address %s %s%s", argv[0], argv[1], VTY_NEWLINE); |
| 647 | return CMD_WARNING; |
| 648 | } |
| 649 | osmo_sockaddr_str_to_sockaddr(&sockaddr_str, &sockaddr.u.sas); |
| 650 | if (gprs_ns2_ip_bind_by_sockaddr(vty_nsi, &sockaddr)) { |
| 651 | vty_out(vty, "A bind with the specified address already exists!%s", VTY_NEWLINE); |
| 652 | return CMD_WARNING; |
| 653 | } |
| 654 | |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 655 | rc = gprs_ns2_ip_bind(vty_nsi, vbind->name, &sockaddr, vbind->dscp, &bind); |
| 656 | if (rc != 0) { |
| 657 | vty_out(vty, "Failed to create the bind (rc %d)!%s", rc, VTY_NEWLINE); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 658 | return CMD_WARNING; |
| 659 | } |
| 660 | |
| 661 | bind->accept_ipaccess = vbind->accept_ipaccess; |
| 662 | bind->accept_sns = vbind->accept_sns; |
| 663 | |
| 664 | return CMD_SUCCESS; |
| 665 | } |
| 666 | |
| 667 | DEFUN(cfg_no_ns_bind_listen, cfg_no_ns_bind_listen_cmd, |
| 668 | "no listen", |
| 669 | NO_STR |
| 670 | "Delete a IP/Port assignment\n" |
| 671 | ) |
| 672 | { |
| 673 | struct vty_bind *vbind = vty->index; |
| 674 | struct gprs_ns2_vc_bind *bind; |
| 675 | |
| 676 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 677 | vty_out(vty, "no listen can be only used with UDP bind%s", VTY_NEWLINE); |
| 678 | return CMD_WARNING; |
| 679 | } |
| 680 | |
| 681 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 682 | if (!bind) |
| 683 | return CMD_ERR_NOTHING_TODO; |
| 684 | |
Daniel Willmann | 9043205 | 2021-01-26 16:09:18 +0100 | [diff] [blame] | 685 | OSMO_ASSERT(bind->ll == GPRS_NS2_LL_UDP); |
Alexander Couzens | 56287d2 | 2021-07-06 10:56:55 +0200 | [diff] [blame] | 686 | gprs_ns2_free_bind(bind); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 687 | return CMD_SUCCESS; |
| 688 | } |
| 689 | |
| 690 | DEFUN(cfg_ns_bind_dscp, cfg_ns_bind_dscp_cmd, |
Harald Welte | c96d716 | 2021-04-27 21:56:25 +0200 | [diff] [blame] | 691 | "dscp <0-63>", |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 692 | "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n") |
| 693 | { |
| 694 | struct vty_bind *vbind = vty->index; |
| 695 | struct gprs_ns2_vc_bind *bind; |
| 696 | uint16_t dscp = atoi(argv[0]); |
| 697 | |
| 698 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 699 | vty_out(vty, "dscp can be only used with UDP bind%s", |
| 700 | VTY_NEWLINE); |
| 701 | return CMD_WARNING; |
| 702 | } |
| 703 | |
| 704 | vbind->dscp = dscp; |
| 705 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 706 | if (bind) |
| 707 | gprs_ns2_ip_bind_set_dscp(bind, dscp); |
| 708 | |
| 709 | return CMD_SUCCESS; |
| 710 | } |
| 711 | |
| 712 | DEFUN(cfg_no_ns_bind_dscp, cfg_no_ns_bind_dscp_cmd, |
| 713 | "no dscp", |
| 714 | "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n") |
| 715 | { |
| 716 | struct vty_bind *vbind = vty->index; |
| 717 | struct gprs_ns2_vc_bind *bind; |
| 718 | uint16_t dscp = 0; |
| 719 | |
| 720 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 721 | vty_out(vty, "dscp can be only used with UDP bind%s", |
| 722 | VTY_NEWLINE); |
| 723 | return CMD_WARNING; |
| 724 | } |
| 725 | |
| 726 | vbind->dscp = dscp; |
| 727 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 728 | if (bind) |
| 729 | gprs_ns2_ip_bind_set_dscp(bind, dscp); |
| 730 | |
| 731 | return CMD_SUCCESS; |
| 732 | } |
| 733 | |
Harald Welte | d99e4ee | 2021-04-28 19:57:12 +0200 | [diff] [blame] | 734 | DEFUN(cfg_ns_bind_priority, cfg_ns_bind_priority_cmd, |
Harald Welte | 5782fec | 2021-04-29 21:28:53 +0200 | [diff] [blame] | 735 | "socket-priority <0-255>", |
Harald Welte | d99e4ee | 2021-04-28 19:57:12 +0200 | [diff] [blame] | 736 | "Set socket priority on the UDP socket\n" "Priority Value (>6 requires CAP_NET_ADMIN)\n") |
| 737 | { |
| 738 | struct vty_bind *vbind = vty->index; |
| 739 | struct gprs_ns2_vc_bind *bind; |
| 740 | uint8_t prio = atoi(argv[0]); |
| 741 | |
| 742 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 743 | vty_out(vty, "dscp can be only used with UDP bind%s", |
| 744 | VTY_NEWLINE); |
| 745 | return CMD_WARNING; |
| 746 | } |
| 747 | |
| 748 | vbind->priority = prio; |
| 749 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 750 | if (bind) |
| 751 | gprs_ns2_ip_bind_set_priority(bind, prio); |
| 752 | |
| 753 | return CMD_SUCCESS; |
| 754 | } |
| 755 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 756 | DEFUN(cfg_ns_bind_ipaccess, cfg_ns_bind_ipaccess_cmd, |
| 757 | "accept-ipaccess", |
| 758 | "Allow to create dynamic NS Entity by NS Reset PDU on UDP (ip.access style)\n" |
| 759 | ) |
| 760 | { |
| 761 | struct vty_bind *vbind = vty->index; |
| 762 | struct gprs_ns2_vc_bind *bind; |
| 763 | |
| 764 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 765 | vty_out(vty, "accept-ipaccess can be only used with UDP bind%s", |
| 766 | VTY_NEWLINE); |
| 767 | return CMD_WARNING; |
| 768 | } |
| 769 | |
| 770 | vbind->accept_ipaccess = true; |
| 771 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 772 | if (bind) |
| 773 | bind->accept_ipaccess = true; |
| 774 | |
| 775 | return CMD_SUCCESS; |
| 776 | } |
| 777 | |
| 778 | DEFUN(cfg_no_ns_bind_ipaccess, cfg_no_ns_bind_ipaccess_cmd, |
| 779 | "no accept-ipaccess", |
| 780 | NO_STR |
| 781 | "Reject NS Reset PDU on UDP (ip.access style)\n" |
| 782 | ) |
| 783 | { |
| 784 | struct vty_bind *vbind = vty->index; |
| 785 | struct gprs_ns2_vc_bind *bind; |
| 786 | |
| 787 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 788 | vty_out(vty, "no accept-ipaccess can be only used with UDP bind%s", |
| 789 | VTY_NEWLINE); |
| 790 | return CMD_WARNING; |
| 791 | } |
| 792 | |
| 793 | vbind->accept_ipaccess = false; |
| 794 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 795 | if (bind) |
| 796 | bind->accept_ipaccess = false; |
| 797 | |
| 798 | return CMD_SUCCESS; |
| 799 | } |
| 800 | |
Harald Welte | 42e3646 | 2021-03-03 18:12:09 +0100 | [diff] [blame] | 801 | DEFUN(cfg_ns_bind_accept_sns, cfg_ns_bind_accept_sns_cmd, |
| 802 | "accept-dynamic-ip-sns", |
| 803 | "Allow to create dynamic NS Entities by IP-SNS PDUs\n" |
| 804 | ) |
| 805 | { |
| 806 | struct vty_bind *vbind = vty->index; |
| 807 | struct gprs_ns2_vc_bind *bind; |
| 808 | |
| 809 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 810 | vty_out(vty, "accept-dynamic-ip-sns can be only used with UDP bind%s", |
| 811 | VTY_NEWLINE); |
| 812 | return CMD_WARNING; |
| 813 | } |
| 814 | |
| 815 | vbind->accept_sns = true; |
| 816 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 817 | if (bind) |
| 818 | bind->accept_sns = true; |
| 819 | |
| 820 | return CMD_SUCCESS; |
| 821 | } |
| 822 | |
| 823 | DEFUN(cfg_no_ns_bind_accept_sns, cfg_no_ns_bind_accept_sns_cmd, |
| 824 | "no accept-dynamic-ip-sns", |
| 825 | NO_STR |
| 826 | "Disable dynamic creation of NS Entities by IP-SNS PDUs\n" |
| 827 | ) |
| 828 | { |
| 829 | struct vty_bind *vbind = vty->index; |
| 830 | struct gprs_ns2_vc_bind *bind; |
| 831 | |
| 832 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 833 | vty_out(vty, "no accept-dynamic-ip-sns can be only used with UDP bind%s", |
| 834 | VTY_NEWLINE); |
| 835 | return CMD_WARNING; |
| 836 | } |
| 837 | |
| 838 | vbind->accept_sns = false; |
| 839 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 840 | if (bind) |
| 841 | bind->accept_sns = false; |
| 842 | |
| 843 | return CMD_SUCCESS; |
| 844 | } |
| 845 | |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 846 | DEFUN(cfg_ns_bind_ip_sns_weight, cfg_ns_bind_ip_sns_weight_cmd, |
| 847 | "ip-sns signalling-weight <0-254> data-weight <0-254>", |
| 848 | "IP SNS\n" |
| 849 | "signalling weight used by IP-SNS dynamic configuration\n" |
| 850 | "signalling weight used by IP-SNS dynamic configuration\n" |
| 851 | "data weight used by IP-SNS dynamic configuration\n" |
| 852 | "data weight used by IP-SNS dynamic configuration\n") |
| 853 | { |
| 854 | struct vty_bind *vbind = vty->index; |
| 855 | struct gprs_ns2_vc_bind *bind; |
| 856 | |
| 857 | int signalling = atoi(argv[0]); |
| 858 | int data = atoi(argv[1]); |
| 859 | |
| 860 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 861 | vty_out(vty, "ip-sns signalling-weight <0-254> data-weight <0-254> can be only used with UDP bind%s", |
| 862 | VTY_NEWLINE); |
| 863 | return CMD_WARNING; |
| 864 | } |
| 865 | |
| 866 | vbind->ip_sns_data_weight = data; |
| 867 | vbind->ip_sns_sig_weight = signalling; |
| 868 | bind = gprs_ns2_bind_by_name(vty_nsi, vbind->name); |
| 869 | if (bind) |
| 870 | gprs_ns2_ip_bind_set_sns_weight(bind, signalling, data); |
| 871 | |
| 872 | return CMD_SUCCESS; |
| 873 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 874 | |
| 875 | DEFUN(cfg_ns_bind_fr, cfg_ns_bind_fr_cmd, |
| 876 | "fr NETIF (fr|frnet)", |
| 877 | "frame relay\n" |
| 878 | IFNAME_STR |
| 879 | "fr (user) is used by BSS or SGSN attached to UNI of a FR network\n" |
| 880 | "frnet (network) is used by SGSN if BSS is directly attached\n" |
| 881 | ) |
| 882 | { |
| 883 | struct vty_bind *vbind = vty->index; |
| 884 | struct gprs_ns2_vc_bind *bind; |
| 885 | const char *netif = argv[0]; |
| 886 | const char *role = argv[1]; |
| 887 | |
| 888 | int rc = 0; |
| 889 | enum osmo_fr_role frrole; |
| 890 | |
| 891 | if (vbind->ll != GPRS_NS2_LL_FR) { |
| 892 | vty_out(vty, "fr can be only used with frame relay bind%s", VTY_NEWLINE); |
| 893 | return CMD_WARNING; |
| 894 | } |
| 895 | |
| 896 | if (!strcmp(role, "fr")) |
| 897 | frrole = FR_ROLE_USER_EQUIPMENT; |
| 898 | else if (!strcmp(role, "frnet")) |
| 899 | frrole = FR_ROLE_NETWORK_EQUIPMENT; |
| 900 | else |
| 901 | return CMD_WARNING; |
| 902 | |
| 903 | bind = gprs_ns2_fr_bind_by_netif(vty_nsi, netif); |
| 904 | if (bind) { |
| 905 | vty_out(vty, "Interface %s already used.%s", netif, VTY_NEWLINE); |
| 906 | return CMD_WARNING; |
| 907 | } |
| 908 | |
| 909 | rc = gprs_ns2_fr_bind(vty_nsi, vbind->name, netif, vty_fr_network, frrole, &bind); |
| 910 | if (rc < 0) { |
| 911 | LOGP(DLNS, LOGL_ERROR, "Failed to bind interface %s on fr. Err: %d\n", netif, rc); |
| 912 | return CMD_WARNING; |
| 913 | } |
| 914 | |
| 915 | return CMD_SUCCESS; |
| 916 | } |
| 917 | |
| 918 | DEFUN(cfg_no_ns_bind_fr, cfg_no_ns_bind_fr_cmd, |
| 919 | "no fr NETIF", |
| 920 | NO_STR |
| 921 | "Delete a frame relay link\n" |
| 922 | "Delete a frame relay link\n" |
| 923 | IFNAME_STR |
| 924 | ) |
| 925 | { |
| 926 | struct vty_bind *vbind = vty->index; |
| 927 | struct gprs_ns2_vc_bind *bind; |
| 928 | const char *netif = argv[0]; |
| 929 | |
| 930 | if (vbind->ll != GPRS_NS2_LL_FR) { |
| 931 | vty_out(vty, "fr can be only used with frame relay bind%s", |
| 932 | VTY_NEWLINE); |
| 933 | return CMD_WARNING; |
| 934 | } |
| 935 | |
| 936 | bind = gprs_ns2_fr_bind_by_netif(vty_nsi, netif); |
| 937 | if (!bind) { |
| 938 | vty_out(vty, "Interface not found.%s", VTY_NEWLINE); |
| 939 | return CMD_WARNING; |
| 940 | } |
| 941 | |
| 942 | if (strcmp(bind->name, vbind->name)) { |
| 943 | vty_out(vty, "The specified interface is not bound to this bind.%s", VTY_NEWLINE); |
| 944 | return CMD_WARNING; |
| 945 | } |
| 946 | |
Alexander Couzens | 56287d2 | 2021-07-06 10:56:55 +0200 | [diff] [blame] | 947 | gprs_ns2_free_bind(bind); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 948 | return CMD_SUCCESS; |
| 949 | } |
| 950 | |
| 951 | |
| 952 | static struct cmd_node ns_nse_node = { |
| 953 | L_NS_NSE_NODE, |
| 954 | "%s(config-ns-nse)# ", |
| 955 | 1, |
| 956 | }; |
| 957 | |
| 958 | DEFUN(cfg_ns_nse_nsvc_fr, cfg_ns_nse_nsvc_fr_cmd, |
| 959 | "nsvc fr NETIF dlci <16-1007> nsvci <0-65535>", |
| 960 | "NS Virtual Connection\n" |
| 961 | "frame relay\n" |
| 962 | "frame relay interface. Must be registered via fr vty\n" |
| 963 | NSVCI_STR |
| 964 | NSVCI_STR |
| 965 | DLCI_STR |
| 966 | DLCI_STR |
| 967 | ) |
| 968 | { |
| 969 | struct gprs_ns2_vc_bind *bind; |
| 970 | struct gprs_ns2_vc *nsvc; |
| 971 | struct gprs_ns2_nse *nse = vty->index; |
| 972 | const char *netif = argv[0]; |
| 973 | uint16_t dlci = atoi(argv[1]); |
| 974 | uint16_t nsvci = atoi(argv[2]); |
| 975 | bool dialect_modified = false; |
| 976 | bool ll_modified = false; |
| 977 | |
| 978 | if (nse->ll != GPRS_NS2_LL_FR && nse->ll != GPRS_NS2_LL_UNDEF) { |
| 979 | vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); |
| 980 | goto err; |
| 981 | } |
| 982 | |
| 983 | if (nse->dialect != GPRS_NS2_DIALECT_STATIC_RESETBLOCK && nse->dialect != GPRS_NS2_DIALECT_UNDEF) { |
| 984 | vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); |
| 985 | goto err; |
| 986 | } |
| 987 | |
| 988 | if (nse->ll == GPRS_NS2_LL_UNDEF) { |
| 989 | nse->ll = GPRS_NS2_LL_FR; |
| 990 | ll_modified = true; |
| 991 | } |
| 992 | |
| 993 | if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 994 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_STATIC_RESETBLOCK); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 995 | dialect_modified = true; |
| 996 | } |
| 997 | |
| 998 | |
| 999 | bind = gprs_ns2_fr_bind_by_netif(vty_nsi, netif); |
| 1000 | if (!bind) { |
| 1001 | vty_out(vty, "Can not find fr interface \"%s\". Please configure it via fr vty.%s", |
| 1002 | netif, VTY_NEWLINE); |
| 1003 | goto err; |
| 1004 | } |
| 1005 | |
| 1006 | if (gprs_ns2_fr_nsvc_by_dlci(bind, dlci)) { |
| 1007 | vty_out(vty, "A NS-VC with the specified DLCI already exist!%s", VTY_NEWLINE); |
| 1008 | goto err; |
| 1009 | } |
| 1010 | |
| 1011 | if (gprs_ns2_nsvc_by_nsvci(vty_nsi, nsvci)) { |
| 1012 | vty_out(vty, "A NS-VC with the specified NS-VCI already exist!%s", VTY_NEWLINE); |
| 1013 | goto err; |
| 1014 | } |
| 1015 | |
| 1016 | nsvc = gprs_ns2_fr_connect(bind, nse, nsvci, dlci); |
| 1017 | if (!nsvc) { |
| 1018 | /* Could not create NS-VC, connect failed */ |
| 1019 | vty_out(vty, "Failed to create the NS-VC%s", VTY_NEWLINE); |
| 1020 | goto err; |
| 1021 | } |
| 1022 | nsvc->persistent = true; |
| 1023 | return CMD_SUCCESS; |
| 1024 | |
| 1025 | err: |
| 1026 | if (ll_modified) |
| 1027 | nse->ll = GPRS_NS2_LL_UNDEF; |
| 1028 | if (dialect_modified) |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1029 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1030 | |
| 1031 | return CMD_WARNING; |
| 1032 | } |
| 1033 | |
| 1034 | DEFUN(cfg_no_ns_nse_nsvc_fr_dlci, cfg_no_ns_nse_nsvc_fr_dlci_cmd, |
| 1035 | "no nsvc fr NETIF dlci <16-1007>", |
| 1036 | NO_STR |
| 1037 | "Delete frame relay NS-VC\n" |
| 1038 | "frame relay\n" |
| 1039 | "frame relay interface. Must be registered via fr vty\n" |
| 1040 | DLCI_STR |
| 1041 | DLCI_STR |
| 1042 | ) |
| 1043 | { |
| 1044 | struct gprs_ns2_vc_bind *bind; |
| 1045 | struct gprs_ns2_vc *nsvc; |
| 1046 | struct gprs_ns2_nse *nse = vty->index; |
| 1047 | const char *netif = argv[0]; |
| 1048 | uint16_t dlci = atoi(argv[1]); |
| 1049 | |
| 1050 | if (nse->ll != GPRS_NS2_LL_FR) { |
| 1051 | vty_out(vty, "This NSE doesn't support frame relay.%s", VTY_NEWLINE); |
| 1052 | return CMD_WARNING; |
| 1053 | } |
| 1054 | |
| 1055 | bind = gprs_ns2_fr_bind_by_netif(vty_nsi, netif); |
| 1056 | if (!bind) { |
| 1057 | vty_out(vty, "Can not find fr interface \"%s\"%s", |
| 1058 | netif, VTY_NEWLINE); |
| 1059 | return CMD_ERR_NOTHING_TODO; |
| 1060 | } |
| 1061 | |
| 1062 | nsvc = gprs_ns2_fr_nsvc_by_dlci(bind, dlci); |
| 1063 | if (!nsvc) { |
| 1064 | vty_out(vty, "Can not find a NS-VC on fr interface %s with dlci %u%s", |
| 1065 | netif, dlci, VTY_NEWLINE); |
| 1066 | return CMD_WARNING; |
| 1067 | } |
| 1068 | |
| 1069 | if (nse != nsvc->nse) { |
| 1070 | vty_out(vty, "The specified NS-VC is not a part of the NSE %u!%s" |
| 1071 | "To remove this NS-VC go to the vty node 'nse %u'%s", |
| 1072 | nse->nsei, VTY_NEWLINE, |
| 1073 | nsvc->nse->nsei, VTY_NEWLINE); |
| 1074 | return CMD_WARNING; |
| 1075 | } |
| 1076 | |
| 1077 | gprs_ns2_free_nsvc(nsvc); |
| 1078 | if (llist_empty(&nse->nsvc)) { |
| 1079 | nse->ll = GPRS_NS2_LL_UNDEF; |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1080 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | return CMD_SUCCESS; |
| 1084 | } |
| 1085 | |
| 1086 | DEFUN(cfg_no_ns_nse_nsvci, cfg_no_ns_nse_nsvci_cmd, |
| 1087 | "no nsvc nsvci <0-65535>", |
| 1088 | NO_STR |
| 1089 | "Delete NSVC\n" |
| 1090 | NSVCI_STR |
| 1091 | NSVCI_STR |
| 1092 | ) |
| 1093 | { |
| 1094 | struct gprs_ns2_vc *nsvc; |
| 1095 | struct gprs_ns2_nse *nse = vty->index; |
| 1096 | uint16_t nsvci = atoi(argv[0]); |
| 1097 | |
| 1098 | switch (nse->dialect) { |
| 1099 | case GPRS_NS2_DIALECT_SNS: |
| 1100 | case GPRS_NS2_DIALECT_STATIC_ALIVE: |
| 1101 | vty_out(vty, "NSE doesn't support NSVCI.%s", VTY_NEWLINE); |
| 1102 | return CMD_WARNING; |
| 1103 | case GPRS_NS2_DIALECT_UNDEF: |
| 1104 | vty_out(vty, "No NSVCs configured%s", VTY_NEWLINE); |
| 1105 | return CMD_WARNING; |
| 1106 | case GPRS_NS2_DIALECT_IPACCESS: |
| 1107 | case GPRS_NS2_DIALECT_STATIC_RESETBLOCK: |
| 1108 | break; |
| 1109 | } |
| 1110 | |
| 1111 | nsvc = gprs_ns2_nsvc_by_nsvci(vty_nsi, nsvci); |
| 1112 | if (!nsvc) { |
| 1113 | vty_out(vty, "Can not find NS-VC with NS-VCI %u%s", nsvci, VTY_NEWLINE); |
| 1114 | return CMD_WARNING; |
| 1115 | } |
| 1116 | |
| 1117 | if (nse != nsvc->nse) { |
| 1118 | vty_out(vty, "NS-VC with NS-VCI %u is not part of this NSE!%s", |
| 1119 | nsvci, VTY_NEWLINE); |
| 1120 | return CMD_WARNING; |
| 1121 | } |
| 1122 | |
| 1123 | gprs_ns2_free_nsvc(nsvc); |
| 1124 | if (llist_empty(&nse->nsvc)) { |
| 1125 | nse->ll = GPRS_NS2_LL_UNDEF; |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1126 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | return CMD_SUCCESS; |
| 1130 | } |
| 1131 | |
Alexander Couzens | bf5d0db | 2021-02-12 04:04:13 +0100 | [diff] [blame] | 1132 | static int ns_nse_nsvc_udp_cmds(struct vty *vty, const char *bind_name, const char *remote_char, uint16_t port, |
| 1133 | uint16_t sig_weight, uint16_t data_weight) |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1134 | { |
| 1135 | struct gprs_ns2_vc_bind *bind; |
| 1136 | struct gprs_ns2_vc *nsvc; |
| 1137 | struct gprs_ns2_nse *nse = vty->index; |
| 1138 | bool dialect_modified = false; |
| 1139 | bool ll_modified = false; |
| 1140 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1141 | struct osmo_sockaddr_str remote_str; |
| 1142 | struct osmo_sockaddr remote; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1143 | |
| 1144 | if (nse->ll == GPRS_NS2_LL_UNDEF) { |
| 1145 | nse->ll = GPRS_NS2_LL_UDP; |
| 1146 | ll_modified = true; |
| 1147 | } |
| 1148 | |
| 1149 | if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1150 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_STATIC_ALIVE); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1151 | dialect_modified = true; |
| 1152 | } |
| 1153 | |
| 1154 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1155 | vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); |
| 1156 | goto err; |
| 1157 | } |
| 1158 | |
| 1159 | if (nse->dialect != GPRS_NS2_DIALECT_STATIC_ALIVE) { |
| 1160 | vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); |
| 1161 | goto err; |
| 1162 | } |
| 1163 | |
Alexander Couzens | bf5d0db | 2021-02-12 04:04:13 +0100 | [diff] [blame] | 1164 | if (osmo_sockaddr_str_from_str(&remote_str, remote_char, port)) { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1165 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1166 | goto err; |
| 1167 | } |
| 1168 | |
| 1169 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1170 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1171 | goto err; |
| 1172 | } |
| 1173 | |
| 1174 | bind = gprs_ns2_bind_by_name(vty_nsi, bind_name); |
| 1175 | if (!bind) { |
| 1176 | vty_out(vty, "Can not find bind with name %s%s", |
| 1177 | bind_name, VTY_NEWLINE); |
| 1178 | goto err; |
| 1179 | } |
| 1180 | |
| 1181 | if (bind->ll != GPRS_NS2_LL_UDP) { |
| 1182 | vty_out(vty, "Bind %s is not an UDP bind.%s", |
| 1183 | bind_name, VTY_NEWLINE); |
| 1184 | goto err; |
| 1185 | } |
| 1186 | |
Alexander Couzens | 7bb39e3 | 2021-02-16 23:06:53 +0100 | [diff] [blame] | 1187 | nsvc = gprs_ns2_nsvc_by_sockaddr_bind(bind, &remote); |
| 1188 | if (nsvc) { |
| 1189 | if (nsvc->nse == nse) |
| 1190 | vty_out(vty, "Specified NSVC is already present in this NSE.%s", VTY_NEWLINE); |
| 1191 | else |
| 1192 | vty_out(vty, "Specified NSVC is already present in another NSE%05u.%s", nsvc->nse->nsei, VTY_NEWLINE); |
| 1193 | goto err; |
| 1194 | } |
| 1195 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1196 | nsvc = gprs_ns2_ip_connect(bind, &remote, nse, 0); |
| 1197 | if (!nsvc) { |
| 1198 | vty_out(vty, "Can not create NS-VC.%s", VTY_NEWLINE); |
| 1199 | goto err; |
| 1200 | } |
Alexander Couzens | bf5d0db | 2021-02-12 04:04:13 +0100 | [diff] [blame] | 1201 | nsvc->sig_weight = sig_weight; |
| 1202 | nsvc->data_weight = data_weight; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1203 | nsvc->persistent = true; |
| 1204 | |
| 1205 | return CMD_SUCCESS; |
| 1206 | |
| 1207 | err: |
| 1208 | if (ll_modified) |
| 1209 | nse->ll = GPRS_NS2_LL_UNDEF; |
| 1210 | if (dialect_modified) |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1211 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1212 | return CMD_WARNING; |
| 1213 | } |
| 1214 | |
Alexander Couzens | bf5d0db | 2021-02-12 04:04:13 +0100 | [diff] [blame] | 1215 | DEFUN(cfg_ns_nse_nsvc_udp, cfg_ns_nse_nsvc_udp_cmd, |
| 1216 | "nsvc udp BIND " VTY_IPV46_CMD " <1-65535>", |
| 1217 | "NS Virtual Connection\n" |
| 1218 | "NS over UDP\n" |
| 1219 | "A unique bind identifier created by ns bind\n" |
| 1220 | "Remote IPv4 Address\n" "Remote IPv6 Address\n" |
| 1221 | "Remote UDP Port\n") |
| 1222 | { |
| 1223 | const char *bind_name = argv[0]; |
| 1224 | const char *remote = argv[1]; |
| 1225 | uint16_t port = atoi(argv[2]); |
| 1226 | uint16_t sig_weight = 1; |
| 1227 | uint16_t data_weight = 1; |
| 1228 | |
| 1229 | return ns_nse_nsvc_udp_cmds(vty, bind_name, remote, port, sig_weight, data_weight); |
| 1230 | } |
| 1231 | |
| 1232 | DEFUN(cfg_ns_nse_nsvc_udp_weights, cfg_ns_nse_nsvc_udp_weights_cmd, |
| 1233 | "nsvc udp BIND " VTY_IPV46_CMD " <1-65535> signalling-weight <0-254> data-weight <0-254>", |
| 1234 | "NS Virtual Connection\n" |
| 1235 | "NS over UDP\n" |
| 1236 | "A unique bind identifier created by ns bind\n" |
| 1237 | "Remote IPv4 Address\n" "Remote IPv6 Address\n" |
| 1238 | "Remote UDP Port\n" |
| 1239 | "Signalling weight of the NSVC (default = 1)\n" |
| 1240 | "Signalling weight of the NSVC (default = 1)\n" |
| 1241 | "Data weight of the NSVC (default = 1)\n" |
| 1242 | "Data weight of the NSVC (default = 1)\n" |
| 1243 | ) |
| 1244 | { |
| 1245 | const char *bind_name = argv[0]; |
| 1246 | const char *remote = argv[1]; |
| 1247 | uint16_t port = atoi(argv[2]); |
| 1248 | uint16_t sig_weight = atoi(argv[3]); |
| 1249 | uint16_t data_weight = atoi(argv[4]); |
| 1250 | |
| 1251 | return ns_nse_nsvc_udp_cmds(vty, bind_name, remote, port, sig_weight, data_weight); |
| 1252 | } |
| 1253 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1254 | DEFUN(cfg_no_ns_nse_nsvc_udp, cfg_no_ns_nse_nsvc_udp_cmd, |
| 1255 | "no nsvc udp BIND " VTY_IPV46_CMD " <1-65535>", |
| 1256 | NO_STR |
| 1257 | "Delete a NS Virtual Connection\n" |
| 1258 | "NS over UDP\n" |
| 1259 | "A unique bind identifier created by ns bind\n" |
| 1260 | "Remote IPv4 Address\n" "Remote IPv6 Address\n" |
| 1261 | "Remote UDP Port\n" |
| 1262 | ) |
| 1263 | { |
| 1264 | struct gprs_ns2_vc_bind *bind; |
| 1265 | struct gprs_ns2_vc *nsvc; |
| 1266 | struct gprs_ns2_nse *nse = vty->index; |
| 1267 | const char *bind_name = argv[0]; |
| 1268 | struct osmo_sockaddr_str remote_str; |
| 1269 | struct osmo_sockaddr remote; |
| 1270 | uint16_t port = atoi(argv[2]); |
| 1271 | |
| 1272 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1273 | vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); |
| 1274 | return CMD_WARNING; |
| 1275 | } |
| 1276 | |
| 1277 | if (nse->dialect != GPRS_NS2_DIALECT_STATIC_ALIVE) { |
| 1278 | vty_out(vty, "This NSE doesn't support UDP with dialect static alive.%s", VTY_NEWLINE); |
| 1279 | return CMD_WARNING; |
| 1280 | } |
| 1281 | |
| 1282 | bind = gprs_ns2_bind_by_name(vty_nsi, bind_name); |
| 1283 | if (!bind) { |
| 1284 | vty_out(vty, "Can not find bind with name %s%s", |
| 1285 | bind_name, VTY_NEWLINE); |
| 1286 | return CMD_WARNING; |
| 1287 | } |
| 1288 | |
| 1289 | if (bind->ll != GPRS_NS2_LL_UDP) { |
| 1290 | vty_out(vty, "Bind %s is not an UDP bind.%s", |
| 1291 | bind_name, VTY_NEWLINE); |
| 1292 | return CMD_WARNING; |
| 1293 | } |
| 1294 | |
| 1295 | if (osmo_sockaddr_str_from_str(&remote_str, argv[1], port)) { |
| 1296 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1297 | return CMD_WARNING; |
| 1298 | } |
| 1299 | |
| 1300 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1301 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1302 | return CMD_WARNING; |
| 1303 | } |
| 1304 | |
| 1305 | nsvc = gprs_ns2_nsvc_by_sockaddr_bind(bind, &remote); |
| 1306 | if (!nsvc) { |
| 1307 | vty_out(vty, "Can not find NS-VC with remote %s:%u%s", |
| 1308 | remote_str.ip, remote_str.port, VTY_NEWLINE); |
| 1309 | return CMD_WARNING; |
| 1310 | } |
| 1311 | |
| 1312 | if (!nsvc->persistent) { |
| 1313 | vty_out(vty, "NS-VC with remote %s:%u is a dynamic NS-VC. Not configured by vty.%s", |
| 1314 | remote_str.ip, remote_str.port, VTY_NEWLINE); |
| 1315 | return CMD_WARNING; |
| 1316 | } |
| 1317 | |
| 1318 | if (nsvc->nse != nse) { |
| 1319 | vty_out(vty, "NS-VC is not part of this NSE!%s", VTY_NEWLINE); |
| 1320 | return CMD_WARNING; |
| 1321 | } |
| 1322 | |
| 1323 | gprs_ns2_free_nsvc(nsvc); |
| 1324 | if (llist_empty(&nse->nsvc)) { |
| 1325 | nse->ll = GPRS_NS2_LL_UNDEF; |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1326 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | return CMD_SUCCESS; |
| 1330 | } |
| 1331 | |
| 1332 | DEFUN(cfg_ns_nse_nsvc_ipa, cfg_ns_nse_nsvc_ipa_cmd, |
| 1333 | "nsvc ipa BIND " VTY_IPV46_CMD " <1-65535> nsvci <0-65535>" , |
| 1334 | "NS Virtual Connection\n" |
| 1335 | "NS over UDP ip.access style (uses RESET/BLOCK)\n" |
| 1336 | "A unique bind identifier created by ns bind\n" |
| 1337 | "Remote IPv4 Address\n" "Remote IPv6 Address\n" |
| 1338 | "Remote UDP Port\n" |
| 1339 | NSVCI_STR |
| 1340 | NSVCI_STR |
| 1341 | ) |
| 1342 | { |
| 1343 | struct gprs_ns2_vc_bind *bind; |
| 1344 | struct gprs_ns2_vc *nsvc; |
| 1345 | struct gprs_ns2_nse *nse = vty->index; |
| 1346 | bool dialect_modified = false; |
| 1347 | bool ll_modified = false; |
| 1348 | |
| 1349 | const char *bind_name = argv[0]; |
| 1350 | struct osmo_sockaddr_str remote_str; |
| 1351 | struct osmo_sockaddr remote; |
| 1352 | uint16_t port = atoi(argv[2]); |
| 1353 | uint16_t nsvci = atoi(argv[3]); |
| 1354 | |
| 1355 | if (nse->ll == GPRS_NS2_LL_UNDEF) { |
| 1356 | nse->ll = GPRS_NS2_LL_UDP; |
| 1357 | ll_modified = true; |
| 1358 | } |
| 1359 | |
| 1360 | if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1361 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_IPACCESS); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1362 | dialect_modified = true; |
| 1363 | } |
| 1364 | |
| 1365 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1366 | vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); |
| 1367 | goto err; |
| 1368 | } |
| 1369 | |
| 1370 | if (nse->dialect != GPRS_NS2_DIALECT_IPACCESS) { |
| 1371 | vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); |
| 1372 | goto err; |
| 1373 | } |
| 1374 | |
| 1375 | if (osmo_sockaddr_str_from_str(&remote_str, argv[1], port)) { |
| 1376 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1377 | goto err; |
| 1378 | } |
| 1379 | |
| 1380 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1381 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1382 | goto err; |
| 1383 | } |
| 1384 | |
| 1385 | bind = gprs_ns2_bind_by_name(vty_nsi, bind_name); |
| 1386 | if (!bind) { |
| 1387 | vty_out(vty, "Can not find bind with name %s%s", |
| 1388 | bind_name, VTY_NEWLINE); |
| 1389 | goto err; |
| 1390 | } |
| 1391 | |
| 1392 | if (bind->ll != GPRS_NS2_LL_UDP) { |
| 1393 | vty_out(vty, "Bind %s is not an UDP bind.%s", |
| 1394 | bind_name, VTY_NEWLINE); |
| 1395 | goto err; |
| 1396 | } |
| 1397 | |
| 1398 | nsvc = gprs_ns2_ip_connect(bind, &remote, nse, nsvci); |
| 1399 | if (!nsvc) { |
| 1400 | vty_out(vty, "Can not create NS-VC.%s", VTY_NEWLINE); |
| 1401 | goto err; |
| 1402 | } |
| 1403 | nsvc->persistent = true; |
| 1404 | |
| 1405 | return CMD_SUCCESS; |
| 1406 | |
| 1407 | err: |
| 1408 | if (ll_modified) |
| 1409 | nse->ll = GPRS_NS2_LL_UNDEF; |
| 1410 | if (dialect_modified) |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1411 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1412 | return CMD_WARNING; |
| 1413 | } |
| 1414 | |
| 1415 | DEFUN(cfg_no_ns_nse_nsvc_ipa, cfg_no_ns_nse_nsvc_ipa_cmd, |
| 1416 | "no nsvc ipa BIND " VTY_IPV46_CMD " <1-65535> nsvci <0-65535>", |
| 1417 | NO_STR |
| 1418 | "Delete a NS Virtual Connection\n" |
| 1419 | "NS over UDP\n" |
| 1420 | "A unique bind identifier created by ns bind\n" |
| 1421 | "Remote IPv4 Address\n" "Remote IPv6 Address\n" |
| 1422 | "Remote UDP Port\n" |
| 1423 | NSVCI_STR |
| 1424 | NSVCI_STR |
| 1425 | ) |
| 1426 | { |
| 1427 | struct gprs_ns2_vc_bind *bind; |
| 1428 | struct gprs_ns2_vc *nsvc; |
| 1429 | struct gprs_ns2_nse *nse = vty->index; |
| 1430 | const char *bind_name = argv[0]; |
| 1431 | struct osmo_sockaddr_str remote_str; |
| 1432 | struct osmo_sockaddr remote; |
| 1433 | uint16_t port = atoi(argv[2]); |
| 1434 | uint16_t nsvci = atoi(argv[3]); |
| 1435 | |
| 1436 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1437 | vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); |
| 1438 | return CMD_WARNING; |
| 1439 | } |
| 1440 | |
| 1441 | if (nse->dialect != GPRS_NS2_DIALECT_IPACCESS) { |
| 1442 | vty_out(vty, "This NSE doesn't support UDP with dialect ipaccess.%s", VTY_NEWLINE); |
| 1443 | return CMD_WARNING; |
| 1444 | } |
| 1445 | |
| 1446 | bind = gprs_ns2_bind_by_name(vty_nsi, bind_name); |
| 1447 | if (!bind) { |
| 1448 | vty_out(vty, "Can not find bind with name %s%s", |
| 1449 | bind_name, VTY_NEWLINE); |
| 1450 | return CMD_WARNING; |
| 1451 | } |
| 1452 | |
| 1453 | if (bind->ll != GPRS_NS2_LL_UDP) { |
| 1454 | vty_out(vty, "Bind %s is not an UDP bind.%s", |
| 1455 | bind_name, VTY_NEWLINE); |
| 1456 | return CMD_WARNING; |
| 1457 | } |
| 1458 | |
| 1459 | if (osmo_sockaddr_str_from_str(&remote_str, argv[1], port)) { |
| 1460 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1461 | return CMD_WARNING; |
| 1462 | } |
| 1463 | |
| 1464 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1465 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1466 | return CMD_WARNING; |
| 1467 | } |
| 1468 | |
| 1469 | nsvc = gprs_ns2_nsvc_by_sockaddr_bind(bind, &remote); |
| 1470 | if (!nsvc) { |
| 1471 | vty_out(vty, "Can not find NS-VC with remote %s:%u%s", |
| 1472 | remote_str.ip, remote_str.port, VTY_NEWLINE); |
| 1473 | return CMD_WARNING; |
| 1474 | } |
| 1475 | |
| 1476 | if (!nsvc->persistent) { |
| 1477 | vty_out(vty, "NS-VC with remote %s:%u is a dynamic NS-VC. Not configured by vty.%s", |
| 1478 | remote_str.ip, remote_str.port, VTY_NEWLINE); |
| 1479 | return CMD_WARNING; |
| 1480 | } |
| 1481 | |
| 1482 | if (nsvc->nse != nse) { |
| 1483 | vty_out(vty, "NS-VC is not part of this NSE!%s", VTY_NEWLINE); |
| 1484 | return CMD_WARNING; |
| 1485 | } |
| 1486 | |
| 1487 | if (!nsvc->nsvci_is_valid) { |
| 1488 | vty_out(vty, "NS-VC doesn't have a nsvci!%s", VTY_NEWLINE); |
| 1489 | return CMD_WARNING; |
| 1490 | } |
| 1491 | |
| 1492 | if (nsvc->nsvci != nsvci) { |
| 1493 | vty_out(vty, "NS-VC has a different nsvci (%u)!%s", |
| 1494 | nsvc->nsvci, VTY_NEWLINE); |
| 1495 | return CMD_WARNING; |
| 1496 | } |
| 1497 | |
| 1498 | gprs_ns2_free_nsvc(nsvc); |
| 1499 | if (llist_empty(&nse->nsvc)) { |
| 1500 | nse->ll = GPRS_NS2_LL_UNDEF; |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1501 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1502 | } |
| 1503 | |
| 1504 | return CMD_SUCCESS; |
| 1505 | } |
| 1506 | |
Alexander Couzens | 5fa431c | 2021-02-08 23:21:54 +0100 | [diff] [blame] | 1507 | DEFUN(cfg_ns_nse_ip_sns_remote, cfg_ns_nse_ip_sns_remote_cmd, |
| 1508 | "ip-sns-remote " VTY_IPV46_CMD " <1-65535>", |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1509 | "SNS Initial Endpoint\n" |
| 1510 | "SGSN IPv4 Address\n" "SGSN IPv6 Address\n" |
| 1511 | "SGSN UDP Port\n" |
| 1512 | ) |
| 1513 | { |
| 1514 | struct gprs_ns2_nse *nse = vty->index; |
| 1515 | bool dialect_modified = false; |
| 1516 | bool ll_modified = false; |
| 1517 | int rc; |
| 1518 | |
| 1519 | /* argv[0] */ |
| 1520 | struct osmo_sockaddr_str remote_str; |
| 1521 | struct osmo_sockaddr remote; |
| 1522 | uint16_t port = atoi(argv[1]); |
| 1523 | |
| 1524 | if (nse->ll == GPRS_NS2_LL_UNDEF) { |
| 1525 | nse->ll = GPRS_NS2_LL_UDP; |
| 1526 | ll_modified = true; |
| 1527 | } |
| 1528 | |
| 1529 | if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1530 | if (ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_SNS) < 0) |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1531 | goto err; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1532 | dialect_modified = true; |
| 1533 | } |
| 1534 | |
| 1535 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1536 | vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); |
| 1537 | goto err; |
| 1538 | } |
| 1539 | |
| 1540 | if (nse->dialect != GPRS_NS2_DIALECT_SNS) { |
| 1541 | vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); |
| 1542 | goto err; |
| 1543 | } |
| 1544 | |
| 1545 | if (osmo_sockaddr_str_from_str(&remote_str, argv[0], port)) { |
| 1546 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1547 | goto err; |
| 1548 | } |
| 1549 | |
| 1550 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1551 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1552 | goto err; |
| 1553 | } |
| 1554 | |
| 1555 | rc = gprs_ns2_sns_add_endpoint(nse, &remote); |
| 1556 | switch (rc) { |
| 1557 | case 0: |
| 1558 | return CMD_SUCCESS; |
| 1559 | case -EADDRINUSE: |
| 1560 | vty_out(vty, "Specified SNS endpoint already part of the NSE.%s", VTY_NEWLINE); |
| 1561 | return CMD_WARNING; |
| 1562 | default: |
| 1563 | vty_out(vty, "Can not add specified SNS endpoint.%s", VTY_NEWLINE); |
| 1564 | return CMD_WARNING; |
| 1565 | } |
| 1566 | |
| 1567 | err: |
| 1568 | if (ll_modified) |
| 1569 | nse->ll = GPRS_NS2_LL_UNDEF; |
| 1570 | if (dialect_modified) |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1571 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1572 | return CMD_WARNING; |
| 1573 | } |
| 1574 | |
Alexander Couzens | 5fa431c | 2021-02-08 23:21:54 +0100 | [diff] [blame] | 1575 | DEFUN(cfg_no_ns_nse_ip_sns_remote, cfg_no_ns_nse_ip_sns_remote_cmd, |
| 1576 | "no ip-sns-remote " VTY_IPV46_CMD " <1-65535>", |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1577 | NO_STR |
| 1578 | "Delete a SNS Initial Endpoint\n" |
| 1579 | "SGSN IPv4 Address\n" "SGSN IPv6 Address\n" |
| 1580 | "SGSN UDP Port\n" |
| 1581 | ) |
| 1582 | { |
| 1583 | struct gprs_ns2_nse *nse = vty->index; |
| 1584 | struct osmo_sockaddr_str remote_str; /* argv[0] */ |
| 1585 | struct osmo_sockaddr remote; |
| 1586 | uint16_t port = atoi(argv[1]); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1587 | |
| 1588 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1589 | vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); |
| 1590 | return CMD_WARNING; |
| 1591 | } |
| 1592 | |
| 1593 | if (nse->dialect != GPRS_NS2_DIALECT_SNS) { |
| 1594 | vty_out(vty, "This NSE doesn't support UDP with dialect ip-sns.%s", VTY_NEWLINE); |
| 1595 | return CMD_WARNING; |
| 1596 | } |
| 1597 | |
| 1598 | if (osmo_sockaddr_str_from_str(&remote_str, argv[0], port)) { |
| 1599 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1600 | return CMD_WARNING; |
| 1601 | } |
| 1602 | |
| 1603 | if (osmo_sockaddr_str_to_sockaddr(&remote_str, &remote.u.sas)) { |
| 1604 | vty_out(vty, "Can not parse IPv4/IPv6 or port.%s", VTY_NEWLINE); |
| 1605 | return CMD_WARNING; |
| 1606 | } |
| 1607 | |
| 1608 | if (gprs_ns2_sns_del_endpoint(nse, &remote)) { |
| 1609 | vty_out(vty, "Can not remove specified SNS endpoint.%s", VTY_NEWLINE); |
| 1610 | return CMD_WARNING; |
| 1611 | } |
| 1612 | |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1613 | if (vty_nse_check_sns(nse)) { |
| 1614 | /* there is still sns configuration valid */ |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1615 | return CMD_SUCCESS; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1616 | } else { |
| 1617 | /* clean up nse to allow other nsvc commands */ |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1618 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1619 | nse->ll = GPRS_NS2_LL_UNDEF; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1620 | } |
| 1621 | |
| 1622 | return CMD_SUCCESS; |
| 1623 | } |
| 1624 | |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 1625 | /* add all IP-SNS default binds to the given NSE */ |
| 1626 | int ns2_sns_add_sns_default_binds(struct gprs_ns2_nse *nse) |
| 1627 | { |
| 1628 | struct vty_nse_bind *vnse_bind; |
| 1629 | int count = 0; |
| 1630 | |
| 1631 | OSMO_ASSERT(nse->ll == GPRS_NS2_LL_UDP); |
| 1632 | OSMO_ASSERT(nse->dialect == GPRS_NS2_DIALECT_SNS); |
| 1633 | |
| 1634 | llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) { |
| 1635 | struct gprs_ns2_vc_bind *bind = gprs_ns2_bind_by_name(vty_nsi, vnse_bind->vbind->name); |
| 1636 | /* the bind might not yet created because "listen" is missing. */ |
| 1637 | if (!bind) |
| 1638 | continue; |
| 1639 | gprs_ns2_sns_add_bind(nse, bind); |
| 1640 | count++; |
| 1641 | } |
| 1642 | return count; |
| 1643 | } |
| 1644 | |
| 1645 | DEFUN(cfg_ns_ip_sns_default_bind, cfg_ns_ip_sns_default_bind_cmd, |
| 1646 | "ip-sns-default bind ID", |
| 1647 | "Defaults for dynamically created NSEs created by IP-SNS in SGSN role\n" |
| 1648 | "IP SNS binds\n" |
| 1649 | "Name of NS udp bind whose IP endpoint will be used as IP-SNS local endpoint. Can be given multiple times.\n") |
| 1650 | { |
| 1651 | struct vty_bind *vbind; |
| 1652 | struct vty_nse_bind *vnse_bind; |
| 1653 | const char *name = argv[0]; |
| 1654 | |
| 1655 | vbind = vty_bind_by_name(name); |
| 1656 | if (!vbind) { |
| 1657 | vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); |
| 1658 | return CMD_WARNING; |
| 1659 | } |
| 1660 | |
| 1661 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 1662 | vty_out(vty, "ip-sns-default bind can only be used with UDP bind%s", VTY_NEWLINE); |
| 1663 | return CMD_WARNING; |
| 1664 | } |
| 1665 | |
| 1666 | llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) { |
| 1667 | if (vnse_bind->vbind == vbind) |
| 1668 | return CMD_SUCCESS; |
| 1669 | } |
| 1670 | |
| 1671 | vnse_bind = talloc(vty_nsi, struct vty_nse_bind); |
| 1672 | if (!vnse_bind) |
| 1673 | return CMD_WARNING; |
| 1674 | vnse_bind->vbind = vbind; |
| 1675 | |
| 1676 | llist_add_tail(&vnse_bind->list, &ip_sns_default_binds); |
| 1677 | |
| 1678 | return CMD_SUCCESS; |
| 1679 | } |
| 1680 | |
| 1681 | DEFUN(cfg_no_ns_ip_sns_default_bind, cfg_no_ns_ip_sns_default_bind_cmd, |
| 1682 | "no ip-sns-default bind ID", |
| 1683 | NO_STR "Defaults for dynamically created NSEs created by IP-SNS in SGSN role\n" |
| 1684 | "IP SNS binds\n" |
| 1685 | "Name of NS udp bind whose IP endpoint will be removed as IP-SNS local endpoint.\n") |
| 1686 | { |
| 1687 | struct vty_bind *vbind; |
| 1688 | struct vty_nse_bind *vnse_bind; |
| 1689 | const char *name = argv[0]; |
| 1690 | |
| 1691 | vbind = vty_bind_by_name(name); |
| 1692 | if (!vbind) { |
| 1693 | vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); |
| 1694 | return CMD_WARNING; |
| 1695 | } |
| 1696 | |
| 1697 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 1698 | vty_out(vty, "ip-sns-default bind can only be used with UDP bind%s", VTY_NEWLINE); |
| 1699 | return CMD_WARNING; |
| 1700 | } |
| 1701 | |
| 1702 | llist_for_each_entry(vnse_bind, &ip_sns_default_binds, list) { |
| 1703 | if (vnse_bind->vbind == vbind) { |
| 1704 | llist_del(&vnse_bind->list); |
| 1705 | talloc_free(vnse_bind); |
| 1706 | return CMD_SUCCESS; |
| 1707 | } |
| 1708 | } |
| 1709 | |
| 1710 | vty_out(vty, "Bind '%s' was not an ip-sns-default bind%s", name, VTY_NEWLINE); |
| 1711 | return CMD_WARNING; |
| 1712 | } |
| 1713 | |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 1714 | DEFUN(cfg_ns_txqueue_max_length, cfg_ns_txqueue_max_length_cmd, |
| 1715 | "txqueue-max-length <1-4096>", |
| 1716 | "Set the maximum length of the txqueue (for UDP)\n" |
| 1717 | "Maximum length of the txqueue\n") |
| 1718 | { |
| 1719 | struct gprs_ns2_vc_bind *bind; |
| 1720 | uint32_t max_length = atoi(argv[0]); |
| 1721 | vty_nsi->txqueue_max_length = max_length; |
| 1722 | |
| 1723 | |
| 1724 | llist_for_each_entry(bind, &vty_nsi->binding, list) { |
| 1725 | if (!gprs_ns2_is_ip_bind(bind)) |
| 1726 | continue; |
| 1727 | |
| 1728 | ns2_ip_set_txqueue_max_length(bind, max_length); |
| 1729 | } |
| 1730 | |
| 1731 | |
| 1732 | return CMD_SUCCESS; |
| 1733 | } |
| 1734 | |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1735 | DEFUN(cfg_ns_nse_ip_sns_bind, cfg_ns_nse_ip_sns_bind_cmd, |
| 1736 | "ip-sns-bind BINDID", |
| 1737 | "IP SNS binds\n" |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 1738 | "Name of NS udp bind whose IP endpoint will be used as IP-SNS local endpoint. Can be given multiple times.\n") |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1739 | { |
| 1740 | struct gprs_ns2_nse *nse = vty->index; |
| 1741 | struct gprs_ns2_vc_bind *bind; |
| 1742 | struct vty_bind *vbind; |
| 1743 | struct vty_nse *vnse; |
| 1744 | const char *name = argv[0]; |
| 1745 | bool ll_modified = false; |
| 1746 | bool dialect_modified = false; |
| 1747 | int rc; |
| 1748 | |
| 1749 | if (nse->ll == GPRS_NS2_LL_UNDEF) { |
| 1750 | nse->ll = GPRS_NS2_LL_UDP; |
| 1751 | ll_modified = true; |
| 1752 | } |
| 1753 | |
| 1754 | if (nse->dialect == GPRS_NS2_DIALECT_UNDEF) { |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1755 | if (ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_SNS) < 0) |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1756 | goto err; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1757 | dialect_modified = true; |
| 1758 | } |
| 1759 | |
| 1760 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1761 | vty_out(vty, "Can not mix NS-VC with different link layer%s", VTY_NEWLINE); |
| 1762 | goto err; |
| 1763 | } |
| 1764 | |
| 1765 | if (nse->dialect != GPRS_NS2_DIALECT_SNS) { |
| 1766 | vty_out(vty, "Can not mix NS-VC with different dialects%s", VTY_NEWLINE); |
| 1767 | goto err; |
| 1768 | } |
| 1769 | |
| 1770 | vbind = vty_bind_by_name(name); |
| 1771 | if (!vbind) { |
| 1772 | vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); |
| 1773 | goto err; |
| 1774 | } |
| 1775 | |
| 1776 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 1777 | vty_out(vty, "ip-sns-bind can only be used with UDP bind%s", |
| 1778 | VTY_NEWLINE); |
| 1779 | goto err; |
| 1780 | } |
| 1781 | |
| 1782 | /* the vnse has been created together when creating the nse node. The parent node should check this already! */ |
| 1783 | vnse = vty_nse_by_nsei(nse->nsei); |
| 1784 | OSMO_ASSERT(vnse); |
| 1785 | |
| 1786 | rc = vty_nse_add_vbind(vnse, vbind); |
| 1787 | switch (rc) { |
| 1788 | case 0: |
| 1789 | break; |
| 1790 | case -EALREADY: |
| 1791 | vty_out(vty, "Failed to add ip-sns-bind %s already present%s", name, VTY_NEWLINE); |
| 1792 | goto err; |
| 1793 | case -ENOMEM: |
| 1794 | vty_out(vty, "Failed to add ip-sns-bind %s out of memory%s", name, VTY_NEWLINE); |
| 1795 | goto err; |
| 1796 | default: |
| 1797 | vty_out(vty, "Failed to add ip-sns-bind %s! %d%s", name, rc, VTY_NEWLINE); |
| 1798 | goto err; |
| 1799 | } |
| 1800 | |
| 1801 | /* the bind might not yet created because "listen" is missing. */ |
| 1802 | bind = gprs_ns2_bind_by_name(vty_nsi, name); |
| 1803 | if (!bind) |
| 1804 | return CMD_SUCCESS; |
| 1805 | |
| 1806 | rc = gprs_ns2_sns_add_bind(nse, bind); |
| 1807 | switch (rc) { |
| 1808 | case 0: |
| 1809 | break; |
| 1810 | case -EALREADY: |
| 1811 | vty_out(vty, "Failed to add ip-sns-bind %s already present%s", name, VTY_NEWLINE); |
| 1812 | goto err; |
| 1813 | case -ENOMEM: |
| 1814 | vty_out(vty, "Failed to add ip-sns-bind %s out of memory%s", name, VTY_NEWLINE); |
| 1815 | goto err; |
| 1816 | default: |
| 1817 | vty_out(vty, "Failed to add ip-sns-bind %s! %d%s", name, rc, VTY_NEWLINE); |
| 1818 | goto err; |
| 1819 | } |
| 1820 | |
| 1821 | return CMD_SUCCESS; |
| 1822 | err: |
| 1823 | if (ll_modified) |
| 1824 | nse->ll = GPRS_NS2_LL_UNDEF; |
| 1825 | if (dialect_modified) |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1826 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1827 | |
| 1828 | return CMD_WARNING; |
| 1829 | } |
| 1830 | |
| 1831 | DEFUN(cfg_no_ns_nse_ip_sns_bind, cfg_no_ns_nse_ip_sns_bind_cmd, |
| 1832 | "no ip-sns-bind BINDID", |
| 1833 | NO_STR |
| 1834 | "IP SNS binds\n" |
Harald Welte | 2230a91 | 2021-03-04 20:09:50 +0100 | [diff] [blame] | 1835 | "Name of NS udp bind whose IP endpoint will not be used as IP-SNS local endpoint\n") |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1836 | { |
| 1837 | struct gprs_ns2_nse *nse = vty->index; |
| 1838 | struct gprs_ns2_vc_bind *bind; |
| 1839 | struct vty_bind *vbind; |
| 1840 | struct vty_nse *vnse; |
| 1841 | const char *name = argv[0]; |
| 1842 | int rc; |
| 1843 | |
| 1844 | if (nse->ll != GPRS_NS2_LL_UDP) { |
| 1845 | vty_out(vty, "This NSE doesn't support UDP.%s", VTY_NEWLINE); |
| 1846 | return CMD_WARNING; |
| 1847 | } |
| 1848 | |
| 1849 | if (nse->dialect != GPRS_NS2_DIALECT_SNS) { |
| 1850 | vty_out(vty, "This NSE doesn't support UDP with dialect ip-sns.%s", VTY_NEWLINE); |
| 1851 | return CMD_WARNING; |
| 1852 | } |
| 1853 | |
| 1854 | vbind = vty_bind_by_name(name); |
| 1855 | if (!vbind) { |
| 1856 | vty_out(vty, "Can not find the given bind '%s'%s", name, VTY_NEWLINE); |
| 1857 | return CMD_WARNING; |
| 1858 | } |
| 1859 | |
| 1860 | if (vbind->ll != GPRS_NS2_LL_UDP) { |
| 1861 | vty_out(vty, "no ip-sns-bind can only be used with UDP bind%s", |
| 1862 | VTY_NEWLINE); |
| 1863 | return CMD_WARNING; |
| 1864 | } |
| 1865 | |
| 1866 | /* the vnse has been created together when creating the nse node. The parent node should check this already! */ |
| 1867 | vnse = vty_nse_by_nsei(nse->nsei); |
| 1868 | OSMO_ASSERT(vnse); |
| 1869 | |
| 1870 | rc = vty_nse_remove_vbind(vnse, vbind); |
| 1871 | switch(rc) { |
| 1872 | case 0: |
| 1873 | break; |
| 1874 | case -ENOENT: |
| 1875 | vty_out(vty, "Bind %s is not part of this NSE%s", name, VTY_NEWLINE); |
| 1876 | return CMD_WARNING; |
| 1877 | case -EINVAL: |
| 1878 | vty_out(vty, "no ip-sns-bind can only be used with UDP bind%s", |
| 1879 | VTY_NEWLINE); |
| 1880 | return CMD_WARNING; |
| 1881 | default: |
| 1882 | return CMD_WARNING; |
| 1883 | } |
| 1884 | |
| 1885 | /* the bind might not exists yet */ |
| 1886 | bind = gprs_ns2_bind_by_name(vty_nsi, name); |
| 1887 | if (bind) |
| 1888 | gprs_ns2_sns_del_bind(nse, bind); |
| 1889 | |
| 1890 | if (!vty_nse_check_sns(nse)) { |
| 1891 | /* clean up nse to allow other nsvc commands */ |
Harald Welte | 06d9bf9 | 2021-03-05 10:20:11 +0100 | [diff] [blame] | 1892 | ns2_nse_set_dialect(nse, GPRS_NS2_DIALECT_UNDEF); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1893 | nse->ll = GPRS_NS2_LL_UNDEF; |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 1894 | } |
| 1895 | |
| 1896 | return CMD_SUCCESS; |
| 1897 | } |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 1898 | |
| 1899 | /* non-config commands */ |
Alexander Couzens | 75b6188 | 2021-03-21 16:18:17 +0100 | [diff] [blame] | 1900 | 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] | 1901 | { |
Harald Welte | dc2d080 | 2020-12-01 18:17:28 +0100 | [diff] [blame] | 1902 | if (nsvc->nsvci_is_valid) |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 1903 | vty_out(vty, " NSVCI %05u: %s %s %s %s %ssince ", nsvc->nsvci, |
Alexander Couzens | 5e040bf | 2021-06-15 23:19:42 +0200 | [diff] [blame] | 1904 | osmo_fsm_inst_state_name(nsvc->fi), |
| 1905 | nsvc->persistent ? "PERSIST" : "DYNAMIC", |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 1906 | gprs_ns2_ll_str(nsvc), |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 1907 | ns2_vc_is_unblocked(nsvc) ? "ALIVE" : "DEAD", |
| 1908 | nsvc->om_blocked ? "(blocked by O&M/vty) " : |
| 1909 | !ns2_vc_is_unblocked(nsvc) ? "(cause: remote) " : ""); |
Harald Welte | dc2d080 | 2020-12-01 18:17:28 +0100 | [diff] [blame] | 1910 | else |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 1911 | vty_out(vty, " %s %s sig_weight=%u data_weight=%u %s %s %ssince ", |
Alexander Couzens | 5e040bf | 2021-06-15 23:19:42 +0200 | [diff] [blame] | 1912 | osmo_fsm_inst_state_name(nsvc->fi), |
| 1913 | nsvc->persistent ? "PERSIST" : "DYNAMIC", |
| 1914 | nsvc->sig_weight, nsvc->data_weight, |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 1915 | gprs_ns2_ll_str(nsvc), |
arehbein | 0d9b6b0 | 2022-10-27 18:28:52 +0200 | [diff] [blame] | 1916 | ns2_vc_is_unblocked(nsvc) ? "ALIVE" : "DEAD", |
| 1917 | !ns2_vc_is_unblocked(nsvc) ? "(cause: remote) " : ""); |
Alexander Couzens | ca5ce0d | 2021-09-05 23:15:56 +0200 | [diff] [blame] | 1918 | |
| 1919 | vty_out_uptime(vty, &nsvc->ts_alive_change); |
| 1920 | vty_out_newline(vty); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1921 | |
| 1922 | if (stats) { |
Alexander Couzens | 1dd9cbf | 2021-03-21 16:22:08 +0100 | [diff] [blame] | 1923 | vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); |
| 1924 | vty_out_stat_item_group(vty, " ", nsvc->statg); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1925 | } |
| 1926 | } |
| 1927 | |
| 1928 | static void dump_nse(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats, bool persistent_only) |
| 1929 | { |
| 1930 | struct gprs_ns2_vc *nsvc; |
Alexander Couzens | 0ea4a4e | 2021-03-21 16:37:23 +0100 | [diff] [blame] | 1931 | unsigned int nsvcs = 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1932 | |
Alexander Couzens | 3e539ed | 2021-03-21 16:25:18 +0100 | [diff] [blame] | 1933 | if (persistent_only && !nse->persistent) |
| 1934 | return; |
| 1935 | |
Alexander Couzens | 2c64c25 | 2021-09-05 23:15:29 +0200 | [diff] [blame] | 1936 | vty_out(vty, "NSEI %05u: %s, %s since ", nse->nsei, gprs_ns2_lltype_str(nse->ll), |
| 1937 | nse->alive ? "ALIVE" : "DEAD"); |
| 1938 | vty_out_uptime(vty, &nse->ts_alive_change); |
| 1939 | vty_out_newline(vty); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1940 | |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 1941 | ns2_sns_dump_vty(vty, " ", nse, stats); |
Alexander Couzens | 0ea4a4e | 2021-03-21 16:37:23 +0100 | [diff] [blame] | 1942 | llist_for_each_entry(nsvc, &nse->nsvc, list) { |
| 1943 | nsvcs++; |
| 1944 | } |
| 1945 | vty_out(vty, " %u NS-VC:%s", nsvcs, VTY_NEWLINE); |
Alexander Couzens | 3e539ed | 2021-03-21 16:25:18 +0100 | [diff] [blame] | 1946 | llist_for_each_entry(nsvc, &nse->nsvc, list) |
| 1947 | ns2_vty_dump_nsvc(vty, nsvc, stats); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1948 | } |
| 1949 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 1950 | static void dump_bind(struct vty *vty, const struct gprs_ns2_vc_bind *bind, bool stats) |
| 1951 | { |
| 1952 | if (bind->dump_vty) |
| 1953 | bind->dump_vty(bind, vty, stats); |
Harald Welte | 7634607 | 2021-01-31 11:54:02 +0100 | [diff] [blame] | 1954 | |
| 1955 | if (stats) { |
| 1956 | vty_out_stat_item_group(vty, " ", bind->statg); |
| 1957 | } |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 1958 | } |
| 1959 | |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 1960 | static void dump_ns_bind(struct vty *vty, const struct gprs_ns2_inst *nsi, bool stats) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1961 | { |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 1962 | struct gprs_ns2_vc_bind *bind; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1963 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 1964 | llist_for_each_entry(bind, &nsi->binding, list) { |
| 1965 | dump_bind(vty, bind, stats); |
| 1966 | } |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | |
| 1970 | static void dump_ns_entities(struct vty *vty, const struct gprs_ns2_inst *nsi, bool stats, bool persistent_only) |
| 1971 | { |
| 1972 | struct gprs_ns2_nse *nse; |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 1973 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1974 | llist_for_each_entry(nse, &nsi->nse, list) { |
| 1975 | dump_nse(vty, nse, stats, persistent_only); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1976 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1977 | } |
| 1978 | |
Harald Welte | 25ee755 | 2020-12-02 22:14:00 +0100 | [diff] [blame] | 1979 | /* Backwards compatibility, among other things for the TestVTYGbproxy which expects |
| 1980 | * 'show ns' to output something about binds */ |
| 1981 | DEFUN_HIDDEN(show_ns, show_ns_cmd, "show ns", |
| 1982 | SHOW_STR SHOW_NS_STR) |
| 1983 | { |
| 1984 | dump_ns_entities(vty, vty_nsi, false, false); |
| 1985 | dump_ns_bind(vty, vty_nsi, false); |
Harald Welte | 069967b | 2021-03-30 12:05:31 +0200 | [diff] [blame] | 1986 | if (vty_fr_network && llist_count(&vty_fr_network->links)) |
| 1987 | osmo_fr_network_dump_vty(vty, vty_fr_network); |
Harald Welte | 25ee755 | 2020-12-02 22:14:00 +0100 | [diff] [blame] | 1988 | return CMD_SUCCESS; |
| 1989 | } |
| 1990 | |
| 1991 | |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 1992 | DEFUN(show_ns_binds, show_ns_binds_cmd, "show ns binds [stats]", |
Daniel Willmann | cb3e9b5 | 2020-12-02 15:50:22 +0100 | [diff] [blame] | 1993 | SHOW_STR SHOW_NS_STR |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 1994 | "Display information about the NS protocol binds\n" |
| 1995 | "Include statistic\n") |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 1996 | { |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 1997 | bool stats = false; |
| 1998 | if (argc > 0) |
| 1999 | stats = true; |
| 2000 | |
| 2001 | dump_ns_bind(vty, vty_nsi, stats); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2002 | return CMD_SUCCESS; |
| 2003 | } |
| 2004 | |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 2005 | DEFUN(show_ns_entities, show_ns_entities_cmd, "show ns entities [stats]", |
Daniel Willmann | cb3e9b5 | 2020-12-02 15:50:22 +0100 | [diff] [blame] | 2006 | SHOW_STR SHOW_NS_STR |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 2007 | "Display information about the NS protocol entities (NSEs)\n" |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2008 | "Include statistics\n") |
| 2009 | { |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 2010 | bool stats = false; |
| 2011 | if (argc > 0) |
| 2012 | stats = true; |
| 2013 | |
| 2014 | dump_ns_entities(vty, vty_nsi, stats, false); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2015 | return CMD_SUCCESS; |
| 2016 | } |
| 2017 | |
| 2018 | DEFUN(show_ns_pers, show_ns_pers_cmd, "show ns persistent", |
Daniel Willmann | cb3e9b5 | 2020-12-02 15:50:22 +0100 | [diff] [blame] | 2019 | SHOW_STR SHOW_NS_STR |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2020 | "Show only persistent NS\n") |
| 2021 | { |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 2022 | dump_ns_entities(vty, vty_nsi, true, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2023 | return CMD_SUCCESS; |
| 2024 | } |
| 2025 | |
| 2026 | DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]", |
Daniel Willmann | cb3e9b5 | 2020-12-02 15:50:22 +0100 | [diff] [blame] | 2027 | SHOW_STR SHOW_NS_STR |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2028 | "Select one NSE by its NSE Identifier\n" |
| 2029 | "Select one NSE by its NS-VC Identifier\n" |
| 2030 | "The Identifier of selected type\n" |
| 2031 | "Include Statistics\n") |
| 2032 | { |
| 2033 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 2034 | struct gprs_ns2_nse *nse; |
| 2035 | struct gprs_ns2_vc *nsvc; |
| 2036 | uint16_t id = atoi(argv[1]); |
| 2037 | bool show_stats = false; |
| 2038 | |
| 2039 | if (argc >= 3) |
| 2040 | show_stats = true; |
| 2041 | |
| 2042 | if (!strcmp(argv[0], "nsei")) { |
| 2043 | nse = gprs_ns2_nse_by_nsei(nsi, id); |
| 2044 | if (!nse) { |
| 2045 | return CMD_WARNING; |
| 2046 | } |
| 2047 | |
| 2048 | dump_nse(vty, nse, show_stats, false); |
| 2049 | } else { |
| 2050 | nsvc = gprs_ns2_nsvc_by_nsvci(nsi, id); |
| 2051 | |
| 2052 | if (!nsvc) { |
| 2053 | vty_out(vty, "No such NS Entity%s", VTY_NEWLINE); |
| 2054 | return CMD_WARNING; |
| 2055 | } |
| 2056 | |
Alexander Couzens | 75b6188 | 2021-03-21 16:18:17 +0100 | [diff] [blame] | 2057 | ns2_vty_dump_nsvc(vty, nsvc, show_stats); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2058 | } |
| 2059 | |
| 2060 | return CMD_SUCCESS; |
| 2061 | } |
| 2062 | |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 2063 | static int nsvc_force_unconf_cb(struct gprs_ns2_vc *nsvc, void *ctx) |
| 2064 | { |
Alexander Couzens | 8dfc24c | 2021-01-25 16:09:23 +0100 | [diff] [blame] | 2065 | ns2_vc_force_unconfigured(nsvc); |
Harald Welte | 7fe8d71 | 2021-01-31 18:40:54 +0100 | [diff] [blame] | 2066 | ns2_vc_fsm_start(nsvc); |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 2067 | return 0; |
| 2068 | } |
| 2069 | |
| 2070 | DEFUN_HIDDEN(nsvc_force_unconf, nsvc_force_unconf_cmd, |
| 2071 | "nsvc nsei <0-65535> force-unconfigured", |
| 2072 | "NS Virtual Connection\n" |
| 2073 | "The NSEI\n" |
| 2074 | "Reset the NSVCs back to initial state\n" |
| 2075 | ) |
| 2076 | { |
| 2077 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 2078 | struct gprs_ns2_nse *nse; |
| 2079 | |
| 2080 | uint16_t id = atoi(argv[0]); |
| 2081 | |
| 2082 | nse = gprs_ns2_nse_by_nsei(nsi, id); |
| 2083 | if (!nse) { |
| 2084 | vty_out(vty, "Could not find NSE for NSEI %u%s", id, VTY_NEWLINE); |
| 2085 | return CMD_WARNING; |
| 2086 | } |
| 2087 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2088 | if (!nse->persistent) { |
| 2089 | gprs_ns2_free_nse(nse); |
| 2090 | } else if (nse->dialect == GPRS_NS2_DIALECT_SNS) { |
Alexander Couzens | 280ed78 | 2020-12-21 18:25:41 +0100 | [diff] [blame] | 2091 | gprs_ns2_free_nsvcs(nse); |
| 2092 | } else { |
| 2093 | /* Perform the operation for all nsvc */ |
| 2094 | gprs_ns2_nse_foreach_nsvc(nse, nsvc_force_unconf_cb, NULL); |
| 2095 | } |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 2096 | |
| 2097 | return CMD_SUCCESS; |
| 2098 | } |
| 2099 | |
Alexander Couzens | d13faaa | 2021-03-01 03:14:19 +0100 | [diff] [blame] | 2100 | DEFUN(nse_restart_sns, nse_restart_sns_cmd, |
| 2101 | "nse <0-65535> restart-sns", |
| 2102 | "NSE specific commands\n" |
| 2103 | "NS Entity ID (NSEI)\n" |
| 2104 | "Restart SNS procedure\n") |
| 2105 | { |
| 2106 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 2107 | struct gprs_ns2_nse *nse; |
| 2108 | |
| 2109 | uint16_t id = atoi(argv[0]); |
| 2110 | nse = gprs_ns2_nse_by_nsei(nsi, id); |
| 2111 | if (!nse) { |
| 2112 | vty_out(vty, "Could not find NSE for NSEI %u%s", id, VTY_NEWLINE); |
| 2113 | return CMD_WARNING; |
| 2114 | } |
| 2115 | |
| 2116 | if (nse->dialect != GPRS_NS2_DIALECT_SNS) { |
| 2117 | vty_out(vty, "Given NSEI %u doesn't use IP-SNS%s", id, VTY_NEWLINE); |
| 2118 | return CMD_WARNING; |
| 2119 | } |
| 2120 | |
| 2121 | gprs_ns2_free_nsvcs(nse); |
| 2122 | return CMD_SUCCESS; |
| 2123 | } |
| 2124 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2125 | DEFUN(nsvc_block, nsvc_block_cmd, |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 2126 | "nsvc <0-65535> (block|unblock|reset)", |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2127 | "NS Virtual Connection\n" |
| 2128 | NSVCI_STR |
| 2129 | "Block a NSVC. As cause code O&M intervention will be used.\n" |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 2130 | "Unblock a NSVC. As cause code O&M intervention will be used.\n" |
| 2131 | "Reset a NSVC. As cause code O&M intervention will be used.\n") |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 2132 | { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2133 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 2134 | struct gprs_ns2_vc *nsvc; |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 2135 | int rc; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 2136 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2137 | uint16_t id = atoi(argv[0]); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 2138 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2139 | nsvc = gprs_ns2_nsvc_by_nsvci(nsi, id); |
| 2140 | if (!nsvc) { |
| 2141 | vty_out(vty, "Could not find NSVCI %05u%s", id, VTY_NEWLINE); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 2142 | return CMD_WARNING; |
| 2143 | } |
| 2144 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2145 | if (!strcmp(argv[1], "block")) { |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 2146 | rc = ns2_vc_block(nsvc); |
| 2147 | switch (rc) { |
| 2148 | case 0: |
| 2149 | vty_out(vty, "The NS-VC %05u will be blocked.%s", id, VTY_NEWLINE); |
| 2150 | return CMD_SUCCESS; |
| 2151 | case -EALREADY: |
| 2152 | vty_out(vty, "The NS-VC %05u is already blocked.%s", id, VTY_NEWLINE); |
| 2153 | return CMD_ERR_NOTHING_TODO; |
| 2154 | default: |
| 2155 | vty_out(vty, "An unknown error %d happend on NS-VC %05u.%s", rc, id, VTY_NEWLINE); |
| 2156 | return CMD_WARNING; |
| 2157 | } |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 2158 | } else if (!strcmp(argv[1], "unblock")) { |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 2159 | rc = ns2_vc_unblock(nsvc); |
| 2160 | switch (rc) { |
| 2161 | case 0: |
| 2162 | vty_out(vty, "The NS-VC %05u will be unblocked.%s", id, VTY_NEWLINE); |
| 2163 | return CMD_SUCCESS; |
| 2164 | case -EALREADY: |
| 2165 | vty_out(vty, "The NS-VC %05u is already unblocked.%s", id, VTY_NEWLINE); |
| 2166 | return CMD_ERR_NOTHING_TODO; |
| 2167 | default: |
| 2168 | vty_out(vty, "An unknown error %d happend on NS-VC %05u.%s", rc, id, VTY_NEWLINE); |
| 2169 | return CMD_WARNING; |
| 2170 | } |
Alexander Couzens | 27e5873 | 2021-03-21 17:12:08 +0100 | [diff] [blame] | 2171 | } else { |
| 2172 | ns2_vc_reset(nsvc); |
Alexander Couzens | e7dfeac | 2021-03-21 17:28:36 +0100 | [diff] [blame] | 2173 | vty_out(vty, "The NS-VC %05u has been resetted.%s", id, VTY_NEWLINE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2174 | } |
| 2175 | |
| 2176 | return CMD_SUCCESS; |
| 2177 | } |
| 2178 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2179 | static void log_set_nse_filter(struct log_target *target, |
| 2180 | struct gprs_ns2_nse *nse) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2181 | { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2182 | if (nse) { |
| 2183 | target->filter_map |= (1 << LOG_FLT_GB_NSE); |
| 2184 | target->filter_data[LOG_FLT_GB_NSE] = nse; |
| 2185 | } else if (target->filter_data[LOG_FLT_GB_NSE]) { |
| 2186 | target->filter_map = ~(1 << LOG_FLT_GB_NSE); |
| 2187 | target->filter_data[LOG_FLT_GB_NSE] = NULL; |
| 2188 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2189 | } |
| 2190 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2191 | static void log_set_nsvc_filter(struct log_target *target, |
| 2192 | struct gprs_ns2_vc *nsvc) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2193 | { |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2194 | if (nsvc) { |
| 2195 | target->filter_map |= (1 << LOG_FLT_GB_NSVC); |
| 2196 | target->filter_data[LOG_FLT_GB_NSVC] = nsvc; |
| 2197 | } else if (target->filter_data[LOG_FLT_GB_NSVC]) { |
| 2198 | target->filter_map = ~(1 << LOG_FLT_GB_NSVC); |
| 2199 | target->filter_data[LOG_FLT_GB_NSVC] = NULL; |
| 2200 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2201 | } |
| 2202 | |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 2203 | DEFUN(logging_fltr_nse, |
| 2204 | logging_fltr_nse_cmd, |
| 2205 | "logging filter nse nsei <0-65535>", |
| 2206 | LOGGING_STR FILTER_STR |
| 2207 | "Filter based on NS Entity\n" |
| 2208 | "Identify NSE by NSEI\n" |
| 2209 | "Numeric identifier\n") |
| 2210 | { |
| 2211 | struct log_target *tgt; |
| 2212 | struct gprs_ns2_nse *nse; |
Daniel Willmann | 8910652 | 2020-12-04 01:36:59 +0100 | [diff] [blame] | 2213 | uint16_t id = atoi(argv[0]); |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 2214 | |
| 2215 | log_tgt_mutex_lock(); |
| 2216 | tgt = osmo_log_vty2tgt(vty); |
| 2217 | if (!tgt) { |
| 2218 | log_tgt_mutex_unlock(); |
| 2219 | return CMD_WARNING; |
| 2220 | } |
| 2221 | |
| 2222 | nse = gprs_ns2_nse_by_nsei(vty_nsi, id); |
| 2223 | if (!nse) { |
| 2224 | vty_out(vty, "No NSE by that identifier%s", VTY_NEWLINE); |
| 2225 | log_tgt_mutex_unlock(); |
| 2226 | return CMD_WARNING; |
| 2227 | } |
| 2228 | |
| 2229 | log_set_nse_filter(tgt, nse); |
| 2230 | log_tgt_mutex_unlock(); |
| 2231 | return CMD_SUCCESS; |
| 2232 | } |
| 2233 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2234 | /* TODO: add filter for single connection by description */ |
| 2235 | DEFUN(logging_fltr_nsvc, |
| 2236 | logging_fltr_nsvc_cmd, |
| 2237 | "logging filter nsvc nsvci <0-65535>", |
| 2238 | LOGGING_STR FILTER_STR |
| 2239 | "Filter based on NS Virtual Connection\n" |
| 2240 | "Identify NS-VC by NSVCI\n" |
| 2241 | "Numeric identifier\n") |
| 2242 | { |
| 2243 | struct log_target *tgt; |
| 2244 | struct gprs_ns2_vc *nsvc; |
Daniel Willmann | 8910652 | 2020-12-04 01:36:59 +0100 | [diff] [blame] | 2245 | uint16_t id = atoi(argv[0]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2246 | |
| 2247 | log_tgt_mutex_lock(); |
| 2248 | tgt = osmo_log_vty2tgt(vty); |
| 2249 | if (!tgt) { |
| 2250 | log_tgt_mutex_unlock(); |
| 2251 | return CMD_WARNING; |
| 2252 | } |
| 2253 | |
| 2254 | nsvc = gprs_ns2_nsvc_by_nsvci(vty_nsi, id); |
| 2255 | if (!nsvc) { |
| 2256 | vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE); |
| 2257 | log_tgt_mutex_unlock(); |
| 2258 | return CMD_WARNING; |
| 2259 | } |
| 2260 | |
| 2261 | log_set_nsvc_filter(tgt, nsvc); |
| 2262 | log_tgt_mutex_unlock(); |
| 2263 | return CMD_SUCCESS; |
| 2264 | } |
| 2265 | |
Alexander Couzens | e43b46e | 2021-01-27 21:52:08 +0100 | [diff] [blame] | 2266 | /*! initialized a reduced vty interface which excludes the configuration nodes besides timeouts. |
| 2267 | * This can be used by the PCU which can be only configured by the BTS/BSC and not by the vty. |
| 2268 | * \param[in] nsi NS instance on which we operate |
| 2269 | * \return 0 on success. |
| 2270 | */ |
| 2271 | int gprs_ns2_vty_init_reduced(struct gprs_ns2_inst *nsi) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2272 | { |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 2273 | vty_nsi = nsi; |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2274 | INIT_LLIST_HEAD(&binds); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 2275 | INIT_LLIST_HEAD(&nses); |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 2276 | INIT_LLIST_HEAD(&ip_sns_default_binds); |
Pau Espin Pedrol | caf5317 | 2021-01-28 13:37:50 +0100 | [diff] [blame] | 2277 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2278 | vty_fr_network = osmo_fr_network_alloc(nsi); |
| 2279 | if (!vty_fr_network) |
| 2280 | return -ENOMEM; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2281 | |
Harald Welte | 25ee755 | 2020-12-02 22:14:00 +0100 | [diff] [blame] | 2282 | install_lib_element_ve(&show_ns_cmd); |
Harald Welte | 2fce19a | 2020-12-01 17:52:55 +0100 | [diff] [blame] | 2283 | install_lib_element_ve(&show_ns_binds_cmd); |
| 2284 | install_lib_element_ve(&show_ns_entities_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 2285 | install_lib_element_ve(&show_ns_pers_cmd); |
| 2286 | install_lib_element_ve(&show_nse_cmd); |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 2287 | install_lib_element_ve(&logging_fltr_nse_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 2288 | install_lib_element_ve(&logging_fltr_nsvc_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2289 | |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 2290 | install_lib_element(ENABLE_NODE, &nsvc_force_unconf_cmd); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2291 | install_lib_element(ENABLE_NODE, &nsvc_block_cmd); |
Alexander Couzens | d13faaa | 2021-03-01 03:14:19 +0100 | [diff] [blame] | 2292 | install_lib_element(ENABLE_NODE, &nse_restart_sns_cmd); |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 2293 | |
Daniel Willmann | 751977b | 2020-12-02 18:59:44 +0100 | [diff] [blame] | 2294 | install_lib_element(CFG_LOG_NODE, &logging_fltr_nse_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 2295 | install_lib_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2296 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 2297 | install_lib_element(CONFIG_NODE, &cfg_ns_cmd); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2298 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2299 | install_node(&ns_node, config_write_ns); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2300 | /* TODO: convert into osmo timer */ |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 2301 | install_lib_element(L_NS_NODE, &cfg_ns_timer_cmd); |
Alexander Couzens | e43b46e | 2021-01-27 21:52:08 +0100 | [diff] [blame] | 2302 | |
| 2303 | return 0; |
| 2304 | } |
| 2305 | |
| 2306 | int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi) |
| 2307 | { |
| 2308 | int rc = gprs_ns2_vty_init_reduced(nsi); |
| 2309 | if (rc) |
| 2310 | return rc; |
| 2311 | |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2312 | install_lib_element(L_NS_NODE, &cfg_ns_nsei_cmd); |
| 2313 | install_lib_element(L_NS_NODE, &cfg_no_ns_nsei_cmd); |
| 2314 | install_lib_element(L_NS_NODE, &cfg_ns_bind_cmd); |
| 2315 | install_lib_element(L_NS_NODE, &cfg_no_ns_bind_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2316 | |
Harald Welte | d164ef8 | 2021-03-04 22:29:17 +0100 | [diff] [blame] | 2317 | install_lib_element(L_NS_NODE, &cfg_ns_ip_sns_default_bind_cmd); |
| 2318 | install_lib_element(L_NS_NODE, &cfg_no_ns_ip_sns_default_bind_cmd); |
| 2319 | |
Daniel Willmann | 3236fdf | 2023-08-29 16:24:56 +0200 | [diff] [blame] | 2320 | install_lib_element(L_NS_NODE, &cfg_ns_txqueue_max_length_cmd); |
| 2321 | |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 2322 | install_node(&ns_bind_node, NULL); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2323 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_listen_cmd); |
| 2324 | install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_listen_cmd); |
| 2325 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_dscp_cmd); |
| 2326 | install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_dscp_cmd); |
Harald Welte | d99e4ee | 2021-04-28 19:57:12 +0200 | [diff] [blame] | 2327 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_priority_cmd); |
Alexander Couzens | c470476 | 2021-02-08 23:13:12 +0100 | [diff] [blame] | 2328 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ip_sns_weight_cmd); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2329 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_ipaccess_cmd); |
| 2330 | install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_ipaccess_cmd); |
| 2331 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_fr_cmd); |
| 2332 | install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_fr_cmd); |
Harald Welte | 42e3646 | 2021-03-03 18:12:09 +0100 | [diff] [blame] | 2333 | install_lib_element(L_NS_BIND_NODE, &cfg_ns_bind_accept_sns_cmd); |
| 2334 | install_lib_element(L_NS_BIND_NODE, &cfg_no_ns_bind_accept_sns_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2335 | |
Alexander Couzens | 260cd52 | 2021-01-28 20:31:31 +0100 | [diff] [blame] | 2336 | install_node(&ns_nse_node, NULL); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2337 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_fr_cmd); |
| 2338 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvci_cmd); |
| 2339 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_fr_dlci_cmd); |
| 2340 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_udp_cmd); |
Alexander Couzens | bf5d0db | 2021-02-12 04:04:13 +0100 | [diff] [blame] | 2341 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_udp_weights_cmd); |
Alexander Couzens | da1bf8e | 2021-01-25 16:27:33 +0100 | [diff] [blame] | 2342 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_udp_cmd); |
| 2343 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_nsvc_ipa_cmd); |
| 2344 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_nsvc_ipa_cmd); |
Alexander Couzens | 5fa431c | 2021-02-08 23:21:54 +0100 | [diff] [blame] | 2345 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_ip_sns_remote_cmd); |
| 2346 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_ip_sns_remote_cmd); |
Alexander Couzens | 6b9d232 | 2021-02-12 03:17:59 +0100 | [diff] [blame] | 2347 | install_lib_element(L_NS_NSE_NODE, &cfg_ns_nse_ip_sns_bind_cmd); |
| 2348 | install_lib_element(L_NS_NSE_NODE, &cfg_no_ns_nse_ip_sns_bind_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 2349 | |
| 2350 | return 0; |
| 2351 | } |