blob: 667db7d030d014348825ea53f956075212db7dbf [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/*
Harald Weltee08da972017-11-13 01:00:26 +09004 * (C) 2009-2014 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
Harald Welte144e0292010-05-13 11:45:07 +02006 *
7 * All Rights Reserved
8 *
Harald Weltee08da972017-11-13 01:00:26 +09009 * SPDX-License-Identifier: GPL-2.0+
10 *
Harald Welte144e0292010-05-13 11:45:07 +020011 * This program is free software; you can redistribute it and/or modify
Harald Welte7fa89c22014-10-26 20:33:09 +010012 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
Harald Welte144e0292010-05-13 11:45:07 +020014 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte7fa89c22014-10-26 20:33:09 +010019 * GNU General Public License for more details.
Harald Welte144e0292010-05-13 11:45:07 +020020 *
Harald Welte7fa89c22014-10-26 20:33:09 +010021 * You should have received a copy of the GNU General Public License
Harald Weltee4cbb3f2011-01-01 15:25:50 +010022 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte144e0292010-05-13 11:45:07 +020023 *
24 */
25
26#include <stdlib.h>
27#include <unistd.h>
28#include <errno.h>
29#include <stdint.h>
30
31#include <arpa/inet.h>
32
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010033#include <osmocom/core/msgb.h>
Harald Weltebfe62e52017-05-15 12:48:30 +020034#include <osmocom/core/byteswap.h>
Pablo Neira Ayusoff663232011-03-22 16:47:59 +010035#include <osmocom/gsm/tlv.h>
36#include <osmocom/core/talloc.h>
37#include <osmocom/core/select.h>
38#include <osmocom/core/rate_ctr.h>
Harald Welte73952e32012-06-16 14:59:56 +080039#include <osmocom/gprs/gprs_ns.h>
40#include <osmocom/gprs/gprs_bssgp.h>
Max37f465e2017-10-24 16:04:55 +020041#include <osmocom/core/socket.h>
Harald Welteac1a7152010-05-19 19:45:32 +020042#include <osmocom/vty/vty.h>
43#include <osmocom/vty/command.h>
44#include <osmocom/vty/logging.h>
45#include <osmocom/vty/telnet_interface.h>
Pablo Neira Ayuso167281e2011-03-28 19:35:00 +020046#include <osmocom/vty/misc.h>
Harald Welte144e0292010-05-13 11:45:07 +020047
Harald Welte4f5883b2012-06-16 16:54:06 +080048#include "common_vty.h"
Harald Welte73952e32012-06-16 14:59:56 +080049
Harald Welte144e0292010-05-13 11:45:07 +020050static struct gprs_ns_inst *vty_nsi = NULL;
51
52/* FIXME: this should go to some common file as it is copied
53 * in vty_interface.c of the BSC */
54static const struct value_string gprs_ns_timer_strs[] = {
55 { 0, "tns-block" },
56 { 1, "tns-block-retries" },
57 { 2, "tns-reset" },
58 { 3, "tns-reset-retries" },
59 { 4, "tns-test" },
60 { 5, "tns-alive" },
61 { 6, "tns-alive-retries" },
62 { 0, NULL }
63};
64
Harald Weltef5430362012-06-17 12:25:53 +080065static void log_set_nsvc_filter(struct log_target *target,
66 struct gprs_nsvc *nsvc)
67{
68 if (nsvc) {
Neels Hofmeyr8b86cd72017-02-23 18:03:28 +010069 target->filter_map |= (1 << LOG_FLT_GB_NSVC);
70 target->filter_data[LOG_FLT_GB_NSVC] = nsvc;
71 } else if (target->filter_data[LOG_FLT_GB_NSVC]) {
72 target->filter_map = ~(1 << LOG_FLT_GB_NSVC);
73 target->filter_data[LOG_FLT_GB_NSVC] = NULL;
Harald Weltef5430362012-06-17 12:25:53 +080074 }
75}
76
Harald Welte144e0292010-05-13 11:45:07 +020077static struct cmd_node ns_node = {
Harald Welte4f5883b2012-06-16 16:54:06 +080078 L_NS_NODE,
Jacob Erlbeck35fe87c2013-10-24 01:33:20 +020079 "%s(config-ns)# ",
Harald Welte144e0292010-05-13 11:45:07 +020080 1,
81};
82
83static int config_write_ns(struct vty *vty)
84{
85 struct gprs_nsvc *nsvc;
86 unsigned int i;
Harald Welte7fb05232010-05-19 15:09:09 +020087 struct in_addr ia;
Harald Welte144e0292010-05-13 11:45:07 +020088
89 vty_out(vty, "ns%s", VTY_NEWLINE);
90
91 llist_for_each_entry(nsvc, &vty_nsi->gprs_nsvcs, list) {
92 if (!nsvc->persistent)
93 continue;
94 vty_out(vty, " nse %u nsvci %u%s",
95 nsvc->nsei, nsvc->nsvci, VTY_NEWLINE);
96 vty_out(vty, " nse %u remote-role %s%s",
97 nsvc->nsei, nsvc->remote_end_is_sgsn ? "sgsn" : "bss",
98 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +020099 switch (nsvc->ll) {
100 case GPRS_NS_LL_UDP:
101 vty_out(vty, " nse %u encapsulation udp%s", nsvc->nsei,
102 VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200103 vty_out(vty, " nse %u remote-ip %s%s",
104 nsvc->nsei,
105 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
106 VTY_NEWLINE);
107 vty_out(vty, " nse %u remote-port %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200108 nsvc->nsei, osmo_ntohs(nsvc->ip.bts_addr.sin_port),
Harald Welte144e0292010-05-13 11:45:07 +0200109 VTY_NEWLINE);
Harald Welteb3ee2652010-05-19 14:38:50 +0200110 break;
111 case GPRS_NS_LL_FR_GRE:
112 vty_out(vty, " nse %u encapsulation framerelay-gre%s",
113 nsvc->nsei, VTY_NEWLINE);
114 vty_out(vty, " nse %u remote-ip %s%s",
115 nsvc->nsei,
116 inet_ntoa(nsvc->frgre.bts_addr.sin_addr),
117 VTY_NEWLINE);
118 vty_out(vty, " nse %u fr-dlci %u%s",
Harald Weltebfe62e52017-05-15 12:48:30 +0200119 nsvc->nsei, osmo_ntohs(nsvc->frgre.bts_addr.sin_port),
Harald Welteb3ee2652010-05-19 14:38:50 +0200120 VTY_NEWLINE);
121 default:
122 break;
Harald Welte144e0292010-05-13 11:45:07 +0200123 }
124 }
125
126 for (i = 0; i < ARRAY_SIZE(vty_nsi->timeout); i++)
127 vty_out(vty, " timer %s %u%s",
128 get_value_string(gprs_ns_timer_strs, i),
129 vty_nsi->timeout[i], VTY_NEWLINE);
130
Harald Welte7fb05232010-05-19 15:09:09 +0200131 if (vty_nsi->nsip.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200132 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200133 vty_out(vty, " encapsulation udp local-ip %s%s",
134 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte7fb05232010-05-19 15:09:09 +0200135 }
Harald Weltece4ccbc2010-05-19 17:02:57 +0200136 if (vty_nsi->nsip.local_port)
137 vty_out(vty, " encapsulation udp local-port %u%s",
138 vty_nsi->nsip.local_port, VTY_NEWLINE);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100139 if (vty_nsi->nsip.dscp)
140 vty_out(vty, " encapsulation udp dscp %d%s",
141 vty_nsi->nsip.dscp, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200142
Harald Welte7fb05232010-05-19 15:09:09 +0200143 vty_out(vty, " encapsulation framerelay-gre enabled %u%s",
144 vty_nsi->frgre.enabled ? 1 : 0, VTY_NEWLINE);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200145 if (vty_nsi->frgre.local_ip) {
Harald Weltebfe62e52017-05-15 12:48:30 +0200146 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Welte7fb05232010-05-19 15:09:09 +0200147 vty_out(vty, " encapsulation framerelay-gre local-ip %s%s",
148 inet_ntoa(ia), VTY_NEWLINE);
149 }
150
Harald Welte144e0292010-05-13 11:45:07 +0200151 return CMD_SUCCESS;
152}
153
154DEFUN(cfg_ns, cfg_ns_cmd,
155 "ns",
156 "Configure the GPRS Network Service")
157{
Harald Welte4f5883b2012-06-16 16:54:06 +0800158 vty->node = L_NS_NODE;
Harald Welte144e0292010-05-13 11:45:07 +0200159 return CMD_SUCCESS;
160}
161
Maxcbf5cdf2017-10-24 18:18:55 +0200162static void dump_nse(struct vty *vty, const struct gprs_nsvc *nsvc, bool stats, bool persistent_only)
Harald Welte92883342010-05-15 23:04:03 +0200163{
Max296511b2017-10-24 18:05:35 +0200164 if (persistent_only)
165 if (!nsvc->persistent)
166 return;
167
Max37f465e2017-10-24 16:04:55 +0200168 vty_out(vty, "NSEI %5u, NS-VC %5u, %5s %9s, ",
Harald Welte92883342010-05-15 23:04:03 +0200169 nsvc->nsei, nsvc->nsvci,
Max4ce24c42017-10-23 15:09:23 +0200170 NS_DESC_A(nsvc->state),
Max37f465e2017-10-24 16:04:55 +0200171 NS_DESC_B(nsvc->state));
172
173 if (nsvc->ll == GPRS_NS_LL_UDP) {
174 char local[INET6_ADDRSTRLEN + 1];
175 int rc = osmo_sock_local_ip((char *)&local, inet_ntoa(nsvc->ip.bts_addr.sin_addr));
176 vty_out(vty, "%s:%u ", (rc < 0) ? "unknown" : local, nsvc->nsi->nsip.local_port);
177 }
178
179 vty_out(vty, "Remote: %-4s, %5s %9s, %s ",
Max32f99712017-10-20 12:27:49 +0200180 nsvc->remote_end_is_sgsn ? "SGSN" : "BSS",
Max4ce24c42017-10-23 15:09:23 +0200181 NS_DESC_A(nsvc->remote_state),
Max37f465e2017-10-24 16:04:55 +0200182 NS_DESC_B(nsvc->remote_state), gprs_ns_ll_str(nsvc));
Max95308592017-10-24 15:54:28 +0200183
Max37f465e2017-10-24 16:04:55 +0200184 vty_out(vty, "%s%s", nsvc->ll == GPRS_NS_LL_UDP ? "UDP" : "FR-GRE", VTY_NEWLINE);
Max95308592017-10-24 15:54:28 +0200185
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200186 if (stats) {
Harald Welte92883342010-05-15 23:04:03 +0200187 vty_out_rate_ctr_group(vty, " ", nsvc->ctrg);
Jacob Erlbeck0a1400f2015-10-06 15:23:25 +0200188 vty_out_stat_item_group(vty, " ", nsvc->statg);
189 }
Harald Welte92883342010-05-15 23:04:03 +0200190}
191
Maxcbf5cdf2017-10-24 18:18:55 +0200192static void dump_ns(struct vty *vty, const struct gprs_ns_inst *nsi, bool stats, bool persistent_only)
Harald Welte144e0292010-05-13 11:45:07 +0200193{
Harald Welte144e0292010-05-13 11:45:07 +0200194 struct gprs_nsvc *nsvc;
Harald Welte7fb05232010-05-19 15:09:09 +0200195 struct in_addr ia;
196
Harald Weltebfe62e52017-05-15 12:48:30 +0200197 ia.s_addr = osmo_htonl(vty_nsi->nsip.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200198 vty_out(vty, "Encapsulation NS-UDP-IP Local IP: %s, UDP Port: %u%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200199 inet_ntoa(ia), vty_nsi->nsip.local_port, VTY_NEWLINE);
200
Harald Weltebfe62e52017-05-15 12:48:30 +0200201 ia.s_addr = osmo_htonl(vty_nsi->frgre.local_ip);
Harald Weltece4ccbc2010-05-19 17:02:57 +0200202 vty_out(vty, "Encapsulation NS-FR-GRE-IP Local IP: %s%s",
Harald Welte7fb05232010-05-19 15:09:09 +0200203 inet_ntoa(ia), VTY_NEWLINE);
Harald Welte144e0292010-05-13 11:45:07 +0200204
205 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
Harald Weltedd1c83c2010-05-13 13:58:08 +0200206 if (nsvc == nsi->unknown_nsvc)
207 continue;
Max296511b2017-10-24 18:05:35 +0200208 dump_nse(vty, nsvc, stats, persistent_only);
Harald Welte144e0292010-05-13 11:45:07 +0200209 }
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200210}
Harald Welte144e0292010-05-13 11:45:07 +0200211
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200212DEFUN(show_ns, show_ns_cmd, "show ns",
213 SHOW_STR "Display information about the NS protocol")
214{
215 struct gprs_ns_inst *nsi = vty_nsi;
Max296511b2017-10-24 18:05:35 +0200216 dump_ns(vty, nsi, false, false);
Harald Welte144e0292010-05-13 11:45:07 +0200217 return CMD_SUCCESS;
218}
219
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200220DEFUN(show_ns_stats, show_ns_stats_cmd, "show ns stats",
221 SHOW_STR
222 "Display information about the NS protocol\n"
223 "Include statistics\n")
224{
225 struct gprs_ns_inst *nsi = vty_nsi;
Max296511b2017-10-24 18:05:35 +0200226 dump_ns(vty, nsi, true, false);
227 return CMD_SUCCESS;
228}
229
230DEFUN(show_ns_pers, show_ns_pers_cmd, "show ns persistent",
231 SHOW_STR
232 "Display information about the NS protocol\n"
233 "Show only persistent NS\n")
234{
235 struct gprs_ns_inst *nsi = vty_nsi;
236 dump_ns(vty, nsi, true, true);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200237 return CMD_SUCCESS;
238}
Harald Welte144e0292010-05-13 11:45:07 +0200239
Harald Welte92883342010-05-15 23:04:03 +0200240DEFUN(show_nse, show_nse_cmd, "show ns (nsei|nsvc) <0-65535> [stats]",
241 SHOW_STR "Display information about the NS protocol\n"
242 "Select one NSE by its NSE Identifier\n"
243 "Select one NSE by its NS-VC Identifier\n"
244 "The Identifier of selected type\n"
245 "Include Statistics\n")
246{
247 struct gprs_ns_inst *nsi = vty_nsi;
248 struct gprs_nsvc *nsvc;
249 uint16_t id = atoi(argv[1]);
Max296511b2017-10-24 18:05:35 +0200250 bool show_stats = false;
Harald Welte92883342010-05-15 23:04:03 +0200251
252 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800253 nsvc = gprs_nsvc_by_nsei(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200254 else
Harald Weltef5430362012-06-17 12:25:53 +0800255 nsvc = gprs_nsvc_by_nsvci(nsi, id);
Harald Welte92883342010-05-15 23:04:03 +0200256
257 if (!nsvc) {
258 vty_out(vty, "No such NS Entity%s", VTY_NEWLINE);
259 return CMD_WARNING;
260 }
261
262 if (argc >= 3)
Max296511b2017-10-24 18:05:35 +0200263 show_stats = true;
Harald Welte92883342010-05-15 23:04:03 +0200264
Max296511b2017-10-24 18:05:35 +0200265 dump_nse(vty, nsvc, show_stats, false);
Harald Welte92883342010-05-15 23:04:03 +0200266 return CMD_SUCCESS;
267}
268
Harald Welte24133c32010-05-15 23:06:26 +0200269#define NSE_CMD_STR "Persistent NS Entity\n" "NS Entity ID (NSEI)\n"
Harald Welte144e0292010-05-13 11:45:07 +0200270
271DEFUN(cfg_nse_nsvc, cfg_nse_nsvci_cmd,
272 "nse <0-65535> nsvci <0-65534>",
273 NSE_CMD_STR
274 "NS Virtual Connection\n"
275 "NS Virtual Connection ID (NSVCI)\n"
276 )
277{
278 uint16_t nsei = atoi(argv[0]);
279 uint16_t nsvci = atoi(argv[1]);
280 struct gprs_nsvc *nsvc;
281
Harald Weltef5430362012-06-17 12:25:53 +0800282 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200283 if (!nsvc) {
Harald Weltef5430362012-06-17 12:25:53 +0800284 nsvc = gprs_nsvc_create(vty_nsi, nsvci);
Harald Welte144e0292010-05-13 11:45:07 +0200285 nsvc->nsei = nsei;
286 }
287 nsvc->nsvci = nsvci;
288 /* All NSVCs that are explicitly configured by VTY are
289 * marked as persistent so we can write them to the config
290 * file at some later point */
291 nsvc->persistent = 1;
292
293 return CMD_SUCCESS;
294}
295
296DEFUN(cfg_nse_remoteip, cfg_nse_remoteip_cmd,
297 "nse <0-65535> remote-ip A.B.C.D",
298 NSE_CMD_STR
299 "Remote IP Address\n"
300 "Remote IP Address\n")
301{
302 uint16_t nsei = atoi(argv[0]);
303 struct gprs_nsvc *nsvc;
304
Harald Weltef5430362012-06-17 12:25:53 +0800305 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200306 if (!nsvc) {
307 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
308 return CMD_WARNING;
309 }
310 inet_aton(argv[1], &nsvc->ip.bts_addr.sin_addr);
311
312 return CMD_SUCCESS;
313
314}
315
316DEFUN(cfg_nse_remoteport, cfg_nse_remoteport_cmd,
317 "nse <0-65535> remote-port <0-65535>",
318 NSE_CMD_STR
319 "Remote UDP Port\n"
320 "Remote UDP Port Number\n")
321{
322 uint16_t nsei = atoi(argv[0]);
323 uint16_t port = atoi(argv[1]);
324 struct gprs_nsvc *nsvc;
325
Harald Weltef5430362012-06-17 12:25:53 +0800326 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200327 if (!nsvc) {
328 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
329 return CMD_WARNING;
330 }
331
Harald Welteb3ee2652010-05-19 14:38:50 +0200332 if (nsvc->ll != GPRS_NS_LL_UDP) {
333 vty_out(vty, "Cannot set UDP Port on non-UDP NSE%s",
334 VTY_NEWLINE);
335 return CMD_WARNING;
336 }
337
Harald Weltebfe62e52017-05-15 12:48:30 +0200338 nsvc->ip.bts_addr.sin_port = osmo_htons(port);
Harald Welte144e0292010-05-13 11:45:07 +0200339
340 return CMD_SUCCESS;
341}
342
Harald Welteb3ee2652010-05-19 14:38:50 +0200343DEFUN(cfg_nse_fr_dlci, cfg_nse_fr_dlci_cmd,
Harald Welte188bda62010-05-28 14:11:49 +0200344 "nse <0-65535> fr-dlci <16-1007>",
Harald Welteb3ee2652010-05-19 14:38:50 +0200345 NSE_CMD_STR
346 "Frame Relay DLCI\n"
347 "Frame Relay DLCI Number\n")
348{
349 uint16_t nsei = atoi(argv[0]);
350 uint16_t dlci = atoi(argv[1]);
351 struct gprs_nsvc *nsvc;
352
Harald Weltef5430362012-06-17 12:25:53 +0800353 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welteb3ee2652010-05-19 14:38:50 +0200354 if (!nsvc) {
355 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
356 return CMD_WARNING;
357 }
358
359 if (nsvc->ll != GPRS_NS_LL_FR_GRE) {
360 vty_out(vty, "Cannot set FR DLCI on non-FR NSE%s",
361 VTY_NEWLINE);
362 return CMD_WARNING;
363 }
364
Harald Weltebfe62e52017-05-15 12:48:30 +0200365 nsvc->frgre.bts_addr.sin_port = osmo_htons(dlci);
Harald Welteb3ee2652010-05-19 14:38:50 +0200366
367 return CMD_SUCCESS;
368}
369
370DEFUN(cfg_nse_encaps, cfg_nse_encaps_cmd,
371 "nse <0-65535> encapsulation (udp|framerelay-gre)",
372 NSE_CMD_STR
373 "Encapsulation for NS\n"
374 "UDP/IP Encapsulation\n" "Frame-Relay/GRE/IP Encapsulation\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 Welteb3ee2652010-05-19 14:38:50 +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], "udp"))
386 nsvc->ll = GPRS_NS_LL_UDP;
387 else
388 nsvc->ll = GPRS_NS_LL_FR_GRE;
389
390 return CMD_SUCCESS;
391}
392
393
Harald Welte144e0292010-05-13 11:45:07 +0200394DEFUN(cfg_nse_remoterole, cfg_nse_remoterole_cmd,
395 "nse <0-65535> remote-role (sgsn|bss)",
396 NSE_CMD_STR
397 "Remote NSE Role\n"
398 "Remote Peer is SGSN\n"
399 "Remote Peer is BSS\n")
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
410 if (!strcmp(argv[1], "sgsn"))
411 nsvc->remote_end_is_sgsn = 1;
412 else
413 nsvc->remote_end_is_sgsn = 0;
414
415 return CMD_SUCCESS;
416}
417
418DEFUN(cfg_no_nse, cfg_no_nse_cmd,
419 "no nse <0-65535>",
Harald Welte24133c32010-05-15 23:06:26 +0200420 "Delete Persistent NS Entity\n"
Harald Welte144e0292010-05-13 11:45:07 +0200421 "Delete " NSE_CMD_STR)
422{
423 uint16_t nsei = atoi(argv[0]);
424 struct gprs_nsvc *nsvc;
425
Harald Weltef5430362012-06-17 12:25:53 +0800426 nsvc = gprs_nsvc_by_nsei(vty_nsi, nsei);
Harald Welte144e0292010-05-13 11:45:07 +0200427 if (!nsvc) {
428 vty_out(vty, "No such NSE (%u)%s", nsei, VTY_NEWLINE);
429 return CMD_WARNING;
430 }
431
Harald Welte24133c32010-05-15 23:06:26 +0200432 if (!nsvc->persistent) {
433 vty_out(vty, "NSEI %u is not a persistent NSE%s",
434 nsei, VTY_NEWLINE);
435 return CMD_WARNING;
436 }
437
438 nsvc->persistent = 0;
Harald Welte144e0292010-05-13 11:45:07 +0200439
440 return CMD_SUCCESS;
441}
442
443DEFUN(cfg_ns_timer, cfg_ns_timer_cmd,
444 "timer " NS_TIMERS " <0-65535>",
445 "Network Service Timer\n"
446 NS_TIMERS_HELP "Timer Value\n")
447{
448 int idx = get_string_value(gprs_ns_timer_strs, argv[0]);
449 int val = atoi(argv[1]);
450
451 if (idx < 0 || idx >= ARRAY_SIZE(vty_nsi->timeout))
452 return CMD_WARNING;
453
454 vty_nsi->timeout[idx] = val;
455
456 return CMD_SUCCESS;
457}
458
Harald Welte7fb05232010-05-19 15:09:09 +0200459#define ENCAPS_STR "NS encapsulation options\n"
460
461DEFUN(cfg_nsip_local_ip, cfg_nsip_local_ip_cmd,
462 "encapsulation udp local-ip A.B.C.D",
463 ENCAPS_STR "NS over UDP Encapsulation\n"
464 "Set the IP address on which we listen for NS/UDP\n"
465 "IP Address\n")
466{
467 struct in_addr ia;
468
469 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200470 vty_nsi->nsip.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200471
472 return CMD_SUCCESS;
473}
474
475DEFUN(cfg_nsip_local_port, cfg_nsip_local_port_cmd,
476 "encapsulation udp local-port <0-65535>",
477 ENCAPS_STR "NS over UDP Encapsulation\n"
478 "Set the UDP port on which we listen for NS/UDP\n"
479 "UDP port number\n")
480{
481 unsigned int port = atoi(argv[0]);
482
483 vty_nsi->nsip.local_port = port;
484
485 return CMD_SUCCESS;
486}
487
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100488DEFUN(cfg_nsip_dscp, cfg_nsip_dscp_cmd,
489 "encapsulation udp dscp <0-255>",
490 ENCAPS_STR "NS over UDP Encapsulation\n"
491 "Set DSCP/TOS on the UDP socket\n" "DSCP Value\n")
492{
493 int dscp = atoi(argv[0]);
494 vty_nsi->nsip.dscp = dscp;
495 return CMD_SUCCESS;
496}
497
Harald Welte7fb05232010-05-19 15:09:09 +0200498DEFUN(cfg_frgre_local_ip, cfg_frgre_local_ip_cmd,
499 "encapsulation framerelay-gre local-ip A.B.C.D",
500 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
501 "Set the IP address on which we listen for NS/FR/GRE\n"
502 "IP Address\n")
503{
504 struct in_addr ia;
505
506 if (!vty_nsi->frgre.enabled) {
507 vty_out(vty, "FR/GRE is not enabled%s", VTY_NEWLINE);
508 return CMD_WARNING;
509 }
510 inet_aton(argv[0], &ia);
Harald Weltebfe62e52017-05-15 12:48:30 +0200511 vty_nsi->frgre.local_ip = osmo_ntohl(ia.s_addr);
Harald Welte7fb05232010-05-19 15:09:09 +0200512
513 return CMD_SUCCESS;
514}
515
516DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
517 "encapsulation framerelay-gre enabled (1|0)",
518 ENCAPS_STR "NS over Frame Relay over GRE Encapsulation\n"
519 "Enable or disable Frame Relay over GRE\n"
520 "Enable\n" "Disable\n")
521{
522 int enabled = atoi(argv[0]);
523
524 vty_nsi->frgre.enabled = enabled;
525
526 return CMD_SUCCESS;
527}
528
Harald Welte43f3b692010-05-14 19:36:59 +0200529DEFUN(nsvc_nsei, nsvc_nsei_cmd,
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200530 "nsvc (nsei|nsvci) <0-65535> (block|unblock|reset)",
Harald Welte43f3b692010-05-14 19:36:59 +0200531 "Perform an operation on a NSVC\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100532 "NSEI to identify NS-VC Identifier (NS-VCI)\n"
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200533 "NS-VC Identifier (NS-VCI)\n"
Holger Hans Peter Freyther887934e2011-11-05 15:14:59 +0100534 "The NSEI\n"
Harald Welte43f3b692010-05-14 19:36:59 +0200535 "Initiate BLOCK procedure\n"
536 "Initiate UNBLOCK procedure\n"
537 "Initiate RESET procedure\n")
538{
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200539 const char *id_type = argv[0];
540 uint16_t id = atoi(argv[1]);
541 const char *operation = argv[2];
Harald Welte43f3b692010-05-14 19:36:59 +0200542 struct gprs_nsvc *nsvc;
543
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200544 if (!strcmp(id_type, "nsei"))
545 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
546 else if (!strcmp(id_type, "nsvci"))
547 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
548 else {
549 vty_out(vty, "%%No such id_type '%s'%s", id_type, VTY_NEWLINE);
550 return CMD_WARNING;
551 }
552
Harald Welte43f3b692010-05-14 19:36:59 +0200553 if (!nsvc) {
Jacob Erlbeck687b6902013-10-24 01:33:19 +0200554 vty_out(vty, "No such %s (%u)%s", id_type, id, VTY_NEWLINE);
Harald Welte43f3b692010-05-14 19:36:59 +0200555 return CMD_WARNING;
556 }
557
558 if (!strcmp(operation, "block"))
559 gprs_ns_tx_block(nsvc, NS_CAUSE_OM_INTERVENTION);
560 else if (!strcmp(operation, "unblock"))
561 gprs_ns_tx_unblock(nsvc);
562 else if (!strcmp(operation, "reset"))
563 gprs_nsvc_reset(nsvc, NS_CAUSE_OM_INTERVENTION);
564 else
565 return CMD_WARNING;
566
567 return CMD_SUCCESS;
568}
569
Harald Welte91f7f4b2010-05-15 23:52:02 +0200570DEFUN(logging_fltr_nsvc,
571 logging_fltr_nsvc_cmd,
572 "logging filter nsvc (nsei|nsvci) <0-65535>",
Harald Welte6703bf72010-05-16 00:00:04 +0200573 LOGGING_STR FILTER_STR
Harald Welte91f7f4b2010-05-15 23:52:02 +0200574 "Filter based on NS Virtual Connection\n"
575 "Identify NS-VC by NSEI\n"
576 "Identify NS-VC by NSVCI\n"
577 "Numeric identifier\n")
578{
Harald Welte43ae94e2011-02-18 21:10:05 +0100579 struct log_target *tgt = osmo_log_vty2tgt(vty);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200580 struct gprs_nsvc *nsvc;
581 uint16_t id = atoi(argv[1]);
582
Harald Welte43ae94e2011-02-18 21:10:05 +0100583 if (!tgt)
Harald Welte91f7f4b2010-05-15 23:52:02 +0200584 return CMD_WARNING;
Harald Welte91f7f4b2010-05-15 23:52:02 +0200585
586 if (!strcmp(argv[0], "nsei"))
Harald Weltef5430362012-06-17 12:25:53 +0800587 nsvc = gprs_nsvc_by_nsei(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200588 else
Harald Weltef5430362012-06-17 12:25:53 +0800589 nsvc = gprs_nsvc_by_nsvci(vty_nsi, id);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200590
591 if (!nsvc) {
592 vty_out(vty, "No NS-VC by that identifier%s", VTY_NEWLINE);
593 return CMD_WARNING;
594 }
595
Harald Welte43ae94e2011-02-18 21:10:05 +0100596 log_set_nsvc_filter(tgt, nsvc);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200597 return CMD_SUCCESS;
598}
Harald Welte43f3b692010-05-14 19:36:59 +0200599
Harald Welte144e0292010-05-13 11:45:07 +0200600int gprs_ns_vty_init(struct gprs_ns_inst *nsi)
601{
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100602 static bool vty_elements_installed = false;
603
Harald Welte144e0292010-05-13 11:45:07 +0200604 vty_nsi = nsi;
605
Neels Hofmeyrc32bfd52017-01-12 22:32:19 +0100606 /* Regression test code may call this function repeatedly, so make sure
607 * that VTY elements are not duplicated, which would assert. */
608 if (vty_elements_installed)
609 return 0;
610 vty_elements_installed = true;
611
Harald Welte144e0292010-05-13 11:45:07 +0200612 install_element_ve(&show_ns_cmd);
Harald Welteaf1d4cb2010-05-13 12:32:30 +0200613 install_element_ve(&show_ns_stats_cmd);
Max296511b2017-10-24 18:05:35 +0200614 install_element_ve(&show_ns_pers_cmd);
Harald Welte92883342010-05-15 23:04:03 +0200615 install_element_ve(&show_nse_cmd);
Harald Welte91f7f4b2010-05-15 23:52:02 +0200616 install_element_ve(&logging_fltr_nsvc_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200617
Harald Welte43ae94e2011-02-18 21:10:05 +0100618 install_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
619
Harald Welte144e0292010-05-13 11:45:07 +0200620 install_element(CONFIG_NODE, &cfg_ns_cmd);
621 install_node(&ns_node, config_write_ns);
Harald Welte4f5883b2012-06-16 16:54:06 +0800622 install_element(L_NS_NODE, &cfg_nse_nsvci_cmd);
623 install_element(L_NS_NODE, &cfg_nse_remoteip_cmd);
624 install_element(L_NS_NODE, &cfg_nse_remoteport_cmd);
625 install_element(L_NS_NODE, &cfg_nse_fr_dlci_cmd);
626 install_element(L_NS_NODE, &cfg_nse_encaps_cmd);
627 install_element(L_NS_NODE, &cfg_nse_remoterole_cmd);
628 install_element(L_NS_NODE, &cfg_no_nse_cmd);
629 install_element(L_NS_NODE, &cfg_ns_timer_cmd);
630 install_element(L_NS_NODE, &cfg_nsip_local_ip_cmd);
631 install_element(L_NS_NODE, &cfg_nsip_local_port_cmd);
Holger Hans Peter Freyther2c3393d2013-03-25 11:59:58 +0100632 install_element(L_NS_NODE, &cfg_nsip_dscp_cmd);
Harald Welte4f5883b2012-06-16 16:54:06 +0800633 install_element(L_NS_NODE, &cfg_frgre_enable_cmd);
634 install_element(L_NS_NODE, &cfg_frgre_local_ip_cmd);
Harald Welte144e0292010-05-13 11:45:07 +0200635
Harald Welte43f3b692010-05-14 19:36:59 +0200636 install_element(ENABLE_NODE, &nsvc_nsei_cmd);
637
Harald Welte144e0292010-05-13 11:45:07 +0200638 return 0;
639}