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 |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 9 | * 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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 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 |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 16 | * GNU General Public License for more details. |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 17 | * |
Harald Welte | 220f487 | 2018-02-04 09:04:16 +0100 | [diff] [blame] | 18 | * You should have received a copy of the GNU General Public License |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 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> |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 28 | #include <osmocom/vty/misc.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 29 | #include <osmocom/core/utils.h> |
| 30 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 31 | #include <osmocom/mgcp_client/mgcp_client.h> |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 32 | |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 33 | #define MGW_STR "Configure MGCP connection to Media Gateway\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 34 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 35 | void *global_mgcp_client_ctx = NULL; |
| 36 | struct mgcp_client_conf *global_mgcp_client_conf = NULL; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 37 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 38 | DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd, |
| 39 | "mgw local-ip A.B.C.D", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 40 | MGW_STR "local bind to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 41 | "local bind IP address\n") |
| 42 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 43 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 44 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 45 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 46 | global_mgcp_client_conf->local_addr = |
| 47 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 48 | return CMD_SUCCESS; |
| 49 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 50 | ALIAS_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 Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 54 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 55 | DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd, |
| 56 | "mgw local-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 57 | MGW_STR "local port to connect to MGW from\n" |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 58 | "local bind port\n") |
| 59 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 60 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 61 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 62 | global_mgcp_client_conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 63 | return CMD_SUCCESS; |
| 64 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 65 | ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 66 | "mgcpgw local-port <0-65535>", |
| 67 | MGW_STR "local bind to connect to MGCP gateway with\n" |
| 68 | "local bind port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 69 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 70 | DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd, |
| 71 | "mgw remote-ip A.B.C.D", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 72 | MGW_STR "remote IP address to reach the MGW at\n" |
| 73 | "remote IP address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 74 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 75 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 76 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 77 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 78 | global_mgcp_client_conf->remote_addr = |
| 79 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 80 | return CMD_SUCCESS; |
| 81 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 82 | ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 83 | "mgcpgw remote-ip A.B.C.D", |
| 84 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 85 | "remote bind IP address\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 86 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 87 | DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd, |
| 88 | "mgw remote-port <0-65535>", |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 89 | MGW_STR "remote port to reach the MGW at\n" |
| 90 | "remote port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 91 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 92 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 93 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 94 | global_mgcp_client_conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 95 | return CMD_SUCCESS; |
| 96 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 97 | ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 98 | "mgcpgw remote-port <0-65535>", |
| 99 | MGW_STR "remote bind to connect to MGCP gateway with\n" |
| 100 | "remote bind port\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 101 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 102 | DEFUN(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd, |
| 103 | "mgw endpoint-range <1-65534> <1-65534>", |
| 104 | MGW_STR "usable range of endpoint identifiers\n" |
Neels Hofmeyr | 54dd4b3 | 2017-10-31 01:18:33 +0100 | [diff] [blame] | 105 | "set first usable endpoint identifier\n" |
| 106 | "set last usable endpoint identifier\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 107 | { |
| 108 | uint16_t first_endpoint = atoi(argv[0]); |
| 109 | uint16_t last_endpoint = atoi(argv[1]); |
| 110 | |
| 111 | if (last_endpoint < first_endpoint) { |
| 112 | vty_out(vty, "last endpoint must be greater than first endpoint!%s", |
| 113 | VTY_NEWLINE); |
| 114 | return CMD_SUCCESS; |
| 115 | } |
| 116 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 117 | global_mgcp_client_conf->first_endpoint = first_endpoint; |
| 118 | global_mgcp_client_conf->last_endpoint = last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 119 | return CMD_SUCCESS; |
| 120 | } |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 121 | ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
| 122 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 123 | MGW_STR "usable range of endpoint identifiers\n" |
| 124 | "set first useable endpoint identifier\n" |
| 125 | "set the last useable endpoint identifier\n") |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 126 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 127 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 128 | #define UDP_PORT_STR "UDP Port number\n" |
| 129 | DEFUN(cfg_mgw_rtp_bts_base_port, |
| 130 | cfg_mgw_rtp_bts_base_port_cmd, |
| 131 | "mgw bts-base <0-65534>", |
| 132 | MGW_STR |
| 133 | BTS_START_STR |
| 134 | UDP_PORT_STR) |
| 135 | { |
| 136 | global_mgcp_client_conf->bts_base = atoi(argv[0]); |
| 137 | return CMD_SUCCESS; |
| 138 | } |
| 139 | ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port, |
| 140 | cfg_mgcpgw_rtp_bts_base_port_cmd, |
| 141 | "mgcpgw bts-base <0-65534>", |
| 142 | MGW_STR |
| 143 | BTS_START_STR |
| 144 | UDP_PORT_STR) |
| 145 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 146 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 147 | { |
| 148 | const char *addr; |
| 149 | int port; |
| 150 | uint16_t first_endpoint; |
| 151 | uint16_t last_endpoint; |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 152 | uint16_t bts_base; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 153 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 154 | addr = global_mgcp_client_conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 155 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 156 | vty_out(vty, "%smgw local-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 157 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 158 | port = global_mgcp_client_conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 159 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 160 | vty_out(vty, "%smgw local-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 161 | (uint16_t)port, VTY_NEWLINE); |
| 162 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 163 | addr = global_mgcp_client_conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 164 | if (addr) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 165 | vty_out(vty, "%smgw remote-ip %s%s", indent, addr, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 166 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 167 | port = global_mgcp_client_conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 168 | if (port >= 0) |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 169 | vty_out(vty, "%smgw remote-port %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 170 | (uint16_t)port, VTY_NEWLINE); |
| 171 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 172 | first_endpoint = global_mgcp_client_conf->first_endpoint; |
| 173 | last_endpoint = global_mgcp_client_conf->last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 174 | if (last_endpoint != 0) { |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 175 | vty_out(vty, "%smgw endpoint-range %u %u%s", indent, |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 176 | first_endpoint, last_endpoint, VTY_NEWLINE); |
| 177 | } |
| 178 | |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 179 | bts_base = global_mgcp_client_conf->bts_base; |
| 180 | if (bts_base) { |
| 181 | vty_out(vty, "%smgw bts-base %u%s", indent, |
| 182 | bts_base, VTY_NEWLINE); |
| 183 | } |
| 184 | |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 185 | return CMD_SUCCESS; |
| 186 | } |
| 187 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 188 | 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] | 189 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 190 | global_mgcp_client_ctx = talloc_ctx; |
| 191 | global_mgcp_client_conf = conf; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 192 | |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 193 | install_element(node, &cfg_mgw_local_ip_cmd); |
| 194 | install_element(node, &cfg_mgw_local_port_cmd); |
| 195 | install_element(node, &cfg_mgw_remote_ip_cmd); |
| 196 | install_element(node, &cfg_mgw_remote_port_cmd); |
| 197 | install_element(node, &cfg_mgw_endpoint_range_cmd); |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 198 | install_element(node, &cfg_mgw_rtp_bts_base_port_cmd); |
Neels Hofmeyr | 87203f2 | 2017-10-31 01:15:45 +0100 | [diff] [blame] | 199 | |
| 200 | /* deprecated 'mgcpgw' commands */ |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 201 | install_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 202 | install_element(node, &cfg_mgcpgw_local_port_cmd); |
| 203 | install_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 204 | install_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 205 | install_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
Neels Hofmeyr | c0dcc3c | 2017-12-02 18:31:34 +0000 | [diff] [blame] | 206 | install_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd); |
Stefan Sperling | 2924825 | 2018-02-22 18:09:28 +0100 | [diff] [blame] | 207 | |
| 208 | osmo_fsm_vty_add_cmds(); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 209 | } |