Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 1 | /* MGCP client interface to quagga VTY */ |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 2 | /* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de> |
| 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 | |
| 27 | #include <osmocom/vty/command.h> |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 28 | #include <osmocom/vty/misc.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 29 | #include <osmocom/core/utils.h> |
| 30 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 31 | #include <osmocom/mgcp_client/mgcp_client.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | e6d8e91 | 2018-08-23 16:36:48 +0200 | [diff] [blame] | 33 | #define MGW_STR MGCP_CLIENT_MGW_STR |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 34 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 35 | void *global_mgcp_client_ctx = NULL; |
| 36 | struct mgcp_client_conf *global_mgcp_client_conf = NULL; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 37 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 38 | DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd, |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 39 | "mgw local-ip " VTY_IPV46_CMD, |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 40 | MGW_STR "local bind to connect to MGW from\n" |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 41 | "local bind IPv4 address\n" |
| 42 | "local bind IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 43 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 44 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 45 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 46 | OSMO_ASSERT(global_mgcp_client_ctx); |
Neels Hofmeyr | c3132fd | 2018-12-19 00:30:34 +0100 | [diff] [blame] | 47 | osmo_talloc_replace_string(global_mgcp_client_ctx, |
| 48 | (char**)&global_mgcp_client_conf->local_addr, |
| 49 | argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 50 | return CMD_SUCCESS; |
| 51 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 52 | ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 53 | "mgcpgw local-ip A.B.C.D", |
| 54 | MGW_STR "local bind to connect to MGCP gateway with\n" |
| 55 | "local bind IP address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 56 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 57 | DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd, |
| 58 | "mgw local-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 59 | MGW_STR "local port to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 60 | "local bind port\n") |
| 61 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 62 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 63 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 64 | global_mgcp_client_conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 65 | return CMD_SUCCESS; |
| 66 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 67 | ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 68 | "mgcpgw local-port <0-65535>", |
| 69 | MGW_STR "local bind to connect to MGCP gateway with\n" |
| 70 | "local bind port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 71 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 72 | DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd, |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 73 | "mgw remote-ip " VTY_IPV46_CMD, |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 74 | MGW_STR "remote IP address to reach the MGW at\n" |
Pau Espin Pedrol | 531470a | 2020-08-31 17:06:55 +0200 | [diff] [blame] | 75 | "remote IPv4 address\n" |
| 76 | "remote IPv6 address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 77 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 78 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 79 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 80 | OSMO_ASSERT(global_mgcp_client_ctx); |
Neels Hofmeyr | c3132fd | 2018-12-19 00:30:34 +0100 | [diff] [blame] | 81 | osmo_talloc_replace_string(global_mgcp_client_ctx, |
| 82 | (char**)&global_mgcp_client_conf->remote_addr, |
| 83 | argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 84 | return CMD_SUCCESS; |
| 85 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 86 | ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 87 | "mgcpgw remote-ip A.B.C.D", |
| 88 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 89 | "remote bind IP address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 90 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 91 | DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd, |
| 92 | "mgw remote-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 93 | MGW_STR "remote port to reach the MGW at\n" |
| 94 | "remote port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 95 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 96 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 97 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 98 | global_mgcp_client_conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 99 | return CMD_SUCCESS; |
| 100 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 101 | ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 102 | "mgcpgw remote-port <0-65535>", |
| 103 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 104 | "remote bind port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 105 | |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 106 | DEFUN_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd, |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 107 | "mgw endpoint-range <1-65534> <1-65534>", |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 108 | MGW_STR "DEPRECATED: the endpoint range cannot be defined by the client\n" |
| 109 | "-\n" "-\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 110 | { |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 111 | vty_out(vty, "Please do not use legacy config 'mgw endpoint-range'" |
| 112 | " (the range can no longer be defined by the MGCP client)%s", |
| 113 | VTY_NEWLINE); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 114 | return CMD_SUCCESS; |
| 115 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 116 | ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
| 117 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 118 | MGW_STR "usable range of endpoint identifiers\n" |
| 119 | "set first useable endpoint identifier\n" |
| 120 | "set the last useable endpoint identifier\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 121 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 122 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 123 | #define UDP_PORT_STR "UDP Port number\n" |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 124 | DEFUN_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 125 | cfg_mgw_rtp_bts_base_port_cmd, |
| 126 | "mgw bts-base <0-65534>", |
| 127 | MGW_STR |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 128 | "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] | 129 | { |
Neels Hofmeyr | 72bc8da | 2018-12-19 00:44:37 +0100 | [diff] [blame] | 130 | vty_out(vty, "Please do not use legacy config 'mgw bts-base'" |
| 131 | " (there is no explicit BTS side in an MGW anymore)%s", |
| 132 | VTY_NEWLINE); |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 133 | return CMD_SUCCESS; |
| 134 | } |
| 135 | ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
| 136 | cfg_mgcpgw_rtp_bts_base_port_cmd, |
| 137 | "mgcpgw bts-base <0-65534>", |
| 138 | MGW_STR |
| 139 | BTS_START_STR |
| 140 | UDP_PORT_STR) |
| 141 | |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 142 | DEFUN(cfg_mgw_endpoint_domain_name, |
| 143 | cfg_mgw_endpoint_domain_name_cmd, |
| 144 | "mgw endpoint-domain NAME", |
| 145 | MGW_STR "Set the domain name to send in MGCP messages, e.g. the part 'foo' in 'rtpbridge/*@foo'.\n" |
| 146 | "Domain name, should be alphanumeric.\n") |
| 147 | { |
| 148 | if (osmo_strlcpy(global_mgcp_client_conf->endpoint_domain_name, argv[0], |
| 149 | sizeof(global_mgcp_client_conf->endpoint_domain_name)) |
| 150 | >= sizeof(global_mgcp_client_conf->endpoint_domain_name)) { |
| 151 | vty_out(vty, "%% Error: 'mgw endpoint-domain' name too long, max length is %zu: '%s'%s", |
| 152 | sizeof(global_mgcp_client_conf->endpoint_domain_name) - 1, argv[0], VTY_NEWLINE); |
| 153 | return CMD_WARNING; |
| 154 | } |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 158 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 159 | { |
| 160 | const char *addr; |
| 161 | int port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 162 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 163 | addr = global_mgcp_client_conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 164 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 165 | vty_out(vty, "%smgw local-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 166 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 167 | port = global_mgcp_client_conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 168 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 169 | vty_out(vty, "%smgw local-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 170 | (uint16_t)port, VTY_NEWLINE); |
| 171 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 172 | addr = global_mgcp_client_conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 173 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 174 | vty_out(vty, "%smgw remote-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 175 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 176 | port = global_mgcp_client_conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 177 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 178 | vty_out(vty, "%smgw remote-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 179 | (uint16_t)port, VTY_NEWLINE); |
| 180 | |
Neels Hofmeyr | ac69ea9 | 2018-12-19 00:27:50 +0100 | [diff] [blame] | 181 | if (global_mgcp_client_conf->endpoint_domain_name[0]) |
| 182 | vty_out(vty, "%smgw endpoint-domain %s%s", indent, |
| 183 | global_mgcp_client_conf->endpoint_domain_name, VTY_NEWLINE); |
| 184 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 185 | return CMD_SUCCESS; |
| 186 | } |
| 187 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 188 | void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 189 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 190 | global_mgcp_client_ctx = talloc_ctx; |
| 191 | global_mgcp_client_conf = conf; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 192 | |
Vadim Yanitskiy | 3ba4095 | 2020-10-04 16:42:04 +0700 | [diff] [blame] | 193 | install_lib_element(node, &cfg_mgw_local_ip_cmd); |
| 194 | install_lib_element(node, &cfg_mgw_local_port_cmd); |
| 195 | install_lib_element(node, &cfg_mgw_remote_ip_cmd); |
| 196 | install_lib_element(node, &cfg_mgw_remote_port_cmd); |
| 197 | install_lib_element(node, &cfg_mgw_endpoint_range_cmd); |
| 198 | install_lib_element(node, &cfg_mgw_rtp_bts_base_port_cmd); |
| 199 | install_lib_element(node, &cfg_mgw_endpoint_domain_name_cmd); |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 200 | |
| 201 | /* deprecated 'mgcpgw' commands */ |
Vadim Yanitskiy | 3ba4095 | 2020-10-04 16:42:04 +0700 | [diff] [blame] | 202 | install_lib_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 203 | install_lib_element(node, &cfg_mgcpgw_local_port_cmd); |
| 204 | install_lib_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 205 | install_lib_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 206 | install_lib_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 207 | install_lib_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd); |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 208 | |
| 209 | osmo_fsm_vty_add_cmds(); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 210 | } |