Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 1 | /* MGCP client interface to quagga VTY */ |
Vadim Yanitskiy | e362456 | 2023-05-18 17:22:26 +0700 | [diff] [blame] | 2 | /* (C) 2016 by sysmocom s.f.m.c. GmbH <info@sysmocom.de> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 3 | * Based on OpenBSC interface to quagga VTY (libmsc/vty_interface_layer3.c) |
| 4 | * (C) 2009 by Harald Welte <laforge@gnumonks.org> |
| 5 | * (C) 2009-2011 by Holger Hans Peter Freyther |
| 6 | * All Rights Reserved |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 16 | * GNU General Public License for more details. |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 17 | * |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | #include <inttypes.h> |
| 24 | #include <stdlib.h> |
| 25 | #include <talloc.h> |
| 26 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 27 | #include <osmocom/vty/vty.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 28 | #include <osmocom/vty/command.h> |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 29 | #include <osmocom/vty/misc.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 30 | #include <osmocom/core/utils.h> |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 31 | #include <osmocom/core/timer.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 33 | #include <osmocom/mgcp_client/mgcp_client.h> |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 34 | #include <osmocom/mgcp_client/mgcp_client_internal.h> |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 35 | #include <osmocom/mgcp_client/mgcp_client_pool_internal.h> |
Pau Espin Pedrol | 5d8b5b0 | 2022-10-13 17:52:40 +0200 | [diff] [blame] | 36 | #include <osmocom/mgcp_client/mgcp_client_pool.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 37 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 38 | #define MGW_STR MGCP_CLIENT_MGW_STR |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 39 | |
Pau Espin Pedrol | f633302 | 2022-10-13 13:20:10 +0200 | [diff] [blame] | 40 | /* Only common (non-pooled) VTY commands will use this talloc context. All |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 41 | * pooled VTY commands will use the pool (global_mgcp_client_pool) as |
| 42 | * talloc context. */ |
| 43 | static void *global_mgcp_client_ctx = NULL; |
| 44 | |
| 45 | /* MGCP Client configuration used with mgcp_client_vty_init(). (This pointer |
| 46 | * points to user provided memory, so it cannot be used as talloc context.) */ |
| 47 | static struct mgcp_client_conf *global_mgcp_client_conf = NULL; |
| 48 | |
| 49 | /* Pointer to the MGCP pool that is managed by mgcp_client_pool_vty_init() */ |
| 50 | static struct mgcp_client_pool *global_mgcp_client_pool = NULL; |
| 51 | |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 52 | static struct mgcp_client_conf *get_mgcp_client_config(struct vty *vty) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 53 | { |
| 54 | if (global_mgcp_client_pool && vty->node == global_mgcp_client_pool->vty_node->node) |
| 55 | return vty->index; |
Pau Espin Pedrol | 80dd576 | 2022-10-17 17:26:43 +0200 | [diff] [blame] | 56 | |
| 57 | /* Global single MGCP config, deprecated: */ |
| 58 | vty_out(vty, "%% MGCP commands outside of 'mgw' nodes are deprecated. " |
Harald Welte | 1a7048d | 2023-01-04 15:37:00 +0100 | [diff] [blame] | 59 | "You should consider reading the User Manual and migrating to 'mgw' node.%s", |
Pau Espin Pedrol | 80dd576 | 2022-10-17 17:26:43 +0200 | [diff] [blame] | 60 | VTY_NEWLINE); |
| 61 | |
| 62 | return global_mgcp_client_conf; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 63 | } |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 64 | |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 65 | static struct mgcp_client *get_mgcp_client(struct vty *vty) |
| 66 | { |
| 67 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 68 | struct mgcp_client_pool_member *pool_member; |
| 69 | |
| 70 | if (global_mgcp_client_pool && vty->node == global_mgcp_client_pool->vty_node->node) { |
| 71 | llist_for_each_entry(pool_member, &global_mgcp_client_pool->member_list, list) { |
| 72 | /* Find matching the conf pointer: */ |
| 73 | if (&pool_member->conf != conf) |
| 74 | continue; |
| 75 | return pool_member->client; |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | /* Global single MGCP config, deprecated: */ |
| 80 | vty_out(vty, "%% MGCP commands outside of 'mgw' nodes are deprecated. " |
| 81 | "You should consider reading the User Manual and migrating to 'mgw' node.%s", |
| 82 | VTY_NEWLINE); |
| 83 | |
| 84 | /* There's no way to obtain the struct mgcp_client in old interface, but anyway it's deprecated. */ |
| 85 | return NULL; |
| 86 | } |
| 87 | |
| 88 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 89 | DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 90 | "local-ip " VTY_IPV46_CMD, |
| 91 | "local bind to connect to MGW from\n" |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 92 | "local bind IPv4 address\n" |
| 93 | "local bind IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 94 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 95 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 96 | |
Neels Hofmeyr | c3132fd | 2018-12-19 00:30:34 +0100 | [diff] [blame] | 97 | osmo_talloc_replace_string(global_mgcp_client_ctx, |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 98 | (char **)&conf->local_addr, |
Neels Hofmeyr | c3132fd | 2018-12-19 00:30:34 +0100 | [diff] [blame] | 99 | argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 100 | return CMD_SUCCESS; |
| 101 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 102 | ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 103 | "mgcpgw local-ip A.B.C.D", |
| 104 | MGW_STR "local bind to connect to MGCP gateway with\n" |
| 105 | "local bind IP address\n") |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 106 | ALIAS_DEPRECATED(cfg_mgw_local_ip, |
| 107 | cfg_mgw_mgw_local_ip_cmd, |
| 108 | "mgw local-ip " VTY_IPV46_CMD, |
| 109 | MGW_STR "local bind to connect to MGW from\n" |
| 110 | "local bind IPv4 address\n" |
| 111 | "local bind IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 112 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 113 | DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 114 | "local-port <0-65535>", |
| 115 | "local port to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 116 | "local bind port\n") |
| 117 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 118 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 119 | |
| 120 | conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 121 | return CMD_SUCCESS; |
| 122 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 123 | ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 124 | "mgcpgw local-port <0-65535>", |
| 125 | MGW_STR "local bind to connect to MGCP gateway with\n" |
| 126 | "local bind port\n") |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 127 | ALIAS_DEPRECATED(cfg_mgw_local_port, |
| 128 | cfg_mgw_mgw_local_port_cmd, |
| 129 | "mgw local-port <0-65535>", |
| 130 | MGW_STR "local port to connect to MGW from\n" |
| 131 | "local bind port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 132 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 133 | DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 134 | "remote-ip " VTY_IPV46_CMD, |
| 135 | "remote IP address to reach the MGW at\n" |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 136 | "remote IPv4 address\n" |
| 137 | "remote IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 138 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 139 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 140 | |
Neels Hofmeyr | c3132fd | 2018-12-19 00:30:34 +0100 | [diff] [blame] | 141 | osmo_talloc_replace_string(global_mgcp_client_ctx, |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 142 | (char **)&conf->remote_addr, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 143 | return CMD_SUCCESS; |
| 144 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 145 | ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 146 | "mgcpgw remote-ip A.B.C.D", |
| 147 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 148 | "remote bind IP address\n") |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 149 | ALIAS_DEPRECATED(cfg_mgw_remote_ip, |
| 150 | cfg_mgw_mgw_remote_ip_cmd, |
| 151 | "mgw remote-ip " VTY_IPV46_CMD, |
| 152 | MGW_STR "remote IP address to reach the MGW at\n" |
| 153 | "remote IPv4 address\n" |
| 154 | "remote IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 155 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 156 | DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 157 | "remote-port <0-65535>", |
| 158 | "remote port to reach the MGW at\n" |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 159 | "remote port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 160 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 161 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 162 | |
| 163 | conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 164 | return CMD_SUCCESS; |
| 165 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 166 | ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 167 | "mgcpgw remote-port <0-65535>", |
| 168 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 169 | "remote bind port\n") |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 170 | ALIAS_DEPRECATED(cfg_mgw_remote_port, |
| 171 | cfg_mgw_mgw_remote_port_cmd, |
| 172 | "mgw remote-port <0-65535>", |
| 173 | MGW_STR "remote port to reach the MGW at\n" |
| 174 | "remote port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 175 | |
Pau Espin Pedrol | 2172f40 | 2022-10-19 16:13:01 +0200 | [diff] [blame] | 176 | DEFUN_DEPRECATED(cfg_mgw_mgw_endpoint_range, cfg_mgw_mgw_endpoint_range_cmd, |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 177 | "mgw endpoint-range <1-65534> <1-65534>", |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 178 | MGW_STR "DEPRECATED: the endpoint range cannot be defined by the client\n" |
| 179 | "-\n" "-\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 180 | { |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 181 | vty_out(vty, "Please do not use legacy config 'mgw endpoint-range'" |
| 182 | " (the range can no longer be defined by the MGCP client)%s", |
| 183 | VTY_NEWLINE); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 184 | return CMD_SUCCESS; |
| 185 | } |
Pau Espin Pedrol | 2172f40 | 2022-10-19 16:13:01 +0200 | [diff] [blame] | 186 | ALIAS_DEPRECATED(cfg_mgw_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 187 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 188 | MGW_STR "usable range of endpoint identifiers\n" |
| 189 | "set first useable endpoint identifier\n" |
| 190 | "set the last useable endpoint identifier\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 191 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 192 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 193 | #define UDP_PORT_STR "UDP Port number\n" |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 194 | DEFUN_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 195 | cfg_mgw_rtp_bts_base_port_cmd, |
| 196 | "mgw bts-base <0-65534>", |
| 197 | MGW_STR |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 198 | "DEPRECATED: there is no explicit BTS side in current osmo-mgw\n" "-\n") |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 199 | { |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 200 | vty_out(vty, "Please do not use legacy config 'mgw bts-base'" |
| 201 | " (there is no explicit BTS side in an MGW anymore)%s", |
| 202 | VTY_NEWLINE); |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 203 | return CMD_SUCCESS; |
| 204 | } |
| 205 | ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
| 206 | cfg_mgcpgw_rtp_bts_base_port_cmd, |
| 207 | "mgcpgw bts-base <0-65534>", |
| 208 | MGW_STR |
| 209 | BTS_START_STR |
| 210 | UDP_PORT_STR) |
| 211 | |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 212 | DEFUN(cfg_mgw_endpoint_domain_name, |
| 213 | cfg_mgw_endpoint_domain_name_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 214 | "endpoint-domain NAME", |
| 215 | "Set the domain name to send in MGCP messages, e.g. the part 'foo' in 'rtpbridge/*@foo'.\n" |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 216 | "Domain name, should be alphanumeric.\n") |
| 217 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 218 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 219 | |
| 220 | if (osmo_strlcpy(conf->endpoint_domain_name, argv[0], sizeof(conf->endpoint_domain_name)) |
| 221 | >= sizeof(conf->endpoint_domain_name)) { |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 222 | vty_out(vty, "%% Error: 'mgw endpoint-domain' name too long, max length is %zu: '%s'%s", |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 223 | sizeof(conf->endpoint_domain_name) - 1, argv[0], VTY_NEWLINE); |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 224 | return CMD_WARNING; |
| 225 | } |
| 226 | return CMD_SUCCESS; |
| 227 | } |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 228 | ALIAS_DEPRECATED(cfg_mgw_endpoint_domain_name, |
| 229 | cfg_mgw_mgw_endpoint_domain_name_cmd, |
| 230 | "mgw endpoint-domain NAME", |
| 231 | MGW_STR "Set the domain name to send in MGCP messages, e.g. the part 'foo' in 'rtpbridge/*@foo'.\n" |
| 232 | "Domain name, should be alphanumeric.\n") |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 233 | |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 234 | DEFUN(cfg_mgw_reset_ep_name, |
| 235 | cfg_mgw_reset_ep_name_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 236 | "reset-endpoint NAME", |
| 237 | "Add an endpoint name that should be reset (DLCX) on connect to the reset-endpoint list," |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 238 | "e.g. 'rtpbridge/*'\n" |
| 239 | "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n") |
| 240 | { |
| 241 | int rc; |
| 242 | struct reset_ep *reset_ep; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 243 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 244 | |
| 245 | /* stop when the address is already in the list */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 246 | llist_for_each_entry(reset_ep, &conf->reset_epnames, list) { |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 247 | if (strcmp(argv[0], reset_ep->name) == 0) { |
| 248 | vty_out(vty, "%% duplicate endpoint name configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 249 | return CMD_WARNING; |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | /* the domain name is not part of the actual endpoint name */ |
| 254 | if (strchr(argv[0], '@')) { |
| 255 | vty_out(vty, "%% the endpoint name must be given without domain name ('%s')%s", |
| 256 | argv[0], VTY_NEWLINE); |
| 257 | return CMD_WARNING; |
| 258 | } |
| 259 | |
| 260 | reset_ep = talloc_zero(global_mgcp_client_ctx, struct reset_ep); |
| 261 | OSMO_ASSERT(reset_ep); |
| 262 | |
| 263 | rc = osmo_strlcpy(reset_ep->name, argv[0], sizeof(reset_ep->name)); |
| 264 | if (rc >= sizeof(reset_ep->name)) { |
| 265 | vty_out(vty, "%% Error: 'mgw reset-endpoint' name too long, max length is %zu: '%s'%s", |
| 266 | sizeof(reset_ep->name) - 1, argv[0], VTY_NEWLINE); |
| 267 | talloc_free(reset_ep); |
| 268 | return CMD_WARNING; |
| 269 | } |
| 270 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 271 | llist_add_tail(&reset_ep->list, &conf->reset_epnames); |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 272 | |
| 273 | return CMD_SUCCESS; |
| 274 | } |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 275 | ALIAS_DEPRECATED(cfg_mgw_reset_ep_name, |
| 276 | cfg_mgw_mgw_reset_ep_name_cmd, |
| 277 | "mgw reset-endpoint NAME", |
| 278 | MGW_STR "Add an endpoint name that should be reset (DLCX) on connect to the reset-endpoint list," |
| 279 | "e.g. 'rtpbridge/*'\n" |
| 280 | "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n") |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 281 | |
| 282 | DEFUN(cfg_mgw_no_reset_ep_name, |
| 283 | cfg_mgw_no_reset_ep_name_cmd, |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 284 | "no reset-endpoint NAME", |
| 285 | NO_STR "remove an endpoint name from the reset-endpoint list, e.g. 'rtpbridge/*'\n" |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 286 | "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n") |
| 287 | { |
| 288 | struct reset_ep *reset_ep; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 289 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 290 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 291 | llist_for_each_entry(reset_ep, &conf->reset_epnames, list) { |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 292 | if (strcmp(argv[0], reset_ep->name) == 0) { |
| 293 | llist_del(&reset_ep->list); |
| 294 | talloc_free(reset_ep); |
| 295 | return CMD_SUCCESS; |
| 296 | } |
| 297 | } |
| 298 | |
| 299 | vty_out(vty, "%% no such endpoint name configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 300 | return CMD_WARNING; |
| 301 | } |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 302 | ALIAS_DEPRECATED(cfg_mgw_no_reset_ep_name, |
| 303 | cfg_mgw_mgw_no_reset_ep_name_cmd, |
| 304 | "no mgw reset-endpoint NAME", |
| 305 | NO_STR MGW_STR "remove an endpoint name from the reset-endpoint list, e.g. 'rtpbridge/*'\n" |
| 306 | "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n") |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 307 | |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 308 | DEFUN(cfg_mgw_mgw_keepalive_req_interval, |
| 309 | cfg_mgw_mgw_keepalive_req_interval_cmd, |
| 310 | "keepalive request-interval <0-4294967295>", |
| 311 | "Monitor if the MGCP link against MGW is still usable\n" |
| 312 | "Send an MGCP command to the MGW at given interval if no other commands are sent\n" |
| 313 | "The interval at which send MGCP commands (s), 0 to disable\n") |
| 314 | { |
| 315 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 316 | struct mgcp_client *mgcp = get_mgcp_client(vty); |
| 317 | |
| 318 | conf->keepalive.req_interval_sec = atoi(argv[0]); |
| 319 | |
| 320 | if (!mgcp) |
| 321 | return CMD_SUCCESS; |
| 322 | |
| 323 | /* If client already exists, apply the change immediately if possible: */ |
| 324 | mgcp->actual.keepalive.req_interval_sec = atoi(argv[0]); |
| 325 | if (mgcp->wq.bfd.fd != -1) { /* UDP MGCP socket connected */ |
| 326 | if (mgcp->actual.keepalive.req_interval_sec > 0) /* Re-schedule: */ |
| 327 | osmo_timer_schedule(&mgcp->keepalive_tx_timer, mgcp->actual.keepalive.req_interval_sec, 0); |
| 328 | else if (osmo_timer_pending(&mgcp->keepalive_tx_timer)) |
| 329 | osmo_timer_del(&mgcp->keepalive_tx_timer); |
| 330 | } /* else: wait until connect() to do first scheduling */ |
| 331 | |
| 332 | return CMD_SUCCESS; |
| 333 | } |
| 334 | |
| 335 | DEFUN(cfg_mgw_mgw_keepalive_req_endpoint, |
| 336 | cfg_mgw_mgw_keepalive_req_endpoint_cmd, |
| 337 | "keepalive request-endpoint NAME", |
| 338 | "Monitor if the MGCP link against MGW is still usable\n" |
| 339 | "Use a given endpoint name when sending an MGCP command to the MGW for keepalive purposes\n" |
| 340 | "The name of the endpoint to use\n") |
| 341 | { |
| 342 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 343 | struct mgcp_client *mgcp = get_mgcp_client(vty); |
| 344 | |
| 345 | OSMO_STRLCPY_ARRAY(conf->keepalive.req_endpoint_name, argv[0]); |
| 346 | |
| 347 | if (!mgcp) |
| 348 | return CMD_SUCCESS; |
| 349 | |
| 350 | /* If client already exists, apply the change immediately if possible: */ |
| 351 | OSMO_STRLCPY_ARRAY(mgcp->actual.keepalive.req_endpoint_name, argv[0]); |
| 352 | |
| 353 | return CMD_SUCCESS; |
| 354 | } |
| 355 | |
| 356 | DEFUN(cfg_mgw_mgw_keepalive_timeout, |
| 357 | cfg_mgw_mgw_keepalive_timeout_cmd, |
| 358 | "keepalive timeout <0-4294967295>", |
| 359 | "Monitor if the MGCP link against MGW is still usable\n" |
| 360 | "Consider the link to the MGW to be down after time without receiving any message from it\n" |
| 361 | "The timeout (s), 0 to disable\n") |
| 362 | { |
| 363 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 364 | struct mgcp_client *mgcp = get_mgcp_client(vty); |
| 365 | |
| 366 | conf->keepalive.timeout_sec = atoi(argv[0]); |
| 367 | |
| 368 | if (!mgcp) |
| 369 | return CMD_SUCCESS; |
| 370 | |
| 371 | /* If client already exists, apply the change immediately if possible: */ |
| 372 | mgcp->actual.keepalive.timeout_sec = atoi(argv[0]); |
| 373 | if (mgcp->wq.bfd.fd != -1) { /* UDP MGCP socket connected */ |
| 374 | if (mgcp->actual.keepalive.timeout_sec > 0) /* Re-schedule: */ |
| 375 | osmo_timer_schedule(&mgcp->keepalive_rx_timer, mgcp->actual.keepalive.timeout_sec, 0); |
| 376 | else if (osmo_timer_pending(&mgcp->keepalive_rx_timer)) |
| 377 | osmo_timer_del(&mgcp->keepalive_rx_timer); |
| 378 | } /* else: wait until connect() to do first scheduling */ |
| 379 | |
| 380 | return CMD_SUCCESS; |
| 381 | } |
| 382 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 383 | static int config_write(struct vty *vty, const char *indent, struct mgcp_client_conf *conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 384 | { |
| 385 | const char *addr; |
| 386 | int port; |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 387 | struct reset_ep *reset_ep; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 388 | |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 389 | /* If caller doesn't the MGW pool API (mgcp_client_pool_vty_init was never called), |
| 390 | * then the "mgw" cmd prefix must be added since the old node always contained it. |
| 391 | */ |
| 392 | const char *mgw_prefix = global_mgcp_client_pool ? "" : "mgw "; |
| 393 | |
| 394 | if (conf->description) /* description never had "mgw" prefix even on old node: */ |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 395 | vty_out(vty, "%sdescription %s%s", indent, conf->description, VTY_NEWLINE); |
| 396 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 397 | addr = conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 398 | if (addr) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 399 | vty_out(vty, "%s%slocal-ip %s%s", indent, mgw_prefix, addr, VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 400 | port = conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 401 | if (port >= 0) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 402 | vty_out(vty, "%s%slocal-port %u%s", indent, mgw_prefix, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 403 | (uint16_t)port, VTY_NEWLINE); |
| 404 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 405 | addr = conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 406 | if (addr) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 407 | vty_out(vty, "%s%sremote-ip %s%s", indent, mgw_prefix, addr, VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 408 | port = conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 409 | if (port >= 0) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 410 | vty_out(vty, "%s%sremote-port %u%s", indent, mgw_prefix, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 411 | (uint16_t)port, VTY_NEWLINE); |
| 412 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 413 | if (conf->endpoint_domain_name[0]) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 414 | vty_out(vty, "%s%sendpoint-domain %s%s", indent, mgw_prefix, |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 415 | conf->endpoint_domain_name, VTY_NEWLINE); |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 416 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 417 | llist_for_each_entry(reset_ep, &conf->reset_epnames, list) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 418 | vty_out(vty, "%s%sreset-endpoint %s%s", indent, mgw_prefix, reset_ep->name, VTY_NEWLINE); |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 419 | |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 420 | if (conf->keepalive.req_interval_sec != 0) |
| 421 | vty_out(vty, "%s%skeepalive request-interval %u%s", indent, mgw_prefix, |
| 422 | conf->keepalive.req_interval_sec, VTY_NEWLINE); |
| 423 | if (strncmp(conf->keepalive.req_endpoint_name, MGCP_CLIENT_KEEPALIVE_DEFAULT_ENDP, |
| 424 | sizeof(conf->keepalive.req_endpoint_name)) != 0) |
| 425 | vty_out(vty, "%s%skeepalive request-endpoint %s%s", indent, mgw_prefix, |
| 426 | conf->keepalive.req_endpoint_name, VTY_NEWLINE); |
| 427 | if (conf->keepalive.timeout_sec != 0) |
| 428 | vty_out(vty, "%s%skeepalive timeout %u%s", indent, mgw_prefix, |
| 429 | conf->keepalive.timeout_sec, VTY_NEWLINE); |
| 430 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 431 | return CMD_SUCCESS; |
| 432 | } |
| 433 | |
Philipp Maier | d6a7e17 | 2021-08-03 16:03:27 +0200 | [diff] [blame] | 434 | /*! Write out MGCP client config to VTY. |
| 435 | * \param[in] vty VTY to which we should print. |
| 436 | * \param[in] string used for indentation (e.g. " "). |
| 437 | * \returns CMD_SUCCESS on success, CMD_WARNING on error */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 438 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
| 439 | { |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 440 | /* If caller supports MGW pool API (mgcp_client_pool_vty_init was |
| 441 | * called), then skip printing any config in this node and print it when |
| 442 | * the whole 'mgw' node is printed. */ |
| 443 | if (global_mgcp_client_pool) |
| 444 | return CMD_SUCCESS; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 445 | return config_write(vty, indent, global_mgcp_client_conf); |
| 446 | } |
| 447 | |
| 448 | static void vty_init_common(void *talloc_ctx, int node) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 449 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 450 | global_mgcp_client_ctx = talloc_ctx; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 451 | |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 452 | /* deprecated 'mgw' commands ('mgw' prepended as first arg) */ |
| 453 | install_lib_element(node, &cfg_mgw_mgw_local_ip_cmd); |
| 454 | install_lib_element(node, &cfg_mgw_mgw_local_port_cmd); |
| 455 | install_lib_element(node, &cfg_mgw_mgw_remote_ip_cmd); |
| 456 | install_lib_element(node, &cfg_mgw_mgw_remote_port_cmd); |
Pau Espin Pedrol | 2172f40 | 2022-10-19 16:13:01 +0200 | [diff] [blame] | 457 | install_lib_element(node, &cfg_mgw_mgw_endpoint_range_cmd); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 458 | install_lib_element(node, &cfg_mgw_mgw_endpoint_domain_name_cmd); |
| 459 | install_lib_element(node, &cfg_mgw_mgw_reset_ep_name_cmd); |
| 460 | install_lib_element(node, &cfg_mgw_mgw_no_reset_ep_name_cmd); |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 461 | install_lib_element(node, &cfg_mgw_mgw_keepalive_req_interval_cmd); |
| 462 | install_lib_element(node, &cfg_mgw_mgw_keepalive_req_endpoint_cmd); |
| 463 | install_lib_element(node, &cfg_mgw_mgw_keepalive_timeout_cmd); |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 464 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 465 | osmo_fsm_vty_add_cmds(); |
| 466 | } |
| 467 | |
Philipp Maier | d6a7e17 | 2021-08-03 16:03:27 +0200 | [diff] [blame] | 468 | /*! Set up MGCP client VTY |
| 469 | * (called once at startup by the application process). |
| 470 | * \param[in] talloc_ctx talloc context to be used by the VTY for allocating memory. |
| 471 | * \param[in] node identifier of the node on which the VTY commands should be installed. |
| 472 | * \param[in] conf user provided memory to to store the MGCP client configuration data. */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 473 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf) |
| 474 | { |
| 475 | global_mgcp_client_conf = conf; |
| 476 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 477 | /* deprecated 'mgcpgw' commands */ |
Vadim Yanitskiy | 3ba4095 | 2020-10-04 16:42:04 +0700 | [diff] [blame] | 478 | install_lib_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 479 | install_lib_element(node, &cfg_mgcpgw_local_port_cmd); |
| 480 | install_lib_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 481 | install_lib_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 482 | install_lib_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 483 | install_lib_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd); |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 484 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 485 | vty_init_common(talloc_ctx, node); |
| 486 | } |
| 487 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 488 | /* Mark whether user called mgcp_client_pool_config_write() and hence support new API */ |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 489 | static bool mgcp_client_pool_config_write_called = false; |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 490 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 491 | static int _mgcp_client_pool_config_write(struct vty *vty, const char *indent) |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 492 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 493 | struct mgcp_client_pool *pool = global_mgcp_client_pool; |
| 494 | struct mgcp_client_pool_member *pool_member; |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 495 | unsigned int subindent_buf_len; |
| 496 | char *subindent; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 497 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 498 | if (!indent) |
| 499 | indent = pool->vty_indent ? : ""; |
| 500 | subindent_buf_len = strlen(indent) + 1 + 1; |
| 501 | subindent = talloc_zero_size(vty, subindent_buf_len); |
| 502 | |
| 503 | snprintf(subindent, subindent_buf_len, "%s ", indent); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 504 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 505 | llist_for_each_entry(pool_member, &pool->member_list, list) { |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 506 | vty_out(vty, "%smgw %u%s", indent, pool_member->nr, VTY_NEWLINE); |
| 507 | config_write(vty, subindent, &pool_member->conf); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 508 | } |
| 509 | |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 510 | /* MGW pool API is supported by user (global_mgcp_client_pool is set |
| 511 | * because mgcp_client_pool_vty_init was called). If single MGW was |
| 512 | * configured through old VTY and no mgw in the new MGW pool VTY is |
| 513 | * replacing it, then output the single MGW converted to the new MGW |
| 514 | * pool VTY. */ |
| 515 | if (llist_empty(&pool->member_list) && pool->mgcp_client_single) { |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 516 | vty_out(vty, "%smgw 0%s", indent, VTY_NEWLINE); |
| 517 | config_write(vty, subindent, global_mgcp_client_conf); |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 520 | talloc_free(subindent); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 521 | return CMD_SUCCESS; |
| 522 | } |
| 523 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 524 | /* Deprecated, used for backward compatibility with older users which didn't call |
| 525 | * mgcp_client_pool_config_write(): */ |
| 526 | static int config_write_pool(struct vty *vty) |
| 527 | { |
| 528 | if (mgcp_client_pool_config_write_called) |
| 529 | return CMD_SUCCESS; |
| 530 | |
| 531 | return _mgcp_client_pool_config_write(vty, NULL); |
| 532 | } |
| 533 | |
| 534 | /*! Write out MGCP client config to VTY. |
| 535 | * \param[in] vty VTY to which we should print. |
| 536 | * \param[in] indent string used for indentation (e.g. " "). |
| 537 | If NULL, indentation passed during mgcp_client_pool_vty_init() will be used. |
| 538 | * \returns CMD_SUCCESS on success, CMD_WARNING on error */ |
| 539 | int mgcp_client_pool_config_write(struct vty *vty, const char *indent) |
| 540 | { |
| 541 | /* Tell internal node write function that the user supports calling proper API: */ |
| 542 | mgcp_client_pool_config_write_called = true; |
| 543 | return _mgcp_client_pool_config_write(vty, indent); |
| 544 | } |
| 545 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 546 | DEFUN_ATTR(cfg_mgw, |
Philipp Maier | d55be05 | 2021-08-19 14:58:31 +0200 | [diff] [blame] | 547 | cfg_mgw_cmd, "mgw <0-255>", "Select a MGCP client config to setup\n" "reference number\n", CMD_ATTR_IMMEDIATE) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 548 | { |
| 549 | int nr = atoi(argv[0]); |
| 550 | struct mgcp_client_pool_member *pool_member; |
| 551 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 552 | pool_member = mgcp_client_pool_find_member_by_nr(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 553 | if (!pool_member) { |
Pau Espin Pedrol | 6ddc79b | 2022-10-13 17:03:42 +0200 | [diff] [blame] | 554 | pool_member = mgcp_client_pool_member_alloc(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 555 | OSMO_ASSERT(pool_member); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | vty->index = &pool_member->conf; |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 559 | vty->index_sub = &pool_member->conf.description; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 560 | vty->node = global_mgcp_client_pool->vty_node->node; |
| 561 | |
| 562 | return CMD_SUCCESS; |
| 563 | } |
| 564 | |
| 565 | DEFUN_ATTR(cfg_no_mgw, |
| 566 | cfg_no_mgw_cmd, |
Philipp Maier | 74e83d3 | 2021-08-20 09:57:27 +0200 | [diff] [blame] | 567 | "no mgw <0-255>", NO_STR "Select a MGCP client config to remove\n" "reference number\n", CMD_ATTR_IMMEDIATE) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 568 | { |
| 569 | int nr = atoi(argv[0]); |
| 570 | struct mgcp_client_pool_member *pool_member; |
| 571 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 572 | pool_member = mgcp_client_pool_find_member_by_nr(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 573 | if (!pool_member) { |
| 574 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 575 | return CMD_WARNING; |
| 576 | } |
| 577 | |
| 578 | /* Make sure that there are no ongoing calls */ |
| 579 | if (pool_member->refcount > 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 580 | vty_out(vty, "%% MGCP client (MGW %s) is still serving ongoing calls -- can't remove it now!%s", |
| 581 | mgcp_client_pool_member_name(pool_member), VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 582 | return CMD_WARNING; |
| 583 | } |
| 584 | |
Pau Espin Pedrol | 6ddc79b | 2022-10-13 17:03:42 +0200 | [diff] [blame] | 585 | mgcp_client_pool_member_free(pool_member); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 586 | |
| 587 | return CMD_SUCCESS; |
| 588 | } |
| 589 | |
| 590 | DEFUN_ATTR(mgw_reconnect, mgw_reconnect_cmd, |
| 591 | "mgw <0-255> reconnect", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 592 | MGW_STR "reference number\n" "reconfigure and reconnect MGCP client\n", CMD_ATTR_IMMEDIATE) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 593 | { |
| 594 | int nr = atoi(argv[0]); |
| 595 | struct mgcp_client_pool_member *pool_member = NULL; |
| 596 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 597 | pool_member = mgcp_client_pool_find_member_by_nr(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 598 | if (!pool_member) { |
| 599 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 600 | return CMD_WARNING; |
| 601 | } |
| 602 | |
| 603 | /* Make sure that there are no ongoing calls */ |
| 604 | if (pool_member->refcount > 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 605 | vty_out(vty, "%% MGCP client (MGW %s) is still serving ongoing calls -- can't reconnect it now!%s", |
| 606 | mgcp_client_pool_member_name(pool_member), VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 607 | return CMD_WARNING; |
| 608 | } |
| 609 | |
Pau Espin Pedrol | 35bd252 | 2022-10-13 17:26:33 +0200 | [diff] [blame] | 610 | if (mgcp_client_pool_member_reinit_client(pool_member) < 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 611 | LOGP(DLMGCP, LOGL_ERROR, "(manual) MGW %s connect failed at (%s:%u)\n", |
| 612 | mgcp_client_pool_member_name(pool_member), pool_member->conf.remote_addr, |
| 613 | pool_member->conf.remote_port); |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 614 | vty_out(vty, "%% MGCP client (MGW %s) initalization failed ('%s')%s", |
| 615 | mgcp_client_pool_member_name(pool_member), argv[0], VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 616 | return CMD_WARNING; |
| 617 | } |
| 618 | |
| 619 | return CMD_SUCCESS; |
| 620 | } |
| 621 | |
| 622 | DEFUN_ATTR(mgw_block, mgw_block_cmd, |
| 623 | "mgw <0-255> block", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 624 | MGW_STR "reference number\n" "block MGCP client so that it won't be used for new calls\n", CMD_ATTR_IMMEDIATE) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 625 | { |
| 626 | int nr = atoi(argv[0]); |
| 627 | struct mgcp_client_pool_member *pool_member = NULL; |
| 628 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 629 | pool_member = mgcp_client_pool_find_member_by_nr(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 630 | if (!pool_member) { |
| 631 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 632 | return CMD_WARNING; |
| 633 | } |
| 634 | |
| 635 | pool_member->blocked = true; |
| 636 | return CMD_SUCCESS; |
| 637 | } |
| 638 | |
| 639 | DEFUN_ATTR(mgw_unblock, mgw_unblock_cmd, |
| 640 | "mgw <0-255> unblock", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 641 | MGW_STR "reference number\n" "unblock MGCP client so that it will be available for new calls\n", CMD_ATTR_IMMEDIATE) |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 642 | { |
| 643 | int nr = atoi(argv[0]); |
| 644 | struct mgcp_client_pool_member *pool_member = NULL; |
| 645 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 646 | pool_member = mgcp_client_pool_find_member_by_nr(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 647 | if (!pool_member) { |
| 648 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 649 | return CMD_WARNING; |
| 650 | } |
| 651 | |
| 652 | pool_member->blocked = false; |
| 653 | return CMD_SUCCESS; |
| 654 | } |
| 655 | |
Pau Espin Pedrol | a6917fe | 2022-10-13 14:40:56 +0200 | [diff] [blame] | 656 | DEFUN(mgw_show, mgw_show_cmd, "show mgw-pool", SHOW_STR "Display information about the MGW-Pool\n") |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 657 | { |
| 658 | vty_out(vty, "%% MGW-Pool:%s", VTY_NEWLINE); |
| 659 | struct mgcp_client_pool_member *pool_member; |
| 660 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 661 | if (llist_empty(&global_mgcp_client_pool->member_list) && global_mgcp_client_pool->mgcp_client_single) { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 662 | vty_out(vty, "%% (pool is empty, single MGCP client will be used)%s", VTY_NEWLINE); |
| 663 | return CMD_SUCCESS; |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 664 | } else if (llist_empty(&global_mgcp_client_pool->member_list)) { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 665 | vty_out(vty, "%% (pool is empty)%s", VTY_NEWLINE); |
| 666 | return CMD_SUCCESS; |
| 667 | } |
| 668 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 669 | llist_for_each_entry(pool_member, &global_mgcp_client_pool->member_list, list) { |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 670 | const struct mgcp_client *cli = pool_member->client; |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 671 | vty_out(vty, "%% MGW %s%s", mgcp_client_pool_member_name(pool_member), VTY_NEWLINE); |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 672 | vty_out(vty, "%% MGCP link: %s,%s%s", |
| 673 | cli && cli->wq.bfd.fd != -1 ? "connected" : "disconnected", |
| 674 | cli && cli->conn_up ? |
| 675 | ((cli->actual.keepalive.timeout_sec > 0) ? "UP" : "MAYBE") : |
| 676 | "DOWN", |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 677 | VTY_NEWLINE); |
| 678 | vty_out(vty, "%% service: %s%s", pool_member->blocked ? "blocked" : "unblocked", VTY_NEWLINE); |
| 679 | vty_out(vty, "%% ongoing calls: %u%s", pool_member->refcount, VTY_NEWLINE); |
| 680 | } |
| 681 | return CMD_SUCCESS; |
| 682 | } |
| 683 | |
| 684 | /*! Set up MGCP client VTY (pooled) |
| 685 | * (called once at startup by the application process). |
| 686 | * \param[in] parent_node identifier of the parent node on which the mgw node appears. |
| 687 | * \param[in] mgw_node identifier that should be used with the newly installed MGW node. |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 688 | * \param[in] indent indentation string to match the indentation in the VTY config. |
| 689 | If NULL, it must be passed explicitly each time mgcp_client_pool_config_write() is called. |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 690 | * \param[in] pool user provided memory to store the configured MGCP client (MGW) pool. */ |
| 691 | void mgcp_client_pool_vty_init(int parent_node, int mgw_node, const char *indent, struct mgcp_client_pool *pool) |
| 692 | { |
Philipp Maier | da3a575 | 2021-08-19 14:24:14 +0200 | [diff] [blame] | 693 | /* A pool must be allocated before this function can be called */ |
| 694 | OSMO_ASSERT(pool); |
| 695 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 696 | /* Never allow this function to be called twice on the same pool */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 697 | OSMO_ASSERT(!pool->vty_node); |
| 698 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 699 | if (indent) { |
| 700 | pool->vty_indent = talloc_strdup(pool, indent); |
| 701 | OSMO_ASSERT(pool->vty_indent); |
| 702 | } |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 703 | pool->vty_node = talloc_zero(pool, struct cmd_node); |
| 704 | OSMO_ASSERT(pool->vty_node); |
| 705 | pool->vty_node->node = mgw_node; |
| 706 | pool->vty_node->vtysh = 1; |
| 707 | pool->vty_node->prompt = talloc_strdup(pool->vty_node, "%s(config-mgw)# "); |
| 708 | |
| 709 | install_lib_element(parent_node, &cfg_mgw_cmd); |
| 710 | install_lib_element(parent_node, &cfg_no_mgw_cmd); |
| 711 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 712 | /* Note: config_write_pool is deprecated and user is expected to |
| 713 | * manually call mgcp_client_pool_config_write() when printing the VTY |
| 714 | * config */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 715 | install_node(pool->vty_node, config_write_pool); |
| 716 | vty_init_common(pool, mgw_node); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 717 | install_lib_element(mgw_node, &cfg_mgw_local_ip_cmd); |
| 718 | install_lib_element(mgw_node, &cfg_mgw_local_port_cmd); |
| 719 | install_lib_element(mgw_node, &cfg_mgw_remote_ip_cmd); |
| 720 | install_lib_element(mgw_node, &cfg_mgw_remote_port_cmd); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 721 | install_lib_element(mgw_node, &cfg_mgw_rtp_bts_base_port_cmd); |
| 722 | install_lib_element(mgw_node, &cfg_mgw_endpoint_domain_name_cmd); |
| 723 | install_lib_element(mgw_node, &cfg_mgw_reset_ep_name_cmd); |
| 724 | install_lib_element(mgw_node, &cfg_mgw_no_reset_ep_name_cmd); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 725 | |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 726 | install_element(mgw_node, &cfg_description_cmd); |
| 727 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 728 | install_lib_element(ENABLE_NODE, &mgw_reconnect_cmd); |
| 729 | install_lib_element(ENABLE_NODE, &mgw_block_cmd); |
| 730 | install_lib_element(ENABLE_NODE, &mgw_unblock_cmd); |
| 731 | |
Pau Espin Pedrol | a6917fe | 2022-10-13 14:40:56 +0200 | [diff] [blame] | 732 | install_lib_element_ve(&mgw_show_cmd); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 733 | |
| 734 | global_mgcp_client_pool = pool; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 735 | } |