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 */ |
Pau Espin Pedrol | 10d9f8d | 2023-06-26 18:49:33 +0200 | [diff] [blame] | 326 | if (mgcp->actual.keepalive.req_interval_sec > 0) { |
| 327 | /* Re-schedule: */ |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 328 | osmo_timer_schedule(&mgcp->keepalive_tx_timer, mgcp->actual.keepalive.req_interval_sec, 0); |
Pau Espin Pedrol | 10d9f8d | 2023-06-26 18:49:33 +0200 | [diff] [blame] | 329 | } else { |
| 330 | if (osmo_timer_pending(&mgcp->keepalive_tx_timer)) |
| 331 | osmo_timer_del(&mgcp->keepalive_tx_timer); |
| 332 | /* Assume link is UP by default, so that this MGW can be selected: */ |
| 333 | mgcp->conn_up = true; |
| 334 | } |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 335 | } /* else: wait until connect() to do first scheduling */ |
| 336 | |
| 337 | return CMD_SUCCESS; |
| 338 | } |
| 339 | |
| 340 | DEFUN(cfg_mgw_mgw_keepalive_req_endpoint, |
| 341 | cfg_mgw_mgw_keepalive_req_endpoint_cmd, |
| 342 | "keepalive request-endpoint NAME", |
| 343 | "Monitor if the MGCP link against MGW is still usable\n" |
| 344 | "Use a given endpoint name when sending an MGCP command to the MGW for keepalive purposes\n" |
| 345 | "The name of the endpoint to use\n") |
| 346 | { |
| 347 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 348 | struct mgcp_client *mgcp = get_mgcp_client(vty); |
| 349 | |
| 350 | OSMO_STRLCPY_ARRAY(conf->keepalive.req_endpoint_name, argv[0]); |
| 351 | |
| 352 | if (!mgcp) |
| 353 | return CMD_SUCCESS; |
| 354 | |
| 355 | /* If client already exists, apply the change immediately if possible: */ |
| 356 | OSMO_STRLCPY_ARRAY(mgcp->actual.keepalive.req_endpoint_name, argv[0]); |
| 357 | |
| 358 | return CMD_SUCCESS; |
| 359 | } |
| 360 | |
| 361 | DEFUN(cfg_mgw_mgw_keepalive_timeout, |
| 362 | cfg_mgw_mgw_keepalive_timeout_cmd, |
| 363 | "keepalive timeout <0-4294967295>", |
| 364 | "Monitor if the MGCP link against MGW is still usable\n" |
| 365 | "Consider the link to the MGW to be down after time without receiving any message from it\n" |
| 366 | "The timeout (s), 0 to disable\n") |
| 367 | { |
| 368 | struct mgcp_client_conf *conf = get_mgcp_client_config(vty); |
| 369 | struct mgcp_client *mgcp = get_mgcp_client(vty); |
| 370 | |
| 371 | conf->keepalive.timeout_sec = atoi(argv[0]); |
| 372 | |
| 373 | if (!mgcp) |
| 374 | return CMD_SUCCESS; |
| 375 | |
| 376 | /* If client already exists, apply the change immediately if possible: */ |
| 377 | mgcp->actual.keepalive.timeout_sec = atoi(argv[0]); |
| 378 | if (mgcp->wq.bfd.fd != -1) { /* UDP MGCP socket connected */ |
Pau Espin Pedrol | 10d9f8d | 2023-06-26 18:49:33 +0200 | [diff] [blame] | 379 | if (mgcp->actual.keepalive.timeout_sec > 0) { |
| 380 | /* Re-schedule: */ |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 381 | osmo_timer_schedule(&mgcp->keepalive_rx_timer, mgcp->actual.keepalive.timeout_sec, 0); |
Pau Espin Pedrol | 10d9f8d | 2023-06-26 18:49:33 +0200 | [diff] [blame] | 382 | } else { |
| 383 | if (osmo_timer_pending(&mgcp->keepalive_rx_timer)) |
| 384 | osmo_timer_del(&mgcp->keepalive_rx_timer); |
| 385 | /* Assume link is UP by default, so that this MGW can be selected: */ |
| 386 | mgcp->conn_up = true; |
| 387 | } |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 388 | } /* else: wait until connect() to do first scheduling */ |
| 389 | |
| 390 | return CMD_SUCCESS; |
| 391 | } |
| 392 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 393 | 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] | 394 | { |
| 395 | const char *addr; |
| 396 | int port; |
Philipp Maier | 3f2c15f | 2021-07-22 11:53:07 +0200 | [diff] [blame] | 397 | struct reset_ep *reset_ep; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 398 | |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 399 | /* If caller doesn't the MGW pool API (mgcp_client_pool_vty_init was never called), |
| 400 | * then the "mgw" cmd prefix must be added since the old node always contained it. |
| 401 | */ |
| 402 | const char *mgw_prefix = global_mgcp_client_pool ? "" : "mgw "; |
| 403 | |
| 404 | if (conf->description) /* description never had "mgw" prefix even on old node: */ |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 405 | vty_out(vty, "%sdescription %s%s", indent, conf->description, VTY_NEWLINE); |
| 406 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 407 | addr = conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 408 | if (addr) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 409 | 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] | 410 | port = conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 411 | if (port >= 0) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 412 | vty_out(vty, "%s%slocal-port %u%s", indent, mgw_prefix, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 413 | (uint16_t)port, VTY_NEWLINE); |
| 414 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 415 | addr = conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 416 | if (addr) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 417 | 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] | 418 | port = conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 419 | if (port >= 0) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 420 | vty_out(vty, "%s%sremote-port %u%s", indent, mgw_prefix, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 421 | (uint16_t)port, VTY_NEWLINE); |
| 422 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 423 | if (conf->endpoint_domain_name[0]) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 424 | vty_out(vty, "%s%sendpoint-domain %s%s", indent, mgw_prefix, |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 425 | conf->endpoint_domain_name, VTY_NEWLINE); |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 426 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 427 | llist_for_each_entry(reset_ep, &conf->reset_epnames, list) |
Pau Espin Pedrol | 103e50a | 2022-10-19 17:22:46 +0200 | [diff] [blame] | 428 | 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] | 429 | |
Pau Espin Pedrol | 563386e | 2023-06-14 12:20:49 +0200 | [diff] [blame] | 430 | if (conf->keepalive.req_interval_sec != 0) |
| 431 | vty_out(vty, "%s%skeepalive request-interval %u%s", indent, mgw_prefix, |
| 432 | conf->keepalive.req_interval_sec, VTY_NEWLINE); |
| 433 | if (strncmp(conf->keepalive.req_endpoint_name, MGCP_CLIENT_KEEPALIVE_DEFAULT_ENDP, |
| 434 | sizeof(conf->keepalive.req_endpoint_name)) != 0) |
| 435 | vty_out(vty, "%s%skeepalive request-endpoint %s%s", indent, mgw_prefix, |
| 436 | conf->keepalive.req_endpoint_name, VTY_NEWLINE); |
| 437 | if (conf->keepalive.timeout_sec != 0) |
| 438 | vty_out(vty, "%s%skeepalive timeout %u%s", indent, mgw_prefix, |
| 439 | conf->keepalive.timeout_sec, VTY_NEWLINE); |
| 440 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 441 | return CMD_SUCCESS; |
| 442 | } |
| 443 | |
Philipp Maier | d6a7e17 | 2021-08-03 16:03:27 +0200 | [diff] [blame] | 444 | /*! Write out MGCP client config to VTY. |
| 445 | * \param[in] vty VTY to which we should print. |
| 446 | * \param[in] string used for indentation (e.g. " "). |
| 447 | * \returns CMD_SUCCESS on success, CMD_WARNING on error */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 448 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
| 449 | { |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 450 | /* If caller supports MGW pool API (mgcp_client_pool_vty_init was |
| 451 | * called), then skip printing any config in this node and print it when |
| 452 | * the whole 'mgw' node is printed. */ |
| 453 | if (global_mgcp_client_pool) |
| 454 | return CMD_SUCCESS; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 455 | return config_write(vty, indent, global_mgcp_client_conf); |
| 456 | } |
| 457 | |
| 458 | static void vty_init_common(void *talloc_ctx, int node) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 459 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 460 | global_mgcp_client_ctx = talloc_ctx; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 461 | |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 462 | /* deprecated 'mgw' commands ('mgw' prepended as first arg) */ |
| 463 | install_lib_element(node, &cfg_mgw_mgw_local_ip_cmd); |
| 464 | install_lib_element(node, &cfg_mgw_mgw_local_port_cmd); |
| 465 | install_lib_element(node, &cfg_mgw_mgw_remote_ip_cmd); |
| 466 | install_lib_element(node, &cfg_mgw_mgw_remote_port_cmd); |
Pau Espin Pedrol | 2172f40 | 2022-10-19 16:13:01 +0200 | [diff] [blame] | 467 | install_lib_element(node, &cfg_mgw_mgw_endpoint_range_cmd); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 468 | install_lib_element(node, &cfg_mgw_mgw_endpoint_domain_name_cmd); |
| 469 | install_lib_element(node, &cfg_mgw_mgw_reset_ep_name_cmd); |
| 470 | 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] | 471 | install_lib_element(node, &cfg_mgw_mgw_keepalive_req_interval_cmd); |
| 472 | install_lib_element(node, &cfg_mgw_mgw_keepalive_req_endpoint_cmd); |
| 473 | install_lib_element(node, &cfg_mgw_mgw_keepalive_timeout_cmd); |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 474 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 475 | osmo_fsm_vty_add_cmds(); |
| 476 | } |
| 477 | |
Philipp Maier | d6a7e17 | 2021-08-03 16:03:27 +0200 | [diff] [blame] | 478 | /*! Set up MGCP client VTY |
| 479 | * (called once at startup by the application process). |
| 480 | * \param[in] talloc_ctx talloc context to be used by the VTY for allocating memory. |
| 481 | * \param[in] node identifier of the node on which the VTY commands should be installed. |
| 482 | * \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] | 483 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf) |
| 484 | { |
| 485 | global_mgcp_client_conf = conf; |
| 486 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 487 | /* deprecated 'mgcpgw' commands */ |
Vadim Yanitskiy | 3ba4095 | 2020-10-04 16:42:04 +0700 | [diff] [blame] | 488 | install_lib_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 489 | install_lib_element(node, &cfg_mgcpgw_local_port_cmd); |
| 490 | install_lib_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 491 | install_lib_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 492 | install_lib_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 493 | install_lib_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd); |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 494 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 495 | vty_init_common(talloc_ctx, node); |
| 496 | } |
| 497 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 498 | /* 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] | 499 | static bool mgcp_client_pool_config_write_called = false; |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 500 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 501 | 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] | 502 | { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 503 | struct mgcp_client_pool *pool = global_mgcp_client_pool; |
| 504 | struct mgcp_client_pool_member *pool_member; |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 505 | unsigned int subindent_buf_len; |
| 506 | char *subindent; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 507 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 508 | if (!indent) |
| 509 | indent = pool->vty_indent ? : ""; |
| 510 | subindent_buf_len = strlen(indent) + 1 + 1; |
| 511 | subindent = talloc_zero_size(vty, subindent_buf_len); |
| 512 | |
| 513 | snprintf(subindent, subindent_buf_len, "%s ", indent); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 514 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 515 | llist_for_each_entry(pool_member, &pool->member_list, list) { |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 516 | vty_out(vty, "%smgw %u%s", indent, pool_member->nr, VTY_NEWLINE); |
| 517 | config_write(vty, subindent, &pool_member->conf); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 518 | } |
| 519 | |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 520 | /* MGW pool API is supported by user (global_mgcp_client_pool is set |
| 521 | * because mgcp_client_pool_vty_init was called). If single MGW was |
| 522 | * configured through old VTY and no mgw in the new MGW pool VTY is |
| 523 | * replacing it, then output the single MGW converted to the new MGW |
| 524 | * pool VTY. */ |
| 525 | if (llist_empty(&pool->member_list) && pool->mgcp_client_single) { |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 526 | vty_out(vty, "%smgw 0%s", indent, VTY_NEWLINE); |
| 527 | config_write(vty, subindent, global_mgcp_client_conf); |
Pau Espin Pedrol | d17a9de | 2022-10-18 12:34:20 +0200 | [diff] [blame] | 528 | } |
| 529 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 530 | talloc_free(subindent); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 531 | return CMD_SUCCESS; |
| 532 | } |
| 533 | |
Pau Espin Pedrol | 3a914e3 | 2022-10-19 17:13:20 +0200 | [diff] [blame] | 534 | /* Deprecated, used for backward compatibility with older users which didn't call |
| 535 | * mgcp_client_pool_config_write(): */ |
| 536 | static int config_write_pool(struct vty *vty) |
| 537 | { |
| 538 | if (mgcp_client_pool_config_write_called) |
| 539 | return CMD_SUCCESS; |
| 540 | |
| 541 | return _mgcp_client_pool_config_write(vty, NULL); |
| 542 | } |
| 543 | |
| 544 | /*! Write out MGCP client config to VTY. |
| 545 | * \param[in] vty VTY to which we should print. |
| 546 | * \param[in] indent string used for indentation (e.g. " "). |
| 547 | If NULL, indentation passed during mgcp_client_pool_vty_init() will be used. |
| 548 | * \returns CMD_SUCCESS on success, CMD_WARNING on error */ |
| 549 | int mgcp_client_pool_config_write(struct vty *vty, const char *indent) |
| 550 | { |
| 551 | /* Tell internal node write function that the user supports calling proper API: */ |
| 552 | mgcp_client_pool_config_write_called = true; |
| 553 | return _mgcp_client_pool_config_write(vty, indent); |
| 554 | } |
| 555 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 556 | DEFUN_ATTR(cfg_mgw, |
Philipp Maier | d55be05 | 2021-08-19 14:58:31 +0200 | [diff] [blame] | 557 | 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] | 558 | { |
| 559 | int nr = atoi(argv[0]); |
| 560 | struct mgcp_client_pool_member *pool_member; |
| 561 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 562 | 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] | 563 | if (!pool_member) { |
Pau Espin Pedrol | 6ddc79b | 2022-10-13 17:03:42 +0200 | [diff] [blame] | 564 | pool_member = mgcp_client_pool_member_alloc(global_mgcp_client_pool, nr); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 565 | OSMO_ASSERT(pool_member); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | vty->index = &pool_member->conf; |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 569 | vty->index_sub = &pool_member->conf.description; |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 570 | vty->node = global_mgcp_client_pool->vty_node->node; |
| 571 | |
| 572 | return CMD_SUCCESS; |
| 573 | } |
| 574 | |
| 575 | DEFUN_ATTR(cfg_no_mgw, |
| 576 | cfg_no_mgw_cmd, |
Philipp Maier | 74e83d3 | 2021-08-20 09:57:27 +0200 | [diff] [blame] | 577 | "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] | 578 | { |
| 579 | int nr = atoi(argv[0]); |
| 580 | struct mgcp_client_pool_member *pool_member; |
| 581 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 582 | 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] | 583 | if (!pool_member) { |
| 584 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 585 | return CMD_WARNING; |
| 586 | } |
| 587 | |
| 588 | /* Make sure that there are no ongoing calls */ |
| 589 | if (pool_member->refcount > 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 590 | vty_out(vty, "%% MGCP client (MGW %s) is still serving ongoing calls -- can't remove it now!%s", |
| 591 | mgcp_client_pool_member_name(pool_member), VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 592 | return CMD_WARNING; |
| 593 | } |
| 594 | |
Pau Espin Pedrol | 6ddc79b | 2022-10-13 17:03:42 +0200 | [diff] [blame] | 595 | mgcp_client_pool_member_free(pool_member); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 596 | |
| 597 | return CMD_SUCCESS; |
| 598 | } |
| 599 | |
| 600 | DEFUN_ATTR(mgw_reconnect, mgw_reconnect_cmd, |
| 601 | "mgw <0-255> reconnect", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 602 | 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] | 603 | { |
| 604 | int nr = atoi(argv[0]); |
| 605 | struct mgcp_client_pool_member *pool_member = NULL; |
| 606 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 607 | 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] | 608 | if (!pool_member) { |
| 609 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 610 | return CMD_WARNING; |
| 611 | } |
| 612 | |
| 613 | /* Make sure that there are no ongoing calls */ |
| 614 | if (pool_member->refcount > 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 615 | vty_out(vty, "%% MGCP client (MGW %s) is still serving ongoing calls -- can't reconnect it now!%s", |
| 616 | mgcp_client_pool_member_name(pool_member), VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 617 | return CMD_WARNING; |
| 618 | } |
| 619 | |
Pau Espin Pedrol | 35bd252 | 2022-10-13 17:26:33 +0200 | [diff] [blame] | 620 | if (mgcp_client_pool_member_reinit_client(pool_member) < 0) { |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 621 | LOGP(DLMGCP, LOGL_ERROR, "(manual) MGW %s connect failed at (%s:%u)\n", |
| 622 | mgcp_client_pool_member_name(pool_member), pool_member->conf.remote_addr, |
| 623 | pool_member->conf.remote_port); |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 624 | vty_out(vty, "%% MGCP client (MGW %s) initalization failed ('%s')%s", |
| 625 | mgcp_client_pool_member_name(pool_member), argv[0], VTY_NEWLINE); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 626 | return CMD_WARNING; |
| 627 | } |
| 628 | |
| 629 | return CMD_SUCCESS; |
| 630 | } |
| 631 | |
| 632 | DEFUN_ATTR(mgw_block, mgw_block_cmd, |
| 633 | "mgw <0-255> block", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 634 | 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] | 635 | { |
| 636 | int nr = atoi(argv[0]); |
| 637 | struct mgcp_client_pool_member *pool_member = NULL; |
| 638 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 639 | 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] | 640 | if (!pool_member) { |
| 641 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 642 | return CMD_WARNING; |
| 643 | } |
| 644 | |
| 645 | pool_member->blocked = true; |
| 646 | return CMD_SUCCESS; |
| 647 | } |
| 648 | |
| 649 | DEFUN_ATTR(mgw_unblock, mgw_unblock_cmd, |
| 650 | "mgw <0-255> unblock", |
Philipp Maier | 8f91a7f | 2021-08-19 14:55:56 +0200 | [diff] [blame] | 651 | 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] | 652 | { |
| 653 | int nr = atoi(argv[0]); |
| 654 | struct mgcp_client_pool_member *pool_member = NULL; |
| 655 | |
Pau Espin Pedrol | ff59215 | 2022-10-13 16:46:25 +0200 | [diff] [blame] | 656 | 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] | 657 | if (!pool_member) { |
| 658 | vty_out(vty, "%% no such MGCP client configured ('%s')%s", argv[0], VTY_NEWLINE); |
| 659 | return CMD_WARNING; |
| 660 | } |
| 661 | |
| 662 | pool_member->blocked = false; |
| 663 | return CMD_SUCCESS; |
| 664 | } |
| 665 | |
Pau Espin Pedrol | a6917fe | 2022-10-13 14:40:56 +0200 | [diff] [blame] | 666 | 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] | 667 | { |
| 668 | vty_out(vty, "%% MGW-Pool:%s", VTY_NEWLINE); |
| 669 | struct mgcp_client_pool_member *pool_member; |
| 670 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 671 | 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] | 672 | vty_out(vty, "%% (pool is empty, single MGCP client will be used)%s", VTY_NEWLINE); |
| 673 | return CMD_SUCCESS; |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 674 | } else if (llist_empty(&global_mgcp_client_pool->member_list)) { |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 675 | vty_out(vty, "%% (pool is empty)%s", VTY_NEWLINE); |
| 676 | return CMD_SUCCESS; |
| 677 | } |
| 678 | |
Pau Espin Pedrol | d4ad77d | 2022-10-13 16:37:12 +0200 | [diff] [blame] | 679 | 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] | 680 | const struct mgcp_client *cli = pool_member->client; |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 681 | 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] | 682 | vty_out(vty, "%% MGCP link: %s,%s%s", |
| 683 | cli && cli->wq.bfd.fd != -1 ? "connected" : "disconnected", |
| 684 | cli && cli->conn_up ? |
| 685 | ((cli->actual.keepalive.timeout_sec > 0) ? "UP" : "MAYBE") : |
| 686 | "DOWN", |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 687 | VTY_NEWLINE); |
| 688 | vty_out(vty, "%% service: %s%s", pool_member->blocked ? "blocked" : "unblocked", VTY_NEWLINE); |
| 689 | vty_out(vty, "%% ongoing calls: %u%s", pool_member->refcount, VTY_NEWLINE); |
| 690 | } |
| 691 | return CMD_SUCCESS; |
| 692 | } |
| 693 | |
| 694 | /*! Set up MGCP client VTY (pooled) |
| 695 | * (called once at startup by the application process). |
| 696 | * \param[in] parent_node identifier of the parent node on which the mgw node appears. |
| 697 | * \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] | 698 | * \param[in] indent indentation string to match the indentation in the VTY config. |
| 699 | 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] | 700 | * \param[in] pool user provided memory to store the configured MGCP client (MGW) pool. */ |
| 701 | void mgcp_client_pool_vty_init(int parent_node, int mgw_node, const char *indent, struct mgcp_client_pool *pool) |
| 702 | { |
Philipp Maier | da3a575 | 2021-08-19 14:24:14 +0200 | [diff] [blame] | 703 | /* A pool must be allocated before this function can be called */ |
| 704 | OSMO_ASSERT(pool); |
| 705 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 706 | /* Never allow this function to be called twice on the same pool */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 707 | OSMO_ASSERT(!pool->vty_node); |
| 708 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 709 | if (indent) { |
| 710 | pool->vty_indent = talloc_strdup(pool, indent); |
| 711 | OSMO_ASSERT(pool->vty_indent); |
| 712 | } |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 713 | pool->vty_node = talloc_zero(pool, struct cmd_node); |
| 714 | OSMO_ASSERT(pool->vty_node); |
| 715 | pool->vty_node->node = mgw_node; |
| 716 | pool->vty_node->vtysh = 1; |
| 717 | pool->vty_node->prompt = talloc_strdup(pool->vty_node, "%s(config-mgw)# "); |
| 718 | |
| 719 | install_lib_element(parent_node, &cfg_mgw_cmd); |
| 720 | install_lib_element(parent_node, &cfg_no_mgw_cmd); |
| 721 | |
Pau Espin Pedrol | 7881f7d | 2022-10-18 14:13:04 +0200 | [diff] [blame] | 722 | /* Note: config_write_pool is deprecated and user is expected to |
| 723 | * manually call mgcp_client_pool_config_write() when printing the VTY |
| 724 | * config */ |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 725 | install_node(pool->vty_node, config_write_pool); |
| 726 | vty_init_common(pool, mgw_node); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 727 | install_lib_element(mgw_node, &cfg_mgw_local_ip_cmd); |
| 728 | install_lib_element(mgw_node, &cfg_mgw_local_port_cmd); |
| 729 | install_lib_element(mgw_node, &cfg_mgw_remote_ip_cmd); |
| 730 | install_lib_element(mgw_node, &cfg_mgw_remote_port_cmd); |
Pau Espin Pedrol | 8c138fe | 2022-10-19 12:47:31 +0200 | [diff] [blame] | 731 | install_lib_element(mgw_node, &cfg_mgw_rtp_bts_base_port_cmd); |
| 732 | install_lib_element(mgw_node, &cfg_mgw_endpoint_domain_name_cmd); |
| 733 | install_lib_element(mgw_node, &cfg_mgw_reset_ep_name_cmd); |
| 734 | install_lib_element(mgw_node, &cfg_mgw_no_reset_ep_name_cmd); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 735 | |
Philipp Maier | df9192e | 2021-09-03 17:50:51 +0200 | [diff] [blame] | 736 | install_element(mgw_node, &cfg_description_cmd); |
| 737 | |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 738 | install_lib_element(ENABLE_NODE, &mgw_reconnect_cmd); |
| 739 | install_lib_element(ENABLE_NODE, &mgw_block_cmd); |
| 740 | install_lib_element(ENABLE_NODE, &mgw_unblock_cmd); |
| 741 | |
Pau Espin Pedrol | a6917fe | 2022-10-13 14:40:56 +0200 | [diff] [blame] | 742 | install_lib_element_ve(&mgw_show_cmd); |
Philipp Maier | 3f4a4cb | 2021-07-26 13:20:05 +0200 | [diff] [blame] | 743 | |
| 744 | global_mgcp_client_pool = pool; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 745 | } |