blob: cc8db5d852fa4f75143e565aeafa515cd17b1cb2 [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>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020032
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020033#define MGW_STR MGCP_CLIENT_MGW_STR
Neels Hofmeyre9920f22017-07-10 15:07:22 +020034
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020035void *global_mgcp_client_ctx = NULL;
36struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020037
Neels Hofmeyr87203f22017-10-31 01:15:45 +010038DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd,
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020039 "mgw local-ip " VTY_IPV46_CMD,
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010040 MGW_STR "local bind to connect to MGW from\n"
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020041 "local bind IPv4 address\n"
42 "local bind IPv6 address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020043{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020044 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020045 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020046 OSMO_ASSERT(global_mgcp_client_ctx);
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010047 osmo_talloc_replace_string(global_mgcp_client_ctx,
48 (char**)&global_mgcp_client_conf->local_addr,
49 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020050 return CMD_SUCCESS;
51}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010052ALIAS_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 Hofmeyre9920f22017-07-10 15:07:22 +020056
Neels Hofmeyr87203f22017-10-31 01:15:45 +010057DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
58 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010059 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020060 "local bind port\n")
61{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020062 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020063 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020064 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020065 return CMD_SUCCESS;
66}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010067ALIAS_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 Hofmeyre9920f22017-07-10 15:07:22 +020071
Neels Hofmeyr87203f22017-10-31 01:15:45 +010072DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020073 "mgw remote-ip " VTY_IPV46_CMD,
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010074 MGW_STR "remote IP address to reach the MGW at\n"
Pau Espin Pedrol531470a2020-08-31 17:06:55 +020075 "remote IPv4 address\n"
76 "remote IPv6 address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020077{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020078 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020079 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020080 OSMO_ASSERT(global_mgcp_client_ctx);
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010081 osmo_talloc_replace_string(global_mgcp_client_ctx,
82 (char**)&global_mgcp_client_conf->remote_addr,
83 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020084 return CMD_SUCCESS;
85}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010086ALIAS_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 Hofmeyre9920f22017-07-10 15:07:22 +020090
Neels Hofmeyr87203f22017-10-31 01:15:45 +010091DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
92 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010093 MGW_STR "remote port to reach the MGW at\n"
94 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020095{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020096 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020097 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020098 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020099 return CMD_SUCCESS;
100}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100101ALIAS_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 Hofmeyre9920f22017-07-10 15:07:22 +0200105
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100106DEFUN_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100107 "mgw endpoint-range <1-65534> <1-65534>",
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100108 MGW_STR "DEPRECATED: the endpoint range cannot be defined by the client\n"
109 "-\n" "-\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200110{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100111 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 Hofmeyre9920f22017-07-10 15:07:22 +0200114 return CMD_SUCCESS;
115}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100116ALIAS_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 Hofmeyre9920f22017-07-10 15:07:22 +0200121
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000122#define BTS_START_STR "First UDP port allocated for the BTS side\n"
123#define UDP_PORT_STR "UDP Port number\n"
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100124DEFUN_DEPRECATED(cfg_mgw_rtp_bts_base_port,
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000125 cfg_mgw_rtp_bts_base_port_cmd,
126 "mgw bts-base <0-65534>",
127 MGW_STR
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100128 "DEPRECATED: there is no explicit BTS side in current osmo-mgw\n" "-\n")
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000129{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100130 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 Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000133 return CMD_SUCCESS;
134}
135ALIAS_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 Hofmeyrac69ea92018-12-19 00:27:50 +0100142DEFUN(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 Hofmeyr3a8e7232017-09-04 01:02:56 +0200158int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200159{
160 const char *addr;
161 int port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200162
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200163 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200164 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100165 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200166 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200167 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200168 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100169 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200170 (uint16_t)port, VTY_NEWLINE);
171
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200172 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200173 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100174 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200175 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200176 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200177 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100178 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200179 (uint16_t)port, VTY_NEWLINE);
180
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100181 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 Hofmeyre9920f22017-07-10 15:07:22 +0200185 return CMD_SUCCESS;
186}
187
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200188void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200189{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200190 global_mgcp_client_ctx = talloc_ctx;
191 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200192
Vadim Yanitskiy3ba40952020-10-04 16:42:04 +0700193 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 Hofmeyr87203f22017-10-31 01:15:45 +0100200
201 /* deprecated 'mgcpgw' commands */
Vadim Yanitskiy3ba40952020-10-04 16:42:04 +0700202 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 Sperling29248252018-02-22 18:09:28 +0100208
209 osmo_fsm_vty_add_cmds();
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200210}