Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 1 | /* E1 vty interface */ |
Harald Welte | 4154755 | 2021-04-28 18:23:21 +0200 | [diff] [blame] | 2 | /* (C) 2011-2021 by Harald Welte <laforge@gnumonks.org> |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 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 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 46 | #define X(x) (1 << x) |
| 47 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 48 | /* CONFIG */ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 49 | |
Sylvain Munaut | b559a53 | 2019-05-09 11:14:26 +0200 | [diff] [blame] | 50 | #define E1_DRIVER_NAMES "(misdn|misdn_lapd|dahdi|e1d|ipa|unixsocket)" |
Harald Welte | ce307b4 | 2011-08-21 01:18:05 +0200 | [diff] [blame] | 51 | #define E1_DRIVER_HELP "mISDN supported E1 Card (kernel LAPD)\n" \ |
| 52 | "mISDN supported E1 Card (userspace LAPD)\n" \ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 53 | "DAHDI supported E1/T1/J1 Card\n" \ |
Harald Welte | 1f92284 | 2020-07-02 11:19:15 +0200 | [diff] [blame] | 54 | "osmo-e1d supported E1 interface\n" \ |
Holger Hans Peter Freyther | 36bac9a | 2012-07-20 23:49:52 +0200 | [diff] [blame] | 55 | "IPA TCP/IP input\n" \ |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 56 | "Unix socket input\n" |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 57 | |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 58 | #define E1_LINE_HELP "Configure E1/T1/J1 Line\n" "Line Number\n" |
| 59 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 60 | /* Note: This requires a full restart of the application, since once created |
| 61 | * an E1 line can not be destroyed again. */ |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 62 | DEFUN(cfg_e1line_driver, cfg_e1_line_driver_cmd, |
| 63 | "e1_line <0-255> driver " E1_DRIVER_NAMES, |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 64 | E1_LINE_HELP "Set driver for this line\n" |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 65 | E1_DRIVER_HELP) |
| 66 | { |
| 67 | struct e1inp_line *line; |
| 68 | int e1_nr = atoi(argv[0]); |
| 69 | |
Pablo Neira Ayuso | 3832c4f | 2011-07-07 17:47:26 +0200 | [diff] [blame] | 70 | line = e1inp_line_find(e1_nr); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 71 | 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 Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 84 | DEFUN_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 Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 89 | { |
| 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 Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 104 | DEFUN_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 Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 109 | { |
| 110 | struct e1inp_line *line; |
| 111 | int e1_nr = atoi(argv[0]); |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 112 | struct sockaddr_un sun; |
| 113 | |
Stefan Sperling | 0d7d0b0 | 2018-09-20 17:34:31 +0200 | [diff] [blame] | 114 | /* 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 Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 116 | vty_out(vty, "%% Socket path length exceeds %zd bytes: '%s'%s", |
Stefan Sperling | 0d7d0b0 | 2018-09-20 17:34:31 +0200 | [diff] [blame] | 117 | sizeof(sun.sun_path) - 1, argv[1], VTY_NEWLINE); |
Stefan Sperling | b24efa5 | 2018-08-28 14:03:41 +0200 | [diff] [blame] | 118 | return CMD_WARNING; |
| 119 | } |
Alexander Couzens | beb10ef | 2016-11-01 22:05:13 +0100 | [diff] [blame] | 120 | |
| 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 Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 132 | #define KEEPALIVE_HELP "Enable keep-alive probing\n" |
| 133 | static 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 Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 155 | DEFUN_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 Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 159 | { |
| 160 | return set_keepalive_params(vty, atoi(argv[0]), |
| 161 | E1INP_USE_DEFAULT, E1INP_USE_DEFAULT, |
| 162 | E1INP_USE_DEFAULT); |
| 163 | } |
| 164 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 165 | DEFUN_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 Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 172 | { |
| 173 | return set_keepalive_params(vty, atoi(argv[0]), |
| 174 | atoi(argv[1]), atoi(argv[2]), atoi(argv[3])); |
| 175 | } |
| 176 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 177 | DEFUN_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 Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 181 | { |
| 182 | return set_keepalive_params(vty, atoi(argv[0]), 0, 0, 0); |
| 183 | } |
| 184 | |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 185 | #define IPA_KEEPALIVE_HELP "Enable IPA PING/PONG keep-alive\n" |
| 186 | static 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 Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 210 | DEFUN_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 Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 215 | { |
| 216 | return set_ipa_keepalive_params(vty, atoi(argv[0]), atoi(argv[1]), atoi(argv[2])); |
| 217 | } |
| 218 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 219 | DEFUN_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 Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 222 | { |
| 223 | return set_ipa_keepalive_params(vty, atoi(argv[0]), 0, 0); |
| 224 | } |
| 225 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 226 | DEFUN_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 Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 230 | { |
| 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 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 248 | DEFUN_ATTR(cfg_e1line_pcap, cfg_e1line_pcap_cmd, |
| 249 | "e1_line <0-255> pcap .FILE", |
| 250 | E1_LINE_HELP "Setup a pcap recording of E1 traffic for line\n" |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 251 | "Filename to save the packets to\n", CMD_ATTR_IMMEDIATE) |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 252 | { |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 253 | struct e1inp_line *line; |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 254 | int fd; |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 255 | int rc; |
| 256 | int e1_nr = atoi(argv[0]); |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 257 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 258 | line = e1inp_line_find(e1_nr); |
| 259 | if (!line) { |
| 260 | vty_out(vty, "%% Line %d doesn't exist%s", e1_nr, VTY_NEWLINE); |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 261 | return CMD_WARNING; |
| 262 | } |
| 263 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 264 | fd = open(argv[1], O_WRONLY | O_CREAT | O_TRUNC, 0660); |
| 265 | if (fd < 0) { |
| 266 | vty_out(vty, "Failed to setup E1 pcap recording to %s%s", argv[1], VTY_NEWLINE); |
| 267 | return CMD_WARNING; |
| 268 | } |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 269 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 270 | rc = e1_set_pcap_fd2(line, fd); |
| 271 | if (rc < 0) { |
| 272 | vty_out(vty, "Failed to write to E1 pcap file %s%s", argv[1], VTY_NEWLINE); |
| 273 | close(fd); |
| 274 | return CMD_WARNING; |
| 275 | } |
| 276 | |
| 277 | osmo_talloc_replace_string(line, &line->pcap_file, argv[1]); |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 278 | return CMD_SUCCESS; |
| 279 | } |
| 280 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 281 | DEFUN_ATTR(cfg_e1line_no_pcap, cfg_e1line_no_pcap_cmd, |
| 282 | "no e1_line <0-255> pcap", |
| 283 | NO_STR E1_LINE_HELP "Disable pcap recording of E1 traffic for line\n", |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 284 | CMD_ATTR_IMMEDIATE) |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 285 | { |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 286 | struct e1inp_line *line; |
| 287 | int e1_nr = atoi(argv[0]); |
| 288 | line = e1inp_line_find(e1_nr); |
| 289 | |
| 290 | e1_set_pcap_fd2(line, -1); |
| 291 | if (line->pcap_file) { |
| 292 | talloc_free(line->pcap_file); |
| 293 | line->pcap_file = NULL; |
| 294 | } |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 295 | return CMD_SUCCESS; |
| 296 | } |
| 297 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 298 | DEFUN_DEPRECATED(cfg_e1_pcap_deprec, cfg_e1_pcap_deprec_cmd, |
| 299 | "pcap .FILE", "Legacy") |
| 300 | { |
| 301 | vty_out(vty, "%% 'pcap' is deprecated and has no effect: use e1_line <0-255> pcap%s", |
| 302 | VTY_NEWLINE); |
| 303 | return CMD_WARNING; |
| 304 | } |
| 305 | |
| 306 | ALIAS_DEPRECATED(cfg_e1_pcap_deprec, cfg_e1_pcap_deprec_no_cmd, |
| 307 | "no pcap", NO_STR); |
| 308 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 309 | DEFUN_ATTR(cfg_e1inp, cfg_e1inp_cmd, |
| 310 | "e1_input", |
| 311 | "Configure E1/T1/J1 TDM input\n", CMD_ATTR_IMMEDIATE) |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 312 | { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 313 | vty->node = L_E1INP_NODE; |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 314 | |
| 315 | return CMD_SUCCESS; |
| 316 | } |
| 317 | |
Philipp Maier | ef5b839 | 2020-10-08 17:35:52 +0200 | [diff] [blame] | 318 | DEFUN_USRATTR(cfg_ipa_bind, |
| 319 | cfg_ipa_bind_cmd, |
| 320 | X(OSMO_ABIS_LIB_ATTR_LINE_UPD), |
| 321 | "ipa bind A.B.C.D", |
| 322 | "ipa driver config\n" |
| 323 | "Set ipa local bind address\n" |
| 324 | "Listen on this IP address (default 0.0.0.0)\n") |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 325 | { |
| 326 | e1inp_ipa_set_bind_addr(argv[0]); |
| 327 | return CMD_SUCCESS; |
| 328 | } |
| 329 | |
Harald Welte | 4154755 | 2021-04-28 18:23:21 +0200 | [diff] [blame] | 330 | DEFUN_USRATTR(cfg_ipa_dscp, cfg_ipa_dscp_cmd, |
| 331 | X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK), |
| 332 | "ipa ip-dscp (oml|rsl) <0-63>", |
| 333 | "ipa driver config\n" |
| 334 | "Set IP DSCP value for outbound packets\n" |
| 335 | "Set IP DSCP for OML link\n" |
| 336 | "Set IP DSCP for RSL link\n" |
| 337 | "IP DSCP Value to use\n") |
| 338 | { |
| 339 | if (!strcmp(argv[0], "oml")) |
| 340 | g_e1inp_ipaccess_pars.oml.dscp = atoi(argv[1]); |
| 341 | else |
| 342 | g_e1inp_ipaccess_pars.rsl.dscp = atoi(argv[1]); |
| 343 | return CMD_SUCCESS; |
| 344 | } |
| 345 | |
| 346 | DEFUN_USRATTR(cfg_ipa_priority, cfg_ipa_priority_cmd, |
| 347 | X(OSMO_ABIS_LIB_ATTR_IPA_NEW_LNK), |
| 348 | "ipa socket-priority (oml|rsl) <0-255>", |
| 349 | "ipa driver config\n" |
| 350 | "Set socket priority value for outbound packets\n" |
| 351 | "Set socket priority for OML link\n" |
| 352 | "Set socket priority for RSL link\n" |
| 353 | "socket priority value to use (>6 requires CAP_NET_ADMIN)\n") |
| 354 | { |
| 355 | if (!strcmp(argv[0], "oml")) |
| 356 | g_e1inp_ipaccess_pars.oml.priority = atoi(argv[1]); |
| 357 | else |
| 358 | g_e1inp_ipaccess_pars.rsl.priority = atoi(argv[1]); |
| 359 | return CMD_SUCCESS; |
| 360 | } |
| 361 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 362 | static int e1inp_config_write(struct vty *vty) |
| 363 | { |
| 364 | struct e1inp_line *line; |
| 365 | |
| 366 | if (llist_empty(&e1inp_line_list)) |
| 367 | return CMD_SUCCESS; |
| 368 | |
| 369 | vty_out(vty, "e1_input%s", VTY_NEWLINE); |
| 370 | |
| 371 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 372 | vty_out(vty, " e1_line %u driver %s%s", line->num, |
| 373 | line->driver->name, VTY_NEWLINE); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 374 | vty_out(vty, " e1_line %u port %u%s", line->num, |
| 375 | line->port_nr, VTY_NEWLINE); |
Harald Welte | 601a9c7 | 2011-08-16 14:17:49 +0200 | [diff] [blame] | 376 | if (line->name) |
| 377 | vty_out(vty, " e1_line %u name %s%s", line->num, |
| 378 | line->name, VTY_NEWLINE); |
Jacob Erlbeck | 86dae84 | 2014-01-16 18:10:37 +0100 | [diff] [blame] | 379 | if (!line->keepalive_num_probes) |
| 380 | vty_out(vty, " no e1_line %u keepalive%s", line->num, |
| 381 | VTY_NEWLINE); |
| 382 | else if (line->keepalive_idle_timeout == E1INP_USE_DEFAULT && |
| 383 | line->keepalive_num_probes == E1INP_USE_DEFAULT && |
| 384 | line->keepalive_probe_interval == E1INP_USE_DEFAULT) |
| 385 | vty_out(vty, " e1_line %u keepalive%s", line->num, |
| 386 | VTY_NEWLINE); |
| 387 | else |
| 388 | vty_out(vty, " e1_line %u keepalive %d %d %d%s", |
| 389 | line->num, |
| 390 | line->keepalive_idle_timeout, |
| 391 | line->keepalive_num_probes, |
| 392 | line->keepalive_probe_interval, |
| 393 | VTY_NEWLINE); |
Eric Wild | ef1f327 | 2019-07-10 18:10:31 +0200 | [diff] [blame] | 394 | if (line->ipa_kap) |
| 395 | vty_out(vty, " e1_line %u ipa-keepalive %d %d%s", line->num, |
| 396 | line->ipa_kap->interval, line->ipa_kap->wait_for_resp, |
| 397 | VTY_NEWLINE); |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 398 | if (line->pcap_file) |
| 399 | vty_out(vty, " e1_line %u pcap %s%s", line->num, |
| 400 | line->pcap_file, VTY_NEWLINE); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 401 | } |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 402 | |
| 403 | const char *ipa_bind = e1inp_ipa_get_bind_addr(); |
| 404 | if (ipa_bind && (strcmp(ipa_bind, "0.0.0.0") != 0)) |
| 405 | vty_out(vty, " ipa bind %s%s", |
| 406 | ipa_bind, VTY_NEWLINE); |
| 407 | |
Harald Welte | 4154755 | 2021-04-28 18:23:21 +0200 | [diff] [blame] | 408 | if (g_e1inp_ipaccess_pars.oml.dscp) |
| 409 | vty_out(vty, " ipa ip-dscp oml %u%s", g_e1inp_ipaccess_pars.oml.dscp, VTY_NEWLINE); |
| 410 | if (g_e1inp_ipaccess_pars.rsl.dscp) |
| 411 | vty_out(vty, " ipa ip-dscp rsl %u%s", g_e1inp_ipaccess_pars.rsl.dscp, VTY_NEWLINE); |
| 412 | if (g_e1inp_ipaccess_pars.oml.priority) |
| 413 | vty_out(vty, " ipa socket-priority oml %u%s", g_e1inp_ipaccess_pars.oml.priority, VTY_NEWLINE); |
| 414 | if (g_e1inp_ipaccess_pars.rsl.priority) |
| 415 | vty_out(vty, " ipa socket-priority rsl %u%s", g_e1inp_ipaccess_pars.rsl.priority, VTY_NEWLINE); |
| 416 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 417 | return CMD_SUCCESS; |
| 418 | } |
| 419 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 420 | /* SHOW */ |
| 421 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 422 | static void e1drv_dump_vty(struct vty *vty, struct e1inp_driver *drv) |
| 423 | { |
| 424 | vty_out(vty, "E1 Input Driver %s%s", drv->name, VTY_NEWLINE); |
| 425 | } |
| 426 | |
| 427 | DEFUN(show_e1drv, |
| 428 | show_e1drv_cmd, |
| 429 | "show e1_driver", |
| 430 | SHOW_STR "Display information about available E1 drivers\n") |
| 431 | { |
| 432 | struct e1inp_driver *drv; |
| 433 | |
| 434 | llist_for_each_entry(drv, &e1inp_driver_list, list) |
| 435 | e1drv_dump_vty(vty, drv); |
| 436 | |
| 437 | return CMD_SUCCESS; |
| 438 | } |
| 439 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 440 | static void e1line_dump_vty(struct vty *vty, struct e1inp_line *line, |
| 441 | int stats) |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 442 | { |
| 443 | vty_out(vty, "E1 Line Number %u, Name %s, Driver %s%s", |
| 444 | line->num, line->name ? line->name : "", |
| 445 | line->driver->name, VTY_NEWLINE); |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 446 | if (line->pcap_file) |
| 447 | vty_out(vty, "PCAP %s%s", line->pcap_file, VTY_NEWLINE); |
Harald Welte | fe05cf5 | 2011-09-26 23:18:41 +0200 | [diff] [blame] | 448 | if (line->driver->vty_show) |
| 449 | line->driver->vty_show(vty, line); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 450 | if (stats) |
| 451 | vty_out_rate_ctr_group(vty, " ", line->rate_ctr); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | DEFUN(show_e1line, |
| 455 | show_e1line_cmd, |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 456 | "show e1_line [line_nr] [stats]", |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 457 | SHOW_STR "Display information about a E1 line\n" |
Holger Hans Peter Freyther | 9e8f1c0 | 2012-07-21 00:09:52 +0200 | [diff] [blame] | 458 | "E1 Line Number\n" "Include statistics\n") |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 459 | { |
| 460 | struct e1inp_line *line; |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 461 | int stats = 0; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 462 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 463 | if (argc >= 1 && strcmp(argv[0], "stats")) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 464 | int num = atoi(argv[0]); |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 465 | if (argc >= 2) |
| 466 | stats = 1; |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 467 | llist_for_each_entry(line, &e1inp_line_list, list) { |
| 468 | if (line->num == num) { |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 469 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 470 | return CMD_SUCCESS; |
| 471 | } |
| 472 | } |
| 473 | return CMD_WARNING; |
| 474 | } |
| 475 | |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 476 | if (argc >= 1 && !strcmp(argv[0], "stats")) |
| 477 | stats = 1; |
| 478 | |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 479 | llist_for_each_entry(line, &e1inp_line_list, list) |
Harald Welte | f2737fc | 2011-08-16 14:30:10 +0200 | [diff] [blame] | 480 | e1line_dump_vty(vty, line, stats); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 481 | |
| 482 | return CMD_SUCCESS; |
| 483 | } |
| 484 | |
| 485 | static void e1ts_dump_vty(struct vty *vty, struct e1inp_ts *ts) |
| 486 | { |
| 487 | if (ts->type == E1INP_TS_TYPE_NONE) |
| 488 | return; |
| 489 | vty_out(vty, "E1 Timeslot %2u of Line %u is Type %s%s", |
| 490 | ts->num, ts->line->num, e1inp_tstype_name(ts->type), |
| 491 | VTY_NEWLINE); |
| 492 | } |
| 493 | |
| 494 | DEFUN(show_e1ts, |
| 495 | show_e1ts_cmd, |
| 496 | "show e1_timeslot [line_nr] [ts_nr]", |
| 497 | SHOW_STR "Display information about a E1 timeslot\n" |
| 498 | "E1 Line Number\n" "E1 Timeslot Number\n") |
| 499 | { |
| 500 | struct e1inp_line *line = NULL; |
| 501 | struct e1inp_ts *ts; |
| 502 | int ts_nr; |
| 503 | |
Holger Hans Peter Freyther | 8cbd9f4 | 2013-07-04 20:00:33 +0200 | [diff] [blame] | 504 | if (argc <= 0) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 505 | llist_for_each_entry(line, &e1inp_line_list, list) { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 506 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 507 | ts = &line->ts[ts_nr]; |
| 508 | e1ts_dump_vty(vty, ts); |
| 509 | } |
| 510 | } |
| 511 | return CMD_SUCCESS; |
| 512 | } |
| 513 | if (argc >= 1) { |
| 514 | int num = atoi(argv[0]); |
| 515 | struct e1inp_line *l; |
| 516 | llist_for_each_entry(l, &e1inp_line_list, list) { |
| 517 | if (l->num == num) { |
| 518 | line = l; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | if (!line) { |
| 523 | vty_out(vty, "E1 line %s is invalid%s", |
| 524 | argv[0], VTY_NEWLINE); |
| 525 | return CMD_WARNING; |
| 526 | } |
| 527 | } |
| 528 | if (argc >= 2) { |
| 529 | ts_nr = atoi(argv[1]); |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 530 | if (ts_nr >= line->num_ts) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 531 | vty_out(vty, "E1 timeslot %s is invalid%s", |
| 532 | argv[1], VTY_NEWLINE); |
| 533 | return CMD_WARNING; |
| 534 | } |
| 535 | ts = &line->ts[ts_nr]; |
| 536 | e1ts_dump_vty(vty, ts); |
| 537 | return CMD_SUCCESS; |
| 538 | } else { |
Harald Welte | c288951 | 2011-09-13 23:49:04 +0100 | [diff] [blame] | 539 | for (ts_nr = 0; ts_nr < line->num_ts; ts_nr++) { |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 540 | ts = &line->ts[ts_nr]; |
| 541 | e1ts_dump_vty(vty, ts); |
| 542 | } |
| 543 | return CMD_SUCCESS; |
| 544 | } |
| 545 | return CMD_SUCCESS; |
| 546 | } |
| 547 | |
| 548 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 549 | struct cmd_node e1inp_node = { |
Harald Welte | cc2241b | 2011-07-19 16:06:06 +0200 | [diff] [blame] | 550 | L_E1INP_NODE, |
Jacob Erlbeck | 1c9dcc1 | 2013-11-11 14:13:13 +0100 | [diff] [blame] | 551 | "%s(config-e1_input)# ", |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 552 | 1, |
| 553 | }; |
| 554 | |
| 555 | int e1inp_vty_init(void) |
| 556 | { |
Vadim Yanitskiy | 82ef2a2 | 2020-10-04 16:15:52 +0700 | [diff] [blame] | 557 | install_lib_element(CONFIG_NODE, &cfg_e1inp_cmd); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 558 | install_node(&e1inp_node, e1inp_config_write); |
Jacob Erlbeck | 37f0695 | 2013-11-11 14:13:12 +0100 | [diff] [blame] | 559 | |
Keith | 2672a2a | 2020-11-12 06:59:37 +0100 | [diff] [blame] | 560 | install_lib_element(L_E1INP_NODE, &cfg_e1line_pcap_cmd); |
| 561 | install_lib_element(L_E1INP_NODE, &cfg_e1line_no_pcap_cmd); |
| 562 | install_lib_element(L_E1INP_NODE, &cfg_e1_pcap_deprec_cmd); |
| 563 | install_lib_element(L_E1INP_NODE, &cfg_e1_pcap_deprec_no_cmd); |
Sylvain Munaut | eb55e2f | 2020-05-08 09:42:51 +0200 | [diff] [blame] | 564 | |
Vadim Yanitskiy | 82ef2a2 | 2020-10-04 16:15:52 +0700 | [diff] [blame] | 565 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_driver_cmd); |
| 566 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_port_cmd); |
| 567 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_socket_cmd); |
| 568 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_name_cmd); |
| 569 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_keepalive_cmd); |
| 570 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_keepalive_params_cmd); |
| 571 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_no_keepalive_cmd); |
| 572 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_ipa_keepalive_cmd); |
| 573 | install_lib_element(L_E1INP_NODE, &cfg_e1_line_no_ipa_keepalive_cmd); |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 574 | |
Vadim Yanitskiy | 82ef2a2 | 2020-10-04 16:15:52 +0700 | [diff] [blame] | 575 | install_lib_element(L_E1INP_NODE, &cfg_ipa_bind_cmd); |
Harald Welte | 4154755 | 2021-04-28 18:23:21 +0200 | [diff] [blame] | 576 | install_lib_element(L_E1INP_NODE, &cfg_ipa_dscp_cmd); |
| 577 | install_lib_element(L_E1INP_NODE, &cfg_ipa_priority_cmd); |
Neels Hofmeyr | 0db1d43 | 2016-02-22 13:29:09 +0100 | [diff] [blame] | 578 | |
Vadim Yanitskiy | 82ef2a2 | 2020-10-04 16:15:52 +0700 | [diff] [blame] | 579 | install_lib_element_ve(&show_e1drv_cmd); |
| 580 | install_lib_element_ve(&show_e1line_cmd); |
| 581 | install_lib_element_ve(&show_e1ts_cmd); |
Harald Welte | 6e37c59 | 2011-08-11 12:43:31 +0200 | [diff] [blame] | 582 | |
Pablo Neira Ayuso | 262aee8 | 2011-07-05 19:17:08 +0200 | [diff] [blame] | 583 | return 0; |
| 584 | } |