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