blob: 16f6a1e0e5bede11a3aaaa82fcfd0c82d19adaa8 [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 Welte799e0c92010-04-30 21:49:24 +020032
33#include <vty/command.h>
34#include <vty/vty.h>
35
Harald Welte799e0c92010-04-30 21:49:24 +020036static struct gbproxy_config *g_cfg = NULL;
37
38/*
39 * vty code for mgcp below
40 */
Harald Welteb77c6972010-05-01 11:28:43 +020041static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020042 GBPROXY_NODE,
43 "%s(gbproxy)#",
44 1,
45};
46
47static int config_write_gbproxy(struct vty *vty)
48{
49 struct in_addr ia;
50
51 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
52
53 if (g_cfg->nsip_listen_ip) {
54 ia.s_addr = htonl(g_cfg->nsip_listen_ip);
55 vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia),
56 VTY_NEWLINE);
57 }
58 vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port,
59 VTY_NEWLINE);
60 ia.s_addr = htonl(g_cfg->nsip_sgsn_ip);
61 vty_out(vty, " nsip sgsn remote ip %s%s", inet_ntoa(ia),
62 VTY_NEWLINE);
63 vty_out(vty, " nsip sgsn remote port %u%s", g_cfg->nsip_sgsn_port,
64 VTY_NEWLINE);
65 vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
66 VTY_NEWLINE);
67 vty_out(vty, " nsip sgsn nsvci %u%s", g_cfg->nsip_sgsn_nsvci,
68 VTY_NEWLINE);
69
70 return CMD_SUCCESS;
71}
72
73DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy",
74 SHOW_STR "Display information about the Gb proxy")
75{
76 /* FIXME: iterate over list of NS-VC's and display their state */
Harald Welteb77c6972010-05-01 11:28:43 +020077 struct gprs_ns_inst *nsi = g_cfg->nsi;
78 struct gprs_nsvc *nsvc;
79
80 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
81 vty_out(vty, "NSEI %5u, NS-VC %5u, %s-mode, %s %s%s",
82 nsvc->nsei, nsvc->nsvci,
83 nsvc->remote_end_is_sgsn ? "BSS" : "SGSN",
84 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
85 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
86 VTY_NEWLINE);
87 if (nsvc->nsi->ll == GPRS_NS_LL_UDP)
88 vty_out(vty, " remote peer %s:%u%s",
89 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
90 ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE);
91 }
Harald Welte799e0c92010-04-30 21:49:24 +020092
93 return CMD_SUCCESS;
94}
95
96DEFUN(cfg_gbproxy,
97 cfg_gbproxy_cmd,
98 "gbproxy",
99 "Configure the Gb proxy")
100{
101 vty->node = GBPROXY_NODE;
102 return CMD_SUCCESS;
103}
104
105DEFUN(cfg_nsip_bss_local_ip,
106 cfg_nsip_bss_local_ip_cmd,
107 "nsip bss local ip A.B.C.D",
108 "Set the IP address on which we listen for BSS connects")
109{
110 struct in_addr ia;
111
112 inet_aton(argv[0], &ia);
113 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
114
115 return CMD_SUCCESS;
116}
117
118DEFUN(cfg_nsip_bss_local_port,
119 cfg_nsip_bss_local_port_cmd,
120 "nsip bss local port <0-65534>",
121 "Set the UDP port on which we listen for BSS connects")
122{
123 unsigned int port = atoi(argv[0]);
124
125 g_cfg->nsip_listen_port = port;
126 return CMD_SUCCESS;
127}
128
129
130DEFUN(cfg_nsip_sgsn_ip,
131 cfg_nsip_sgsn_ip_cmd,
132 "nsip sgsn remote ip A.B.C.D",
133 "Set the IP of the SGSN to which the proxy shall connect")
134{
135 struct in_addr ia;
136
137 inet_aton(argv[0], &ia);
138 g_cfg->nsip_sgsn_ip = ntohl(ia.s_addr);
139
140 return CMD_SUCCESS;
141}
142
143DEFUN(cfg_nsip_sgsn_port,
144 cfg_nsip_sgsn_port_cmd,
145 "nsip sgsn remote port <0-65534>",
146 "Set the UDP port of the SGSN to which the proxy shall connect")
147{
148 unsigned int port = atoi(argv[0]);
149
150 g_cfg->nsip_sgsn_port = port;
151 return CMD_SUCCESS;
152}
153
154DEFUN(cfg_nsip_sgsn_nsei,
155 cfg_nsip_sgsn_nsei_cmd,
156 "nsip sgsn nsei <0-65534>",
157 "Set the NSEI to be used in the connection with the SGSN")
158{
159 unsigned int port = atoi(argv[0]);
160
161 g_cfg->nsip_sgsn_nsei = port;
162 return CMD_SUCCESS;
163}
164
165DEFUN(cfg_nsip_sgsn_nsvci,
166 cfg_nsip_sgsn_nsvci_cmd,
167 "nsip sgsn nsvci <0-65534>",
168 "Set the NSVCI to be used in the connection with the SGSN")
169{
170 unsigned int port = atoi(argv[0]);
171
172 g_cfg->nsip_sgsn_nsvci = port;
173 return CMD_SUCCESS;
174}
175
176
177int gbproxy_vty_init(void)
178{
179 install_element(VIEW_NODE, &show_gbproxy_cmd);
180
181 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
182 install_node(&gbproxy_node, config_write_gbproxy);
183 install_default(GBPROXY_NODE);
184 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd);
185 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd);
186 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_ip_cmd);
187 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_port_cmd);
188 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
189 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsvci_cmd);
190
191 return 0;
192}
193
194int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
195{
196 int rc;
197
198 g_cfg = cfg;
199 rc = vty_read_config_file(config_file);
200 if (rc < 0) {
201 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
202 return rc;
203 }
204
205 return 0;
206}
207