From 0bd8a4b5b39797901407c69de2da7992ebecb931 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Fri, 13 Nov 2020 20:09:33 +0100 Subject: ns2: permit multiple nsvci in one nse in VTY Change-Id: I4ad454320d0a03e81b399f55e8bd0ee57402dad0 --- src/gb/gprs_ns2_vty.c | 98 ++++++++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 44 deletions(-) (limited to 'src/gb/gprs_ns2_vty.c') diff --git a/src/gb/gprs_ns2_vty.c b/src/gb/gprs_ns2_vty.c index 4eb9d37a..1759a121 100644 --- a/src/gb/gprs_ns2_vty.c +++ b/src/gb/gprs_ns2_vty.c @@ -126,12 +126,14 @@ static struct cmd_node ns_node = { 1, }; -static struct ns2_vty_vc *vtyvc_alloc(uint16_t nsei) { +static struct ns2_vty_vc *vtyvc_alloc(uint16_t nsei, uint16_t nsvci) +{ struct ns2_vty_vc *vtyvc = talloc_zero(vty_nsi, struct ns2_vty_vc); if (!vtyvc) return vtyvc; vtyvc->nsei = nsei; + vtyvc->nsvci = nsvci; llist_add(&vtyvc->list, &priv.vtyvc); @@ -146,18 +148,19 @@ static void ns2_vc_free(struct ns2_vty_vc *vtyvc) { talloc_free(vtyvc); } -static struct ns2_vty_vc *vtyvc_by_nsei(uint16_t nsei, bool alloc_missing) { +static struct ns2_vty_vc *vtyvc_by_nsei_nsvci(uint16_t nsei, uint16_t nsvci, bool alloc_missing) +{ struct ns2_vty_vc *vtyvc; llist_for_each_entry(vtyvc, &priv.vtyvc, list) { - if (vtyvc->nsei == nsei) + if (vtyvc->nsei == nsei && vtyvc->nsvci == nsvci) return vtyvc; } if (!alloc_missing) return NULL; - vtyvc = vtyvc_alloc(nsei); + vtyvc = vtyvc_alloc(nsei, nsvci); if (!vtyvc) return vtyvc; @@ -206,36 +209,29 @@ static int config_write_ns(struct vty *vty) vty_out(vty, " nse %u nsvci %u%s", vtyvc->nsei, vtyvc->nsvci, VTY_NEWLINE); - vty_out(vty, " nse %u remote-role %s%s", - vtyvc->nsei, vtyvc->remote_end_is_sgsn ? "sgsn" : "bss", - VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u remote-role %s%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->remote_end_is_sgsn ? "sgsn" : "bss", VTY_NEWLINE); switch (vtyvc->ll) { case GPRS_NS_LL_UDP: - vty_out(vty, " nse %u encapsulation udp%s", vtyvc->nsei, VTY_NEWLINE); - vty_out(vty, " nse %u remote-ip %s%s", - vtyvc->nsei, - vtyvc->remote.ip, - VTY_NEWLINE); - vty_out(vty, " nse %u remote-port %u%s", - vtyvc->nsei, vtyvc->remote.port, + vty_out(vty, " nse %u nsvci %u encapsulation udp%s", vtyvc->nsei, vtyvc->nsvci, VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u remote-ip %s%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->remote.ip, VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u remote-port %u%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->remote.port, VTY_NEWLINE); break; case GPRS_NS_LL_FR_GRE: - vty_out(vty, " nse %u encapsulation framerelay-gre%s", - vtyvc->nsei, VTY_NEWLINE); - vty_out(vty, " nse %u remote-ip %s%s", - vtyvc->nsei, - vtyvc->remote.ip, - VTY_NEWLINE); - vty_out(vty, " nse %u fr-dlci %u%s", - vtyvc->nsei, vtyvc->frdlci, - VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u encapsulation framerelay-gre%s", vtyvc->nsei, + vtyvc->nsvci, VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u remote-ip %s%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->remote.ip, VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u fr-dlci %u%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->frdlci, VTY_NEWLINE); break; case GPRS_NS_LL_FR: - vty_out(vty, " nse %u fr %s dlci %u%s", - vtyvc->nsei, vtyvc->netif, vtyvc->frdlci, - VTY_NEWLINE); + vty_out(vty, " nse %u nsvci %u fr %s dlci %u%s", vtyvc->nsei, vtyvc->nsvci, + vtyvc->netif, vtyvc->frdlci, VTY_NEWLINE); break; default: break; @@ -420,7 +416,7 @@ DEFUN(cfg_nse_fr, cfg_nse_fr_cmd, const char *name = argv[3]; uint16_t dlci = atoi(argv[4]); - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; @@ -451,7 +447,7 @@ DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, uint16_t nsei = atoi(argv[0]); uint16_t nsvci = atoi(argv[1]); - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; @@ -463,37 +459,43 @@ DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, } DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd, - "nse <0-65535> remote-ip " VTY_IPV46_CMD, + "nse <0-65535> nsvci <0-65535> remote-ip " VTY_IPV46_CMD, NSE_CMD_STR + "NS Virtual Connection\n" + "NS Virtual Connection ID (NSVCI)\n" "Remote IP Address\n" "Remote IPv4 Address\n" "Remote IPv6 Address\n") { uint16_t nsei = atoi(argv[0]); + uint16_t nsvci = atoi(argv[1]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; } - osmo_sockaddr_str_from_str2(&vtyvc->remote, argv[1]); + osmo_sockaddr_str_from_str2(&vtyvc->remote, argv[2]); return CMD_SUCCESS; } DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, - "nse <0-65535> remote-port <0-65535>", + "nse <0-65535> nsvci <0-65535> remote-port <0-65535>", NSE_CMD_STR + "NS Virtual Connection\n" + "NS Virtual Connection ID (NSVCI)\n" "Remote UDP Port\n" "Remote UDP Port Number\n") { uint16_t nsei = atoi(argv[0]); - uint16_t port = atoi(argv[1]); + uint16_t nsvci = atoi(argv[1]); + uint16_t port = atoi(argv[2]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; @@ -507,6 +509,8 @@ DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, "nse <0-65535> nsvci <0-65535> fr-dlci <16-1007>", NSE_CMD_STR + "NS Virtual Connection\n" + "NS Virtual Connection ID (NSVCI)\n" "Frame Relay DLCI\n" "Frame Relay DLCI Number\n") { @@ -515,7 +519,7 @@ DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, uint16_t dlci = atoi(argv[2]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; @@ -527,27 +531,29 @@ DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, } vtyvc->frdlci = dlci; - vtyvc->nsvci = nsvci; return CMD_SUCCESS; } DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, - "nse <0-65535> encapsulation (udp|framerelay-gre)", + "nse <0-65535> nsvci <0-65535> encapsulation (udp|framerelay-gre)", NSE_CMD_STR + "NS Virtual Connection\n" + "NS Virtual Connection ID (NSVCI)\n" "Encapsulation for NS\n" "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n") { uint16_t nsei = atoi(argv[0]); + uint16_t nsvci = atoi(argv[1]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; } - if (!strcmp(argv[1], "udp")) + if (!strcmp(argv[2], "udp")) vtyvc->ll = GPRS_NS_LL_UDP; else vtyvc->ll = GPRS_NS_LL_FR_GRE; @@ -556,22 +562,25 @@ DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, } DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, - "nse <0-65535> remote-role (sgsn|bss)", + "nse <0-65535> nsvci <0-65535> remote-role (sgsn|bss)", NSE_CMD_STR + "NS Virtual Connection\n" + "NS Virtual Connection ID (NSVCI)\n" "Remote NSE Role\n" "Remote Peer is SGSN\n" "Remote Peer is BSS\n") { uint16_t nsei = atoi(argv[0]); + uint16_t nsvci = atoi(argv[1]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, true); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, true); if (!vtyvc) { vty_out(vty, "Can not allocate space %s", VTY_NEWLINE); return CMD_WARNING; } - if (!strcmp(argv[1], "sgsn")) + if (!strcmp(argv[2], "sgsn")) vtyvc->remote_end_is_sgsn = 1; else vtyvc->remote_end_is_sgsn = 0; @@ -580,14 +589,15 @@ DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, } DEFUN(cfg_no_nse, cfg_no_nse_cmd, - "no nse <0-65535>", + "no nse <0-65535> nsvci <0-65535>", "Delete Persistent NS Entity\n" "Delete " NSE_CMD_STR) { uint16_t nsei = atoi(argv[0]); + uint16_t nsvci = atoi(argv[1]); struct ns2_vty_vc *vtyvc; - vtyvc = vtyvc_by_nsei(nsei, false); + vtyvc = vtyvc_by_nsei_nsvci(nsei, nsvci, false); if (!vtyvc) { vty_out(vty, "The NSE %d does not exists.%s", nsei, VTY_NEWLINE); return CMD_WARNING; -- cgit v1.2.3