blob: bdccb3ff7785e0bf43a4becbc78bb4ee9d8c9fa7 [file] [log] [blame]
Harald Welte144e0292010-05-13 11:45:07 +02001/* 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 Welte7fa89c22014-10-26 20:33:09 +01008 * 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 Welte144e0292010-05-13 11:45:07 +020010 * (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 Welte7fa89c22014-10-26 20:33:09 +010015 * GNU General Public License for more details.
Harald Welte144e0292010-05-13 11:45:07 +020016 *
Harald Welte7fa89c22014-10-26 20:33:09 +010017 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010018 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte144e0292010-05-13 11:45:07 +020019 *
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 Ayusoff663232011-03-22 16:47:59 +010029#include <osmocom/core/msgb.h>
Harald Weltebfe62e52017-05-15 12:48:30 +020030#include <osmocom/core/byteswap.h>
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010031#include <osmocom/gsm/tlv.h>
32#include <osmocom/core/talloc.h>
33#include <osmocom/core/select.h>
34#include <osmocom/core/rate_ctr.h>
Harald Welte73952e32012-06-16 14:59:56 +080035#include <osmocom/gprs/gprs_ns.h>
36#include <osmocom/gprs/gprs_bssgp.h>
Harald Welte144e0292010-05-13 11:45:07 +020037
Harald Welteac1a7152010-05-19 19:45:32 +020038#include <osmocom/vty/vty.h>
39#include <osmocom/vty/command.h>
40#include <osmocom/vty/logging.h>
41#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayuso167281e2011-03-28 19:35:00 +020042#include <osmocom/vty/misc.h>
Harald Welte144e0292010-05-13 11:45:07 +020043
Harald Welte4f5883b2012-06-16 16:54:06 +080044#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080045
Harald Welte144e0292010-05-13 11:45:07 +020046static struct gprs_ns_inst *vty_nsi = NULL;
47
48/* FIXME: this should go to some common file as it is copied
49 * in vty_interface.c of the BSC */
50static const struct value_string gprs_ns_timer_strs[] = {
51 { 0, "tns-block" },
52 { 1, "tns-block-retries" },
53 { 2, "tns-reset" },
54 { 3, "tns-reset-retries" },
55 { 4, "tns-test" },
56 { 5, "tns-alive" },
57 { 6, "tns-alive-retries" },
58 { 0, NULL }
59};
60
Harald Weltef5430362012-06-17 12:25:53 +080061static void log_set_nsvc_filter(struct log_target *target,
62 struct gprs_nsvc *nsvc)
63{
64 if (nsvc) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010065 target->filter_map |= (1 << LOG_FLT_GB_NSVC);
66 target->filter_data[LOG_FLT_GB_NSVC] = nsvc;
67 } else if (target->filter_data[LOG_FLT_GB_NSVC]) {
68 target->filter_map = ~(1 << LOG_FLT_GB_NSVC);
69 target->filter_data[LOG_FLT_GB_NSVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080070 }
71}
72
Harald Welte144e0292010-05-13 11:45:07 +020073static struct cmd_node ns_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080074 L_NS_NODE,
Jacob Erlbeck35fe87c2013-10-24 01:33:20 +020075 "%s(config-ns)# ",
Harald Welte144e0292010-05-13 11:45:07 +020076 1,
77};
78
79static int config_write_ns(struct vty *vty)
80{
81 struct gprs_nsvc *nsvc;
82 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020083 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020084
85 vty_out(vty, "ns%s", VTY_NEWLINE);
86
87 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
88 if (!nsvc->persistent)
89 continue;
90 vty_out(vty, " nse %u nsvci %u%s",
91 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
92 vty_out(vty, " nse %u remote-role %s%s",
93 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
94 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020095 switch (nsvc->ll) {
96 case GPRS_NS_LL_UDP:
97 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
98 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +020099 vty_out(vty, " nse %u remote-ip %s%s",
100 nsvc->nsei,
101 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
102 VTY_NEWLINE);
103 vty_out(vty, " nse %u remote-port %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200104 nsvc->nsei, osmo_ntohs(nsvc->ip.bts_addr.sin_port),
Harald Welte144e0292010-05-13 11:45:07 +0200105 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +0200106 break;
107 case GPRS_NS_LL_FR_GRE:
108 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
109 nsvc->nsei, VTY_NEWLINE);
110 vty_out(vty, " nse %u remote-ip %s%s",
111 nsvc->nsei,
112 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
113 VTY_NEWLINE);
114 vty_out(vty, " nse %u fr-dlci %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200115 nsvc->nsei, osmo_ntohs(nsvc->frgre.bts_addr.sin_port),
Harald Welteb3ee2652010-05-19 14:38:50 +0200116 VTY_NEWLINE);
117 default:
118 break;
Harald Welte144e0292010-05-13 11:45:07 +0200119 }
120 }
121
122 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
123 vty_out(vty, " timer %s %u%s",
124 get_value_string(gprs_ns_timer_strs, i),
125 vty_nsi->timeout[i], VTY_NEWLINE);
126
Harald Welte7fb05232010-05-19 15:09:09 +0200127 if (vty_nsi->nsip.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200128 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200129 vty_out(vty, " encapsulation udp local-ip %s%s",
130 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200131 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200132 if (vty_nsi->nsip.local_port)
133 vty_out(vty, " encapsulation udp local-port %u%s",
134 vty_nsi->nsip.local_port, VTY_NEWLINE);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100135 if (vty_nsi->nsip.dscp)
136 vty_out(vty, " encapsulation udp dscp %d%s",
137 vty_nsi->nsip.dscp, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200138
Harald Welte7fb05232010-05-19 15:09:09 +0200139 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
140 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200141 if (vty_nsi->frgre.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200142 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200143 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
144 inet_ntoa(ia), VTY_NEWLINE);
145 }
146
Harald Welte144e0292010-05-13 11:45:07 +0200147 return CMD_SUCCESS;
148}
149
150DEFUN(cfg_ns, cfg_ns_cmd,
151 "ns",
152 "Configure the GPRS Network Service")
153{
Harald Welte4f5883b2012-06-16 16:54:06 +0800154 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200155 return CMD_SUCCESS;
156}
157
Harald Welte92883342010-05-15 23:04:03 +0200158static void dump_nse(struct vty *vty, struct gprs_nsvc *nsvc, int stats)
159{
160 vty_out(vty, "NSEI %5u, NS-VC %5u, Remote: %-4s, %5s %9s",
161 nsvc->nsei, nsvc->nsvci,
162 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
163 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
164 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED");
Harald Welteb3ee2652010-05-19 14:38:50 +0200165 if (nsvc->ll == GPRS_NS_LL_UDP || nsvc->ll == GPRS_NS_LL_FR_GRE)
166 vty_out(vty, ", %s %15s:%u",
Harald Weltece4ccbc2010-05-19 17:02:57 +0200167 nsvc->ll == GPRS_NS_LL_UDP ? "UDP " : "FR-GRE",
Harald Welte92883342010-05-15 23:04:03 +0200168 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
Harald Weltebfe62e52017-05-15 12:48:30 +0200169 osmo_ntohs(nsvc->ip.bts_addr.sin_port));
Harald Welte92883342010-05-15 23:04:03 +0200170 vty_out(vty, "%s", VTY_NEWLINE);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200171 if (stats) {
Harald Welte92883342010-05-15 23:04:03 +0200172 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200173 vty_out_stat_item_group(vty, " ", nsvc->statg);
174 }
Harald Welte92883342010-05-15 23:04:03 +0200175}
176
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200177static void dump_ns(struct vty *vty, struct gprs_ns_inst *nsi, int stats)
Harald Welte144e0292010-05-13 11:45:07 +0200178{
Harald Welte144e0292010-05-13 11:45:07 +0200179 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200180 struct in_addr ia;
181
Harald Weltebfe62e52017-05-15 12:48:30 +0200182 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200183 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200184 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
185
Harald Weltebfe62e52017-05-15 12:48:30 +0200186 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200187 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200188 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200189
190 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200191 if (nsvc == nsi->unknown_nsvc)
192 continue;
Harald Welte92883342010-05-15 23:04:03 +0200193 dump_nse(vty, nsvc, stats);
Harald Welte144e0292010-05-13 11:45:07 +0200194 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200195}
Harald Welte144e0292010-05-13 11:45:07 +0200196
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200197DEFUN(show_ns, show_ns_cmd, "show ns",
198 SHOW_STR "Display information about the NS protocol")
199{
200 struct gprs_ns_inst *nsi = vty_nsi;
201 dump_ns(vty, nsi, 0);
Harald Welte144e0292010-05-13 11:45:07 +0200202 return CMD_SUCCESS;
203}
204
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200205DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
206 SHOW_STR
207 "Display information about the NS protocol\n"
208 "Include statistics\n")
209{
210 struct gprs_ns_inst *nsi = vty_nsi;
211 dump_ns(vty, nsi, 1);
212 return CMD_SUCCESS;
213}
Harald Welte144e0292010-05-13 11:45:07 +0200214
Harald Welte92883342010-05-15 23:04:03 +0200215DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
216 SHOW_STR "Display information about the NS protocol\n"
217 "Select one NSE by its NSE Identifier\n"
218 "Select one NSE by its NS-VC Identifier\n"
219 "The Identifier of selected type\n"
220 "Include Statistics\n")
221{
222 struct gprs_ns_inst *nsi = vty_nsi;
223 struct gprs_nsvc *nsvc;
224 uint16_t id = atoi(argv[1]);
225 int show_stats = 0;
226
227 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800228 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200229 else
Harald Weltef5430362012-06-17 12:25:53 +0800230 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200231
232 if (!nsvc) {
233 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
234 return CMD_WARNING;
235 }
236
237 if (argc >= 3)
238 show_stats = 1;
239
240 dump_nse(vty, nsvc, show_stats);
241 return CMD_SUCCESS;
242}
243
Harald Welte24133c32010-05-15 23:06:26 +0200244#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200245
246DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
247 "nse <0-65535> nsvci <0-65534>",
248 NSE_CMD_STR
249 "NS Virtual Connection\n"
250 "NS Virtual Connection ID (NSVCI)\n"
251 )
252{
253 uint16_t nsei = atoi(argv[0]);
254 uint16_t nsvci = atoi(argv[1]);
255 struct gprs_nsvc *nsvc;
256
Harald Weltef5430362012-06-17 12:25:53 +0800257 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200258 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800259 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200260 nsvc->nsei = nsei;
261 }
262 nsvc->nsvci = nsvci;
263 /* All NSVCs that are explicitly configured by VTY are
264 * marked as persistent so we can write them to the config
265 * file at some later point */
266 nsvc->persistent = 1;
267
268 return CMD_SUCCESS;
269}
270
271DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
272 "nse <0-65535> remote-ip A.B.C.D",
273 NSE_CMD_STR
274 "Remote IP Address\n"
275 "Remote IP Address\n")
276{
277 uint16_t nsei = atoi(argv[0]);
278 struct gprs_nsvc *nsvc;
279
Harald Weltef5430362012-06-17 12:25:53 +0800280 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200281 if (!nsvc) {
282 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
283 return CMD_WARNING;
284 }
285 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
286
287 return CMD_SUCCESS;
288
289}
290
291DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
292 "nse <0-65535> remote-port <0-65535>",
293 NSE_CMD_STR
294 "Remote UDP Port\n"
295 "Remote UDP Port Number\n")
296{
297 uint16_t nsei = atoi(argv[0]);
298 uint16_t port = atoi(argv[1]);
299 struct gprs_nsvc *nsvc;
300
Harald Weltef5430362012-06-17 12:25:53 +0800301 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200302 if (!nsvc) {
303 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
304 return CMD_WARNING;
305 }
306
Harald Welteb3ee2652010-05-19 14:38:50 +0200307 if (nsvc->ll != GPRS_NS_LL_UDP) {
308 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
309 VTY_NEWLINE);
310 return CMD_WARNING;
311 }
312
Harald Weltebfe62e52017-05-15 12:48:30 +0200313 nsvc->ip.bts_addr.sin_port = osmo_htons(port);
Harald Welte144e0292010-05-13 11:45:07 +0200314
315 return CMD_SUCCESS;
316}
317
Harald Welteb3ee2652010-05-19 14:38:50 +0200318DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200319 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200320 NSE_CMD_STR
321 "Frame Relay DLCI\n"
322 "Frame Relay DLCI Number\n")
323{
324 uint16_t nsei = atoi(argv[0]);
325 uint16_t dlci = atoi(argv[1]);
326 struct gprs_nsvc *nsvc;
327
Harald Weltef5430362012-06-17 12:25:53 +0800328 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200329 if (!nsvc) {
330 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
331 return CMD_WARNING;
332 }
333
334 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
335 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
336 VTY_NEWLINE);
337 return CMD_WARNING;
338 }
339
Harald Weltebfe62e52017-05-15 12:48:30 +0200340 nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci);
Harald Welteb3ee2652010-05-19 14:38:50 +0200341
342 return CMD_SUCCESS;
343}
344
345DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
346 "nse <0-65535> encapsulation (udp|framerelay-gre)",
347 NSE_CMD_STR
348 "Encapsulation for NS\n"
349 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\n")
350{
351 uint16_t nsei = atoi(argv[0]);
352 struct gprs_nsvc *nsvc;
353
Harald Weltef5430362012-06-17 12:25:53 +0800354 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200355 if (!nsvc) {
356 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
357 return CMD_WARNING;
358 }
359
360 if (!strcmp(argv[1], "udp"))
361 nsvc->ll = GPRS_NS_LL_UDP;
362 else
363 nsvc->ll = GPRS_NS_LL_FR_GRE;
364
365 return CMD_SUCCESS;
366}
367
368
Harald Welte144e0292010-05-13 11:45:07 +0200369DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
370 "nse <0-65535> remote-role (sgsn|bss)",
371 NSE_CMD_STR
372 "Remote NSE Role\n"
373 "Remote Peer is SGSN\n"
374 "Remote Peer is BSS\n")
375{
376 uint16_t nsei = atoi(argv[0]);
377 struct gprs_nsvc *nsvc;
378
Harald Weltef5430362012-06-17 12:25:53 +0800379 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200380 if (!nsvc) {
381 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
382 return CMD_WARNING;
383 }
384
385 if (!strcmp(argv[1], "sgsn"))
386 nsvc->remote_end_is_sgsn = 1;
387 else
388 nsvc->remote_end_is_sgsn = 0;
389
390 return CMD_SUCCESS;
391}
392
393DEFUN(cfg_no_nse, cfg_no_nse_cmd,
394 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200395 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200396 "Delete " NSE_CMD_STR)
397{
398 uint16_t nsei = atoi(argv[0]);
399 struct gprs_nsvc *nsvc;
400
Harald Weltef5430362012-06-17 12:25:53 +0800401 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200402 if (!nsvc) {
403 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
404 return CMD_WARNING;
405 }
406
Harald Welte24133c32010-05-15 23:06:26 +0200407 if (!nsvc->persistent) {
408 vty_out(vty, "NSEI %u is not a persistent NSE%s",
409 nsei, VTY_NEWLINE);
410 return CMD_WARNING;
411 }
412
413 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200414
415 return CMD_SUCCESS;
416}
417
418DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
419 "timer " NS_TIMERS " <0-65535>",
420 "Network Service Timer\n"
421 NS_TIMERS_HELP "Timer Value\n")
422{
423 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
424 int val = atoi(argv[1]);
425
426 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
427 return CMD_WARNING;
428
429 vty_nsi->timeout[idx] = val;
430
431 return CMD_SUCCESS;
432}
433
Harald Welte7fb05232010-05-19 15:09:09 +0200434#define ENCAPS_STR "NS encapsulation options\n"
435
436DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
437 "encapsulation udp local-ip A.B.C.D",
438 ENCAPS_STR "NS over UDP Encapsulation\n"
439 "Set the IP address on which we listen for NS/UDP\n"
440 "IP Address\n")
441{
442 struct in_addr ia;
443
444 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200445 vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200446
447 return CMD_SUCCESS;
448}
449
450DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
451 "encapsulation udp local-port <0-65535>",
452 ENCAPS_STR "NS over UDP Encapsulation\n"
453 "Set the UDP port on which we listen for NS/UDP\n"
454 "UDP port number\n")
455{
456 unsigned int port = atoi(argv[0]);
457
458 vty_nsi->nsip.local_port = port;
459
460 return CMD_SUCCESS;
461}
462
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100463DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
464 "encapsulation udp dscp <0-255>",
465 ENCAPS_STR "NS over UDP Encapsulation\n"
466 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
467{
468 int dscp = atoi(argv[0]);
469 vty_nsi->nsip.dscp = dscp;
470 return CMD_SUCCESS;
471}
472
Harald Welte7fb05232010-05-19 15:09:09 +0200473DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
474 "encapsulation framerelay-gre local-ip A.B.C.D",
475 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
476 "Set the IP address on which we listen for NS/FR/GRE\n"
477 "IP Address\n")
478{
479 struct in_addr ia;
480
481 if (!vty_nsi->frgre.enabled) {
482 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
483 return CMD_WARNING;
484 }
485 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200486 vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200487
488 return CMD_SUCCESS;
489}
490
491DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
492 "encapsulation framerelay-gre enabled (1|0)",
493 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
494 "Enable or disable Frame Relay over GRE\n"
495 "Enable\n" "Disable\n")
496{
497 int enabled = atoi(argv[0]);
498
499 vty_nsi->frgre.enabled = enabled;
500
501 return CMD_SUCCESS;
502}
503
Harald Welte43f3b692010-05-14 19:36:59 +0200504DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200505 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200506 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100507 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200508 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100509 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200510 "Initiate BLOCK procedure\n"
511 "Initiate UNBLOCK procedure\n"
512 "Initiate RESET procedure\n")
513{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200514 const char *id_type = argv[0];
515 uint16_t id = atoi(argv[1]);
516 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200517 struct gprs_nsvc *nsvc;
518
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200519 if (!strcmp(id_type, "nsei"))
520 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
521 else if (!strcmp(id_type, "nsvci"))
522 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
523 else {
524 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
525 return CMD_WARNING;
526 }
527
Harald Welte43f3b692010-05-14 19:36:59 +0200528 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200529 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200530 return CMD_WARNING;
531 }
532
533 if (!strcmp(operation, "block"))
534 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
535 else if (!strcmp(operation, "unblock"))
536 gprs_ns_tx_unblock(nsvc);
537 else if (!strcmp(operation, "reset"))
538 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
539 else
540 return CMD_WARNING;
541
542 return CMD_SUCCESS;
543}
544
Harald Welte91f7f4b2010-05-15 23:52:02 +0200545DEFUN(logging_fltr_nsvc,
546 logging_fltr_nsvc_cmd,
547 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200548 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200549 "Filter based on NS Virtual Connection\n"
550 "Identify NS-VC by NSEI\n"
551 "Identify NS-VC by NSVCI\n"
552 "Numeric identifier\n")
553{
Harald Welte43ae94e2011-02-18 21:10:05 +0100554 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200555 struct gprs_nsvc *nsvc;
556 uint16_t id = atoi(argv[1]);
557
Harald Welte43ae94e2011-02-18 21:10:05 +0100558 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200559 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200560
561 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800562 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200563 else
Harald Weltef5430362012-06-17 12:25:53 +0800564 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200565
566 if (!nsvc) {
567 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
568 return CMD_WARNING;
569 }
570
Harald Welte43ae94e2011-02-18 21:10:05 +0100571 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200572 return CMD_SUCCESS;
573}
Harald Welte43f3b692010-05-14 19:36:59 +0200574
Harald Welte144e0292010-05-13 11:45:07 +0200575int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
576{
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100577 static bool vty_elements_installed = false;
578
Harald Welte144e0292010-05-13 11:45:07 +0200579 vty_nsi = nsi;
580
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100581 /* Regression test code may call this function repeatedly, so make sure
582 * that VTY elements are not duplicated, which would assert. */
583 if (vty_elements_installed)
584 return 0;
585 vty_elements_installed = true;
586
Harald Welte144e0292010-05-13 11:45:07 +0200587 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200588 install_element_ve(&show_ns_stats_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200589 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200590 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200591
Harald Welte43ae94e2011-02-18 21:10:05 +0100592 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
593
Harald Welte144e0292010-05-13 11:45:07 +0200594 install_element(CONFIG_NODE, &cfg_ns_cmd);
595 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800596 install_default(L_NS_NODE);
597 install_element(L_NS_NODE, &libgb_exit_cmd);
598 install_element(L_NS_NODE, &libgb_end_cmd);
599 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}