blob: ca45f93da12b98fac4ebdf345c61f7580e52989e [file] [log] [blame]
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +02001/* E1 vty interface */
Harald Welte41547552021-04-28 18:23:21 +02002/* (C) 2011-2021 by Harald Welte <laforge@gnumonks.org>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +02003 * All Rights Reserved
4 *
Harald Welte323d39d2017-11-13 01:09:21 +09005 * SPDX-License-Identifier: AGPL-3.0+
6 *
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +02007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21#include "internal.h"
22
Sylvain Munauteb55e2f2020-05-08 09:42:51 +020023#include <fcntl.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020024#include <stdlib.h>
25#include <unistd.h>
Harald Welted4f8f682011-08-19 13:28:48 +020026#include <string.h>
Sylvain Munauteb55e2f2020-05-08 09:42:51 +020027#include <sys/stat.h>
28#include <sys/types.h>
Stefan Sperlingb24efa52018-08-28 14:03:41 +020029#include <sys/un.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020030
Harald Weltef2737fc2011-08-16 14:30:10 +020031#include <osmocom/core/linuxlist.h>
32#include <osmocom/core/talloc.h>
33#include <osmocom/core/utils.h>
34#include <osmocom/gsm/gsm_utils.h>
35
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020036#include <osmocom/vty/command.h>
37#include <osmocom/vty/buffer.h>
38#include <osmocom/vty/vty.h>
39#include <osmocom/vty/logging.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020040#include <osmocom/vty/misc.h>
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020041#include <osmocom/vty/telnet_interface.h>
42
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020043#include <osmocom/abis/e1_input.h>
Eric Wildef1f3272019-07-10 18:10:31 +020044#include <osmocom/abis/ipa.h>
Harald Weltef2737fc2011-08-16 14:30:10 +020045
Philipp Maieref5b8392020-10-08 17:35:52 +020046#define X(x) (1 << x)
47
Harald Weltef2737fc2011-08-16 14:30:10 +020048/* CONFIG */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020049
Sylvain Munautb559a532019-05-09 11:14:26 +020050#define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|e1d|ipa|unixsocket)"
Harald Weltece307b42011-08-21 01:18:05 +020051#define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \
52 "mISDN supported E1 Card (userspace LAPD)\n" \
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020053 "DAHDI supported E1/T1/J1 Card\n" \
Harald Welte1f922842020-07-02 11:19:15 +020054 "osmo-e1d supported E1 interface\n" \
Holger Hans Peter Freyther36bac9a2012-07-20 23:49:52 +020055 "IPA TCP/IP input\n" \
Alexander Couzensbeb10ef2016-11-01 22:05:13 +010056 "Unix socket input\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020057
Harald Welte601a9c72011-08-16 14:17:49 +020058#define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n"
59
Philipp Maieref5b8392020-10-08 17:35:52 +020060/* Note: This requires a full restart of the application, since once created
61 * an E1 line can not be destroyed again. */
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020062DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd,
63 "e1_line <0-255> driver " E1_DRIVER_NAMES,
Harald Welte601a9c72011-08-16 14:17:49 +020064 E1_LINE_HELP "Set driver for this line\n"
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020065 E1_DRIVER_HELP)
66{
67 struct e1inp_line *line;
68 int e1_nr = atoi(argv[0]);
69
Pablo Neira Ayuso3832c4f2011-07-07 17:47:26 +020070 line = e1inp_line_find(e1_nr);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +020071 if (line) {
72 vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE);
73 return CMD_WARNING;
74 }
75 line = e1inp_line_create(e1_nr, argv[1]);
76 if (!line) {
77 vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE);
78 return CMD_WARNING;
79 }
80
81 return CMD_SUCCESS;
82}
83
Philipp Maieref5b8392020-10-08 17:35:52 +020084DEFUN_USRATTR(cfg_e1line_port, cfg_e1_line_port_cmd,
85 X(OSMO_ABIS_LIB_ATTR_LINE_UPD),
86 "e1_line <0-255> port <0-255>",
87 E1_LINE_HELP "Set physical port/span/card number\n"
88 "E1/T1 Port/Span/Card number\n")
Harald Weltec2889512011-09-13 23:49:04 +010089{
90 struct e1inp_line *line;
91 int e1_nr = atoi(argv[0]);
92
93 line = e1inp_line_find(e1_nr);
94 if (!line) {
95 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
96 return CMD_WARNING;
97 }
98
99 line->port_nr = atoi(argv[1]);
100
101 return CMD_SUCCESS;
102}
103
Philipp Maieref5b8392020-10-08 17:35:52 +0200104DEFUN_USRATTR(cfg_e1line_socket, cfg_e1_line_socket_cmd,
105 X(OSMO_ABIS_LIB_ATTR_LINE_UPD),
106 "e1_line <0-255> socket .SOCKET",
107 E1_LINE_HELP "Set socket path for unixsocket\n"
108 "socket path\n")
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100109{
110 struct e1inp_line *line;
111 int e1_nr = atoi(argv[0]);
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200112 struct sockaddr_un sun;
113
Stefan Sperling0d7d0b02018-09-20 17:34:31 +0200114 /* Don't exceed the maximum unix socket path length, including a NUL byte. See the unix(7) man page.*/
115 if (strlen(argv[1]) > sizeof(sun.sun_path) - 1) {
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200116 vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s",
Stefan Sperling0d7d0b02018-09-20 17:34:31 +0200117 sizeof(sun.sun_path) - 1, argv[1], VTY_NEWLINE);
Stefan Sperlingb24efa52018-08-28 14:03:41 +0200118 return CMD_WARNING;
119 }
Alexander Couzensbeb10ef2016-11-01 22:05:13 +0100120
121 line = e1inp_line_find(e1_nr);
122 if (!line) {
123 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
124 return CMD_WARNING;
125 }
126
127 line->sock_path = talloc_strdup(line, argv[1]);
128
129 return CMD_SUCCESS;
130}
131
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100132#define KEEPALIVE_HELP "Enable keep-alive probing\n"
133static int set_keepalive_params(struct vty *vty, int e1_nr,
134 int idle, int num_probes, int probe_interval)
135{
136 struct e1inp_line *line = e1inp_line_find(e1_nr);
137
138 if (!line) {
139 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
140 return CMD_WARNING;
141 }
142 if (!line->driver->has_keepalive && num_probes != 0) {
143 vty_out(vty, "%% Driver '%s' does not support keep alive%s",
144 line->driver->name, VTY_NEWLINE);
145 return CMD_WARNING;
146 }
147
148 line->keepalive_idle_timeout = idle;
149 line->keepalive_num_probes = num_probes;
150 line->keepalive_probe_interval = probe_interval;
151
152 return CMD_SUCCESS;
153}
154
Philipp Maieref5b8392020-10-08 17:35:52 +0200155DEFUN_USRATTR(cfg_e1line_keepalive, cfg_e1_line_keepalive_cmd,
156 X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK),
157 "e1_line <0-255> keepalive",
158 E1_LINE_HELP KEEPALIVE_HELP)
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100159{
160 return set_keepalive_params(vty, atoi(argv[0]),
161 E1INP_USE_DEFAULT, E1INP_USE_DEFAULT,
162 E1INP_USE_DEFAULT);
163}
164
Philipp Maieref5b8392020-10-08 17:35:52 +0200165DEFUN_USRATTR(cfg_e1line_keepalive_params, cfg_e1_line_keepalive_params_cmd,
166 X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK),
167 "e1_line <0-255> keepalive <1-300> <1-20> <1-300>",
168 E1_LINE_HELP KEEPALIVE_HELP
169 "Idle interval in seconds before probes are sent\n"
170 "Number of probes to sent\n"
171 "Delay between probe packets in seconds\n")
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100172{
173 return set_keepalive_params(vty, atoi(argv[0]),
174 atoi(argv[1]), atoi(argv[2]), atoi(argv[3]));
175}
176
Philipp Maieref5b8392020-10-08 17:35:52 +0200177DEFUN_USRATTR(cfg_e1line_no_keepalive, cfg_e1_line_no_keepalive_cmd,
178 X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK),
179 "no e1_line <0-255> keepalive",
180 NO_STR E1_LINE_HELP KEEPALIVE_HELP)
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100181{
182 return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0);
183}
184
Eric Wildef1f3272019-07-10 18:10:31 +0200185#define IPA_KEEPALIVE_HELP "Enable IPA PING/PONG keep-alive\n"
186static int set_ipa_keepalive_params(struct vty *vty, int e1_nr, int interval, int wait_for_resp)
187{
188 struct e1inp_line *line = e1inp_line_find(e1_nr);
189
190 if (!line) {
191 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
192 return CMD_WARNING;
193 }
194
195 if (strcmp(line->driver->name, "ipa") != 0) {
196 vty_out(vty, "%% Line %d doesn't use the ipa driver%s", e1_nr, VTY_NEWLINE);
197 return CMD_WARNING;
198 }
199
200 TALLOC_FREE(line->ipa_kap);
201 if (interval) {
202 line->ipa_kap = talloc_zero(line, struct ipa_keepalive_params);
203 line->ipa_kap->wait_for_resp = wait_for_resp;
204 line->ipa_kap->interval = interval;
205 }
206
207 return CMD_SUCCESS;
208}
209
Philipp Maieref5b8392020-10-08 17:35:52 +0200210DEFUN_ATTR(cfg_e1line_ipa_keepalive, cfg_e1_line_ipa_keepalive_cmd,
211 "e1_line <0-255> ipa-keepalive <1-300> <1-300>",
212 E1_LINE_HELP IPA_KEEPALIVE_HELP
213 "Idle interval in seconds before probes are sent\n"
214 "Time to wait for PONG response\n", CMD_ATTR_IMMEDIATE)
Eric Wildef1f3272019-07-10 18:10:31 +0200215{
216 return set_ipa_keepalive_params(vty, atoi(argv[0]), atoi(argv[1]), atoi(argv[2]));
217}
218
Philipp Maieref5b8392020-10-08 17:35:52 +0200219DEFUN_ATTR(cfg_e1line_no_ipa_keepalive, cfg_e1_line_no_ipa_keepalive_cmd,
220 "no e1_line <0-255> ipa-keepalive",
221 NO_STR E1_LINE_HELP IPA_KEEPALIVE_HELP, CMD_ATTR_IMMEDIATE)
Eric Wildef1f3272019-07-10 18:10:31 +0200222{
223 return set_ipa_keepalive_params(vty, atoi(argv[0]), 0, 0);
224}
225
Philipp Maieref5b8392020-10-08 17:35:52 +0200226DEFUN_ATTR(cfg_e1line_name, cfg_e1_line_name_cmd,
227 "e1_line <0-255> name .LINE",
228 E1_LINE_HELP "Set name for this line\n" "Human readable name\n",
229 CMD_ATTR_IMMEDIATE)
Harald Welte601a9c72011-08-16 14:17:49 +0200230{
231 struct e1inp_line *line;
232 int e1_nr = atoi(argv[0]);
233
234 line = e1inp_line_find(e1_nr);
235 if (!line) {
236 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
237 return CMD_WARNING;
238 }
239 if (line->name) {
240 talloc_free((void *)line->name);
241 line->name = NULL;
242 }
243 line->name = talloc_strdup(line, argv[1]);
244
245 return CMD_SUCCESS;
246}
247
Daniel Willmannc20af052022-12-15 11:50:34 +0100248DEFUN_ATTR(cfg_e1line_connect_timeout, cfg_e1_line_connect_timeout_cmd,
249 "e1_line <0-255> connect-timeout <0-60>",
250 E1_LINE_HELP "Set connect timeout\n" "Connect timeout in seconds (0 to disable)\n",
251 CMD_ATTR_IMMEDIATE)
252{
253 struct e1inp_line *line;
254 int e1_nr = atoi(argv[0]);
255 unsigned int timeout = atoi(argv[1]);
256
257 line = e1inp_line_find(e1_nr);
258 if (!line) {
259 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
260 return CMD_WARNING;
261 }
262 line->connect_timeout = timeout;
263
264 return CMD_SUCCESS;
265}
266
267
Keith2672a2a2020-11-12 06:59:37 +0100268DEFUN_ATTR(cfg_e1line_pcap, cfg_e1line_pcap_cmd,
269 "e1_line <0-255> pcap .FILE",
270 E1_LINE_HELP "Setup a pcap recording of E1 traffic for line\n"
Philipp Maieref5b8392020-10-08 17:35:52 +0200271 "Filename to save the packets to\n", CMD_ATTR_IMMEDIATE)
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200272{
Keith2672a2a2020-11-12 06:59:37 +0100273 struct e1inp_line *line;
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200274 int fd;
Keith2672a2a2020-11-12 06:59:37 +0100275 int rc;
276 int e1_nr = atoi(argv[0]);
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200277
Keith2672a2a2020-11-12 06:59:37 +0100278 line = e1inp_line_find(e1_nr);
279 if (!line) {
280 vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE);
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200281 return CMD_WARNING;
282 }
283
Keith2672a2a2020-11-12 06:59:37 +0100284 fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0660);
285 if (fd < 0) {
286 vty_out(vty, "Failed to setup E1 pcap recording to %s%s", argv[1], VTY_NEWLINE);
287 return CMD_WARNING;
288 }
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200289
Keith2672a2a2020-11-12 06:59:37 +0100290 rc = e1_set_pcap_fd2(line, fd);
291 if (rc < 0) {
292 vty_out(vty, "Failed to write to E1 pcap file %s%s", argv[1], VTY_NEWLINE);
293 close(fd);
294 return CMD_WARNING;
295 }
296
297 osmo_talloc_replace_string(line, &line->pcap_file, argv[1]);
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200298 return CMD_SUCCESS;
299}
300
Keith2672a2a2020-11-12 06:59:37 +0100301DEFUN_ATTR(cfg_e1line_no_pcap, cfg_e1line_no_pcap_cmd,
302 "no e1_line <0-255> pcap",
303 NO_STR E1_LINE_HELP "Disable pcap recording of E1 traffic for line\n",
Philipp Maieref5b8392020-10-08 17:35:52 +0200304 CMD_ATTR_IMMEDIATE)
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200305{
Keith2672a2a2020-11-12 06:59:37 +0100306 struct e1inp_line *line;
307 int e1_nr = atoi(argv[0]);
308 line = e1inp_line_find(e1_nr);
309
310 e1_set_pcap_fd2(line, -1);
311 if (line->pcap_file) {
312 talloc_free(line->pcap_file);
313 line->pcap_file = NULL;
314 }
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200315 return CMD_SUCCESS;
316}
317
Keith2672a2a2020-11-12 06:59:37 +0100318DEFUN_DEPRECATED(cfg_e1_pcap_deprec, cfg_e1_pcap_deprec_cmd,
319 "pcap .FILE", "Legacy")
320{
321 vty_out(vty, "%% 'pcap' is deprecated and has no effect: use e1_line <0-255> pcap%s",
322 VTY_NEWLINE);
323 return CMD_WARNING;
324}
325
326ALIAS_DEPRECATED(cfg_e1_pcap_deprec, cfg_e1_pcap_deprec_no_cmd,
327 "no pcap", NO_STR);
328
Philipp Maieref5b8392020-10-08 17:35:52 +0200329DEFUN_ATTR(cfg_e1inp, cfg_e1inp_cmd,
330 "e1_input",
331 "Configure E1/T1/J1 TDM input\n", CMD_ATTR_IMMEDIATE)
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200332{
Harald Weltecc2241b2011-07-19 16:06:06 +0200333 vty->node = L_E1INP_NODE;
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200334
335 return CMD_SUCCESS;
336}
337
Philipp Maieref5b8392020-10-08 17:35:52 +0200338DEFUN_USRATTR(cfg_ipa_bind,
339 cfg_ipa_bind_cmd,
340 X(OSMO_ABIS_LIB_ATTR_LINE_UPD),
341 "ipa bind A.B.C.D",
342 "ipa driver config\n"
343 "Set ipa local bind address\n"
344 "Listen on this IP address (default 0.0.0.0)\n")
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100345{
346 e1inp_ipa_set_bind_addr(argv[0]);
347 return CMD_SUCCESS;
348}
349
Harald Welte41547552021-04-28 18:23:21 +0200350DEFUN_USRATTR(cfg_ipa_dscp, cfg_ipa_dscp_cmd,
351 X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK),
352 "ipa ip-dscp (oml|rsl) <0-63>",
353 "ipa driver config\n"
354 "Set IP DSCP value for outbound packets\n"
355 "Set IP DSCP for OML link\n"
356 "Set IP DSCP for RSL link\n"
357 "IP DSCP Value to use\n")
358{
359 if (!strcmp(argv[0], "oml"))
360 g_e1inp_ipaccess_pars.oml.dscp = atoi(argv[1]);
361 else
362 g_e1inp_ipaccess_pars.rsl.dscp = atoi(argv[1]);
363 return CMD_SUCCESS;
364}
365
366DEFUN_USRATTR(cfg_ipa_priority, cfg_ipa_priority_cmd,
367 X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK),
368 "ipa socket-priority (oml|rsl) <0-255>",
369 "ipa driver config\n"
370 "Set socket priority value for outbound packets\n"
371 "Set socket priority for OML link\n"
372 "Set socket priority for RSL link\n"
373 "socket priority value to use (>6 requires CAP_NET_ADMIN)\n")
374{
375 if (!strcmp(argv[0], "oml"))
376 g_e1inp_ipaccess_pars.oml.priority = atoi(argv[1]);
377 else
378 g_e1inp_ipaccess_pars.rsl.priority = atoi(argv[1]);
379 return CMD_SUCCESS;
380}
381
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200382static int e1inp_config_write(struct vty *vty)
383{
384 struct e1inp_line *line;
385
386 if (llist_empty(&e1inp_line_list))
387 return CMD_SUCCESS;
388
389 vty_out(vty, "e1_input%s", VTY_NEWLINE);
390
391 llist_for_each_entry(line, &e1inp_line_list, list) {
392 vty_out(vty, " e1_line %u driver %s%s", line->num,
393 line->driver->name, VTY_NEWLINE);
Harald Weltec2889512011-09-13 23:49:04 +0100394 vty_out(vty, " e1_line %u port %u%s", line->num,
395 line->port_nr, VTY_NEWLINE);
Harald Welte601a9c72011-08-16 14:17:49 +0200396 if (line->name)
397 vty_out(vty, " e1_line %u name %s%s", line->num,
398 line->name, VTY_NEWLINE);
Daniel Willmannc20af052022-12-15 11:50:34 +0100399 if (line->connect_timeout != 0)
400 vty_out(vty, " e1_line %u connect-timeout %u%s", line->num, line->connect_timeout,
401 VTY_NEWLINE);
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100402 if (!line->keepalive_num_probes)
403 vty_out(vty, " no e1_line %u keepalive%s", line->num,
404 VTY_NEWLINE);
Oliver Smithef0f7c22022-11-23 12:32:36 +0100405 else if (line->keepalive_idle_timeout != E1INP_USE_DEFAULT ||
406 line->keepalive_num_probes != E1INP_USE_DEFAULT ||
407 line->keepalive_probe_interval != E1INP_USE_DEFAULT)
Jacob Erlbeck86dae842014-01-16 18:10:37 +0100408 vty_out(vty, " e1_line %u keepalive %d %d %d%s",
409 line->num,
410 line->keepalive_idle_timeout,
411 line->keepalive_num_probes,
412 line->keepalive_probe_interval,
413 VTY_NEWLINE);
Eric Wildef1f3272019-07-10 18:10:31 +0200414 if (line->ipa_kap)
415 vty_out(vty, " e1_line %u ipa-keepalive %d %d%s", line->num,
416 line->ipa_kap->interval, line->ipa_kap->wait_for_resp,
417 VTY_NEWLINE);
Keith2672a2a2020-11-12 06:59:37 +0100418 if (line->pcap_file)
419 vty_out(vty, " e1_line %u pcap %s%s", line->num,
420 line->pcap_file, VTY_NEWLINE);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200421 }
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100422
423 const char *ipa_bind = e1inp_ipa_get_bind_addr();
424 if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0))
425 vty_out(vty, " ipa bind %s%s",
426 ipa_bind, VTY_NEWLINE);
427
Harald Welte41547552021-04-28 18:23:21 +0200428 if (g_e1inp_ipaccess_pars.oml.dscp)
429 vty_out(vty, " ipa ip-dscp oml %u%s", g_e1inp_ipaccess_pars.oml.dscp, VTY_NEWLINE);
430 if (g_e1inp_ipaccess_pars.rsl.dscp)
431 vty_out(vty, " ipa ip-dscp rsl %u%s", g_e1inp_ipaccess_pars.rsl.dscp, VTY_NEWLINE);
432 if (g_e1inp_ipaccess_pars.oml.priority)
433 vty_out(vty, " ipa socket-priority oml %u%s", g_e1inp_ipaccess_pars.oml.priority, VTY_NEWLINE);
434 if (g_e1inp_ipaccess_pars.rsl.priority)
435 vty_out(vty, " ipa socket-priority rsl %u%s", g_e1inp_ipaccess_pars.rsl.priority, VTY_NEWLINE);
436
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200437 return CMD_SUCCESS;
438}
439
Harald Weltef2737fc2011-08-16 14:30:10 +0200440/* SHOW */
441
Harald Welte6e37c592011-08-11 12:43:31 +0200442static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv)
443{
444 vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE);
445}
446
447DEFUN(show_e1drv,
448 show_e1drv_cmd,
449 "show e1_driver",
450 SHOW_STR "Display information about available E1 drivers\n")
451{
452 struct e1inp_driver *drv;
453
454 llist_for_each_entry(drv, &e1inp_driver_list, list)
455 e1drv_dump_vty(vty, drv);
456
457 return CMD_SUCCESS;
458}
459
Harald Weltef2737fc2011-08-16 14:30:10 +0200460static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line,
461 int stats)
Harald Welte6e37c592011-08-11 12:43:31 +0200462{
463 vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s",
464 line->num, line->name ? line->name : "",
465 line->driver->name, VTY_NEWLINE);
Keith2672a2a2020-11-12 06:59:37 +0100466 if (line->pcap_file)
467 vty_out(vty, "PCAP %s%s", line->pcap_file, VTY_NEWLINE);
Harald Weltefe05cf52011-09-26 23:18:41 +0200468 if (line->driver->vty_show)
469 line->driver->vty_show(vty, line);
Harald Weltef2737fc2011-08-16 14:30:10 +0200470 if (stats)
471 vty_out_rate_ctr_group(vty, " ", line->rate_ctr);
Harald Welte6e37c592011-08-11 12:43:31 +0200472}
473
474DEFUN(show_e1line,
475 show_e1line_cmd,
Keithdf088b02021-05-04 15:12:32 -0500476 "show e1_line [<0-255>] [stats]",
Harald Welte6e37c592011-08-11 12:43:31 +0200477 SHOW_STR "Display information about a E1 line\n"
Holger Hans Peter Freyther9e8f1c02012-07-21 00:09:52 +0200478 "E1 Line Number\n" "Include statistics\n")
Harald Welte6e37c592011-08-11 12:43:31 +0200479{
480 struct e1inp_line *line;
Harald Weltef2737fc2011-08-16 14:30:10 +0200481 int stats = 0;
Harald Welte6e37c592011-08-11 12:43:31 +0200482
Harald Weltef2737fc2011-08-16 14:30:10 +0200483 if (argc >= 1 && strcmp(argv[0], "stats")) {
Harald Welte6e37c592011-08-11 12:43:31 +0200484 int num = atoi(argv[0]);
Harald Weltef2737fc2011-08-16 14:30:10 +0200485 if (argc >= 2)
486 stats = 1;
Harald Welte6e37c592011-08-11 12:43:31 +0200487 llist_for_each_entry(line, &e1inp_line_list, list) {
488 if (line->num == num) {
Harald Weltef2737fc2011-08-16 14:30:10 +0200489 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200490 return CMD_SUCCESS;
491 }
492 }
493 return CMD_WARNING;
494 }
495
Harald Weltef2737fc2011-08-16 14:30:10 +0200496 if (argc >= 1 && !strcmp(argv[0], "stats"))
497 stats = 1;
498
Harald Welte6e37c592011-08-11 12:43:31 +0200499 llist_for_each_entry(line, &e1inp_line_list, list)
Harald Weltef2737fc2011-08-16 14:30:10 +0200500 e1line_dump_vty(vty, line, stats);
Harald Welte6e37c592011-08-11 12:43:31 +0200501
502 return CMD_SUCCESS;
503}
504
505static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts)
506{
507 if (ts->type == E1INP_TS_TYPE_NONE)
508 return;
509 vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s",
Keithdf088b02021-05-04 15:12:32 -0500510 ts->num-1, ts->line->num, e1inp_tstype_name(ts->type),
Harald Welte6e37c592011-08-11 12:43:31 +0200511 VTY_NEWLINE);
512}
513
514DEFUN(show_e1ts,
515 show_e1ts_cmd,
Keithdf088b02021-05-04 15:12:32 -0500516 "show e1_timeslot [<0-255>] [<0-31>]",
Harald Welte6e37c592011-08-11 12:43:31 +0200517 SHOW_STR "Display information about a E1 timeslot\n"
518 "E1 Line Number\n" "E1 Timeslot Number\n")
519{
520 struct e1inp_line *line = NULL;
521 struct e1inp_ts *ts;
522 int ts_nr;
523
Holger Hans Peter Freyther8cbd9f42013-07-04 20:00:33 +0200524 if (argc <= 0) {
Harald Welte6e37c592011-08-11 12:43:31 +0200525 llist_for_each_entry(line, &e1inp_line_list, list) {
Harald Weltec2889512011-09-13 23:49:04 +0100526 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200527 ts = &line->ts[ts_nr];
528 e1ts_dump_vty(vty, ts);
529 }
530 }
531 return CMD_SUCCESS;
532 }
533 if (argc >= 1) {
534 int num = atoi(argv[0]);
535 struct e1inp_line *l;
536 llist_for_each_entry(l, &e1inp_line_list, list) {
537 if (l->num == num) {
538 line = l;
539 break;
540 }
541 }
542 if (!line) {
543 vty_out(vty, "E1 line %s is invalid%s",
544 argv[0], VTY_NEWLINE);
545 return CMD_WARNING;
546 }
547 }
548 if (argc >= 2) {
549 ts_nr = atoi(argv[1]);
Harald Weltec2889512011-09-13 23:49:04 +0100550 if (ts_nr >= line->num_ts) {
Harald Welte6e37c592011-08-11 12:43:31 +0200551 vty_out(vty, "E1 timeslot %s is invalid%s",
552 argv[1], VTY_NEWLINE);
553 return CMD_WARNING;
554 }
555 ts = &line->ts[ts_nr];
556 e1ts_dump_vty(vty, ts);
557 return CMD_SUCCESS;
558 } else {
Harald Weltec2889512011-09-13 23:49:04 +0100559 for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) {
Harald Welte6e37c592011-08-11 12:43:31 +0200560 ts = &line->ts[ts_nr];
561 e1ts_dump_vty(vty, ts);
562 }
563 return CMD_SUCCESS;
564 }
565 return CMD_SUCCESS;
566}
567
568
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200569struct cmd_node e1inp_node = {
Harald Weltecc2241b2011-07-19 16:06:06 +0200570 L_E1INP_NODE,
Jacob Erlbeck1c9dcc12013-11-11 14:13:13 +0100571 "%s(config-e1_input)# ",
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200572 1,
573};
574
575int e1inp_vty_init(void)
576{
Vadim Yanitskiy82ef2a22020-10-04 16:15:52 +0700577 install_lib_element(CONFIG_NODE, &cfg_e1inp_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200578 install_node(&e1inp_node, e1inp_config_write);
Jacob Erlbeck37f06952013-11-11 14:13:12 +0100579
Keith2672a2a2020-11-12 06:59:37 +0100580 install_lib_element(L_E1INP_NODE, &cfg_e1line_pcap_cmd);
581 install_lib_element(L_E1INP_NODE, &cfg_e1line_no_pcap_cmd);
582 install_lib_element(L_E1INP_NODE, &cfg_e1_pcap_deprec_cmd);
583 install_lib_element(L_E1INP_NODE, &cfg_e1_pcap_deprec_no_cmd);
Sylvain Munauteb55e2f2020-05-08 09:42:51 +0200584
Vadim Yanitskiy82ef2a22020-10-04 16:15:52 +0700585 install_lib_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd);
586 install_lib_element(L_E1INP_NODE, &cfg_e1_line_port_cmd);
587 install_lib_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd);
588 install_lib_element(L_E1INP_NODE, &cfg_e1_line_name_cmd);
Daniel Willmannc20af052022-12-15 11:50:34 +0100589 install_lib_element(L_E1INP_NODE, &cfg_e1_line_connect_timeout_cmd);
Vadim Yanitskiy82ef2a22020-10-04 16:15:52 +0700590 install_lib_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd);
591 install_lib_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd);
592 install_lib_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd);
593 install_lib_element(L_E1INP_NODE, &cfg_e1_line_ipa_keepalive_cmd);
594 install_lib_element(L_E1INP_NODE, &cfg_e1_line_no_ipa_keepalive_cmd);
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200595
Vadim Yanitskiy82ef2a22020-10-04 16:15:52 +0700596 install_lib_element(L_E1INP_NODE, &cfg_ipa_bind_cmd);
Harald Welte41547552021-04-28 18:23:21 +0200597 install_lib_element(L_E1INP_NODE, &cfg_ipa_dscp_cmd);
598 install_lib_element(L_E1INP_NODE, &cfg_ipa_priority_cmd);
Neels Hofmeyr0db1d432016-02-22 13:29:09 +0100599
Vadim Yanitskiy82ef2a22020-10-04 16:15:52 +0700600 install_lib_element_ve(&show_e1drv_cmd);
601 install_lib_element_ve(&show_e1line_cmd);
602 install_lib_element_ve(&show_e1ts_cmd);
Harald Welte6e37c592011-08-11 12:43:31 +0200603
Pablo Neira Ayuso262aee82011-07-05 19:17:08 +0200604 return 0;
605}