blob: 3b1a6987b7f4bb1bf62d366855a2f2dfcc46333e [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>
Harald Welte144e0292010-05-13 11:45:07 +020038
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{
Max32f99712017-10-20 12:27:49 +0200161 vty_out(vty, "NSEI %5u, NS-VC %5u, %5s %9s, Remote: %-4s, %5s %9s",
Harald Welte92883342010-05-15 23:04:03 +0200162 nsvc->nsei, nsvc->nsvci,
Harald Welte92883342010-05-15 23:04:03 +0200163 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
Max32f99712017-10-20 12:27:49 +0200164 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
165 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
166 nsvc->remote_state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
167 nsvc->remote_state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200168 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
169 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200170 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200171 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
Harald Weltebfe62e52017-05-15 12:48:30 +0200172 osmo_ntohs(nsvc->ip.bts_addr.sin_port));
Harald Welte92883342010-05-15 23:04:03 +0200173 vty_out(vty, "%s", VTY_NEWLINE);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200174 if (stats) {
Harald Welte92883342010-05-15 23:04:03 +0200175 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200176 vty_out_stat_item_group(vty, " ", nsvc->statg);
177 }
Harald Welte92883342010-05-15 23:04:03 +0200178}
179
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200180static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200181{
Harald Welte144e0292010-05-13 11:45:07 +0200182 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200183 struct in_addr ia;
184
Harald Weltebfe62e52017-05-15 12:48:30 +0200185 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200186 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200187 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
188
Harald Weltebfe62e52017-05-15 12:48:30 +0200189 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200190 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200191 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200192
193 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200194 if (nsvc == nsi->unknown_nsvc)
195 continue;
Harald Welte92883342010-05-15 23:04:03 +0200196 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200197 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200198}
Harald Welte144e0292010-05-13 11:45:07 +0200199
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200200DEFUN(show_ns, show_ns_cmd, "show ns",
201 SHOW_STR "Display information about the NS protocol")
202{
203 struct gprs_ns_inst *nsi = vty_nsi;
204 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200205 return CMD_SUCCESS;
206}
207
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200208DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
209 SHOW_STR
210 "Display information about the NS protocol\n"
211 "Include statistics\n")
212{
213 struct gprs_ns_inst *nsi = vty_nsi;
214 dump_ns(vty, nsi, 1);
215 return CMD_SUCCESS;
216}
Harald Welte144e0292010-05-13 11:45:07 +0200217
Harald Welte92883342010-05-15 23:04:03 +0200218DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
219 SHOW_STR "Display information about the NS protocol\n"
220 "Select one NSE by its NSE Identifier\n"
221 "Select one NSE by its NS-VC Identifier\n"
222 "The Identifier of selected type\n"
223 "Include Statistics\n")
224{
225 struct gprs_ns_inst *nsi = vty_nsi;
226 struct gprs_nsvc *nsvc;
227 uint16_t id = atoi(argv[1]);
228 int show_stats = 0;
229
230 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800231 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200232 else
Harald Weltef5430362012-06-17 12:25:53 +0800233 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200234
235 if (!nsvc) {
236 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
237 return CMD_WARNING;
238 }
239
240 if (argc >= 3)
241 show_stats = 1;
242
243 dump_nse(vty, nsvc, show_stats);
244 return CMD_SUCCESS;
245}
246
Harald Welte24133c32010-05-15 23:06:26 +0200247#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200248
249DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
250 "nse <0-65535> nsvci <0-65534>",
251 NSE_CMD_STR
252 "NS Virtual Connection\n"
253 "NS Virtual Connection ID (NSVCI)\n"
254 )
255{
256 uint16_t nsei = atoi(argv[0]);
257 uint16_t nsvci = atoi(argv[1]);
258 struct gprs_nsvc *nsvc;
259
Harald Weltef5430362012-06-17 12:25:53 +0800260 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200261 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800262 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200263 nsvc->nsei = nsei;
264 }
265 nsvc->nsvci = nsvci;
266 /* All NSVCs that are explicitly configured by VTY are
267 * marked as persistent so we can write them to the config
268 * file at some later point */
269 nsvc->persistent = 1;
270
271 return CMD_SUCCESS;
272}
273
274DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
275 "nse <0-65535> remote-ip A.B.C.D",
276 NSE_CMD_STR
277 "Remote IP Address\n"
278 "Remote IP Address\n")
279{
280 uint16_t nsei = atoi(argv[0]);
281 struct gprs_nsvc *nsvc;
282
Harald Weltef5430362012-06-17 12:25:53 +0800283 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200284 if (!nsvc) {
285 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
286 return CMD_WARNING;
287 }
288 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
289
290 return CMD_SUCCESS;
291
292}
293
294DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
295 "nse <0-65535> remote-port <0-65535>",
296 NSE_CMD_STR
297 "Remote UDP Port\n"
298 "Remote UDP Port Number\n")
299{
300 uint16_t nsei = atoi(argv[0]);
301 uint16_t port = atoi(argv[1]);
302 struct gprs_nsvc *nsvc;
303
Harald Weltef5430362012-06-17 12:25:53 +0800304 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200305 if (!nsvc) {
306 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
307 return CMD_WARNING;
308 }
309
Harald Welteb3ee2652010-05-19 14:38:50 +0200310 if (nsvc->ll != GPRS_NS_LL_UDP) {
311 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
312 VTY_NEWLINE);
313 return CMD_WARNING;
314 }
315
Harald Weltebfe62e52017-05-15 12:48:30 +0200316 nsvc->ip.bts_addr.sin_port = osmo_htons(port);
Harald Welte144e0292010-05-13 11:45:07 +0200317
318 return CMD_SUCCESS;
319}
320
Harald Welteb3ee2652010-05-19 14:38:50 +0200321DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200322 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200323 NSE_CMD_STR
324 "Frame Relay DLCI\n"
325 "Frame Relay DLCI Number\n")
326{
327 uint16_t nsei = atoi(argv[0]);
328 uint16_t dlci = atoi(argv[1]);
329 struct gprs_nsvc *nsvc;
330
Harald Weltef5430362012-06-17 12:25:53 +0800331 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200332 if (!nsvc) {
333 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
334 return CMD_WARNING;
335 }
336
337 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
338 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
339 VTY_NEWLINE);
340 return CMD_WARNING;
341 }
342
Harald Weltebfe62e52017-05-15 12:48:30 +0200343 nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci);
Harald Welteb3ee2652010-05-19 14:38:50 +0200344
345 return CMD_SUCCESS;
346}
347
348DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
349 "nse <0-65535> encapsulation (udp|framerelay-gre)",
350 NSE_CMD_STR
351 "Encapsulation for NS\n"
352 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
353{
354 uint16_t nsei = atoi(argv[0]);
355 struct gprs_nsvc *nsvc;
356
Harald Weltef5430362012-06-17 12:25:53 +0800357 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200358 if (!nsvc) {
359 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
360 return CMD_WARNING;
361 }
362
363 if (!strcmp(argv[1], "udp"))
364 nsvc->ll = GPRS_NS_LL_UDP;
365 else
366 nsvc->ll = GPRS_NS_LL_FR_GRE;
367
368 return CMD_SUCCESS;
369}
370
371
Harald Welte144e0292010-05-13 11:45:07 +0200372DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
373 "nse <0-65535> remote-role (sgsn|bss)",
374 NSE_CMD_STR
375 "Remote NSE Role\n"
376 "Remote Peer is SGSN\n"
377 "Remote Peer is BSS\n")
378{
379 uint16_t nsei = atoi(argv[0]);
380 struct gprs_nsvc *nsvc;
381
Harald Weltef5430362012-06-17 12:25:53 +0800382 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200383 if (!nsvc) {
384 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
385 return CMD_WARNING;
386 }
387
388 if (!strcmp(argv[1], "sgsn"))
389 nsvc->remote_end_is_sgsn = 1;
390 else
391 nsvc->remote_end_is_sgsn = 0;
392
393 return CMD_SUCCESS;
394}
395
396DEFUN(cfg_no_nse, cfg_no_nse_cmd,
397 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200398 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200399 "Delete " NSE_CMD_STR)
400{
401 uint16_t nsei = atoi(argv[0]);
402 struct gprs_nsvc *nsvc;
403
Harald Weltef5430362012-06-17 12:25:53 +0800404 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200405 if (!nsvc) {
406 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
407 return CMD_WARNING;
408 }
409
Harald Welte24133c32010-05-15 23:06:26 +0200410 if (!nsvc->persistent) {
411 vty_out(vty, "NSEI %u is not a persistent NSE%s",
412 nsei, VTY_NEWLINE);
413 return CMD_WARNING;
414 }
415
416 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200417
418 return CMD_SUCCESS;
419}
420
421DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
422 "timer " NS_TIMERS " <0-65535>",
423 "Network Service Timer\n"
424 NS_TIMERS_HELP "Timer Value\n")
425{
426 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
427 int val = atoi(argv[1]);
428
429 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
430 return CMD_WARNING;
431
432 vty_nsi->timeout[idx] = val;
433
434 return CMD_SUCCESS;
435}
436
Harald Welte7fb05232010-05-19 15:09:09 +0200437#define ENCAPS_STR "NS encapsulation options\n"
438
439DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
440 "encapsulation udp local-ip A.B.C.D",
441 ENCAPS_STR "NS over UDP Encapsulation\n"
442 "Set the IP address on which we listen for NS/UDP\n"
443 "IP Address\n")
444{
445 struct in_addr ia;
446
447 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200448 vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200449
450 return CMD_SUCCESS;
451}
452
453DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
454 "encapsulation udp local-port <0-65535>",
455 ENCAPS_STR "NS over UDP Encapsulation\n"
456 "Set the UDP port on which we listen for NS/UDP\n"
457 "UDP port number\n")
458{
459 unsigned int port = atoi(argv[0]);
460
461 vty_nsi->nsip.local_port = port;
462
463 return CMD_SUCCESS;
464}
465
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100466DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
467 "encapsulation udp dscp <0-255>",
468 ENCAPS_STR "NS over UDP Encapsulation\n"
469 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
470{
471 int dscp = atoi(argv[0]);
472 vty_nsi->nsip.dscp = dscp;
473 return CMD_SUCCESS;
474}
475
Harald Welte7fb05232010-05-19 15:09:09 +0200476DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
477 "encapsulation framerelay-gre local-ip A.B.C.D",
478 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
479 "Set the IP address on which we listen for NS/FR/GRE\n"
480 "IP Address\n")
481{
482 struct in_addr ia;
483
484 if (!vty_nsi->frgre.enabled) {
485 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
486 return CMD_WARNING;
487 }
488 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200489 vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200490
491 return CMD_SUCCESS;
492}
493
494DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
495 "encapsulation framerelay-gre enabled (1|0)",
496 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
497 "Enable or disable Frame Relay over GRE\n"
498 "Enable\n" "Disable\n")
499{
500 int enabled = atoi(argv[0]);
501
502 vty_nsi->frgre.enabled = enabled;
503
504 return CMD_SUCCESS;
505}
506
Harald Welte43f3b692010-05-14 19:36:59 +0200507DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200508 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200509 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100510 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200511 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100512 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200513 "Initiate BLOCK procedure\n"
514 "Initiate UNBLOCK procedure\n"
515 "Initiate RESET procedure\n")
516{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200517 const char *id_type = argv[0];
518 uint16_t id = atoi(argv[1]);
519 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200520 struct gprs_nsvc *nsvc;
521
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200522 if (!strcmp(id_type, "nsei"))
523 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
524 else if (!strcmp(id_type, "nsvci"))
525 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
526 else {
527 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
528 return CMD_WARNING;
529 }
530
Harald Welte43f3b692010-05-14 19:36:59 +0200531 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200532 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200533 return CMD_WARNING;
534 }
535
536 if (!strcmp(operation, "block"))
537 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
538 else if (!strcmp(operation, "unblock"))
539 gprs_ns_tx_unblock(nsvc);
540 else if (!strcmp(operation, "reset"))
541 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
542 else
543 return CMD_WARNING;
544
545 return CMD_SUCCESS;
546}
547
Harald Welte91f7f4b2010-05-15 23:52:02 +0200548DEFUN(logging_fltr_nsvc,
549 logging_fltr_nsvc_cmd,
550 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200551 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200552 "Filter based on NS Virtual Connection\n"
553 "Identify NS-VC by NSEI\n"
554 "Identify NS-VC by NSVCI\n"
555 "Numeric identifier\n")
556{
Harald Welte43ae94e2011-02-18 21:10:05 +0100557 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200558 struct gprs_nsvc *nsvc;
559 uint16_t id = atoi(argv[1]);
560
Harald Welte43ae94e2011-02-18 21:10:05 +0100561 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200562 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200563
564 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800565 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200566 else
Harald Weltef5430362012-06-17 12:25:53 +0800567 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200568
569 if (!nsvc) {
570 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
571 return CMD_WARNING;
572 }
573
Harald Welte43ae94e2011-02-18 21:10:05 +0100574 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200575 return CMD_SUCCESS;
576}
Harald Welte43f3b692010-05-14 19:36:59 +0200577
Harald Welte144e0292010-05-13 11:45:07 +0200578int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
579{
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100580 static bool vty_elements_installed = false;
581
Harald Welte144e0292010-05-13 11:45:07 +0200582 vty_nsi = nsi;
583
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100584 /* Regression test code may call this function repeatedly, so make sure
585 * that VTY elements are not duplicated, which would assert. */
586 if (vty_elements_installed)
587 return 0;
588 vty_elements_installed = true;
589
Harald Welte144e0292010-05-13 11:45:07 +0200590 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200591 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200592 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200593 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200594
Harald Welte43ae94e2011-02-18 21:10:05 +0100595 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
596
Harald Welte144e0292010-05-13 11:45:07 +0200597 install_element(CONFIG_NODE, &cfg_ns_cmd);
598 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800599 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
600 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
601 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
602 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
603 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
604 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
605 install_element(L_NS_NODE, &cfg_no_nse_cmd);
606 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
607 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
608 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100609 install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
Harald Welte4f5883b2012-06-16 16:54:06 +0800610 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
611 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200612
Harald Welte43f3b692010-05-14 19:36:59 +0200613 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
614
Harald Welte144e0292010-05-13 11:45:07 +0200615 return 0;
616}