Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 1 | /* MGCPGW client interface to quagga VTY */ |
| 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 | |
| 30 | #include <osmocom/legacy_mgcp/vty.h> |
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 | |
| 33 | #define MGCPGW_STR "MGCP gateway configuration for RTP streams\n" |
| 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 | |
| 38 | DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 39 | "mgcpgw local-ip A.B.C.D", |
| 40 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 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 | } |
| 50 | |
| 51 | DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 52 | "mgcpgw local-port <0-65535>", |
| 53 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 54 | "local bind port\n") |
| 55 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 56 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 57 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 58 | global_mgcp_client_conf->local_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 59 | return CMD_SUCCESS; |
| 60 | } |
| 61 | |
| 62 | DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 63 | "mgcpgw remote-ip A.B.C.D", |
| 64 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 65 | "remote bind IP address\n") |
| 66 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 67 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 68 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 69 | OSMO_ASSERT(global_mgcp_client_ctx); |
| 70 | global_mgcp_client_conf->remote_addr = |
| 71 | talloc_strdup(global_mgcp_client_ctx, argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 72 | return CMD_SUCCESS; |
| 73 | } |
| 74 | |
| 75 | DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 76 | "mgcpgw remote-port <0-65535>", |
| 77 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 78 | "remote bind port\n") |
| 79 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 80 | if (!global_mgcp_client_conf) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 81 | return CMD_ERR_NOTHING_TODO; |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 82 | global_mgcp_client_conf->remote_port = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 83 | return CMD_SUCCESS; |
| 84 | } |
| 85 | |
| 86 | DEFUN(cfg_mgcpgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd, |
| 87 | "mgcpgw endpoint-range <1-65534> <1-65534>", |
| 88 | MGCPGW_STR "usable range of endpoint identifiers\n" |
| 89 | "set first useable endpoint identifier\n" |
| 90 | "set the last useable endpoint identifier\n") |
| 91 | { |
| 92 | uint16_t first_endpoint = atoi(argv[0]); |
| 93 | uint16_t last_endpoint = atoi(argv[1]); |
| 94 | |
| 95 | if (last_endpoint < first_endpoint) { |
| 96 | vty_out(vty, "last endpoint must be greater than first endpoint!%s", |
| 97 | VTY_NEWLINE); |
| 98 | return CMD_SUCCESS; |
| 99 | } |
| 100 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 101 | global_mgcp_client_conf->first_endpoint = first_endpoint; |
| 102 | global_mgcp_client_conf->last_endpoint = last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 103 | return CMD_SUCCESS; |
| 104 | } |
| 105 | |
| 106 | #define BTS_START_STR "First UDP port allocated for the BTS side\n" |
| 107 | #define UDP_PORT_STR "UDP Port number\n" |
| 108 | DEFUN(cfg_mgcp_rtp_bts_base_port, |
| 109 | cfg_mgcp_rtp_bts_base_port_cmd, |
| 110 | "mgcpgw bts-base <0-65534>", |
| 111 | MGCPGW_STR |
| 112 | BTS_START_STR |
| 113 | UDP_PORT_STR) |
| 114 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 115 | global_mgcp_client_conf->bts_base = atoi(argv[0]); |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 116 | return CMD_SUCCESS; |
| 117 | } |
| 118 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 119 | int mgcp_client_config_write(struct vty *vty, const char *indent) |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 120 | { |
| 121 | const char *addr; |
| 122 | int port; |
| 123 | uint16_t first_endpoint; |
| 124 | uint16_t last_endpoint; |
| 125 | uint16_t bts_base; |
| 126 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 127 | addr = global_mgcp_client_conf->local_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 128 | if (addr) |
| 129 | vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr, |
| 130 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 131 | port = global_mgcp_client_conf->local_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 132 | if (port >= 0) |
| 133 | vty_out(vty, "%smgcpgw local-port %u%s", indent, |
| 134 | (uint16_t)port, VTY_NEWLINE); |
| 135 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 136 | addr = global_mgcp_client_conf->remote_addr; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 137 | if (addr) |
| 138 | vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr, |
| 139 | VTY_NEWLINE); |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 140 | port = global_mgcp_client_conf->remote_port; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 141 | if (port >= 0) |
| 142 | vty_out(vty, "%smgcpgw remote-port %u%s", indent, |
| 143 | (uint16_t)port, VTY_NEWLINE); |
| 144 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 145 | first_endpoint = global_mgcp_client_conf->first_endpoint; |
| 146 | last_endpoint = global_mgcp_client_conf->last_endpoint; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 147 | if (last_endpoint != 0) { |
| 148 | vty_out(vty, "%smgcpgw endpoint-range %u %u%s", indent, |
| 149 | first_endpoint, last_endpoint, VTY_NEWLINE); |
| 150 | } |
| 151 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 152 | bts_base = global_mgcp_client_conf->bts_base; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 153 | if (bts_base) { |
| 154 | vty_out(vty, "%smgcpgw bts-base %u%s", indent, |
| 155 | bts_base, VTY_NEWLINE); |
| 156 | } |
| 157 | |
| 158 | return CMD_SUCCESS; |
| 159 | } |
| 160 | |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 161 | 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] | 162 | { |
Neels Hofmeyr | 3a8e723 | 2017-09-04 01:02:56 +0200 | [diff] [blame] | 163 | global_mgcp_client_ctx = talloc_ctx; |
| 164 | global_mgcp_client_conf = conf; |
Neels Hofmeyr | e9920f2 | 2017-07-10 15:07:22 +0200 | [diff] [blame] | 165 | |
| 166 | install_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 167 | install_element(node, &cfg_mgcpgw_local_port_cmd); |
| 168 | install_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 169 | install_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 170 | install_element(node, &cfg_mgcpgw_endpoint_range_cmd); |
| 171 | install_element(node, &cfg_mgcp_rtp_bts_base_port_cmd); |
| 172 | } |