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 | |
| 4 | /* (C) 2009-2014 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2016-2017 by sysmocom - s.f.m.c. GmbH |
| 6 | * (C) 2020 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de> |
| 7 | * Author: Alexander Couzens <lynxis@fe80.eu> |
| 8 | * |
| 9 | * All Rights Reserved |
| 10 | * |
| 11 | * SPDX-License-Identifier: GPL-2.0+ |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <stdlib.h> |
| 29 | #include <unistd.h> |
| 30 | #include <errno.h> |
| 31 | #include <stdint.h> |
| 32 | |
| 33 | #include <arpa/inet.h> |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 34 | #include <net/if.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 35 | |
| 36 | #include <osmocom/core/msgb.h> |
| 37 | #include <osmocom/core/byteswap.h> |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 38 | #include <osmocom/core/fsm.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 39 | #include <osmocom/core/talloc.h> |
| 40 | #include <osmocom/core/select.h> |
| 41 | #include <osmocom/core/rate_ctr.h> |
| 42 | #include <osmocom/core/socket.h> |
| 43 | #include <osmocom/core/sockaddr_str.h> |
| 44 | #include <osmocom/core/linuxlist.h> |
| 45 | #include <osmocom/core/socket.h> |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 46 | #include <osmocom/gprs/frame_relay.h> |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 47 | #include <osmocom/gprs/gprs_ns2.h> |
| 48 | #include <osmocom/gsm/tlv.h> |
| 49 | #include <osmocom/vty/vty.h> |
| 50 | #include <osmocom/vty/command.h> |
| 51 | #include <osmocom/vty/logging.h> |
| 52 | #include <osmocom/vty/telnet_interface.h> |
| 53 | #include <osmocom/vty/misc.h> |
| 54 | |
| 55 | #include "gprs_ns2_internal.h" |
| 56 | |
| 57 | struct ns2_vty_priv { |
| 58 | /* global listen */ |
| 59 | struct osmo_sockaddr_str udp; |
| 60 | struct osmo_sockaddr_str frgreaddr; |
| 61 | int dscp; |
| 62 | enum gprs_ns2_vc_mode vc_mode; |
| 63 | /* force vc mode if another configuration forces |
| 64 | * the vc mode. E.g. SNS configuration */ |
| 65 | bool force_vc_mode; |
Daniel Willmann | 4fb27a8 | 2020-09-25 15:39:46 +0200 | [diff] [blame] | 66 | const char *force_vc_mode_reason; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 67 | bool frgre; |
| 68 | |
| 69 | struct llist_head vtyvc; |
| 70 | }; |
| 71 | |
| 72 | struct ns2_vty_vc { |
| 73 | struct llist_head list; |
| 74 | |
| 75 | struct osmo_sockaddr_str remote; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 76 | enum gprs_ns2_ll ll; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 77 | |
| 78 | /* old vty code doesnt support multiple NSVCI per NSEI */ |
| 79 | uint16_t nsei; |
| 80 | uint16_t nsvci; |
| 81 | uint16_t frdlci; |
| 82 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 83 | struct { |
| 84 | enum osmo_fr_role role; |
| 85 | } fr; |
| 86 | |
| 87 | char netif[IF_NAMESIZE]; |
| 88 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 89 | bool remote_end_is_sgsn; |
| 90 | bool configured; |
| 91 | }; |
| 92 | |
| 93 | static struct gprs_ns2_inst *vty_nsi = NULL; |
| 94 | static struct ns2_vty_priv priv; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 95 | static struct osmo_fr_network *vty_fr_network = NULL; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 96 | |
| 97 | /* FIXME: this should go to some common file as it is copied |
| 98 | * in vty_interface.c of the BSC */ |
| 99 | static const struct value_string gprs_ns_timer_strs[] = { |
| 100 | { 0, "tns-block" }, |
| 101 | { 1, "tns-block-retries" }, |
| 102 | { 2, "tns-reset" }, |
| 103 | { 3, "tns-reset-retries" }, |
| 104 | { 4, "tns-test" }, |
| 105 | { 5, "tns-alive" }, |
| 106 | { 6, "tns-alive-retries" }, |
| 107 | { 7, "tsns-prov" }, |
| 108 | { 0, NULL } |
| 109 | }; |
| 110 | |
| 111 | static void log_set_nsvc_filter(struct log_target *target, |
| 112 | struct gprs_ns2_vc *nsvc) |
| 113 | { |
| 114 | if (nsvc) { |
| 115 | target->filter_map |= (1 << LOG_FLT_GB_NSVC); |
| 116 | target->filter_data[LOG_FLT_GB_NSVC] = nsvc; |
| 117 | } else if (target->filter_data[LOG_FLT_GB_NSVC]) { |
| 118 | target->filter_map = ~(1 << LOG_FLT_GB_NSVC); |
| 119 | target->filter_data[LOG_FLT_GB_NSVC] = NULL; |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | static struct cmd_node ns_node = { |
| 124 | L_NS_NODE, |
| 125 | "%s(config-ns)# ", |
| 126 | 1, |
| 127 | }; |
| 128 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 129 | static struct ns2_vty_vc *vtyvc_alloc(uint16_t nsei) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 130 | struct ns2_vty_vc *vtyvc = talloc_zero(vty_nsi, struct ns2_vty_vc); |
| 131 | if (!vtyvc) |
| 132 | return vtyvc; |
| 133 | |
| 134 | vtyvc->nsei = nsei; |
| 135 | |
| 136 | llist_add(&vtyvc->list, &priv.vtyvc); |
| 137 | |
| 138 | return vtyvc; |
| 139 | } |
| 140 | |
| 141 | static void ns2_vc_free(struct ns2_vty_vc *vtyvc) { |
| 142 | if (!vtyvc) |
| 143 | return; |
| 144 | |
| 145 | llist_del(&vtyvc->list); |
| 146 | talloc_free(vtyvc); |
| 147 | } |
| 148 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 149 | static struct ns2_vty_vc *vtyvc_by_nsei(uint16_t nsei, bool alloc_missing) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 150 | struct ns2_vty_vc *vtyvc; |
Alexander Couzens | 1f0625f | 2020-09-23 18:22:20 +0200 | [diff] [blame] | 151 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 152 | llist_for_each_entry(vtyvc, &priv.vtyvc, list) { |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 153 | if (vtyvc->nsei == nsei) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 154 | return vtyvc; |
| 155 | } |
| 156 | |
Alexander Couzens | 1f0625f | 2020-09-23 18:22:20 +0200 | [diff] [blame] | 157 | if (!alloc_missing) |
| 158 | return NULL; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 159 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 160 | vtyvc = vtyvc_alloc(nsei); |
Alexander Couzens | 1f0625f | 2020-09-23 18:22:20 +0200 | [diff] [blame] | 161 | if (!vtyvc) |
| 162 | return vtyvc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 163 | |
Alexander Couzens | 1f0625f | 2020-09-23 18:22:20 +0200 | [diff] [blame] | 164 | vtyvc->nsei = nsei; |
| 165 | return vtyvc; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static int config_write_ns(struct vty *vty) |
| 169 | { |
| 170 | struct ns2_vty_vc *vtyvc; |
| 171 | unsigned int i; |
| 172 | struct osmo_sockaddr_str sockstr; |
| 173 | |
| 174 | vty_out(vty, "ns%s", VTY_NEWLINE); |
| 175 | |
| 176 | /* global configuration must be written first, as some of it may be |
| 177 | * relevant when creating the NSE/NSVC later below */ |
| 178 | |
| 179 | vty_out(vty, " encapsulation framerelay-gre enabled %u%s", |
| 180 | priv.frgre ? 1 : 0, VTY_NEWLINE); |
| 181 | |
| 182 | if (priv.frgre) { |
| 183 | if (strlen(priv.frgreaddr.ip)) { |
| 184 | vty_out(vty, " encapsulation framerelay-gre local-ip %s%s", |
| 185 | sockstr.ip, VTY_NEWLINE); |
| 186 | } |
| 187 | } else { |
| 188 | if (strlen(priv.udp.ip)) { |
| 189 | vty_out(vty, " encapsulation udp local-ip %s%s", |
| 190 | priv.udp.ip, VTY_NEWLINE); |
| 191 | } |
| 192 | |
| 193 | if (priv.udp.port) |
| 194 | vty_out(vty, " encapsulation udp local-port %u%s", |
| 195 | priv.udp.port, VTY_NEWLINE); |
| 196 | } |
| 197 | |
| 198 | if (priv.dscp) |
| 199 | vty_out(vty, " encapsulation udp dscp %d%s", |
| 200 | priv.dscp, VTY_NEWLINE); |
| 201 | |
| 202 | vty_out(vty, " encapsulation udp use-reset-block-unblock %s%s", |
| 203 | priv.vc_mode == NS2_VC_MODE_BLOCKRESET ? "enabled" : "disabled", VTY_NEWLINE); |
| 204 | |
| 205 | llist_for_each_entry(vtyvc, &priv.vtyvc, list) { |
| 206 | vty_out(vty, " nse %u nsvci %u%s", |
| 207 | vtyvc->nsei, vtyvc->nsvci, VTY_NEWLINE); |
| 208 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 209 | vty_out(vty, " nse %u remote-role %s%s", |
| 210 | vtyvc->nsei, vtyvc->remote_end_is_sgsn ? "sgsn" : "bss", |
| 211 | VTY_NEWLINE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 212 | |
| 213 | switch (vtyvc->ll) { |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 214 | case GPRS_NS2_LL_UDP: |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 215 | vty_out(vty, " nse %u encapsulation udp%s", vtyvc->nsei, VTY_NEWLINE); |
| 216 | vty_out(vty, " nse %u remote-ip %s%s", |
| 217 | vtyvc->nsei, |
| 218 | vtyvc->remote.ip, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 219 | VTY_NEWLINE); |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 220 | vty_out(vty, " nse %u remote-port %u%s", |
| 221 | vtyvc->nsei, vtyvc->remote.port, |
| 222 | VTY_NEWLINE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 223 | break; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 224 | case GPRS_NS2_LL_FR_GRE: |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 225 | vty_out(vty, " nse %u encapsulation framerelay-gre%s", |
| 226 | vtyvc->nsei, VTY_NEWLINE); |
| 227 | vty_out(vty, " nse %u remote-ip %s%s", |
| 228 | vtyvc->nsei, |
| 229 | vtyvc->remote.ip, |
| 230 | VTY_NEWLINE); |
| 231 | vty_out(vty, " nse %u fr-dlci %u%s", |
| 232 | vtyvc->nsei, vtyvc->frdlci, |
| 233 | VTY_NEWLINE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 234 | break; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 235 | case GPRS_NS2_LL_FR: |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 236 | vty_out(vty, " nse %u fr %s dlci %u%s", |
| 237 | vtyvc->nsei, vtyvc->netif, vtyvc->frdlci, |
| 238 | VTY_NEWLINE); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 239 | break; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 240 | default: |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++) |
| 246 | vty_out(vty, " timer %s %u%s", |
| 247 | get_value_string(gprs_ns_timer_strs, i), |
| 248 | vty_nsi->timeout[i], VTY_NEWLINE); |
| 249 | |
| 250 | return CMD_SUCCESS; |
| 251 | } |
| 252 | |
| 253 | DEFUN(cfg_ns, cfg_ns_cmd, |
| 254 | "ns", |
| 255 | "Configure the GPRS Network Service") |
| 256 | { |
| 257 | vty->node = L_NS_NODE; |
| 258 | return CMD_SUCCESS; |
| 259 | } |
| 260 | |
| 261 | static void dump_nsvc(struct vty *vty, struct gprs_ns2_vc *nsvc, bool stats) |
| 262 | { |
Daniel Willmann | ed1fa01 | 2020-11-06 15:40:27 +0100 | [diff] [blame] | 263 | vty_out(vty, " %s%s", gprs_ns2_ll_str(nsvc), VTY_NEWLINE); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 264 | |
| 265 | if (stats) { |
| 266 | vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); |
| 267 | vty_out_stat_item_group(vty, " ", nsvc->statg); |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | static void dump_nse(struct vty *vty, const struct gprs_ns2_nse *nse, bool stats, bool persistent_only) |
| 272 | { |
| 273 | struct gprs_ns2_vc *nsvc; |
| 274 | |
| 275 | vty_out(vty, "NSEI %5u%s", |
| 276 | nse->nsei, VTY_NEWLINE); |
| 277 | |
| 278 | gprs_ns2_sns_dump_vty(vty, nse, stats); |
| 279 | llist_for_each_entry(nsvc, &nse->nsvc, list) { |
| 280 | if (persistent_only) { |
| 281 | if (nsvc->persistent) |
| 282 | dump_nsvc(vty, nsvc, stats); |
| 283 | } else { |
| 284 | dump_nsvc(vty, nsvc, stats); |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 289 | static void dump_bind(struct vty *vty, const struct gprs_ns2_vc_bind *bind, bool stats) |
| 290 | { |
| 291 | if (bind->dump_vty) |
| 292 | bind->dump_vty(bind, vty, stats); |
| 293 | } |
| 294 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 295 | static void dump_ns(struct vty *vty, const struct gprs_ns2_inst *nsi, bool stats, bool persistent_only) |
| 296 | { |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 297 | struct gprs_ns2_vc_bind *bind; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 298 | struct gprs_ns2_nse *nse; |
| 299 | |
Alexander Couzens | 22f3471 | 2020-10-02 02:34:39 +0200 | [diff] [blame] | 300 | llist_for_each_entry(bind, &nsi->binding, list) { |
| 301 | dump_bind(vty, bind, stats); |
| 302 | } |
| 303 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 304 | llist_for_each_entry(nse, &nsi->nse, list) { |
| 305 | dump_nse(vty, nse, stats, persistent_only); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | } |
| 309 | |
| 310 | DEFUN(show_ns, show_ns_cmd, "show ns", |
| 311 | SHOW_STR "Display information about the NS protocol") |
| 312 | { |
| 313 | dump_ns(vty, vty_nsi, false, false); |
| 314 | return CMD_SUCCESS; |
| 315 | } |
| 316 | |
| 317 | DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats", |
| 318 | SHOW_STR |
| 319 | "Display information about the NS protocol\n" |
| 320 | "Include statistics\n") |
| 321 | { |
| 322 | dump_ns(vty, vty_nsi, true, false); |
| 323 | return CMD_SUCCESS; |
| 324 | } |
| 325 | |
| 326 | DEFUN(show_ns_pers, show_ns_pers_cmd, "show ns persistent", |
| 327 | SHOW_STR |
| 328 | "Display information about the NS protocol\n" |
| 329 | "Show only persistent NS\n") |
| 330 | { |
| 331 | dump_ns(vty, vty_nsi, true, true); |
| 332 | return CMD_SUCCESS; |
| 333 | } |
| 334 | |
| 335 | DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]", |
| 336 | SHOW_STR "Display information about the NS protocol\n" |
| 337 | "Select one NSE by its NSE Identifier\n" |
| 338 | "Select one NSE by its NS-VC Identifier\n" |
| 339 | "The Identifier of selected type\n" |
| 340 | "Include Statistics\n") |
| 341 | { |
| 342 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 343 | struct gprs_ns2_nse *nse; |
| 344 | struct gprs_ns2_vc *nsvc; |
| 345 | uint16_t id = atoi(argv[1]); |
| 346 | bool show_stats = false; |
| 347 | |
| 348 | if (argc >= 3) |
| 349 | show_stats = true; |
| 350 | |
| 351 | if (!strcmp(argv[0], "nsei")) { |
| 352 | nse = gprs_ns2_nse_by_nsei(nsi, id); |
| 353 | if (!nse) { |
| 354 | return CMD_WARNING; |
| 355 | } |
| 356 | |
| 357 | dump_nse(vty, nse, show_stats, false); |
| 358 | } else { |
| 359 | nsvc = gprs_ns2_nsvc_by_nsvci(nsi, id); |
| 360 | |
| 361 | if (!nsvc) { |
| 362 | vty_out(vty, "No such NS Entity%s", VTY_NEWLINE); |
| 363 | return CMD_WARNING; |
| 364 | } |
| 365 | |
| 366 | dump_nsvc(vty, nsvc, show_stats); |
| 367 | } |
| 368 | |
| 369 | return CMD_SUCCESS; |
| 370 | } |
| 371 | |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 372 | static int nsvc_force_unconf_cb(struct gprs_ns2_vc *nsvc, void *ctx) |
| 373 | { |
| 374 | gprs_ns2_vc_force_unconfigured(nsvc); |
| 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | DEFUN_HIDDEN(nsvc_force_unconf, nsvc_force_unconf_cmd, |
| 379 | "nsvc nsei <0-65535> force-unconfigured", |
| 380 | "NS Virtual Connection\n" |
| 381 | "The NSEI\n" |
| 382 | "Reset the NSVCs back to initial state\n" |
| 383 | ) |
| 384 | { |
| 385 | struct gprs_ns2_inst *nsi = vty_nsi; |
| 386 | struct gprs_ns2_nse *nse; |
| 387 | |
| 388 | uint16_t id = atoi(argv[0]); |
| 389 | |
| 390 | nse = gprs_ns2_nse_by_nsei(nsi, id); |
| 391 | if (!nse) { |
| 392 | vty_out(vty, "Could not find NSE for NSEI %u%s", id, VTY_NEWLINE); |
| 393 | return CMD_WARNING; |
| 394 | } |
| 395 | |
| 396 | /* Perform the operation for all nsvc */ |
| 397 | gprs_ns2_nse_foreach_nsvc(nse, nsvc_force_unconf_cb, NULL); |
| 398 | |
| 399 | return CMD_SUCCESS; |
| 400 | } |
| 401 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 402 | #define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n" |
| 403 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 404 | DEFUN(cfg_nse_fr, cfg_nse_fr_cmd, |
| 405 | "nse <0-65535> nsvci <0-65535> (fr|frnet) NETIF dlci <0-1023>", |
| 406 | NSE_CMD_STR |
| 407 | "NS Virtual Connection\n" |
| 408 | "NS Virtual Connection ID (NSVCI)\n" |
| 409 | "frame relay\n" |
| 410 | IFNAME_STR |
| 411 | "Data Link connection identifier\n" |
| 412 | "Data Link connection identifier\n" |
| 413 | ) |
| 414 | { |
| 415 | struct ns2_vty_vc *vtyvc; |
| 416 | |
| 417 | uint16_t nsei = atoi(argv[0]); |
| 418 | uint16_t nsvci = atoi(argv[1]); |
| 419 | const char *role = argv[2]; |
| 420 | const char *name = argv[3]; |
| 421 | uint16_t dlci = atoi(argv[4]); |
| 422 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 423 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 424 | if (!vtyvc) { |
| 425 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 426 | return CMD_WARNING; |
| 427 | } |
| 428 | |
| 429 | if (!strcmp(role, "fr")) |
| 430 | vtyvc->fr.role = FR_ROLE_USER_EQUIPMENT; |
| 431 | else if (!strcmp(role, "frnet")) |
| 432 | vtyvc->fr.role = FR_ROLE_NETWORK_EQUIPMENT; |
| 433 | |
| 434 | osmo_strlcpy(vtyvc->netif, name, sizeof(vtyvc->netif)); |
| 435 | vtyvc->frdlci = dlci; |
| 436 | vtyvc->nsvci = nsvci; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 437 | vtyvc->ll = GPRS_NS2_LL_FR; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 438 | |
| 439 | return CMD_SUCCESS; |
| 440 | } |
| 441 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 442 | DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, |
| 443 | "nse <0-65535> nsvci <0-65535>", |
| 444 | NSE_CMD_STR |
| 445 | "NS Virtual Connection\n" |
| 446 | "NS Virtual Connection ID (NSVCI)\n" |
| 447 | ) |
| 448 | { |
| 449 | struct ns2_vty_vc *vtyvc; |
| 450 | |
| 451 | uint16_t nsei = atoi(argv[0]); |
| 452 | uint16_t nsvci = atoi(argv[1]); |
| 453 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 454 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 455 | if (!vtyvc) { |
| 456 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 457 | return CMD_WARNING; |
| 458 | } |
| 459 | |
| 460 | vtyvc->nsvci = nsvci; |
| 461 | |
| 462 | return CMD_SUCCESS; |
| 463 | } |
| 464 | |
| 465 | DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd, |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 466 | "nse <0-65535> remote-ip " VTY_IPV46_CMD, |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 467 | NSE_CMD_STR |
| 468 | "Remote IP Address\n" |
Alexander Couzens | c82c40a | 2020-09-24 05:55:48 +0200 | [diff] [blame] | 469 | "Remote IPv4 Address\n" |
| 470 | "Remote IPv6 Address\n") |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 471 | { |
| 472 | uint16_t nsei = atoi(argv[0]); |
| 473 | struct ns2_vty_vc *vtyvc; |
| 474 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 475 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 476 | if (!vtyvc) { |
| 477 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 478 | return CMD_WARNING; |
| 479 | } |
| 480 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 481 | osmo_sockaddr_str_from_str2(&vtyvc->remote, argv[1]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 482 | |
| 483 | return CMD_SUCCESS; |
| 484 | } |
| 485 | |
| 486 | DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 487 | "nse <0-65535> remote-port <0-65535>", |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 488 | NSE_CMD_STR |
| 489 | "Remote UDP Port\n" |
| 490 | "Remote UDP Port Number\n") |
| 491 | { |
| 492 | uint16_t nsei = atoi(argv[0]); |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 493 | uint16_t port = atoi(argv[1]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 494 | struct ns2_vty_vc *vtyvc; |
| 495 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 496 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 497 | if (!vtyvc) { |
| 498 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 499 | return CMD_WARNING; |
| 500 | } |
| 501 | |
| 502 | vtyvc->remote.port = port; |
| 503 | |
| 504 | return CMD_SUCCESS; |
| 505 | } |
| 506 | |
| 507 | DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 508 | "nse <0-65535> nsvci <0-65535> fr-dlci <16-1007>", |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 509 | NSE_CMD_STR |
| 510 | "Frame Relay DLCI\n" |
| 511 | "Frame Relay DLCI Number\n") |
| 512 | { |
| 513 | uint16_t nsei = atoi(argv[0]); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 514 | uint16_t nsvci = atoi(argv[1]); |
| 515 | uint16_t dlci = atoi(argv[2]); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 516 | struct ns2_vty_vc *vtyvc; |
| 517 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 518 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 519 | if (!vtyvc) { |
| 520 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 521 | return CMD_WARNING; |
| 522 | } |
| 523 | |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 524 | vtyvc->frdlci = dlci; |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 525 | vtyvc->nsvci = nsvci; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 526 | |
| 527 | return CMD_SUCCESS; |
| 528 | } |
| 529 | |
| 530 | DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 531 | "nse <0-65535> encapsulation (udp|framerelay-gre)", |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 532 | NSE_CMD_STR |
| 533 | "Encapsulation for NS\n" |
| 534 | "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n") |
| 535 | { |
| 536 | uint16_t nsei = atoi(argv[0]); |
| 537 | struct ns2_vty_vc *vtyvc; |
| 538 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 539 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 540 | if (!vtyvc) { |
| 541 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 542 | return CMD_WARNING; |
| 543 | } |
| 544 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 545 | if (!strcmp(argv[1], "udp")) |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 546 | vtyvc->ll = GPRS_NS2_LL_UDP; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 547 | else |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 548 | vtyvc->ll = GPRS_NS2_LL_FR_GRE; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 549 | |
| 550 | return CMD_SUCCESS; |
| 551 | } |
| 552 | |
| 553 | DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 554 | "nse <0-65535> remote-role (sgsn|bss)", |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 555 | NSE_CMD_STR |
| 556 | "Remote NSE Role\n" |
| 557 | "Remote Peer is SGSN\n" |
| 558 | "Remote Peer is BSS\n") |
| 559 | { |
| 560 | uint16_t nsei = atoi(argv[0]); |
| 561 | struct ns2_vty_vc *vtyvc; |
| 562 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 563 | vtyvc = vtyvc_by_nsei(nsei, true); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 564 | if (!vtyvc) { |
| 565 | vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); |
| 566 | return CMD_WARNING; |
| 567 | } |
| 568 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 569 | if (!strcmp(argv[1], "sgsn")) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 570 | vtyvc->remote_end_is_sgsn = 1; |
| 571 | else |
| 572 | vtyvc->remote_end_is_sgsn = 0; |
| 573 | |
| 574 | return CMD_SUCCESS; |
| 575 | } |
| 576 | |
| 577 | DEFUN(cfg_no_nse, cfg_no_nse_cmd, |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 578 | "no nse <0-65535>", |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 579 | "Delete Persistent NS Entity\n" |
| 580 | "Delete " NSE_CMD_STR) |
| 581 | { |
| 582 | uint16_t nsei = atoi(argv[0]); |
| 583 | struct ns2_vty_vc *vtyvc; |
| 584 | |
Harald Welte | 6d4db23 | 2020-11-25 19:33:42 +0100 | [diff] [blame^] | 585 | vtyvc = vtyvc_by_nsei(nsei, false); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 586 | if (!vtyvc) { |
| 587 | vty_out(vty, "The NSE %d does not exists.%s", nsei, VTY_NEWLINE); |
| 588 | return CMD_WARNING; |
| 589 | } |
| 590 | |
| 591 | ns2_vc_free(vtyvc); |
| 592 | |
| 593 | return CMD_SUCCESS; |
| 594 | } |
| 595 | |
| 596 | DEFUN(cfg_ns_timer, cfg_ns_timer_cmd, |
| 597 | "timer " NS_TIMERS " <0-65535>", |
| 598 | "Network Service Timer\n" |
| 599 | NS_TIMERS_HELP "Timer Value\n") |
| 600 | { |
| 601 | int idx = get_string_value(gprs_ns_timer_strs, argv[0]); |
| 602 | int val = atoi(argv[1]); |
| 603 | |
| 604 | if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout)) |
| 605 | return CMD_WARNING; |
| 606 | |
| 607 | vty_nsi->timeout[idx] = val; |
| 608 | |
| 609 | return CMD_SUCCESS; |
| 610 | } |
| 611 | |
| 612 | #define ENCAPS_STR "NS encapsulation options\n" |
| 613 | |
| 614 | DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd, |
| 615 | "encapsulation udp local-ip " VTY_IPV46_CMD, |
| 616 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 617 | "Set the IP address on which we listen for NS/UDP\n" |
Alexander Couzens | c82c40a | 2020-09-24 05:55:48 +0200 | [diff] [blame] | 618 | "IPv4 Address\n" |
| 619 | "IPv6 Address\n") |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 620 | { |
| 621 | osmo_sockaddr_str_from_str2(&priv.udp, argv[0]); |
| 622 | |
| 623 | return CMD_SUCCESS; |
| 624 | } |
| 625 | |
| 626 | DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd, |
| 627 | "encapsulation udp local-port <0-65535>", |
| 628 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 629 | "Set the UDP port on which we listen for NS/UDP\n" |
| 630 | "UDP port number\n") |
| 631 | { |
| 632 | unsigned int port = atoi(argv[0]); |
| 633 | |
| 634 | priv.udp.port = port; |
| 635 | |
| 636 | return CMD_SUCCESS; |
| 637 | } |
| 638 | |
| 639 | DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd, |
| 640 | "encapsulation udp dscp <0-255>", |
| 641 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 642 | "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n") |
| 643 | { |
| 644 | int dscp = atoi(argv[0]); |
| 645 | struct gprs_ns2_vc_bind *bind; |
| 646 | |
| 647 | priv.dscp = dscp; |
| 648 | |
| 649 | llist_for_each_entry(bind, &vty_nsi->binding, list) { |
| 650 | if (gprs_ns2_is_ip_bind(bind)) |
| 651 | gprs_ns2_ip_bind_set_dscp(bind, dscp); |
| 652 | } |
| 653 | |
| 654 | return CMD_SUCCESS; |
| 655 | } |
| 656 | |
| 657 | DEFUN(cfg_nsip_res_block_unblock, cfg_nsip_res_block_unblock_cmd, |
| 658 | "encapsulation udp use-reset-block-unblock (enabled|disabled)", |
| 659 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 660 | "Use NS-{RESET,BLOCK,UNBLOCK} procedures in violation of 3GPP TS 48.016\n" |
| 661 | "Enable NS-{RESET,BLOCK,UNBLOCK}\n" |
| 662 | "Disable NS-{RESET,BLOCK,UNBLOCK}\n") |
| 663 | { |
| 664 | enum gprs_ns2_vc_mode vc_mode; |
| 665 | struct gprs_ns2_vc_bind *bind; |
| 666 | |
| 667 | if (!strcmp(argv[0], "enabled")) |
| 668 | vc_mode = NS2_VC_MODE_BLOCKRESET; |
| 669 | else |
| 670 | vc_mode = NS2_VC_MODE_ALIVE; |
| 671 | |
| 672 | if (priv.force_vc_mode) { |
| 673 | if (priv.vc_mode != vc_mode) |
| 674 | { |
| 675 | vty_out(vty, "Ignoring use-reset-block because it's already set by %s.%s", |
| 676 | priv.force_vc_mode_reason, VTY_NEWLINE); |
| 677 | return CMD_WARNING; |
| 678 | } |
| 679 | |
| 680 | return CMD_SUCCESS; |
| 681 | } |
| 682 | |
| 683 | priv.vc_mode = vc_mode; |
| 684 | |
| 685 | llist_for_each_entry(bind, &vty_nsi->binding, list) { |
| 686 | gprs_ns2_bind_set_mode(bind, priv.vc_mode); |
| 687 | } |
| 688 | |
| 689 | return CMD_SUCCESS; |
| 690 | } |
| 691 | |
| 692 | DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd, |
| 693 | "encapsulation framerelay-gre local-ip " VTY_IPV46_CMD, |
| 694 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 695 | "Set the IP address on which we listen for NS/FR/GRE\n" |
Alexander Couzens | c82c40a | 2020-09-24 05:55:48 +0200 | [diff] [blame] | 696 | "IPv4 Address\n" |
| 697 | "IPv6 Address\n") |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 698 | { |
| 699 | osmo_sockaddr_str_from_str2(&priv.frgreaddr, argv[0]); |
| 700 | |
| 701 | return CMD_SUCCESS; |
| 702 | } |
| 703 | |
| 704 | DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd, |
| 705 | "encapsulation framerelay-gre enabled (1|0)", |
| 706 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 707 | "Enable or disable Frame Relay over GRE\n" |
| 708 | "Enable\n" "Disable\n") |
| 709 | { |
| 710 | int enabled = atoi(argv[0]); |
| 711 | |
| 712 | priv.frgre = enabled; |
| 713 | |
| 714 | return CMD_SUCCESS; |
| 715 | } |
| 716 | |
| 717 | /* TODO: allow vty to reset/block/unblock nsvc/nsei */ |
| 718 | |
| 719 | /* TODO: add filter for NSEI as ns1 code does */ |
| 720 | /* TODO: add filter for single connection by description */ |
| 721 | DEFUN(logging_fltr_nsvc, |
| 722 | logging_fltr_nsvc_cmd, |
| 723 | "logging filter nsvc nsvci <0-65535>", |
| 724 | LOGGING_STR FILTER_STR |
| 725 | "Filter based on NS Virtual Connection\n" |
| 726 | "Identify NS-VC by NSVCI\n" |
| 727 | "Numeric identifier\n") |
| 728 | { |
| 729 | struct log_target *tgt; |
| 730 | struct gprs_ns2_vc *nsvc; |
| 731 | uint16_t id = atoi(argv[1]); |
| 732 | |
| 733 | log_tgt_mutex_lock(); |
| 734 | tgt = osmo_log_vty2tgt(vty); |
| 735 | if (!tgt) { |
| 736 | log_tgt_mutex_unlock(); |
| 737 | return CMD_WARNING; |
| 738 | } |
| 739 | |
| 740 | nsvc = gprs_ns2_nsvc_by_nsvci(vty_nsi, id); |
| 741 | if (!nsvc) { |
| 742 | vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE); |
| 743 | log_tgt_mutex_unlock(); |
| 744 | return CMD_WARNING; |
| 745 | } |
| 746 | |
| 747 | log_set_nsvc_filter(tgt, nsvc); |
| 748 | log_tgt_mutex_unlock(); |
| 749 | return CMD_SUCCESS; |
| 750 | } |
| 751 | |
Alexander Couzens | 1fac6f7 | 2020-10-01 19:08:38 +0200 | [diff] [blame] | 752 | /** |
| 753 | * gprs_ns2_vty_init initialize the vty |
| 754 | * \param[inout] nsi |
| 755 | * \param[in] default_bind set the default address to bind to. Can be NULL. |
| 756 | * \return 0 on success |
| 757 | */ |
Vadim Yanitskiy | a07f25e | 2020-10-09 21:47:01 +0700 | [diff] [blame] | 758 | int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi, |
| 759 | const struct osmo_sockaddr_str *default_bind) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 760 | { |
| 761 | static bool vty_elements_installed = false; |
| 762 | |
| 763 | vty_nsi = nsi; |
| 764 | memset(&priv, 0, sizeof(struct ns2_vty_priv)); |
| 765 | INIT_LLIST_HEAD(&priv.vtyvc); |
| 766 | priv.vc_mode = NS2_VC_MODE_BLOCKRESET; |
Alexander Couzens | 1fac6f7 | 2020-10-01 19:08:38 +0200 | [diff] [blame] | 767 | if (default_bind) |
| 768 | memcpy(&priv.udp, default_bind, sizeof(*default_bind)); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 769 | |
| 770 | /* Regression test code may call this function repeatedly, so make sure |
| 771 | * that VTY elements are not duplicated, which would assert. */ |
| 772 | if (vty_elements_installed) |
| 773 | return 0; |
| 774 | vty_elements_installed = true; |
| 775 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 776 | install_lib_element_ve(&show_ns_cmd); |
| 777 | install_lib_element_ve(&show_ns_stats_cmd); |
| 778 | install_lib_element_ve(&show_ns_pers_cmd); |
| 779 | install_lib_element_ve(&show_nse_cmd); |
| 780 | install_lib_element_ve(&logging_fltr_nsvc_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 781 | |
Daniel Willmann | dbab714 | 2020-11-18 14:19:56 +0100 | [diff] [blame] | 782 | install_lib_element(ENABLE_NODE, &nsvc_force_unconf_cmd); |
| 783 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 784 | install_lib_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 785 | |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 786 | install_lib_element(CONFIG_NODE, &cfg_ns_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 787 | install_node(&ns_node, config_write_ns); |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 788 | install_lib_element(L_NS_NODE, &cfg_nse_fr_cmd); |
Vadim Yanitskiy | 8e7c496 | 2020-10-04 15:37:31 +0700 | [diff] [blame] | 789 | install_lib_element(L_NS_NODE, &cfg_nse_nsvci_cmd); |
| 790 | install_lib_element(L_NS_NODE, &cfg_nse_remoteip_cmd); |
| 791 | install_lib_element(L_NS_NODE, &cfg_nse_remoteport_cmd); |
| 792 | install_lib_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd); |
| 793 | install_lib_element(L_NS_NODE, &cfg_nse_encaps_cmd); |
| 794 | install_lib_element(L_NS_NODE, &cfg_nse_remoterole_cmd); |
| 795 | install_lib_element(L_NS_NODE, &cfg_no_nse_cmd); |
| 796 | install_lib_element(L_NS_NODE, &cfg_ns_timer_cmd); |
| 797 | install_lib_element(L_NS_NODE, &cfg_nsip_local_ip_cmd); |
| 798 | install_lib_element(L_NS_NODE, &cfg_nsip_local_port_cmd); |
| 799 | install_lib_element(L_NS_NODE, &cfg_nsip_dscp_cmd); |
| 800 | install_lib_element(L_NS_NODE, &cfg_nsip_res_block_unblock_cmd); |
| 801 | install_lib_element(L_NS_NODE, &cfg_frgre_enable_cmd); |
| 802 | install_lib_element(L_NS_NODE, &cfg_frgre_local_ip_cmd); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 803 | |
| 804 | /* TODO: nsvc/nsei command to reset states or reset/block/unblock nsei/nsvcs */ |
| 805 | |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | /*! |
| 810 | * \brief gprs_ns2_vty_create parse the vty tree into ns nodes |
| 811 | * It has to be in different steps to ensure the bind is created before creating VCs. |
| 812 | * \return 0 on success |
| 813 | */ |
| 814 | int gprs_ns2_vty_create() { |
| 815 | struct ns2_vty_vc *vtyvc; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 816 | struct gprs_ns2_vc_bind *bind, *fr; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 817 | struct gprs_ns2_nse *nse; |
| 818 | struct gprs_ns2_vc *nsvc; |
| 819 | struct osmo_sockaddr sockaddr; |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 820 | int rc = 0; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 821 | |
| 822 | if (!vty_nsi) |
| 823 | return -1; |
| 824 | |
| 825 | /* create binds, only support a single bind. either FR or UDP */ |
| 826 | if (priv.frgre) { |
| 827 | /* TODO not yet supported !*/ |
| 828 | return -1; |
| 829 | } else { |
| 830 | /* UDP */ |
| 831 | osmo_sockaddr_str_to_sockaddr(&priv.udp, &sockaddr.u.sas); |
Alexander Couzens | 477ffb0 | 2020-10-01 19:05:28 +0200 | [diff] [blame] | 832 | if (gprs_ns2_ip_bind(vty_nsi, &sockaddr, priv.dscp, &bind)) { |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 833 | /* TODO: could not bind on the specific address */ |
| 834 | return -1; |
| 835 | } |
| 836 | gprs_ns2_bind_set_mode(bind, priv.vc_mode); |
| 837 | } |
| 838 | |
| 839 | /* create vcs */ |
| 840 | llist_for_each_entry(vtyvc, &priv.vtyvc, list) { |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 841 | /* validate settings */ |
| 842 | switch (vtyvc->ll) { |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 843 | case GPRS_NS2_LL_UDP: |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 844 | if (strlen(vtyvc->remote.ip) == 0) { |
| 845 | /* Invalid IP for VC */ |
| 846 | continue; |
| 847 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 848 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 849 | if (!vtyvc->remote.port) { |
| 850 | /* Invalid port for VC */ |
| 851 | continue; |
| 852 | } |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 853 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 854 | if (osmo_sockaddr_str_to_sockaddr(&vtyvc->remote, &sockaddr.u.sas)) { |
| 855 | /* Invalid sockaddr for VC */ |
| 856 | continue; |
| 857 | } |
| 858 | break; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 859 | case GPRS_NS2_LL_FR: |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 860 | break; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 861 | case GPRS_NS2_LL_FR_GRE: |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 862 | continue; |
| 863 | } |
| 864 | |
| 865 | nse = gprs_ns2_nse_by_nsei(vty_nsi, vtyvc->nsei); |
| 866 | if (!nse) { |
Alexander Couzens | aac9016 | 2020-11-19 02:44:04 +0100 | [diff] [blame] | 867 | nse = gprs_ns2_create_nse(vty_nsi, vtyvc->nsei, vtyvc->ll); |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 868 | if (!nse) { |
| 869 | /* Could not create NSE for VTY */ |
| 870 | continue; |
| 871 | } |
| 872 | } |
| 873 | nse->persistent = true; |
| 874 | |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 875 | switch (vtyvc->ll) { |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 876 | case GPRS_NS2_LL_UDP: |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 877 | nsvc = gprs_ns2_ip_connect(bind, |
| 878 | &sockaddr, |
| 879 | nse, |
| 880 | vtyvc->nsvci); |
| 881 | if (!nsvc) { |
| 882 | /* Could not create NSVC, connect failed */ |
| 883 | continue; |
| 884 | } |
| 885 | nsvc->persistent = true; |
| 886 | break; |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 887 | case GPRS_NS2_LL_FR: { |
Alexander Couzens | 841817e | 2020-11-19 00:41:29 +0100 | [diff] [blame] | 888 | if (vty_fr_network == NULL) { |
| 889 | /* TODO: add a switch for BSS/SGSN/gbproxy */ |
| 890 | vty_fr_network = osmo_fr_network_alloc(vty_nsi); |
| 891 | } |
| 892 | fr = gprs_ns2_fr_bind_by_netif( |
| 893 | vty_nsi, |
| 894 | vtyvc->netif); |
| 895 | if (!fr) { |
| 896 | rc = gprs_ns2_fr_bind(vty_nsi, vtyvc->netif, vty_fr_network, vtyvc->fr.role, &fr); |
| 897 | if (rc < 0) { |
| 898 | LOGP(DLNS, LOGL_ERROR, "Can not create fr bind on device %s err: %d\n", vtyvc->netif, rc); |
| 899 | return rc; |
| 900 | } |
| 901 | } |
| 902 | |
| 903 | nsvc = gprs_ns2_fr_connect(fr, vtyvc->nsei, vtyvc->nsvci, vtyvc->frdlci); |
| 904 | if (!nsvc) { |
| 905 | /* Could not create NSVC, connect failed */ |
| 906 | continue; |
| 907 | } |
| 908 | nsvc->persistent = true; |
| 909 | break; |
| 910 | } |
Alexander Couzens | 24a14ac | 2020-11-19 02:34:49 +0100 | [diff] [blame] | 911 | case GPRS_NS2_LL_FR_GRE: |
Alexander Couzens | d745a0e | 2020-10-07 00:50:00 +0200 | [diff] [blame] | 912 | continue; |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | /*! |
| 921 | * \brief ns2_vty_bind_apply will be called when a new bind is created to apply vty settings |
| 922 | * \param bind |
| 923 | * \return |
| 924 | */ |
| 925 | void ns2_vty_bind_apply(struct gprs_ns2_vc_bind *bind) |
| 926 | { |
| 927 | gprs_ns2_bind_set_mode(bind, priv.vc_mode); |
| 928 | } |
| 929 | |
| 930 | /*! |
| 931 | * \brief ns2_vty_force_vc_mode force a mode and prevents the vty from overwriting it. |
| 932 | * \param force if true mode and reason will be set. false to allow modification via vty. |
| 933 | * \param mode |
| 934 | * \param reason A description shown to the user when a vty command wants to change the mode. |
| 935 | */ |
Daniel Willmann | 4fb27a8 | 2020-09-25 15:39:46 +0200 | [diff] [blame] | 936 | void gprs_ns2_vty_force_vc_mode(bool force, enum gprs_ns2_vc_mode mode, const char *reason) |
Alexander Couzens | 6a16149 | 2020-07-12 13:45:50 +0200 | [diff] [blame] | 937 | { |
| 938 | priv.force_vc_mode = force; |
| 939 | |
| 940 | if (force) { |
| 941 | priv.vc_mode = mode; |
| 942 | priv.force_vc_mode_reason = reason; |
| 943 | } |
| 944 | } |