blob: 4b71b1bd2fd124e510272d9c097d91169d213a38 [file] [log] [blame]
Harald Welte799e0c92010-04-30 21:49:24 +02001/*
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 Welteb77c6972010-05-01 11:28:43 +020030#include <openbsc/gb_proxy.h>
31#include <openbsc/gprs_ns.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020032#include <openbsc/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020033
34#include <vty/command.h>
35#include <vty/vty.h>
36
Harald Welte799e0c92010-04-30 21:49:24 +020037static struct gbproxy_config *g_cfg = NULL;
38
39/*
40 * vty code for mgcp below
41 */
Harald Welteb77c6972010-05-01 11:28:43 +020042static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020043 GBPROXY_NODE,
44 "%s(gbproxy)#",
45 1,
46};
47
48static 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 Welted9c69cc2010-05-12 15:57:38 +000056 vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia),
Harald Welte799e0c92010-04-30 21:49:24 +020057 VTY_NEWLINE);
58 }
Harald Welted9c69cc2010-05-12 15:57:38 +000059 vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port,
Harald Welte799e0c92010-04-30 21:49:24 +020060 VTY_NEWLINE);
Harald Welted9c69cc2010-05-12 15:57:38 +000061 vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020062 VTY_NEWLINE);
Harald Welte799e0c92010-04-30 21:49:24 +020063
64 return CMD_SUCCESS;
65}
66
Harald Welte799e0c92010-04-30 21:49:24 +020067DEFUN(cfg_gbproxy,
68 cfg_gbproxy_cmd,
69 "gbproxy",
70 "Configure the Gb proxy")
71{
72 vty->node = GBPROXY_NODE;
73 return CMD_SUCCESS;
74}
75
76DEFUN(cfg_nsip_bss_local_ip,
77 cfg_nsip_bss_local_ip_cmd,
78 "nsip bss local ip A.B.C.D",
79 "Set the IP address on which we listen for BSS connects")
80{
81 struct in_addr ia;
82
83 inet_aton(argv[0], &ia);
84 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
85
86 return CMD_SUCCESS;
87}
88
89DEFUN(cfg_nsip_bss_local_port,
90 cfg_nsip_bss_local_port_cmd,
91 "nsip bss local port <0-65534>",
92 "Set the UDP port on which we listen for BSS connects")
93{
94 unsigned int port = atoi(argv[0]);
95
96 g_cfg->nsip_listen_port = port;
97 return CMD_SUCCESS;
98}
99
Harald Welte799e0c92010-04-30 21:49:24 +0200100DEFUN(cfg_nsip_sgsn_nsei,
101 cfg_nsip_sgsn_nsei_cmd,
102 "nsip sgsn nsei <0-65534>",
103 "Set the NSEI to be used in the connection with the SGSN")
104{
105 unsigned int port = atoi(argv[0]);
106
107 g_cfg->nsip_sgsn_nsei = port;
108 return CMD_SUCCESS;
109}
110
Harald Welte799e0c92010-04-30 21:49:24 +0200111int gbproxy_vty_init(void)
112{
Harald Welte995a2d32010-05-12 16:50:52 +0000113 install_element_ve(&show_gbproxy_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200114
115 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
116 install_node(&gbproxy_node, config_write_gbproxy);
117 install_default(GBPROXY_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200118 install_element(GBPROXY_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200119 install_element(GBPROXY_NODE, &ournode_end_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200120 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd);
121 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200122 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200123
124 return 0;
125}
126
127int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
128{
129 int rc;
130
131 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200132 rc = vty_read_config_file(config_file, NULL);
Harald Welte799e0c92010-04-30 21:49:24 +0200133 if (rc < 0) {
134 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
135 return rc;
136 }
137
138 return 0;
139}
140