Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 1 | /* VTY interface for our GPRS Networks Service (NS) implementation */ |
| 2 | |
| 3 | /* (C) 2009-2010 by Harald Welte <laforge@gnumonks.org> |
| 4 | * |
| 5 | * All Rights Reserved |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 15 | * GNU General Public License for more details. |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 16 | * |
Harald Welte | 7fa89c2 | 2014-10-26 20:33:09 +0100 | [diff] [blame] | 17 | * You should have received a copy of the GNU General Public License |
Harald Welte | e4cbb3f | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <stdlib.h> |
| 23 | #include <unistd.h> |
| 24 | #include <errno.h> |
| 25 | #include <stdint.h> |
| 26 | |
| 27 | #include <arpa/inet.h> |
| 28 | |
Pablo Neira Ayuso | ff66323 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/msgb.h> |
| 30 | #include <osmocom/gsm/tlv.h> |
| 31 | #include <osmocom/core/talloc.h> |
| 32 | #include <osmocom/core/select.h> |
| 33 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 34 | #include <osmocom/gprs/gprs_ns.h> |
| 35 | #include <osmocom/gprs/gprs_bssgp.h> |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 36 | |
Harald Welte | ac1a715 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 37 | #include <osmocom/vty/vty.h> |
| 38 | #include <osmocom/vty/command.h> |
| 39 | #include <osmocom/vty/logging.h> |
| 40 | #include <osmocom/vty/telnet_interface.h> |
Pablo Neira Ayuso | 167281e | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 41 | #include <osmocom/vty/misc.h> |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 42 | |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 43 | #include "common_vty.h" |
Harald Welte | 73952e3 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 44 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 45 | static struct gprs_ns_inst *vty_nsi = NULL; |
| 46 | |
| 47 | /* FIXME: this should go to some common file as it is copied |
| 48 | * in vty_interface.c of the BSC */ |
| 49 | static const struct value_string gprs_ns_timer_strs[] = { |
| 50 | { 0, "tns-block" }, |
| 51 | { 1, "tns-block-retries" }, |
| 52 | { 2, "tns-reset" }, |
| 53 | { 3, "tns-reset-retries" }, |
| 54 | { 4, "tns-test" }, |
| 55 | { 5, "tns-alive" }, |
| 56 | { 6, "tns-alive-retries" }, |
| 57 | { 0, NULL } |
| 58 | }; |
| 59 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 60 | static void log_set_nsvc_filter(struct log_target *target, |
| 61 | struct gprs_nsvc *nsvc) |
| 62 | { |
| 63 | if (nsvc) { |
Neels Hofmeyr | 8b86cd7 | 2017-02-23 18:03:28 +0100 | [diff] [blame] | 64 | target->filter_map |= (1 << LOG_FLT_GB_NSVC); |
| 65 | target->filter_data[LOG_FLT_GB_NSVC] = nsvc; |
| 66 | } else if (target->filter_data[LOG_FLT_GB_NSVC]) { |
| 67 | target->filter_map = ~(1 << LOG_FLT_GB_NSVC); |
| 68 | target->filter_data[LOG_FLT_GB_NSVC] = NULL; |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 72 | static struct cmd_node ns_node = { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 73 | L_NS_NODE, |
Jacob Erlbeck | 35fe87c | 2013-10-24 01:33:20 +0200 | [diff] [blame] | 74 | "%s(config-ns)# ", |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 75 | 1, |
| 76 | }; |
| 77 | |
| 78 | static int config_write_ns(struct vty *vty) |
| 79 | { |
| 80 | struct gprs_nsvc *nsvc; |
| 81 | unsigned int i; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 82 | struct in_addr ia; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 83 | |
| 84 | vty_out(vty, "ns%s", VTY_NEWLINE); |
| 85 | |
| 86 | llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) { |
| 87 | if (!nsvc->persistent) |
| 88 | continue; |
| 89 | vty_out(vty, " nse %u nsvci %u%s", |
| 90 | nsvc->nsei, nsvc->nsvci, VTY_NEWLINE); |
| 91 | vty_out(vty, " nse %u remote-role %s%s", |
| 92 | nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss", |
| 93 | VTY_NEWLINE); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 94 | switch (nsvc->ll) { |
| 95 | case GPRS_NS_LL_UDP: |
| 96 | vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei, |
| 97 | VTY_NEWLINE); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 98 | vty_out(vty, " nse %u remote-ip %s%s", |
| 99 | nsvc->nsei, |
| 100 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 101 | VTY_NEWLINE); |
| 102 | vty_out(vty, " nse %u remote-port %u%s", |
| 103 | nsvc->nsei, ntohs(nsvc->ip.bts_addr.sin_port), |
| 104 | VTY_NEWLINE); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 105 | break; |
| 106 | case GPRS_NS_LL_FR_GRE: |
| 107 | vty_out(vty, " nse %u encapsulation framerelay-gre%s", |
| 108 | nsvc->nsei, VTY_NEWLINE); |
| 109 | vty_out(vty, " nse %u remote-ip %s%s", |
| 110 | nsvc->nsei, |
| 111 | inet_ntoa(nsvc->frgre.bts_addr.sin_addr), |
| 112 | VTY_NEWLINE); |
| 113 | vty_out(vty, " nse %u fr-dlci %u%s", |
| 114 | nsvc->nsei, ntohs(nsvc->frgre.bts_addr.sin_port), |
| 115 | VTY_NEWLINE); |
| 116 | default: |
| 117 | break; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | |
| 121 | for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++) |
| 122 | vty_out(vty, " timer %s %u%s", |
| 123 | get_value_string(gprs_ns_timer_strs, i), |
| 124 | vty_nsi->timeout[i], VTY_NEWLINE); |
| 125 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 126 | if (vty_nsi->nsip.local_ip) { |
| 127 | ia.s_addr = htonl(vty_nsi->nsip.local_ip); |
| 128 | vty_out(vty, " encapsulation udp local-ip %s%s", |
| 129 | inet_ntoa(ia), VTY_NEWLINE); |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 130 | } |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 131 | if (vty_nsi->nsip.local_port) |
| 132 | vty_out(vty, " encapsulation udp local-port %u%s", |
| 133 | vty_nsi->nsip.local_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 134 | if (vty_nsi->nsip.dscp) |
| 135 | vty_out(vty, " encapsulation udp dscp %d%s", |
| 136 | vty_nsi->nsip.dscp, VTY_NEWLINE); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 137 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 138 | vty_out(vty, " encapsulation framerelay-gre enabled %u%s", |
| 139 | vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 140 | if (vty_nsi->frgre.local_ip) { |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 141 | ia.s_addr = htonl(vty_nsi->frgre.local_ip); |
| 142 | vty_out(vty, " encapsulation framerelay-gre local-ip %s%s", |
| 143 | inet_ntoa(ia), VTY_NEWLINE); |
| 144 | } |
| 145 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 146 | return CMD_SUCCESS; |
| 147 | } |
| 148 | |
| 149 | DEFUN(cfg_ns, cfg_ns_cmd, |
| 150 | "ns", |
| 151 | "Configure the GPRS Network Service") |
| 152 | { |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 153 | vty->node = L_NS_NODE; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 154 | return CMD_SUCCESS; |
| 155 | } |
| 156 | |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 157 | static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats) |
| 158 | { |
| 159 | vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s", |
| 160 | nsvc->nsei, nsvc->nsvci, |
| 161 | nsvc->remote_end_is_sgsn ? "SGSN" : "BSS", |
| 162 | nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD", |
| 163 | nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED"); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 164 | if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE) |
| 165 | vty_out(vty, ", %s %15s:%u", |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 166 | nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE", |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 167 | inet_ntoa(nsvc->ip.bts_addr.sin_addr), |
| 168 | ntohs(nsvc->ip.bts_addr.sin_port)); |
| 169 | vty_out(vty, "%s", VTY_NEWLINE); |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 170 | if (stats) { |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 171 | vty_out_rate_ctr_group(vty, " ", nsvc->ctrg); |
Jacob Erlbeck | 0a1400f | 2015-10-06 15:23:25 +0200 | [diff] [blame] | 172 | vty_out_stat_item_group(vty, " ", nsvc->statg); |
| 173 | } |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 176 | static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats) |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 177 | { |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 178 | struct gprs_nsvc *nsvc; |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 179 | struct in_addr ia; |
| 180 | |
| 181 | ia.s_addr = htonl(vty_nsi->nsip.local_ip); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 182 | vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s", |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 183 | inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE); |
| 184 | |
| 185 | ia.s_addr = htonl(vty_nsi->frgre.local_ip); |
Harald Welte | ce4ccbc | 2010-05-19 17:02:57 +0200 | [diff] [blame] | 186 | vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s", |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 187 | inet_ntoa(ia), VTY_NEWLINE); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 188 | |
| 189 | llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) { |
Harald Welte | dd1c83c | 2010-05-13 13:58:08 +0200 | [diff] [blame] | 190 | if (nsvc == nsi->unknown_nsvc) |
| 191 | continue; |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 192 | dump_nse(vty, nsvc, stats); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 193 | } |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 194 | } |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 195 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 196 | DEFUN(show_ns, show_ns_cmd, "show ns", |
| 197 | SHOW_STR "Display information about the NS protocol") |
| 198 | { |
| 199 | struct gprs_ns_inst *nsi = vty_nsi; |
| 200 | dump_ns(vty, nsi, 0); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 201 | return CMD_SUCCESS; |
| 202 | } |
| 203 | |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 204 | DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats", |
| 205 | SHOW_STR |
| 206 | "Display information about the NS protocol\n" |
| 207 | "Include statistics\n") |
| 208 | { |
| 209 | struct gprs_ns_inst *nsi = vty_nsi; |
| 210 | dump_ns(vty, nsi, 1); |
| 211 | return CMD_SUCCESS; |
| 212 | } |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 213 | |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 214 | DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]", |
| 215 | SHOW_STR "Display information about the NS protocol\n" |
| 216 | "Select one NSE by its NSE Identifier\n" |
| 217 | "Select one NSE by its NS-VC Identifier\n" |
| 218 | "The Identifier of selected type\n" |
| 219 | "Include Statistics\n") |
| 220 | { |
| 221 | struct gprs_ns_inst *nsi = vty_nsi; |
| 222 | struct gprs_nsvc *nsvc; |
| 223 | uint16_t id = atoi(argv[1]); |
| 224 | int show_stats = 0; |
| 225 | |
| 226 | if (!strcmp(argv[0], "nsei")) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 227 | nsvc = gprs_nsvc_by_nsei(nsi, id); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 228 | else |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 229 | nsvc = gprs_nsvc_by_nsvci(nsi, id); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 230 | |
| 231 | if (!nsvc) { |
| 232 | vty_out(vty, "No such NS Entity%s", VTY_NEWLINE); |
| 233 | return CMD_WARNING; |
| 234 | } |
| 235 | |
| 236 | if (argc >= 3) |
| 237 | show_stats = 1; |
| 238 | |
| 239 | dump_nse(vty, nsvc, show_stats); |
| 240 | return CMD_SUCCESS; |
| 241 | } |
| 242 | |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 243 | #define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n" |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 244 | |
| 245 | DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd, |
| 246 | "nse <0-65535> nsvci <0-65534>", |
| 247 | NSE_CMD_STR |
| 248 | "NS Virtual Connection\n" |
| 249 | "NS Virtual Connection ID (NSVCI)\n" |
| 250 | ) |
| 251 | { |
| 252 | uint16_t nsei = atoi(argv[0]); |
| 253 | uint16_t nsvci = atoi(argv[1]); |
| 254 | struct gprs_nsvc *nsvc; |
| 255 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 256 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 257 | if (!nsvc) { |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 258 | nsvc = gprs_nsvc_create(vty_nsi, nsvci); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 259 | nsvc->nsei = nsei; |
| 260 | } |
| 261 | nsvc->nsvci = nsvci; |
| 262 | /* All NSVCs that are explicitly configured by VTY are |
| 263 | * marked as persistent so we can write them to the config |
| 264 | * file at some later point */ |
| 265 | nsvc->persistent = 1; |
| 266 | |
| 267 | return CMD_SUCCESS; |
| 268 | } |
| 269 | |
| 270 | DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd, |
| 271 | "nse <0-65535> remote-ip A.B.C.D", |
| 272 | NSE_CMD_STR |
| 273 | "Remote IP Address\n" |
| 274 | "Remote IP Address\n") |
| 275 | { |
| 276 | uint16_t nsei = atoi(argv[0]); |
| 277 | struct gprs_nsvc *nsvc; |
| 278 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 279 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 280 | if (!nsvc) { |
| 281 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 282 | return CMD_WARNING; |
| 283 | } |
| 284 | inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr); |
| 285 | |
| 286 | return CMD_SUCCESS; |
| 287 | |
| 288 | } |
| 289 | |
| 290 | DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd, |
| 291 | "nse <0-65535> remote-port <0-65535>", |
| 292 | NSE_CMD_STR |
| 293 | "Remote UDP Port\n" |
| 294 | "Remote UDP Port Number\n") |
| 295 | { |
| 296 | uint16_t nsei = atoi(argv[0]); |
| 297 | uint16_t port = atoi(argv[1]); |
| 298 | struct gprs_nsvc *nsvc; |
| 299 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 300 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 301 | if (!nsvc) { |
| 302 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 303 | return CMD_WARNING; |
| 304 | } |
| 305 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 306 | if (nsvc->ll != GPRS_NS_LL_UDP) { |
| 307 | vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s", |
| 308 | VTY_NEWLINE); |
| 309 | return CMD_WARNING; |
| 310 | } |
| 311 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 312 | nsvc->ip.bts_addr.sin_port = htons(port); |
| 313 | |
| 314 | return CMD_SUCCESS; |
| 315 | } |
| 316 | |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 317 | DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd, |
Harald Welte | 188bda6 | 2010-05-28 14:11:49 +0200 | [diff] [blame] | 318 | "nse <0-65535> fr-dlci <16-1007>", |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 319 | NSE_CMD_STR |
| 320 | "Frame Relay DLCI\n" |
| 321 | "Frame Relay DLCI Number\n") |
| 322 | { |
| 323 | uint16_t nsei = atoi(argv[0]); |
| 324 | uint16_t dlci = atoi(argv[1]); |
| 325 | struct gprs_nsvc *nsvc; |
| 326 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 327 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 328 | if (!nsvc) { |
| 329 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 330 | return CMD_WARNING; |
| 331 | } |
| 332 | |
| 333 | if (nsvc->ll != GPRS_NS_LL_FR_GRE) { |
| 334 | vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s", |
| 335 | VTY_NEWLINE); |
| 336 | return CMD_WARNING; |
| 337 | } |
| 338 | |
| 339 | nsvc->frgre.bts_addr.sin_port = htons(dlci); |
| 340 | |
| 341 | return CMD_SUCCESS; |
| 342 | } |
| 343 | |
| 344 | DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd, |
| 345 | "nse <0-65535> encapsulation (udp|framerelay-gre)", |
| 346 | NSE_CMD_STR |
| 347 | "Encapsulation for NS\n" |
| 348 | "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n") |
| 349 | { |
| 350 | uint16_t nsei = atoi(argv[0]); |
| 351 | struct gprs_nsvc *nsvc; |
| 352 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 353 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | b3ee265 | 2010-05-19 14:38:50 +0200 | [diff] [blame] | 354 | if (!nsvc) { |
| 355 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 356 | return CMD_WARNING; |
| 357 | } |
| 358 | |
| 359 | if (!strcmp(argv[1], "udp")) |
| 360 | nsvc->ll = GPRS_NS_LL_UDP; |
| 361 | else |
| 362 | nsvc->ll = GPRS_NS_LL_FR_GRE; |
| 363 | |
| 364 | return CMD_SUCCESS; |
| 365 | } |
| 366 | |
| 367 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 368 | DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd, |
| 369 | "nse <0-65535> remote-role (sgsn|bss)", |
| 370 | NSE_CMD_STR |
| 371 | "Remote NSE Role\n" |
| 372 | "Remote Peer is SGSN\n" |
| 373 | "Remote Peer is BSS\n") |
| 374 | { |
| 375 | uint16_t nsei = atoi(argv[0]); |
| 376 | struct gprs_nsvc *nsvc; |
| 377 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 378 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 379 | if (!nsvc) { |
| 380 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 381 | return CMD_WARNING; |
| 382 | } |
| 383 | |
| 384 | if (!strcmp(argv[1], "sgsn")) |
| 385 | nsvc->remote_end_is_sgsn = 1; |
| 386 | else |
| 387 | nsvc->remote_end_is_sgsn = 0; |
| 388 | |
| 389 | return CMD_SUCCESS; |
| 390 | } |
| 391 | |
| 392 | DEFUN(cfg_no_nse, cfg_no_nse_cmd, |
| 393 | "no nse <0-65535>", |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 394 | "Delete Persistent NS Entity\n" |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 395 | "Delete " NSE_CMD_STR) |
| 396 | { |
| 397 | uint16_t nsei = atoi(argv[0]); |
| 398 | struct gprs_nsvc *nsvc; |
| 399 | |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 400 | nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 401 | if (!nsvc) { |
| 402 | vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE); |
| 403 | return CMD_WARNING; |
| 404 | } |
| 405 | |
Harald Welte | 24133c3 | 2010-05-15 23:06:26 +0200 | [diff] [blame] | 406 | if (!nsvc->persistent) { |
| 407 | vty_out(vty, "NSEI %u is not a persistent NSE%s", |
| 408 | nsei, VTY_NEWLINE); |
| 409 | return CMD_WARNING; |
| 410 | } |
| 411 | |
| 412 | nsvc->persistent = 0; |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 413 | |
| 414 | return CMD_SUCCESS; |
| 415 | } |
| 416 | |
| 417 | DEFUN(cfg_ns_timer, cfg_ns_timer_cmd, |
| 418 | "timer " NS_TIMERS " <0-65535>", |
| 419 | "Network Service Timer\n" |
| 420 | NS_TIMERS_HELP "Timer Value\n") |
| 421 | { |
| 422 | int idx = get_string_value(gprs_ns_timer_strs, argv[0]); |
| 423 | int val = atoi(argv[1]); |
| 424 | |
| 425 | if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout)) |
| 426 | return CMD_WARNING; |
| 427 | |
| 428 | vty_nsi->timeout[idx] = val; |
| 429 | |
| 430 | return CMD_SUCCESS; |
| 431 | } |
| 432 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 433 | #define ENCAPS_STR "NS encapsulation options\n" |
| 434 | |
| 435 | DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd, |
| 436 | "encapsulation udp local-ip A.B.C.D", |
| 437 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 438 | "Set the IP address on which we listen for NS/UDP\n" |
| 439 | "IP Address\n") |
| 440 | { |
| 441 | struct in_addr ia; |
| 442 | |
| 443 | inet_aton(argv[0], &ia); |
| 444 | vty_nsi->nsip.local_ip = ntohl(ia.s_addr); |
| 445 | |
| 446 | return CMD_SUCCESS; |
| 447 | } |
| 448 | |
| 449 | DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd, |
| 450 | "encapsulation udp local-port <0-65535>", |
| 451 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 452 | "Set the UDP port on which we listen for NS/UDP\n" |
| 453 | "UDP port number\n") |
| 454 | { |
| 455 | unsigned int port = atoi(argv[0]); |
| 456 | |
| 457 | vty_nsi->nsip.local_port = port; |
| 458 | |
| 459 | return CMD_SUCCESS; |
| 460 | } |
| 461 | |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 462 | DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd, |
| 463 | "encapsulation udp dscp <0-255>", |
| 464 | ENCAPS_STR "NS over UDP Encapsulation\n" |
| 465 | "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n") |
| 466 | { |
| 467 | int dscp = atoi(argv[0]); |
| 468 | vty_nsi->nsip.dscp = dscp; |
| 469 | return CMD_SUCCESS; |
| 470 | } |
| 471 | |
Harald Welte | 7fb0523 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 472 | DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd, |
| 473 | "encapsulation framerelay-gre local-ip A.B.C.D", |
| 474 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 475 | "Set the IP address on which we listen for NS/FR/GRE\n" |
| 476 | "IP Address\n") |
| 477 | { |
| 478 | struct in_addr ia; |
| 479 | |
| 480 | if (!vty_nsi->frgre.enabled) { |
| 481 | vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE); |
| 482 | return CMD_WARNING; |
| 483 | } |
| 484 | inet_aton(argv[0], &ia); |
| 485 | vty_nsi->frgre.local_ip = ntohl(ia.s_addr); |
| 486 | |
| 487 | return CMD_SUCCESS; |
| 488 | } |
| 489 | |
| 490 | DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd, |
| 491 | "encapsulation framerelay-gre enabled (1|0)", |
| 492 | ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n" |
| 493 | "Enable or disable Frame Relay over GRE\n" |
| 494 | "Enable\n" "Disable\n") |
| 495 | { |
| 496 | int enabled = atoi(argv[0]); |
| 497 | |
| 498 | vty_nsi->frgre.enabled = enabled; |
| 499 | |
| 500 | return CMD_SUCCESS; |
| 501 | } |
| 502 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 503 | DEFUN(nsvc_nsei, nsvc_nsei_cmd, |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 504 | "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)", |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 505 | "Perform an operation on a NSVC\n" |
Holger Hans Peter Freyther | 887934e | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 506 | "NSEI to identify NS-VC Identifier (NS-VCI)\n" |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 507 | "NS-VC Identifier (NS-VCI)\n" |
Holger Hans Peter Freyther | 887934e | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 508 | "The NSEI\n" |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 509 | "Initiate BLOCK procedure\n" |
| 510 | "Initiate UNBLOCK procedure\n" |
| 511 | "Initiate RESET procedure\n") |
| 512 | { |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 513 | const char *id_type = argv[0]; |
| 514 | uint16_t id = atoi(argv[1]); |
| 515 | const char *operation = argv[2]; |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 516 | struct gprs_nsvc *nsvc; |
| 517 | |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 518 | if (!strcmp(id_type, "nsei")) |
| 519 | nsvc = gprs_nsvc_by_nsei(vty_nsi, id); |
| 520 | else if (!strcmp(id_type, "nsvci")) |
| 521 | nsvc = gprs_nsvc_by_nsvci(vty_nsi, id); |
| 522 | else { |
| 523 | vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE); |
| 524 | return CMD_WARNING; |
| 525 | } |
| 526 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 527 | if (!nsvc) { |
Jacob Erlbeck | 687b690 | 2013-10-24 01:33:19 +0200 | [diff] [blame] | 528 | vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE); |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 529 | return CMD_WARNING; |
| 530 | } |
| 531 | |
| 532 | if (!strcmp(operation, "block")) |
| 533 | gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 534 | else if (!strcmp(operation, "unblock")) |
| 535 | gprs_ns_tx_unblock(nsvc); |
| 536 | else if (!strcmp(operation, "reset")) |
| 537 | gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION); |
| 538 | else |
| 539 | return CMD_WARNING; |
| 540 | |
| 541 | return CMD_SUCCESS; |
| 542 | } |
| 543 | |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 544 | DEFUN(logging_fltr_nsvc, |
| 545 | logging_fltr_nsvc_cmd, |
| 546 | "logging filter nsvc (nsei|nsvci) <0-65535>", |
Harald Welte | 6703bf7 | 2010-05-16 00:00:04 +0200 | [diff] [blame] | 547 | LOGGING_STR FILTER_STR |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 548 | "Filter based on NS Virtual Connection\n" |
| 549 | "Identify NS-VC by NSEI\n" |
| 550 | "Identify NS-VC by NSVCI\n" |
| 551 | "Numeric identifier\n") |
| 552 | { |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 553 | struct log_target *tgt = osmo_log_vty2tgt(vty); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 554 | struct gprs_nsvc *nsvc; |
| 555 | uint16_t id = atoi(argv[1]); |
| 556 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 557 | if (!tgt) |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 558 | return CMD_WARNING; |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 559 | |
| 560 | if (!strcmp(argv[0], "nsei")) |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 561 | nsvc = gprs_nsvc_by_nsei(vty_nsi, id); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 562 | else |
Harald Welte | f543036 | 2012-06-17 12:25:53 +0800 | [diff] [blame] | 563 | nsvc = gprs_nsvc_by_nsvci(vty_nsi, id); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 564 | |
| 565 | if (!nsvc) { |
| 566 | vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE); |
| 567 | return CMD_WARNING; |
| 568 | } |
| 569 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 570 | log_set_nsvc_filter(tgt, nsvc); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 571 | return CMD_SUCCESS; |
| 572 | } |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 573 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 574 | int gprs_ns_vty_init(struct gprs_ns_inst *nsi) |
| 575 | { |
Neels Hofmeyr | c32bfd5 | 2017-01-12 22:32:19 +0100 | [diff] [blame] | 576 | static bool vty_elements_installed = false; |
| 577 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 578 | vty_nsi = nsi; |
| 579 | |
Neels Hofmeyr | c32bfd5 | 2017-01-12 22:32:19 +0100 | [diff] [blame] | 580 | /* Regression test code may call this function repeatedly, so make sure |
| 581 | * that VTY elements are not duplicated, which would assert. */ |
| 582 | if (vty_elements_installed) |
| 583 | return 0; |
| 584 | vty_elements_installed = true; |
| 585 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 586 | install_element_ve(&show_ns_cmd); |
Harald Welte | af1d4cb | 2010-05-13 12:32:30 +0200 | [diff] [blame] | 587 | install_element_ve(&show_ns_stats_cmd); |
Harald Welte | 9288334 | 2010-05-15 23:04:03 +0200 | [diff] [blame] | 588 | install_element_ve(&show_nse_cmd); |
Harald Welte | 91f7f4b | 2010-05-15 23:52:02 +0200 | [diff] [blame] | 589 | install_element_ve(&logging_fltr_nsvc_cmd); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 590 | |
Harald Welte | 43ae94e | 2011-02-18 21:10:05 +0100 | [diff] [blame] | 591 | install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd); |
| 592 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 593 | install_element(CONFIG_NODE, &cfg_ns_cmd); |
| 594 | install_node(&ns_node, config_write_ns); |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 595 | install_default(L_NS_NODE); |
| 596 | install_element(L_NS_NODE, &libgb_exit_cmd); |
| 597 | install_element(L_NS_NODE, &libgb_end_cmd); |
| 598 | install_element(L_NS_NODE, &cfg_nse_nsvci_cmd); |
| 599 | install_element(L_NS_NODE, &cfg_nse_remoteip_cmd); |
| 600 | install_element(L_NS_NODE, &cfg_nse_remoteport_cmd); |
| 601 | install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd); |
| 602 | install_element(L_NS_NODE, &cfg_nse_encaps_cmd); |
| 603 | install_element(L_NS_NODE, &cfg_nse_remoterole_cmd); |
| 604 | install_element(L_NS_NODE, &cfg_no_nse_cmd); |
| 605 | install_element(L_NS_NODE, &cfg_ns_timer_cmd); |
| 606 | install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd); |
| 607 | install_element(L_NS_NODE, &cfg_nsip_local_port_cmd); |
Holger Hans Peter Freyther | 2c3393d | 2013-03-25 11:59:58 +0100 | [diff] [blame] | 608 | install_element(L_NS_NODE, &cfg_nsip_dscp_cmd); |
Harald Welte | 4f5883b | 2012-06-16 16:54:06 +0800 | [diff] [blame] | 609 | install_element(L_NS_NODE, &cfg_frgre_enable_cmd); |
| 610 | install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd); |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 611 | |
Harald Welte | 43f3b69 | 2010-05-14 19:36:59 +0200 | [diff] [blame] | 612 | install_element(ENABLE_NODE, &nsvc_nsei_cmd); |
| 613 | |
Harald Welte | 144e029 | 2010-05-13 11:45:07 +0200 | [diff] [blame] | 614 | return 0; |
| 615 | } |