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