blob: 9b33eeb624a80d3a0babd6e5aeaff4294612b8b7 [file] [log] [blame]
Neels Hofmeyr87203f22017-10-31 01:15:45 +01001/* MGCP client interface to quagga VTY */
Neels Hofmeyre9920f22017-07-10 15:07:22 +02002/* (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 Welte220f4872018-02-04 09:04:16 +01009 * 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 Hofmeyre9920f22017-07-10 15:07:22 +020011 * (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 Welte220f4872018-02-04 09:04:16 +010016 * GNU General Public License for more details.
Neels Hofmeyre9920f22017-07-10 15:07:22 +020017 *
Harald Welte220f4872018-02-04 09:04:16 +010018 * You should have received a copy of the GNU General Public License
Neels Hofmeyre9920f22017-07-10 15:07:22 +020019 * 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 Sperling29248252018-02-22 18:09:28 +010028#include <osmocom/vty/misc.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020029#include <osmocom/core/utils.h>
30
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020031#include <osmocom/mgcp_client/mgcp_client.h>
Philipp Maier3f2c15f2021-07-22 11:53:07 +020032#include <osmocom/mgcp_client/mgcp_client_internal.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020033
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020034#define MGW_STR MGCP_CLIENT_MGW_STR
Neels Hofmeyre9920f22017-07-10 15:07:22 +020035
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020036void *global_mgcp_client_ctx = NULL;
37struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020038
Neels Hofmeyr87203f22017-10-31 01:15:45 +010039DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd,
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020040 "mgw local-ip " VTY_IPV46_CMD,
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010041 MGW_STR "local bind to connect to MGW from\n"
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020042 "local bind IPv4 address\n"
43 "local bind IPv6 address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020044{
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010045 osmo_talloc_replace_string(global_mgcp_client_ctx,
46 (char**)&global_mgcp_client_conf->local_addr,
47 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020048 return CMD_SUCCESS;
49}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010050ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd,
51 "mgcpgw local-ip A.B.C.D",
52 MGW_STR "local bind to connect to MGCP gateway with\n"
53 "local bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020054
Neels Hofmeyr87203f22017-10-31 01:15:45 +010055DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
56 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010057 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020058 "local bind port\n")
59{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020060 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020061 return CMD_SUCCESS;
62}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010063ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd,
64 "mgcpgw local-port <0-65535>",
65 MGW_STR "local bind to connect to MGCP gateway with\n"
66 "local bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020067
Neels Hofmeyr87203f22017-10-31 01:15:45 +010068DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020069 "mgw remote-ip " VTY_IPV46_CMD,
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010070 MGW_STR "remote IP address to reach the MGW at\n"
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020071 "remote IPv4 address\n"
72 "remote IPv6 address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020073{
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010074 osmo_talloc_replace_string(global_mgcp_client_ctx,
75 (char**)&global_mgcp_client_conf->remote_addr,
76 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020077 return CMD_SUCCESS;
78}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010079ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
80 "mgcpgw remote-ip A.B.C.D",
81 MGW_STR "remote bind to connect to MGCP gateway with\n"
82 "remote bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020083
Neels Hofmeyr87203f22017-10-31 01:15:45 +010084DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
85 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010086 MGW_STR "remote port to reach the MGW at\n"
87 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020088{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020089 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020090 return CMD_SUCCESS;
91}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010092ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd,
93 "mgcpgw remote-port <0-65535>",
94 MGW_STR "remote bind to connect to MGCP gateway with\n"
95 "remote bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020096
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +010097DEFUN_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
Neels Hofmeyr87203f22017-10-31 01:15:45 +010098 "mgw endpoint-range <1-65534> <1-65534>",
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +010099 MGW_STR "DEPRECATED: the endpoint range cannot be defined by the client\n"
100 "-\n" "-\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200101{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100102 vty_out(vty, "Please do not use legacy config 'mgw endpoint-range'"
103 " (the range can no longer be defined by the MGCP client)%s",
104 VTY_NEWLINE);
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200105 return CMD_SUCCESS;
106}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100107ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
108 "mgcpgw endpoint-range <1-65534> <1-65534>",
109 MGW_STR "usable range of endpoint identifiers\n"
110 "set first useable endpoint identifier\n"
111 "set the last useable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200112
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000113#define BTS_START_STR "First UDP port allocated for the BTS side\n"
114#define UDP_PORT_STR "UDP Port number\n"
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100115DEFUN_DEPRECATED(cfg_mgw_rtp_bts_base_port,
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000116 cfg_mgw_rtp_bts_base_port_cmd,
117 "mgw bts-base <0-65534>",
118 MGW_STR
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100119 "DEPRECATED: there is no explicit BTS side in current osmo-mgw\n" "-\n")
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000120{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100121 vty_out(vty, "Please do not use legacy config 'mgw bts-base'"
122 " (there is no explicit BTS side in an MGW anymore)%s",
123 VTY_NEWLINE);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000124 return CMD_SUCCESS;
125}
126ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port,
127 cfg_mgcpgw_rtp_bts_base_port_cmd,
128 "mgcpgw bts-base <0-65534>",
129 MGW_STR
130 BTS_START_STR
131 UDP_PORT_STR)
132
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100133DEFUN(cfg_mgw_endpoint_domain_name,
134 cfg_mgw_endpoint_domain_name_cmd,
135 "mgw endpoint-domain NAME",
136 MGW_STR "Set the domain name to send in MGCP messages, e.g. the part 'foo' in 'rtpbridge/*@foo'.\n"
137 "Domain name, should be alphanumeric.\n")
138{
139 if (osmo_strlcpy(global_mgcp_client_conf->endpoint_domain_name, argv[0],
140 sizeof(global_mgcp_client_conf->endpoint_domain_name))
141 >= sizeof(global_mgcp_client_conf->endpoint_domain_name)) {
142 vty_out(vty, "%% Error: 'mgw endpoint-domain' name too long, max length is %zu: '%s'%s",
143 sizeof(global_mgcp_client_conf->endpoint_domain_name) - 1, argv[0], VTY_NEWLINE);
144 return CMD_WARNING;
145 }
146 return CMD_SUCCESS;
147}
148
Philipp Maier3f2c15f2021-07-22 11:53:07 +0200149DEFUN(cfg_mgw_reset_ep_name,
150 cfg_mgw_reset_ep_name_cmd,
151 "mgw reset-endpoint NAME",
152 MGW_STR "Add an endpoint name that should be reset (DLCX) on connect to the reset-endpoint list,"
153 "e.g. 'rtpbridge/*'\n"
154 "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n")
155{
156 int rc;
157 struct reset_ep *reset_ep;
158
159 /* stop when the address is already in the list */
160 llist_for_each_entry(reset_ep, &global_mgcp_client_conf->reset_epnames, list) {
161 if (strcmp(argv[0], reset_ep->name) == 0) {
162 vty_out(vty, "%% duplicate endpoint name configured ('%s')%s", argv[0], VTY_NEWLINE);
163 return CMD_WARNING;
164 }
165 }
166
167 /* the domain name is not part of the actual endpoint name */
168 if (strchr(argv[0], '@')) {
169 vty_out(vty, "%% the endpoint name must be given without domain name ('%s')%s",
170 argv[0], VTY_NEWLINE);
171 return CMD_WARNING;
172 }
173
174 reset_ep = talloc_zero(global_mgcp_client_ctx, struct reset_ep);
175 OSMO_ASSERT(reset_ep);
176
177 rc = osmo_strlcpy(reset_ep->name, argv[0], sizeof(reset_ep->name));
178 if (rc >= sizeof(reset_ep->name)) {
179 vty_out(vty, "%% Error: 'mgw reset-endpoint' name too long, max length is %zu: '%s'%s",
180 sizeof(reset_ep->name) - 1, argv[0], VTY_NEWLINE);
181 talloc_free(reset_ep);
182 return CMD_WARNING;
183 }
184
185 llist_add_tail(&reset_ep->list, &global_mgcp_client_conf->reset_epnames);
186
187 return CMD_SUCCESS;
188}
189
190DEFUN(cfg_mgw_no_reset_ep_name,
191 cfg_mgw_no_reset_ep_name_cmd,
192 "no mgw reset-endpoint NAME",
193 MGW_STR "remove an endpoint name from the reset-endpoint list, e.g. 'rtpbridge/*'\n"
194 "Endpoint name, e.g. 'rtpbridge/*' or 'ds/e1-0/s-3/su16-4'.\n")
195{
196 struct reset_ep *reset_ep;
197
198 llist_for_each_entry(reset_ep, &global_mgcp_client_conf->reset_epnames, list) {
199 if (strcmp(argv[0], reset_ep->name) == 0) {
200 llist_del(&reset_ep->list);
201 talloc_free(reset_ep);
202 return CMD_SUCCESS;
203 }
204 }
205
206 vty_out(vty, "%% no such endpoint name configured ('%s')%s", argv[0], VTY_NEWLINE);
207 return CMD_WARNING;
208}
209
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200210int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200211{
212 const char *addr;
213 int port;
Philipp Maier3f2c15f2021-07-22 11:53:07 +0200214 struct reset_ep *reset_ep;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200215
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200216 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200217 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100218 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200219 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200220 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200221 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100222 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200223 (uint16_t)port, VTY_NEWLINE);
224
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200225 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200226 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100227 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200228 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200229 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200230 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100231 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200232 (uint16_t)port, VTY_NEWLINE);
233
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100234 if (global_mgcp_client_conf->endpoint_domain_name[0])
235 vty_out(vty, "%smgw endpoint-domain %s%s", indent,
236 global_mgcp_client_conf->endpoint_domain_name, VTY_NEWLINE);
237
Philipp Maier3f2c15f2021-07-22 11:53:07 +0200238 llist_for_each_entry(reset_ep, &global_mgcp_client_conf->reset_epnames, list)
239 vty_out(vty, "%smgw reset-endpoint %s%s", indent, reset_ep->name, VTY_NEWLINE);
240
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200241 return CMD_SUCCESS;
242}
243
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200244void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200245{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200246 global_mgcp_client_ctx = talloc_ctx;
247 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200248
Vadim Yanitskiy3ba40952020-10-04 16:42:04 +0700249 install_lib_element(node, &cfg_mgw_local_ip_cmd);
250 install_lib_element(node, &cfg_mgw_local_port_cmd);
251 install_lib_element(node, &cfg_mgw_remote_ip_cmd);
252 install_lib_element(node, &cfg_mgw_remote_port_cmd);
253 install_lib_element(node, &cfg_mgw_endpoint_range_cmd);
254 install_lib_element(node, &cfg_mgw_rtp_bts_base_port_cmd);
255 install_lib_element(node, &cfg_mgw_endpoint_domain_name_cmd);
Philipp Maier3f2c15f2021-07-22 11:53:07 +0200256 install_lib_element(node, &cfg_mgw_reset_ep_name_cmd);
257 install_lib_element(node, &cfg_mgw_no_reset_ep_name_cmd);
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100258
259 /* deprecated 'mgcpgw' commands */
Vadim Yanitskiy3ba40952020-10-04 16:42:04 +0700260 install_lib_element(node, &cfg_mgcpgw_local_ip_cmd);
261 install_lib_element(node, &cfg_mgcpgw_local_port_cmd);
262 install_lib_element(node, &cfg_mgcpgw_remote_ip_cmd);
263 install_lib_element(node, &cfg_mgcpgw_remote_port_cmd);
264 install_lib_element(node, &cfg_mgcpgw_endpoint_range_cmd);
265 install_lib_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd);
Stefan Sperling29248252018-02-22 18:09:28 +0100266
267 osmo_fsm_vty_add_cmds();
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200268}