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 |
| 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 Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 30 | #include <osmocom/mgcp_client/mgcp_client.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 31 | |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 32 | #define MGW_STR "Configure MGCP connection to Media Gateway\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 33 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 34 | void *global_mgcp_client_ctx = NULL; |
| 35 | struct mgcp_client_conf *global_mgcp_client_conf = NULL; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 36 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 37 | DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd, |
| 38 | "mgw local-ip A.B.C.D", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 39 | MGW_STR "local bind to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 40 | "local bind IP address\n") |
| 41 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 42 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 43 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 44 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 45 | global_mgcp_client_conf->local_addr = |
| 46 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 47 | return CMD_SUCCESS; |
| 48 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 49 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 53 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 54 | DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd, |
| 55 | "mgw local-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 56 | MGW_STR "local port to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 57 | "local bind port\n") |
| 58 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 59 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 60 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 61 | global_mgcp_client_conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 62 | return CMD_SUCCESS; |
| 63 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 64 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 68 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 69 | DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd, |
| 70 | "mgw remote-ip A.B.C.D", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 71 | MGW_STR "remote IP address to reach the MGW at\n" |
| 72 | "remote IP address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 73 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 74 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 75 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 76 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 77 | global_mgcp_client_conf->remote_addr = |
| 78 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 79 | return CMD_SUCCESS; |
| 80 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 81 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 85 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 86 | DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd, |
| 87 | "mgw remote-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 88 | MGW_STR "remote port to reach the MGW at\n" |
| 89 | "remote port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 90 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 91 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 92 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 93 | global_mgcp_client_conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 94 | return CMD_SUCCESS; |
| 95 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 96 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 100 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 101 | DEFUN(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 Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 104 | "set first usable endpoint identifier\n" |
| 105 | "set last usable endpoint identifier\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 106 | { |
| 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 Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 116 | global_mgcp_client_conf->first_endpoint = first_endpoint; |
| 117 | global_mgcp_client_conf->last_endpoint = last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 118 | return CMD_SUCCESS; |
| 119 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 120 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 125 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 126 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 127 | #define UDP_PORT_STR "UDP Port number\n" |
| 128 | DEFUN(cfg_mgw_rtp_bts_base_port, |
| 129 | cfg_mgw_rtp_bts_base_port_cmd, |
| 130 | "mgw bts-base <0-65534>", |
| 131 | MGW_STR |
| 132 | BTS_START_STR |
| 133 | UDP_PORT_STR) |
| 134 | { |
| 135 | global_mgcp_client_conf->bts_base = atoi(argv[0]); |
| 136 | return CMD_SUCCESS; |
| 137 | } |
| 138 | ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
| 139 | cfg_mgcpgw_rtp_bts_base_port_cmd, |
| 140 | "mgcpgw bts-base <0-65534>", |
| 141 | MGW_STR |
| 142 | BTS_START_STR |
| 143 | UDP_PORT_STR) |
| 144 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 145 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 146 | { |
| 147 | const char *addr; |
| 148 | int port; |
| 149 | uint16_t first_endpoint; |
| 150 | uint16_t last_endpoint; |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 151 | uint16_t bts_base; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 152 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 153 | addr = global_mgcp_client_conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 154 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 155 | vty_out(vty, "%smgw local-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 156 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 157 | port = global_mgcp_client_conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 158 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 159 | vty_out(vty, "%smgw local-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 160 | (uint16_t)port, VTY_NEWLINE); |
| 161 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 162 | addr = global_mgcp_client_conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 163 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 164 | vty_out(vty, "%smgw remote-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 165 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 166 | port = global_mgcp_client_conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 167 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 168 | vty_out(vty, "%smgw remote-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 169 | (uint16_t)port, VTY_NEWLINE); |
| 170 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 171 | first_endpoint = global_mgcp_client_conf->first_endpoint; |
| 172 | last_endpoint = global_mgcp_client_conf->last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 173 | if (last_endpoint != 0) { |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 174 | vty_out(vty, "%smgw endpoint-range %u %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 175 | first_endpoint, last_endpoint, VTY_NEWLINE); |
| 176 | } |
| 177 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 178 | bts_base = global_mgcp_client_conf->bts_base; |
| 179 | if (bts_base) { |
| 180 | vty_out(vty, "%smgw bts-base %u%s", indent, |
| 181 | bts_base, VTY_NEWLINE); |
| 182 | } |
| 183 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 187 | 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] | 188 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 189 | global_mgcp_client_ctx = talloc_ctx; |
| 190 | global_mgcp_client_conf = conf; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 191 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 192 | install_element(node, &cfg_mgw_local_ip_cmd); |
| 193 | install_element(node, &cfg_mgw_local_port_cmd); |
| 194 | install_element(node, &cfg_mgw_remote_ip_cmd); |
| 195 | install_element(node, &cfg_mgw_remote_port_cmd); |
| 196 | install_element(node, &cfg_mgw_endpoint_range_cmd); |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 197 | install_element(node, &cfg_mgw_rtp_bts_base_port_cmd); |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 198 | |
| 199 | /* deprecated 'mgcpgw' commands */ |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 200 | 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 Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 205 | install_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 206 | } |