blob: d4e78f1cc099c9c76a0cb2c9699cc69317d4e82c [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,
39 "mgw local-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010040 MGW_STR "local bind to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020041 "local bind IP address\n")
42{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020043 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020044 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020045 OSMO_ASSERT(global_mgcp_client_ctx);
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010046 osmo_talloc_replace_string(global_mgcp_client_ctx,
47 (char**)&global_mgcp_client_conf->local_addr,
48 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020049 return CMD_SUCCESS;
50}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010051ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd,
52 "mgcpgw local-ip A.B.C.D",
53 MGW_STR "local bind to connect to MGCP gateway with\n"
54 "local bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020055
Neels Hofmeyr87203f22017-10-31 01:15:45 +010056DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
57 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010058 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020059 "local bind port\n")
60{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020061 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020062 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020063 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020064 return CMD_SUCCESS;
65}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010066ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd,
67 "mgcpgw local-port <0-65535>",
68 MGW_STR "local bind to connect to MGCP gateway with\n"
69 "local bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020070
Neels Hofmeyr87203f22017-10-31 01:15:45 +010071DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
72 "mgw remote-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010073 MGW_STR "remote IP address to reach the MGW at\n"
74 "remote IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020075{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020076 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020077 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020078 OSMO_ASSERT(global_mgcp_client_ctx);
Neels Hofmeyrc3132fd2018-12-19 00:30:34 +010079 osmo_talloc_replace_string(global_mgcp_client_ctx,
80 (char**)&global_mgcp_client_conf->remote_addr,
81 argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020082 return CMD_SUCCESS;
83}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010084ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
85 "mgcpgw remote-ip A.B.C.D",
86 MGW_STR "remote bind to connect to MGCP gateway with\n"
87 "remote bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020088
Neels Hofmeyr87203f22017-10-31 01:15:45 +010089DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
90 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010091 MGW_STR "remote port to reach the MGW at\n"
92 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020093{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020094 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020095 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020096 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020097 return CMD_SUCCESS;
98}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010099ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd,
100 "mgcpgw remote-port <0-65535>",
101 MGW_STR "remote bind to connect to MGCP gateway with\n"
102 "remote bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200103
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100104DEFUN_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100105 "mgw endpoint-range <1-65534> <1-65534>",
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100106 MGW_STR "DEPRECATED: the endpoint range cannot be defined by the client\n"
107 "-\n" "-\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200108{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100109 vty_out(vty, "Please do not use legacy config 'mgw endpoint-range'"
110 " (the range can no longer be defined by the MGCP client)%s",
111 VTY_NEWLINE);
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200112 return CMD_SUCCESS;
113}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100114ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
115 "mgcpgw endpoint-range <1-65534> <1-65534>",
116 MGW_STR "usable range of endpoint identifiers\n"
117 "set first useable endpoint identifier\n"
118 "set the last useable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200119
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000120#define BTS_START_STR "First UDP port allocated for the BTS side\n"
121#define UDP_PORT_STR "UDP Port number\n"
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100122DEFUN_DEPRECATED(cfg_mgw_rtp_bts_base_port,
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000123 cfg_mgw_rtp_bts_base_port_cmd,
124 "mgw bts-base <0-65534>",
125 MGW_STR
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100126 "DEPRECATED: there is no explicit BTS side in current osmo-mgw\n" "-\n")
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000127{
Neels Hofmeyr72bc8da2018-12-19 00:44:37 +0100128 vty_out(vty, "Please do not use legacy config 'mgw bts-base'"
129 " (there is no explicit BTS side in an MGW anymore)%s",
130 VTY_NEWLINE);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000131 return CMD_SUCCESS;
132}
133ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port,
134 cfg_mgcpgw_rtp_bts_base_port_cmd,
135 "mgcpgw bts-base <0-65534>",
136 MGW_STR
137 BTS_START_STR
138 UDP_PORT_STR)
139
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100140DEFUN(cfg_mgw_endpoint_domain_name,
141 cfg_mgw_endpoint_domain_name_cmd,
142 "mgw endpoint-domain NAME",
143 MGW_STR "Set the domain name to send in MGCP messages, e.g. the part 'foo' in 'rtpbridge/*@foo'.\n"
144 "Domain name, should be alphanumeric.\n")
145{
146 if (osmo_strlcpy(global_mgcp_client_conf->endpoint_domain_name, argv[0],
147 sizeof(global_mgcp_client_conf->endpoint_domain_name))
148 >= sizeof(global_mgcp_client_conf->endpoint_domain_name)) {
149 vty_out(vty, "%% Error: 'mgw endpoint-domain' name too long, max length is %zu: '%s'%s",
150 sizeof(global_mgcp_client_conf->endpoint_domain_name) - 1, argv[0], VTY_NEWLINE);
151 return CMD_WARNING;
152 }
153 return CMD_SUCCESS;
154}
155
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200156int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200157{
158 const char *addr;
159 int port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200160
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200161 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200162 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100163 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200164 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200165 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200166 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100167 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200168 (uint16_t)port, VTY_NEWLINE);
169
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200170 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200171 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100172 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200173 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200174 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200175 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100176 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200177 (uint16_t)port, VTY_NEWLINE);
178
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100179 if (global_mgcp_client_conf->endpoint_domain_name[0])
180 vty_out(vty, "%smgw endpoint-domain %s%s", indent,
181 global_mgcp_client_conf->endpoint_domain_name, VTY_NEWLINE);
182
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200183 return CMD_SUCCESS;
184}
185
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200186void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200187{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200188 global_mgcp_client_ctx = talloc_ctx;
189 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200190
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100191 install_element(node, &cfg_mgw_local_ip_cmd);
192 install_element(node, &cfg_mgw_local_port_cmd);
193 install_element(node, &cfg_mgw_remote_ip_cmd);
194 install_element(node, &cfg_mgw_remote_port_cmd);
195 install_element(node, &cfg_mgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000196 install_element(node, &cfg_mgw_rtp_bts_base_port_cmd);
Neels Hofmeyrac69ea92018-12-19 00:27:50 +0100197 install_element(node, &cfg_mgw_endpoint_domain_name_cmd);
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100198
199 /* deprecated 'mgcpgw' commands */
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200200 install_element(node, &cfg_mgcpgw_local_ip_cmd);
201 install_element(node, &cfg_mgcpgw_local_port_cmd);
202 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
203 install_element(node, &cfg_mgcpgw_remote_port_cmd);
204 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000205 install_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd);
Stefan Sperling29248252018-02-22 18:09:28 +0100206
207 osmo_fsm_vty_add_cmds();
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200208}