Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 3 | * (C) 2010 by On-Waves |
| 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License along |
| 17 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | #include <sys/types.h> |
| 23 | #include <sys/socket.h> |
| 24 | #include <netinet/in.h> |
| 25 | #include <arpa/inet.h> |
| 26 | |
| 27 | #include <osmocore/talloc.h> |
| 28 | |
| 29 | #include <openbsc/debug.h> |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 30 | #include <openbsc/gb_proxy.h> |
| 31 | #include <openbsc/gprs_ns.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 32 | #include <openbsc/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 33 | |
| 34 | #include <vty/command.h> |
| 35 | #include <vty/vty.h> |
| 36 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 37 | static struct gbproxy_config *g_cfg = NULL; |
| 38 | |
| 39 | /* |
| 40 | * vty code for mgcp below |
| 41 | */ |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 42 | static struct cmd_node gbproxy_node = { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 43 | GBPROXY_NODE, |
| 44 | "%s(gbproxy)#", |
| 45 | 1, |
| 46 | }; |
| 47 | |
| 48 | static int config_write_gbproxy(struct vty *vty) |
| 49 | { |
| 50 | struct in_addr ia; |
| 51 | |
| 52 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 53 | |
| 54 | if (g_cfg->nsip_listen_ip) { |
| 55 | ia.s_addr = htonl(g_cfg->nsip_listen_ip); |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 56 | vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia), |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 57 | VTY_NEWLINE); |
| 58 | } |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 59 | vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 60 | VTY_NEWLINE); |
| 61 | ia.s_addr = htonl(g_cfg->nsip_sgsn_ip); |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 62 | vty_out(vty, " nsip sgsn remote ip %s%s", inet_ntoa(ia), |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 63 | VTY_NEWLINE); |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 64 | vty_out(vty, " nsip sgsn remote port %u%s", g_cfg->nsip_sgsn_port, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 65 | VTY_NEWLINE); |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 66 | vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 67 | VTY_NEWLINE); |
Harald Welte | d9c69cc | 2010-05-12 15:57:38 +0000 | [diff] [blame] | 68 | vty_out(vty, " nsip sgsn nsvci %u%s", g_cfg->nsip_sgsn_nsvci, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 69 | VTY_NEWLINE); |
| 70 | |
| 71 | return CMD_SUCCESS; |
| 72 | } |
| 73 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 74 | DEFUN(cfg_gbproxy, |
| 75 | cfg_gbproxy_cmd, |
| 76 | "gbproxy", |
| 77 | "Configure the Gb proxy") |
| 78 | { |
| 79 | vty->node = GBPROXY_NODE; |
| 80 | return CMD_SUCCESS; |
| 81 | } |
| 82 | |
| 83 | DEFUN(cfg_nsip_bss_local_ip, |
| 84 | cfg_nsip_bss_local_ip_cmd, |
| 85 | "nsip bss local ip A.B.C.D", |
| 86 | "Set the IP address on which we listen for BSS connects") |
| 87 | { |
| 88 | struct in_addr ia; |
| 89 | |
| 90 | inet_aton(argv[0], &ia); |
| 91 | g_cfg->nsip_listen_ip = ntohl(ia.s_addr); |
| 92 | |
| 93 | return CMD_SUCCESS; |
| 94 | } |
| 95 | |
| 96 | DEFUN(cfg_nsip_bss_local_port, |
| 97 | cfg_nsip_bss_local_port_cmd, |
| 98 | "nsip bss local port <0-65534>", |
| 99 | "Set the UDP port on which we listen for BSS connects") |
| 100 | { |
| 101 | unsigned int port = atoi(argv[0]); |
| 102 | |
| 103 | g_cfg->nsip_listen_port = port; |
| 104 | return CMD_SUCCESS; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | DEFUN(cfg_nsip_sgsn_ip, |
| 109 | cfg_nsip_sgsn_ip_cmd, |
| 110 | "nsip sgsn remote ip A.B.C.D", |
| 111 | "Set the IP of the SGSN to which the proxy shall connect") |
| 112 | { |
| 113 | struct in_addr ia; |
| 114 | |
| 115 | inet_aton(argv[0], &ia); |
| 116 | g_cfg->nsip_sgsn_ip = ntohl(ia.s_addr); |
| 117 | |
| 118 | return CMD_SUCCESS; |
| 119 | } |
| 120 | |
| 121 | DEFUN(cfg_nsip_sgsn_port, |
| 122 | cfg_nsip_sgsn_port_cmd, |
| 123 | "nsip sgsn remote port <0-65534>", |
| 124 | "Set the UDP port of the SGSN to which the proxy shall connect") |
| 125 | { |
| 126 | unsigned int port = atoi(argv[0]); |
| 127 | |
| 128 | g_cfg->nsip_sgsn_port = port; |
| 129 | return CMD_SUCCESS; |
| 130 | } |
| 131 | |
| 132 | DEFUN(cfg_nsip_sgsn_nsei, |
| 133 | cfg_nsip_sgsn_nsei_cmd, |
| 134 | "nsip sgsn nsei <0-65534>", |
| 135 | "Set the NSEI to be used in the connection with the SGSN") |
| 136 | { |
| 137 | unsigned int port = atoi(argv[0]); |
| 138 | |
| 139 | g_cfg->nsip_sgsn_nsei = port; |
| 140 | return CMD_SUCCESS; |
| 141 | } |
| 142 | |
| 143 | DEFUN(cfg_nsip_sgsn_nsvci, |
| 144 | cfg_nsip_sgsn_nsvci_cmd, |
| 145 | "nsip sgsn nsvci <0-65534>", |
| 146 | "Set the NSVCI to be used in the connection with the SGSN") |
| 147 | { |
| 148 | unsigned int port = atoi(argv[0]); |
| 149 | |
| 150 | g_cfg->nsip_sgsn_nsvci = port; |
| 151 | return CMD_SUCCESS; |
| 152 | } |
| 153 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 154 | int gbproxy_vty_init(void) |
| 155 | { |
Harald Welte | 995a2d3 | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 156 | install_element_ve(&show_gbproxy_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 157 | |
| 158 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 159 | install_node(&gbproxy_node, config_write_gbproxy); |
| 160 | install_default(GBPROXY_NODE); |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 161 | install_element(GBPROXY_NODE, &ournode_exit_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 162 | install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd); |
| 163 | install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd); |
| 164 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_ip_cmd); |
| 165 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_port_cmd); |
| 166 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
| 167 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsvci_cmd); |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 173 | { |
| 174 | int rc; |
| 175 | |
| 176 | g_cfg = cfg; |
| 177 | rc = vty_read_config_file(config_file); |
| 178 | if (rc < 0) { |
| 179 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 180 | return rc; |
| 181 | } |
| 182 | |
| 183 | return 0; |
| 184 | } |
| 185 | |