blob: 1d58bb5432cf94fffa6009775613e06f849888c6 [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
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
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
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
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>
28#include <osmocom/core/utils.h>
29
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020030#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020031
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010032#define MGW_STR "Configure MGCP connection to Media Gateway\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020033
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020034void *global_mgcp_client_ctx = NULL;
35struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020036
Neels Hofmeyr87203f22017-10-31 01:15:45 +010037DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd,
38 "mgw local-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010039 MGW_STR "local bind to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020040 "local bind IP address\n")
41{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020042 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020043 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020044 OSMO_ASSERT(global_mgcp_client_ctx);
45 global_mgcp_client_conf->local_addr =
46 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020047 return CMD_SUCCESS;
48}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010049ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd,
50 "mgcpgw local-ip A.B.C.D",
51 MGW_STR "local bind to connect to MGCP gateway with\n"
52 "local bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020053
Neels Hofmeyr87203f22017-10-31 01:15:45 +010054DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
55 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010056 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020057 "local bind port\n")
58{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020059 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020060 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020061 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020062 return CMD_SUCCESS;
63}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010064ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd,
65 "mgcpgw local-port <0-65535>",
66 MGW_STR "local bind to connect to MGCP gateway with\n"
67 "local bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020068
Neels Hofmeyr87203f22017-10-31 01:15:45 +010069DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
70 "mgw remote-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010071 MGW_STR "remote IP address to reach the MGW at\n"
72 "remote IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020073{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020074 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020075 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020076 OSMO_ASSERT(global_mgcp_client_ctx);
77 global_mgcp_client_conf->remote_addr =
78 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020079 return CMD_SUCCESS;
80}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010081ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
82 "mgcpgw remote-ip A.B.C.D",
83 MGW_STR "remote bind to connect to MGCP gateway with\n"
84 "remote bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020085
Neels Hofmeyr87203f22017-10-31 01:15:45 +010086DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
87 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010088 MGW_STR "remote port to reach the MGW at\n"
89 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020090{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020091 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020092 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020093 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020094 return CMD_SUCCESS;
95}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010096ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd,
97 "mgcpgw remote-port <0-65535>",
98 MGW_STR "remote bind to connect to MGCP gateway with\n"
99 "remote bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200100
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100101DEFUN(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
102 "mgw endpoint-range <1-65534> <1-65534>",
103 MGW_STR "usable range of endpoint identifiers\n"
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +0100104 "set first usable endpoint identifier\n"
105 "set last usable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200106{
107 uint16_t first_endpoint = atoi(argv[0]);
108 uint16_t last_endpoint = atoi(argv[1]);
109
110 if (last_endpoint < first_endpoint) {
111 vty_out(vty, "last endpoint must be greater than first endpoint!%s",
112 VTY_NEWLINE);
113 return CMD_SUCCESS;
114 }
115
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200116 global_mgcp_client_conf->first_endpoint = first_endpoint;
117 global_mgcp_client_conf->last_endpoint = last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200118 return CMD_SUCCESS;
119}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100120ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
121 "mgcpgw endpoint-range <1-65534> <1-65534>",
122 MGW_STR "usable range of endpoint identifiers\n"
123 "set first useable endpoint identifier\n"
124 "set the last useable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200125
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200126int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200127{
128 const char *addr;
129 int port;
130 uint16_t first_endpoint;
131 uint16_t last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200132
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200133 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200134 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100135 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200136 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200137 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200138 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100139 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200140 (uint16_t)port, VTY_NEWLINE);
141
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200142 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200143 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100144 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200145 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200146 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200147 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100148 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200149 (uint16_t)port, VTY_NEWLINE);
150
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200151 first_endpoint = global_mgcp_client_conf->first_endpoint;
152 last_endpoint = global_mgcp_client_conf->last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200153 if (last_endpoint != 0) {
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100154 vty_out(vty, "%smgw endpoint-range %u %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200155 first_endpoint, last_endpoint, VTY_NEWLINE);
156 }
157
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200158 return CMD_SUCCESS;
159}
160
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200161void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200162{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200163 global_mgcp_client_ctx = talloc_ctx;
164 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200165
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100166 install_element(node, &cfg_mgw_local_ip_cmd);
167 install_element(node, &cfg_mgw_local_port_cmd);
168 install_element(node, &cfg_mgw_remote_ip_cmd);
169 install_element(node, &cfg_mgw_remote_port_cmd);
170 install_element(node, &cfg_mgw_endpoint_range_cmd);
171
172 /* deprecated 'mgcpgw' commands */
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200173 install_element(node, &cfg_mgcpgw_local_ip_cmd);
174 install_element(node, &cfg_mgcpgw_local_port_cmd);
175 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
176 install_element(node, &cfg_mgcpgw_remote_port_cmd);
177 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200178}