blob: c6fb141e4395b4b59ff933bf7e6ba044442c2305 [file] [log] [blame]
Neels Hofmeyr17518fe2017-06-20 04:35:06 +02001/*! \file gprs_ns_vty.c
2 * VTY interface for our GPRS Networks Service (NS) implementation. */
3/*
4 * (C) 2009-2010 by Harald Welte <laforge@gnumonks.org>
Harald Welte144e0292010-05-13 11:45:07 +02005 *
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
Harald Welte7fa89c22014-10-26 20:33:09 +01009 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
Harald Welte144e0292010-05-13 11:45:07 +020011 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte7fa89c22014-10-26 20:33:09 +010016 * GNU General Public License for more details.
Harald Welte144e0292010-05-13 11:45:07 +020017 *
Harald Welte7fa89c22014-10-26 20:33:09 +010018 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010019 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte144e0292010-05-13 11:45:07 +020020 *
21 */
22
23#include <stdlib.h>
24#include <unistd.h>
25#include <errno.h>
26#include <stdint.h>
27
28#include <arpa/inet.h>
29
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010030#include <osmocom/core/msgb.h>
Harald Weltebfe62e52017-05-15 12:48:30 +020031#include <osmocom/core/byteswap.h>
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010032#include <osmocom/gsm/tlv.h>
33#include <osmocom/core/talloc.h>
34#include <osmocom/core/select.h>
35#include <osmocom/core/rate_ctr.h>
Harald Welte73952e32012-06-16 14:59:56 +080036#include <osmocom/gprs/gprs_ns.h>
37#include <osmocom/gprs/gprs_bssgp.h>
Max37f465e2017-10-24 16:04:55 +020038#include <osmocom/core/socket.h>
Harald Welteac1a7152010-05-19 19:45:32 +020039#include <osmocom/vty/vty.h>
40#include <osmocom/vty/command.h>
41#include <osmocom/vty/logging.h>
42#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayuso167281e2011-03-28 19:35:00 +020043#include <osmocom/vty/misc.h>
Harald Welte144e0292010-05-13 11:45:07 +020044
Harald Welte4f5883b2012-06-16 16:54:06 +080045#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080046
Harald Welte144e0292010-05-13 11:45:07 +020047static struct gprs_ns_inst *vty_nsi = NULL;
48
49/* FIXME: this should go to some common file as it is copied
50 * in vty_interface.c of the BSC */
51static const struct value_string gprs_ns_timer_strs[] = {
52 { 0, "tns-block" },
53 { 1, "tns-block-retries" },
54 { 2, "tns-reset" },
55 { 3, "tns-reset-retries" },
56 { 4, "tns-test" },
57 { 5, "tns-alive" },
58 { 6, "tns-alive-retries" },
59 { 0, NULL }
60};
61
Harald Weltef5430362012-06-17 12:25:53 +080062static void log_set_nsvc_filter(struct log_target *target,
63 struct gprs_nsvc *nsvc)
64{
65 if (nsvc) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010066 target->filter_map |= (1 << LOG_FLT_GB_NSVC);
67 target->filter_data[LOG_FLT_GB_NSVC] = nsvc;
68 } else if (target->filter_data[LOG_FLT_GB_NSVC]) {
69 target->filter_map = ~(1 << LOG_FLT_GB_NSVC);
70 target->filter_data[LOG_FLT_GB_NSVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080071 }
72}
73
Harald Welte144e0292010-05-13 11:45:07 +020074static struct cmd_node ns_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080075 L_NS_NODE,
Jacob Erlbeck35fe87c2013-10-24 01:33:20 +020076 "%s(config-ns)# ",
Harald Welte144e0292010-05-13 11:45:07 +020077 1,
78};
79
80static int config_write_ns(struct vty *vty)
81{
82 struct gprs_nsvc *nsvc;
83 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020084 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020085
86 vty_out(vty, "ns%s", VTY_NEWLINE);
87
88 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
89 if (!nsvc->persistent)
90 continue;
91 vty_out(vty, " nse %u nsvci %u%s",
92 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
93 vty_out(vty, " nse %u remote-role %s%s",
94 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
95 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020096 switch (nsvc->ll) {
97 case GPRS_NS_LL_UDP:
98 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
99 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200100 vty_out(vty, " nse %u remote-ip %s%s",
101 nsvc->nsei,
102 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
103 VTY_NEWLINE);
104 vty_out(vty, " nse %u remote-port %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200105 nsvc->nsei, osmo_ntohs(nsvc->ip.bts_addr.sin_port),
Harald Welte144e0292010-05-13 11:45:07 +0200106 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +0200107 break;
108 case GPRS_NS_LL_FR_GRE:
109 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
110 nsvc->nsei, VTY_NEWLINE);
111 vty_out(vty, " nse %u remote-ip %s%s",
112 nsvc->nsei,
113 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
114 VTY_NEWLINE);
115 vty_out(vty, " nse %u fr-dlci %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200116 nsvc->nsei, osmo_ntohs(nsvc->frgre.bts_addr.sin_port),
Harald Welteb3ee2652010-05-19 14:38:50 +0200117 VTY_NEWLINE);
118 default:
119 break;
Harald Welte144e0292010-05-13 11:45:07 +0200120 }
121 }
122
123 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
124 vty_out(vty, " timer %s %u%s",
125 get_value_string(gprs_ns_timer_strs, i),
126 vty_nsi->timeout[i], VTY_NEWLINE);
127
Harald Welte7fb05232010-05-19 15:09:09 +0200128 if (vty_nsi->nsip.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200129 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200130 vty_out(vty, " encapsulation udp local-ip %s%s",
131 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200132 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200133 if (vty_nsi->nsip.local_port)
134 vty_out(vty, " encapsulation udp local-port %u%s",
135 vty_nsi->nsip.local_port, VTY_NEWLINE);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100136 if (vty_nsi->nsip.dscp)
137 vty_out(vty, " encapsulation udp dscp %d%s",
138 vty_nsi->nsip.dscp, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200139
Harald Welte7fb05232010-05-19 15:09:09 +0200140 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
141 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200142 if (vty_nsi->frgre.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200143 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200144 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
145 inet_ntoa(ia), VTY_NEWLINE);
146 }
147
Harald Welte144e0292010-05-13 11:45:07 +0200148 return CMD_SUCCESS;
149}
150
151DEFUN(cfg_ns, cfg_ns_cmd,
152 "ns",
153 "Configure the GPRS Network Service")
154{
Harald Welte4f5883b2012-06-16 16:54:06 +0800155 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200156 return CMD_SUCCESS;
157}
158
Harald Welte92883342010-05-15 23:04:03 +0200159static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
160{
Max37f465e2017-10-24 16:04:55 +0200161 vty_out(vty, "NSEI %5u, NS-VC %5u, %5s %9s, ",
Harald Welte92883342010-05-15 23:04:03 +0200162 nsvc->nsei, nsvc->nsvci,
Max4ce24c42017-10-23 15:09:23 +0200163 NS_DESC_A(nsvc->state),
Max37f465e2017-10-24 16:04:55 +0200164 NS_DESC_B(nsvc->state));
165
166 if (nsvc->ll == GPRS_NS_LL_UDP) {
167 char local[INET6_ADDRSTRLEN + 1];
168 int rc = osmo_sock_local_ip((char *)&local, inet_ntoa(nsvc->ip.bts_addr.sin_addr));
169 vty_out(vty, "%s:%u ", (rc < 0) ? "unknown" : local, nsvc->nsi->nsip.local_port);
170 }
171
172 vty_out(vty, "Remote: %-4s, %5s %9s, %s ",
Max32f99712017-10-20 12:27:49 +0200173 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
Max4ce24c42017-10-23 15:09:23 +0200174 NS_DESC_A(nsvc->remote_state),
Max37f465e2017-10-24 16:04:55 +0200175 NS_DESC_B(nsvc->remote_state), gprs_ns_ll_str(nsvc));
Max95308592017-10-24 15:54:28 +0200176
Max37f465e2017-10-24 16:04:55 +0200177 vty_out(vty, "%s%s", nsvc->ll == GPRS_NS_LL_UDP ? "UDP" : "FR-GRE", VTY_NEWLINE);
Max95308592017-10-24 15:54:28 +0200178
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200179 if (stats) {
Harald Welte92883342010-05-15 23:04:03 +0200180 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200181 vty_out_stat_item_group(vty, " ", nsvc->statg);
182 }
Harald Welte92883342010-05-15 23:04:03 +0200183}
184
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200185static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200186{
Harald Welte144e0292010-05-13 11:45:07 +0200187 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200188 struct in_addr ia;
189
Harald Weltebfe62e52017-05-15 12:48:30 +0200190 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200191 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200192 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
193
Harald Weltebfe62e52017-05-15 12:48:30 +0200194 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200195 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200196 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200197
198 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200199 if (nsvc == nsi->unknown_nsvc)
200 continue;
Harald Welte92883342010-05-15 23:04:03 +0200201 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200202 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200203}
Harald Welte144e0292010-05-13 11:45:07 +0200204
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200205DEFUN(show_ns, show_ns_cmd, "show ns",
206 SHOW_STR "Display information about the NS protocol")
207{
208 struct gprs_ns_inst *nsi = vty_nsi;
209 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200210 return CMD_SUCCESS;
211}
212
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200213DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
214 SHOW_STR
215 "Display information about the NS protocol\n"
216 "Include statistics\n")
217{
218 struct gprs_ns_inst *nsi = vty_nsi;
219 dump_ns(vty, nsi, 1);
220 return CMD_SUCCESS;
221}
Harald Welte144e0292010-05-13 11:45:07 +0200222
Harald Welte92883342010-05-15 23:04:03 +0200223DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
224 SHOW_STR "Display information about the NS protocol\n"
225 "Select one NSE by its NSE Identifier\n"
226 "Select one NSE by its NS-VC Identifier\n"
227 "The Identifier of selected type\n"
228 "Include Statistics\n")
229{
230 struct gprs_ns_inst *nsi = vty_nsi;
231 struct gprs_nsvc *nsvc;
232 uint16_t id = atoi(argv[1]);
233 int show_stats = 0;
234
235 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800236 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200237 else
Harald Weltef5430362012-06-17 12:25:53 +0800238 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200239
240 if (!nsvc) {
241 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
242 return CMD_WARNING;
243 }
244
245 if (argc >= 3)
246 show_stats = 1;
247
248 dump_nse(vty, nsvc, show_stats);
249 return CMD_SUCCESS;
250}
251
Harald Welte24133c32010-05-15 23:06:26 +0200252#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200253
254DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
255 "nse <0-65535> nsvci <0-65534>",
256 NSE_CMD_STR
257 "NS Virtual Connection\n"
258 "NS Virtual Connection ID (NSVCI)\n"
259 )
260{
261 uint16_t nsei = atoi(argv[0]);
262 uint16_t nsvci = atoi(argv[1]);
263 struct gprs_nsvc *nsvc;
264
Harald Weltef5430362012-06-17 12:25:53 +0800265 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200266 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800267 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200268 nsvc->nsei = nsei;
269 }
270 nsvc->nsvci = nsvci;
271 /* All NSVCs that are explicitly configured by VTY are
272 * marked as persistent so we can write them to the config
273 * file at some later point */
274 nsvc->persistent = 1;
275
276 return CMD_SUCCESS;
277}
278
279DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
280 "nse <0-65535> remote-ip A.B.C.D",
281 NSE_CMD_STR
282 "Remote IP Address\n"
283 "Remote IP Address\n")
284{
285 uint16_t nsei = atoi(argv[0]);
286 struct gprs_nsvc *nsvc;
287
Harald Weltef5430362012-06-17 12:25:53 +0800288 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200289 if (!nsvc) {
290 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
291 return CMD_WARNING;
292 }
293 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
294
295 return CMD_SUCCESS;
296
297}
298
299DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
300 "nse <0-65535> remote-port <0-65535>",
301 NSE_CMD_STR
302 "Remote UDP Port\n"
303 "Remote UDP Port Number\n")
304{
305 uint16_t nsei = atoi(argv[0]);
306 uint16_t port = atoi(argv[1]);
307 struct gprs_nsvc *nsvc;
308
Harald Weltef5430362012-06-17 12:25:53 +0800309 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200310 if (!nsvc) {
311 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
312 return CMD_WARNING;
313 }
314
Harald Welteb3ee2652010-05-19 14:38:50 +0200315 if (nsvc->ll != GPRS_NS_LL_UDP) {
316 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
317 VTY_NEWLINE);
318 return CMD_WARNING;
319 }
320
Harald Weltebfe62e52017-05-15 12:48:30 +0200321 nsvc->ip.bts_addr.sin_port = osmo_htons(port);
Harald Welte144e0292010-05-13 11:45:07 +0200322
323 return CMD_SUCCESS;
324}
325
Harald Welteb3ee2652010-05-19 14:38:50 +0200326DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200327 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200328 NSE_CMD_STR
329 "Frame Relay DLCI\n"
330 "Frame Relay DLCI Number\n")
331{
332 uint16_t nsei = atoi(argv[0]);
333 uint16_t dlci = atoi(argv[1]);
334 struct gprs_nsvc *nsvc;
335
Harald Weltef5430362012-06-17 12:25:53 +0800336 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200337 if (!nsvc) {
338 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
339 return CMD_WARNING;
340 }
341
342 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
343 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
344 VTY_NEWLINE);
345 return CMD_WARNING;
346 }
347
Harald Weltebfe62e52017-05-15 12:48:30 +0200348 nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci);
Harald Welteb3ee2652010-05-19 14:38:50 +0200349
350 return CMD_SUCCESS;
351}
352
353DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
354 "nse <0-65535> encapsulation (udp|framerelay-gre)",
355 NSE_CMD_STR
356 "Encapsulation for NS\n"
357 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
358{
359 uint16_t nsei = atoi(argv[0]);
360 struct gprs_nsvc *nsvc;
361
Harald Weltef5430362012-06-17 12:25:53 +0800362 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200363 if (!nsvc) {
364 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
365 return CMD_WARNING;
366 }
367
368 if (!strcmp(argv[1], "udp"))
369 nsvc->ll = GPRS_NS_LL_UDP;
370 else
371 nsvc->ll = GPRS_NS_LL_FR_GRE;
372
373 return CMD_SUCCESS;
374}
375
376
Harald Welte144e0292010-05-13 11:45:07 +0200377DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
378 "nse <0-65535> remote-role (sgsn|bss)",
379 NSE_CMD_STR
380 "Remote NSE Role\n"
381 "Remote Peer is SGSN\n"
382 "Remote Peer is BSS\n")
383{
384 uint16_t nsei = atoi(argv[0]);
385 struct gprs_nsvc *nsvc;
386
Harald Weltef5430362012-06-17 12:25:53 +0800387 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200388 if (!nsvc) {
389 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
390 return CMD_WARNING;
391 }
392
393 if (!strcmp(argv[1], "sgsn"))
394 nsvc->remote_end_is_sgsn = 1;
395 else
396 nsvc->remote_end_is_sgsn = 0;
397
398 return CMD_SUCCESS;
399}
400
401DEFUN(cfg_no_nse, cfg_no_nse_cmd,
402 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200403 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200404 "Delete " NSE_CMD_STR)
405{
406 uint16_t nsei = atoi(argv[0]);
407 struct gprs_nsvc *nsvc;
408
Harald Weltef5430362012-06-17 12:25:53 +0800409 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200410 if (!nsvc) {
411 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
412 return CMD_WARNING;
413 }
414
Harald Welte24133c32010-05-15 23:06:26 +0200415 if (!nsvc->persistent) {
416 vty_out(vty, "NSEI %u is not a persistent NSE%s",
417 nsei, VTY_NEWLINE);
418 return CMD_WARNING;
419 }
420
421 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200422
423 return CMD_SUCCESS;
424}
425
426DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
427 "timer " NS_TIMERS " <0-65535>",
428 "Network Service Timer\n"
429 NS_TIMERS_HELP "Timer Value\n")
430{
431 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
432 int val = atoi(argv[1]);
433
434 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
435 return CMD_WARNING;
436
437 vty_nsi->timeout[idx] = val;
438
439 return CMD_SUCCESS;
440}
441
Harald Welte7fb05232010-05-19 15:09:09 +0200442#define ENCAPS_STR "NS encapsulation options\n"
443
444DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
445 "encapsulation udp local-ip A.B.C.D",
446 ENCAPS_STR "NS over UDP Encapsulation\n"
447 "Set the IP address on which we listen for NS/UDP\n"
448 "IP Address\n")
449{
450 struct in_addr ia;
451
452 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200453 vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200454
455 return CMD_SUCCESS;
456}
457
458DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
459 "encapsulation udp local-port <0-65535>",
460 ENCAPS_STR "NS over UDP Encapsulation\n"
461 "Set the UDP port on which we listen for NS/UDP\n"
462 "UDP port number\n")
463{
464 unsigned int port = atoi(argv[0]);
465
466 vty_nsi->nsip.local_port = port;
467
468 return CMD_SUCCESS;
469}
470
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100471DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
472 "encapsulation udp dscp <0-255>",
473 ENCAPS_STR "NS over UDP Encapsulation\n"
474 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
475{
476 int dscp = atoi(argv[0]);
477 vty_nsi->nsip.dscp = dscp;
478 return CMD_SUCCESS;
479}
480
Harald Welte7fb05232010-05-19 15:09:09 +0200481DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
482 "encapsulation framerelay-gre local-ip A.B.C.D",
483 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
484 "Set the IP address on which we listen for NS/FR/GRE\n"
485 "IP Address\n")
486{
487 struct in_addr ia;
488
489 if (!vty_nsi->frgre.enabled) {
490 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
491 return CMD_WARNING;
492 }
493 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200494 vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200495
496 return CMD_SUCCESS;
497}
498
499DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
500 "encapsulation framerelay-gre enabled (1|0)",
501 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
502 "Enable or disable Frame Relay over GRE\n"
503 "Enable\n" "Disable\n")
504{
505 int enabled = atoi(argv[0]);
506
507 vty_nsi->frgre.enabled = enabled;
508
509 return CMD_SUCCESS;
510}
511
Harald Welte43f3b692010-05-14 19:36:59 +0200512DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200513 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200514 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100515 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200516 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100517 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200518 "Initiate BLOCK procedure\n"
519 "Initiate UNBLOCK procedure\n"
520 "Initiate RESET procedure\n")
521{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200522 const char *id_type = argv[0];
523 uint16_t id = atoi(argv[1]);
524 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200525 struct gprs_nsvc *nsvc;
526
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200527 if (!strcmp(id_type, "nsei"))
528 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
529 else if (!strcmp(id_type, "nsvci"))
530 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
531 else {
532 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
533 return CMD_WARNING;
534 }
535
Harald Welte43f3b692010-05-14 19:36:59 +0200536 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200537 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200538 return CMD_WARNING;
539 }
540
541 if (!strcmp(operation, "block"))
542 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
543 else if (!strcmp(operation, "unblock"))
544 gprs_ns_tx_unblock(nsvc);
545 else if (!strcmp(operation, "reset"))
546 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
547 else
548 return CMD_WARNING;
549
550 return CMD_SUCCESS;
551}
552
Harald Welte91f7f4b2010-05-15 23:52:02 +0200553DEFUN(logging_fltr_nsvc,
554 logging_fltr_nsvc_cmd,
555 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200556 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200557 "Filter based on NS Virtual Connection\n"
558 "Identify NS-VC by NSEI\n"
559 "Identify NS-VC by NSVCI\n"
560 "Numeric identifier\n")
561{
Harald Welte43ae94e2011-02-18 21:10:05 +0100562 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200563 struct gprs_nsvc *nsvc;
564 uint16_t id = atoi(argv[1]);
565
Harald Welte43ae94e2011-02-18 21:10:05 +0100566 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200567 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200568
569 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800570 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200571 else
Harald Weltef5430362012-06-17 12:25:53 +0800572 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200573
574 if (!nsvc) {
575 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
576 return CMD_WARNING;
577 }
578
Harald Welte43ae94e2011-02-18 21:10:05 +0100579 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200580 return CMD_SUCCESS;
581}
Harald Welte43f3b692010-05-14 19:36:59 +0200582
Harald Welte144e0292010-05-13 11:45:07 +0200583int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
584{
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100585 static bool vty_elements_installed = false;
586
Harald Welte144e0292010-05-13 11:45:07 +0200587 vty_nsi = nsi;
588
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100589 /* Regression test code may call this function repeatedly, so make sure
590 * that VTY elements are not duplicated, which would assert. */
591 if (vty_elements_installed)
592 return 0;
593 vty_elements_installed = true;
594
Harald Welte144e0292010-05-13 11:45:07 +0200595 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200596 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200597 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200598 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200599
Harald Welte43ae94e2011-02-18 21:10:05 +0100600 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
601
Harald Welte144e0292010-05-13 11:45:07 +0200602 install_element(CONFIG_NODE, &cfg_ns_cmd);
603 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800604 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
605 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
606 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
607 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
608 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
609 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
610 install_element(L_NS_NODE, &cfg_no_nse_cmd);
611 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
612 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
613 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100614 install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
Harald Welte4f5883b2012-06-16 16:54:06 +0800615 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
616 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200617
Harald Welte43f3b692010-05-14 19:36:59 +0200618 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
619
Harald Welte144e0292010-05-13 11:45:07 +0200620 return 0;
621}