Neels Hofmeyr | a1756f3 | 2016-05-20 21:59:55 +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 | |
| 29 | #include <openbsc/vty.h> |
| 30 | #include <openbsc/mgcpgw_client.h> |
| 31 | |
| 32 | #define MGCPGW_STR "MGCP gateway configuration for RTP streams\n" |
| 33 | |
| 34 | struct mgcpgw_client_conf *global_mgcpgw_client_conf = NULL; |
| 35 | |
| 36 | DEFUN(cfg_mgcpgw_local_ip, cfg_mgcpgw_local_ip_cmd, |
| 37 | "mgcpgw local-ip A.B.C.D", |
| 38 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 39 | "local bind IP address\n") |
| 40 | { |
| 41 | if (!global_mgcpgw_client_conf) |
| 42 | return CMD_ERR_NOTHING_TODO; |
| 43 | global_mgcpgw_client_conf->local_addr = |
| 44 | talloc_strdup(gsmnet_from_vty(vty), argv[0]); |
| 45 | return CMD_SUCCESS; |
| 46 | } |
| 47 | |
| 48 | DEFUN(cfg_mgcpgw_local_port, cfg_mgcpgw_local_port_cmd, |
| 49 | "mgcpgw local-port <0-65535>", |
| 50 | MGCPGW_STR "local bind to connect to MGCP gateway with\n" |
| 51 | "local bind port\n") |
| 52 | { |
| 53 | if (!global_mgcpgw_client_conf) |
| 54 | return CMD_ERR_NOTHING_TODO; |
| 55 | global_mgcpgw_client_conf->local_port = atoi(argv[0]); |
| 56 | return CMD_SUCCESS; |
| 57 | } |
| 58 | |
| 59 | DEFUN(cfg_mgcpgw_remote_ip, cfg_mgcpgw_remote_ip_cmd, |
| 60 | "mgcpgw remote-ip A.B.C.D", |
| 61 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 62 | "remote bind IP address\n") |
| 63 | { |
| 64 | if (!global_mgcpgw_client_conf) |
| 65 | return CMD_ERR_NOTHING_TODO; |
| 66 | global_mgcpgw_client_conf->remote_addr = |
| 67 | talloc_strdup(gsmnet_from_vty(vty), argv[0]); |
| 68 | return CMD_SUCCESS; |
| 69 | } |
| 70 | |
| 71 | DEFUN(cfg_mgcpgw_remote_port, cfg_mgcpgw_remote_port_cmd, |
| 72 | "mgcpgw remote-port <0-65535>", |
| 73 | MGCPGW_STR "remote bind to connect to MGCP gateway with\n" |
| 74 | "remote bind port\n") |
| 75 | { |
| 76 | if (!global_mgcpgw_client_conf) |
| 77 | return CMD_ERR_NOTHING_TODO; |
| 78 | global_mgcpgw_client_conf->remote_port = atoi(argv[0]); |
| 79 | return CMD_SUCCESS; |
| 80 | } |
| 81 | |
| 82 | int mgcpgw_client_config_write(struct vty *vty, const char *indent) |
| 83 | { |
| 84 | const char *addr; |
| 85 | int port; |
| 86 | |
| 87 | addr = global_mgcpgw_client_conf->local_addr; |
| 88 | if (addr) |
| 89 | vty_out(vty, "%smgcpgw local-ip %s%s", indent, addr, |
| 90 | VTY_NEWLINE); |
| 91 | port = global_mgcpgw_client_conf->local_port; |
| 92 | if (port >= 0) |
| 93 | vty_out(vty, "%smgcpgw local-port %u%s", indent, |
| 94 | (uint16_t)port, VTY_NEWLINE); |
| 95 | |
| 96 | addr = global_mgcpgw_client_conf->remote_addr; |
| 97 | if (addr) |
| 98 | vty_out(vty, "%smgcpgw remote-ip %s%s", indent, addr, |
| 99 | VTY_NEWLINE); |
| 100 | port = global_mgcpgw_client_conf->remote_port; |
| 101 | if (port >= 0) |
| 102 | vty_out(vty, "%smgcpgw remote-port %u%s", indent, |
| 103 | (uint16_t)port, VTY_NEWLINE); |
| 104 | |
| 105 | return CMD_SUCCESS; |
| 106 | } |
| 107 | |
| 108 | void mgcpgw_client_vty_init(int node, struct mgcpgw_client_conf *conf) |
| 109 | { |
| 110 | global_mgcpgw_client_conf = conf; |
| 111 | |
| 112 | install_element(node, &cfg_mgcpgw_local_ip_cmd); |
| 113 | install_element(node, &cfg_mgcpgw_local_port_cmd); |
| 114 | install_element(node, &cfg_mgcpgw_remote_ip_cmd); |
| 115 | install_element(node, &cfg_mgcpgw_remote_port_cmd); |
| 116 | } |