Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 1 | /* E1 vty interface */ |
| 2 | /* (C) 2011 by Harald Welte <laforge@gnumonks.org> |
| 3 | * All Rights Reserved |
| 4 | * |
Harald Welte | 323d39d | 2017-11-13 01:09:21 +0900 | [diff] [blame] | 5 | * SPDX-License-Identifier: AGPL-3.0+ |
| 6 | * |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 7 | * 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 Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 23 | #include <fcntl.h> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 24 | #include <stdlib.h> |
| 25 | #include <unistd.h> |
Harald Welte | d4f8f68 | 2011-08-19 13:28:48 +0200 | [diff] [blame] | 26 | #include <string.h> |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 27 | #include <sys/stat.h> |
| 28 | #include <sys/types.h> |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 29 | #include <sys/un.h> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 30 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 31 | #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 Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 36 | #include <osmocom/vty/command.h> |
| 37 | #include <osmocom/vty/buffer.h> |
| 38 | #include <osmocom/vty/vty.h> |
| 39 | #include <osmocom/vty/logging.h> |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 40 | #include <osmocom/vty/misc.h> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 41 | #include <osmocom/vty/telnet_interface.h> |
| 42 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 43 | #include <osmocom/abis/e1_input.h> |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 44 | #include <osmocom/abis/ipa.h> |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 45 | |
| 46 | /* CONFIG */ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 47 | |
Sylvain Munaut | b559a53 | 2019-05-09 11:14:26 +0200 | [diff] [blame] | 48 | #define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|e1d|ipa|unixsocket)" |
Harald Welte | ce307b4 | 2011-08-21 01:18:05 +0200 | [diff] [blame] | 49 | #define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \ |
| 50 | "mISDN supported E1 Card (userspace LAPD)\n" \ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 51 | "DAHDI supported E1/T1/J1 Card\n" \ |
Harald Welte | 1f92284 | 2020-07-02 11:19:15 +0200 | [diff] [blame] | 52 | "osmo-e1d supported E1 interface\n" \ |
Holger Hans Peter Freyther | 36bac9a | 2012-07-20 23:49:52 +0200 | [diff] [blame] | 53 | "IPA TCP/IP input\n" \ |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 54 | "Unix socket input\n" |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 55 | |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 56 | #define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n" |
| 57 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 58 | DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd, |
| 59 | "e1_line <0-255> driver " E1_DRIVER_NAMES, |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 60 | E1_LINE_HELP "Set driver for this line\n" |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 61 | E1_DRIVER_HELP) |
| 62 | { |
| 63 | struct e1inp_line *line; |
| 64 | int e1_nr = atoi(argv[0]); |
| 65 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 66 | line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 67 | if (line) { |
| 68 | vty_out(vty, "%% Line %d already exists%s", e1_nr, VTY_NEWLINE); |
| 69 | return CMD_WARNING; |
| 70 | } |
| 71 | line = e1inp_line_create(e1_nr, argv[1]); |
| 72 | if (!line) { |
| 73 | vty_out(vty, "%% Error creating line %d%s", e1_nr, VTY_NEWLINE); |
| 74 | return CMD_WARNING; |
| 75 | } |
| 76 | |
| 77 | return CMD_SUCCESS; |
| 78 | } |
| 79 | |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 80 | DEFUN(cfg_e1line_port, cfg_e1_line_port_cmd, |
Harald Welte | 356918f | 2011-09-26 22:54:51 +0200 | [diff] [blame] | 81 | "e1_line <0-255> port <0-255>", |
| 82 | E1_LINE_HELP "Set physical port/span/card number\n" |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 83 | "E1/T1 Port/Span/Card number\n") |
| 84 | { |
| 85 | struct e1inp_line *line; |
| 86 | int e1_nr = atoi(argv[0]); |
| 87 | |
| 88 | line = e1inp_line_find(e1_nr); |
| 89 | if (!line) { |
| 90 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 91 | return CMD_WARNING; |
| 92 | } |
| 93 | |
| 94 | line->port_nr = atoi(argv[1]); |
| 95 | |
| 96 | return CMD_SUCCESS; |
| 97 | } |
| 98 | |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 99 | DEFUN(cfg_e1line_socket, cfg_e1_line_socket_cmd, |
| 100 | "e1_line <0-255> socket .SOCKET", |
| 101 | E1_LINE_HELP "Set socket path for unixsocket\n" |
| 102 | "socket path\n") |
| 103 | { |
| 104 | struct e1inp_line *line; |
| 105 | int e1_nr = atoi(argv[0]); |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 106 | struct sockaddr_un sun; |
| 107 | |
Stefan Sperling | 0d7d0b0 | 2018-09-20 17:34:31 +0200 | [diff] [blame] | 108 | /* Don't exceed the maximum unix socket path length, including a NUL byte. See the unix(7) man page.*/ |
| 109 | if (strlen(argv[1]) > sizeof(sun.sun_path) - 1) { |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 110 | vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s", |
Stefan Sperling | 0d7d0b0 | 2018-09-20 17:34:31 +0200 | [diff] [blame] | 111 | sizeof(sun.sun_path) - 1, argv[1], VTY_NEWLINE); |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 112 | return CMD_WARNING; |
| 113 | } |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 114 | |
| 115 | line = e1inp_line_find(e1_nr); |
| 116 | if (!line) { |
| 117 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 118 | return CMD_WARNING; |
| 119 | } |
| 120 | |
| 121 | line->sock_path = talloc_strdup(line, argv[1]); |
| 122 | |
| 123 | return CMD_SUCCESS; |
| 124 | } |
| 125 | |
Jacob Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 126 | #define KEEPALIVE_HELP "Enable keep-alive probing\n" |
| 127 | static int set_keepalive_params(struct vty *vty, int e1_nr, |
| 128 | int idle, int num_probes, int probe_interval) |
| 129 | { |
| 130 | struct e1inp_line *line = e1inp_line_find(e1_nr); |
| 131 | |
| 132 | if (!line) { |
| 133 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 134 | return CMD_WARNING; |
| 135 | } |
| 136 | if (!line->driver->has_keepalive && num_probes != 0) { |
| 137 | vty_out(vty, "%% Driver '%s' does not support keep alive%s", |
| 138 | line->driver->name, VTY_NEWLINE); |
| 139 | return CMD_WARNING; |
| 140 | } |
| 141 | |
| 142 | line->keepalive_idle_timeout = idle; |
| 143 | line->keepalive_num_probes = num_probes; |
| 144 | line->keepalive_probe_interval = probe_interval; |
| 145 | |
| 146 | return CMD_SUCCESS; |
| 147 | } |
| 148 | |
| 149 | DEFUN(cfg_e1line_keepalive, cfg_e1_line_keepalive_cmd, |
| 150 | "e1_line <0-255> keepalive", |
| 151 | E1_LINE_HELP KEEPALIVE_HELP) |
| 152 | { |
| 153 | return set_keepalive_params(vty, atoi(argv[0]), |
| 154 | E1INP_USE_DEFAULT, E1INP_USE_DEFAULT, |
| 155 | E1INP_USE_DEFAULT); |
| 156 | } |
| 157 | |
| 158 | DEFUN(cfg_e1line_keepalive_params, cfg_e1_line_keepalive_params_cmd, |
| 159 | "e1_line <0-255> keepalive <1-300> <1-20> <1-300>", |
| 160 | E1_LINE_HELP KEEPALIVE_HELP |
| 161 | "Idle interval in seconds before probes are sent\n" |
| 162 | "Number of probes to sent\n" |
| 163 | "Delay between probe packets in seconds\n") |
| 164 | { |
| 165 | return set_keepalive_params(vty, atoi(argv[0]), |
| 166 | atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); |
| 167 | } |
| 168 | |
| 169 | DEFUN(cfg_e1line_no_keepalive, cfg_e1_line_no_keepalive_cmd, |
| 170 | "no e1_line <0-255> keepalive", |
| 171 | NO_STR E1_LINE_HELP KEEPALIVE_HELP) |
| 172 | { |
| 173 | return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0); |
| 174 | } |
| 175 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 176 | #define IPA_KEEPALIVE_HELP "Enable IPA PING/PONG keep-alive\n" |
| 177 | static int set_ipa_keepalive_params(struct vty *vty, int e1_nr, int interval, int wait_for_resp) |
| 178 | { |
| 179 | struct e1inp_line *line = e1inp_line_find(e1_nr); |
| 180 | |
| 181 | if (!line) { |
| 182 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 183 | return CMD_WARNING; |
| 184 | } |
| 185 | |
| 186 | if (strcmp(line->driver->name, "ipa") != 0) { |
| 187 | vty_out(vty, "%% Line %d doesn't use the ipa driver%s", e1_nr, VTY_NEWLINE); |
| 188 | return CMD_WARNING; |
| 189 | } |
| 190 | |
| 191 | TALLOC_FREE(line->ipa_kap); |
| 192 | if (interval) { |
| 193 | line->ipa_kap = talloc_zero(line, struct ipa_keepalive_params); |
| 194 | line->ipa_kap->wait_for_resp = wait_for_resp; |
| 195 | line->ipa_kap->interval = interval; |
| 196 | } |
| 197 | |
| 198 | return CMD_SUCCESS; |
| 199 | } |
| 200 | |
| 201 | DEFUN(cfg_e1line_ipa_keepalive, cfg_e1_line_ipa_keepalive_cmd, |
| 202 | "e1_line <0-255> ipa-keepalive <1-300> <1-300>", |
| 203 | E1_LINE_HELP IPA_KEEPALIVE_HELP |
| 204 | "Idle interval in seconds before probes are sent\n" |
| 205 | "Time to wait for PONG response\n") |
| 206 | { |
| 207 | return set_ipa_keepalive_params(vty, atoi(argv[0]), atoi(argv[1]), atoi(argv[2])); |
| 208 | } |
| 209 | |
| 210 | DEFUN(cfg_e1line_no_ipa_keepalive, cfg_e1_line_no_ipa_keepalive_cmd, |
| 211 | "no e1_line <0-255> ipa-keepalive", |
| 212 | NO_STR E1_LINE_HELP IPA_KEEPALIVE_HELP) |
| 213 | { |
| 214 | return set_ipa_keepalive_params(vty, atoi(argv[0]), 0, 0); |
| 215 | } |
| 216 | |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 217 | DEFUN(cfg_e1line_name, cfg_e1_line_name_cmd, |
| 218 | "e1_line <0-255> name .LINE", |
| 219 | E1_LINE_HELP "Set name for this line\n" "Human readable name\n") |
| 220 | { |
| 221 | struct e1inp_line *line; |
| 222 | int e1_nr = atoi(argv[0]); |
| 223 | |
| 224 | line = e1inp_line_find(e1_nr); |
| 225 | if (!line) { |
| 226 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
| 227 | return CMD_WARNING; |
| 228 | } |
| 229 | if (line->name) { |
| 230 | talloc_free((void *)line->name); |
| 231 | line->name = NULL; |
| 232 | } |
| 233 | line->name = talloc_strdup(line, argv[1]); |
| 234 | |
| 235 | return CMD_SUCCESS; |
| 236 | } |
| 237 | |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 238 | DEFUN(cfg_e1_pcap, cfg_e1_pcap_cmd, |
| 239 | "pcap .FILE", |
| 240 | "Setup a pcap recording of all E1 traffic\n" |
| 241 | "Filename to save the packets to\n") |
| 242 | { |
| 243 | int fd; |
| 244 | |
| 245 | fd = open(argv[0], O_WRONLY | O_CREAT | O_TRUNC, 0660); |
| 246 | if (fd < 0) { |
| 247 | vty_out(vty, "Failed to setup E1 pcap recording to %s.%s", argv[0], VTY_NEWLINE); |
| 248 | return CMD_WARNING; |
| 249 | } |
| 250 | |
| 251 | e1_set_pcap_fd(fd); |
| 252 | |
| 253 | return CMD_SUCCESS; |
| 254 | } |
| 255 | |
| 256 | DEFUN(cfg_e1_no_pcap, cfg_e1_no_pcap_cmd, |
| 257 | "no pcap", |
| 258 | NO_STR "Disable pcap recording of all E1 traffic\n") |
| 259 | { |
| 260 | e1_set_pcap_fd(-1); |
| 261 | return CMD_SUCCESS; |
| 262 | } |
| 263 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 264 | DEFUN(cfg_e1inp, cfg_e1inp_cmd, |
| 265 | "e1_input", |
| 266 | "Configure E1/T1/J1 TDM input\n") |
| 267 | { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 268 | vty->node = L_E1INP_NODE; |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 269 | |
| 270 | return CMD_SUCCESS; |
| 271 | } |
| 272 | |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 273 | DEFUN(cfg_ipa_bind, |
| 274 | cfg_ipa_bind_cmd, |
| 275 | "ipa bind A.B.C.D", |
| 276 | "ipa driver config\n" |
| 277 | "Set ipa local bind address\n" |
| 278 | "Listen on this IP address (default 0.0.0.0)\n") |
| 279 | { |
| 280 | e1inp_ipa_set_bind_addr(argv[0]); |
| 281 | return CMD_SUCCESS; |
| 282 | } |
| 283 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 284 | static int e1inp_config_write(struct vty *vty) |
| 285 | { |
| 286 | struct e1inp_line *line; |
| 287 | |
| 288 | if (llist_empty(&e1inp_line_list)) |
| 289 | return CMD_SUCCESS; |
| 290 | |
| 291 | vty_out(vty, "e1_input%s", VTY_NEWLINE); |
| 292 | |
| 293 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 294 | vty_out(vty, " e1_line %u driver %s%s", line->num, |
| 295 | line->driver->name, VTY_NEWLINE); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 296 | vty_out(vty, " e1_line %u port %u%s", line->num, |
| 297 | line->port_nr, VTY_NEWLINE); |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 298 | if (line->name) |
| 299 | vty_out(vty, " e1_line %u name %s%s", line->num, |
| 300 | line->name, VTY_NEWLINE); |
Jacob Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 301 | if (!line->keepalive_num_probes) |
| 302 | vty_out(vty, " no e1_line %u keepalive%s", line->num, |
| 303 | VTY_NEWLINE); |
| 304 | else if (line->keepalive_idle_timeout == E1INP_USE_DEFAULT && |
| 305 | line->keepalive_num_probes == E1INP_USE_DEFAULT && |
| 306 | line->keepalive_probe_interval == E1INP_USE_DEFAULT) |
| 307 | vty_out(vty, " e1_line %u keepalive%s", line->num, |
| 308 | VTY_NEWLINE); |
| 309 | else |
| 310 | vty_out(vty, " e1_line %u keepalive %d %d %d%s", |
| 311 | line->num, |
| 312 | line->keepalive_idle_timeout, |
| 313 | line->keepalive_num_probes, |
| 314 | line->keepalive_probe_interval, |
| 315 | VTY_NEWLINE); |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 316 | if (line->ipa_kap) |
| 317 | vty_out(vty, " e1_line %u ipa-keepalive %d %d%s", line->num, |
| 318 | line->ipa_kap->interval, line->ipa_kap->wait_for_resp, |
| 319 | VTY_NEWLINE); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 320 | } |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 321 | |
| 322 | const char *ipa_bind = e1inp_ipa_get_bind_addr(); |
| 323 | if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0)) |
| 324 | vty_out(vty, " ipa bind %s%s", |
| 325 | ipa_bind, VTY_NEWLINE); |
| 326 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 327 | return CMD_SUCCESS; |
| 328 | } |
| 329 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 330 | /* SHOW */ |
| 331 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 332 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 333 | { |
| 334 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 335 | } |
| 336 | |
| 337 | DEFUN(show_e1drv, |
| 338 | show_e1drv_cmd, |
| 339 | "show e1_driver", |
| 340 | SHOW_STR "Display information about available E1 drivers\n") |
| 341 | { |
| 342 | struct e1inp_driver *drv; |
| 343 | |
| 344 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 345 | e1drv_dump_vty(vty, drv); |
| 346 | |
| 347 | return CMD_SUCCESS; |
| 348 | } |
| 349 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 350 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line, |
| 351 | int stats) |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 352 | { |
| 353 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 354 | line->num, line->name ? line->name : "", |
| 355 | line->driver->name, VTY_NEWLINE); |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 356 | if (line->driver->vty_show) |
| 357 | line->driver->vty_show(vty, line); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 358 | if (stats) |
| 359 | vty_out_rate_ctr_group(vty, " ", line->rate_ctr); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 360 | } |
| 361 | |
| 362 | DEFUN(show_e1line, |
| 363 | show_e1line_cmd, |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 364 | "show e1_line [line_nr] [stats]", |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 365 | SHOW_STR "Display information about a E1 line\n" |
Holger Hans Peter Freyther | 9e8f1c0 | 2012-07-21 00:09:52 +0200 | [diff] [blame] | 366 | "E1 Line Number\n" "Include statistics\n") |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 367 | { |
| 368 | struct e1inp_line *line; |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 369 | int stats = 0; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 370 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 371 | if (argc >= 1 && strcmp(argv[0], "stats")) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 372 | int num = atoi(argv[0]); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 373 | if (argc >= 2) |
| 374 | stats = 1; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 375 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 376 | if (line->num == num) { |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 377 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 378 | return CMD_SUCCESS; |
| 379 | } |
| 380 | } |
| 381 | return CMD_WARNING; |
| 382 | } |
| 383 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 384 | if (argc >= 1 && !strcmp(argv[0], "stats")) |
| 385 | stats = 1; |
| 386 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 387 | llist_for_each_entry(line, &e1inp_line_list, list) |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 388 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 389 | |
| 390 | return CMD_SUCCESS; |
| 391 | } |
| 392 | |
| 393 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 394 | { |
| 395 | if (ts->type == E1INP_TS_TYPE_NONE) |
| 396 | return; |
| 397 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 398 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 399 | VTY_NEWLINE); |
| 400 | } |
| 401 | |
| 402 | DEFUN(show_e1ts, |
| 403 | show_e1ts_cmd, |
| 404 | "show e1_timeslot [line_nr] [ts_nr]", |
| 405 | SHOW_STR "Display information about a E1 timeslot\n" |
| 406 | "E1 Line Number\n" "E1 Timeslot Number\n") |
| 407 | { |
| 408 | struct e1inp_line *line = NULL; |
| 409 | struct e1inp_ts *ts; |
| 410 | int ts_nr; |
| 411 | |
Holger Hans Peter Freyther | 8cbd9f4 | 2013-07-04 20:00:33 +0200 | [diff] [blame] | 412 | if (argc <= 0) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 413 | llist_for_each_entry(line, &e1inp_line_list, list) { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 414 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 415 | ts = &line->ts[ts_nr]; |
| 416 | e1ts_dump_vty(vty, ts); |
| 417 | } |
| 418 | } |
| 419 | return CMD_SUCCESS; |
| 420 | } |
| 421 | if (argc >= 1) { |
| 422 | int num = atoi(argv[0]); |
| 423 | struct e1inp_line *l; |
| 424 | llist_for_each_entry(l, &e1inp_line_list, list) { |
| 425 | if (l->num == num) { |
| 426 | line = l; |
| 427 | break; |
| 428 | } |
| 429 | } |
| 430 | if (!line) { |
| 431 | vty_out(vty, "E1 line %s is invalid%s", |
| 432 | argv[0], VTY_NEWLINE); |
| 433 | return CMD_WARNING; |
| 434 | } |
| 435 | } |
| 436 | if (argc >= 2) { |
| 437 | ts_nr = atoi(argv[1]); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 438 | if (ts_nr >= line->num_ts) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 439 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 440 | argv[1], VTY_NEWLINE); |
| 441 | return CMD_WARNING; |
| 442 | } |
| 443 | ts = &line->ts[ts_nr]; |
| 444 | e1ts_dump_vty(vty, ts); |
| 445 | return CMD_SUCCESS; |
| 446 | } else { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 447 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 448 | ts = &line->ts[ts_nr]; |
| 449 | e1ts_dump_vty(vty, ts); |
| 450 | } |
| 451 | return CMD_SUCCESS; |
| 452 | } |
| 453 | return CMD_SUCCESS; |
| 454 | } |
| 455 | |
| 456 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 457 | struct cmd_node e1inp_node = { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 458 | L_E1INP_NODE, |
Jacob Erlbeck | 1c9dcc1 | 2013-11-11 14:13:13 +0100 | [diff] [blame] | 459 | "%s(config-e1_input)# ", |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 460 | 1, |
| 461 | }; |
| 462 | |
| 463 | int e1inp_vty_init(void) |
| 464 | { |
| 465 | install_element(CONFIG_NODE, &cfg_e1inp_cmd); |
| 466 | install_node(&e1inp_node, e1inp_config_write); |
Jacob Erlbeck | 37f0695 | 2013-11-11 14:13:12 +0100 | [diff] [blame] | 467 | |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 468 | install_element(L_E1INP_NODE, &cfg_e1_pcap_cmd); |
| 469 | install_element(L_E1INP_NODE, &cfg_e1_no_pcap_cmd); |
| 470 | |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 471 | install_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 472 | install_element(L_E1INP_NODE, &cfg_e1_line_port_cmd); |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 473 | install_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd); |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 474 | install_element(L_E1INP_NODE, &cfg_e1_line_name_cmd); |
Jacob Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 475 | install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd); |
| 476 | install_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd); |
| 477 | install_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd); |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 478 | install_element(L_E1INP_NODE, &cfg_e1_line_ipa_keepalive_cmd); |
| 479 | install_element(L_E1INP_NODE, &cfg_e1_line_no_ipa_keepalive_cmd); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 480 | |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 481 | install_element(L_E1INP_NODE, &cfg_ipa_bind_cmd); |
| 482 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 483 | install_element_ve(&show_e1drv_cmd); |
| 484 | install_element_ve(&show_e1line_cmd); |
| 485 | install_element_ve(&show_e1ts_cmd); |
| 486 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 487 | return 0; |
| 488 | } |