blob: 0bbd313a9db5a832b0827e73aaa8c2f02110bffe [file] [log] [blame]
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +08001/* OpenBSC NAT interface to quagga VTY */
2/* (C) 2010 by Holger Hans Peter Freyther
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
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +080022#include <openbsc/vty.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080023#include <openbsc/bsc_nat.h>
Holger Hans Peter Freytherc2b31ed2010-07-31 05:17:17 +080024#include <openbsc/bsc_nat_sccp.h>
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +080025#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080026#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +080027#include <openbsc/mgcp.h>
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +020028#include <openbsc/vty.h>
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080029
30#include <osmocore/talloc.h>
Holger Hans Peter Freytherb2c38eb2010-06-17 18:16:00 +080031#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +080032#include <osmocore/utils.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080033
Harald Welted5db12c2010-08-03 15:11:51 +020034#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080035
36#include <stdlib.h>
37
38static struct bsc_nat *_nat;
39
40static struct cmd_node nat_node = {
41 NAT_NODE,
42 "%s(nat)#",
43 1,
44};
45
46static struct cmd_node bsc_node = {
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080047 NAT_BSC_NODE,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080048 "%s(bsc)#",
49 1,
50};
51
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080052static void write_acc_lst(struct vty *vty, struct bsc_nat_acc_lst *lst)
53{
54 struct bsc_nat_acc_lst_entry *entry;
55
56 llist_for_each_entry(entry, &lst->fltr_list, list) {
57 if (entry->imsi_allow)
58 vty_out(vty, " access-list %s imsi-allow %s%s",
59 lst->name, entry->imsi_allow, VTY_NEWLINE);
60 if (entry->imsi_deny)
61 vty_out(vty, " access-list %s imsi-deny %s%s",
62 lst->name, entry->imsi_deny, VTY_NEWLINE);
63 }
64}
65
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080066static int config_write_nat(struct vty *vty)
67{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +080068 struct bsc_nat_acc_lst *lst;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080069
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080070 vty_out(vty, "nat%s", VTY_NEWLINE);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +080071 vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +020072 vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +080073 vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE);
74 vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE);
75 vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +080076 if (_nat->token)
77 vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +080078 vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080079 if (_nat->acc_lst_name)
80 vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE);
81
82 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080083 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080084 }
85
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080086 return CMD_SUCCESS;
87}
88
89static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
90{
91 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
92 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freytherd1278c12010-04-16 16:52:20 +020093 vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +080094 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +080095 if (bsc->description)
96 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080097 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +080098 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080099}
100
101static int config_write_bsc(struct vty *vty)
102{
103 struct bsc_config *bsc;
104
105 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
106 config_write_bsc_single(vty, bsc);
107 return CMD_SUCCESS;
108}
109
110
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800111DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
112 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800113{
114 struct sccp_connections *con;
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800115 vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800116
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800117 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800118 vty_out(vty, "For BSC Nr: %d lac: %d; BSC ref: 0x%x; MUX ref: 0x%x; Network has ref: %d ref: 0x%x MSC/BSC mux: 0x%x/0x%x type: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200119 con->bsc->cfg ? con->bsc->cfg->nr : -1,
120 con->bsc->cfg ? con->bsc->cfg->lac : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800121 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200122 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800123 con->has_remote_ref,
124 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800125 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800126 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200127 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800128 }
129
130 return CMD_SUCCESS;
131}
132
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800133DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
134 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800135{
136 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200137 struct sockaddr_in sock;
138 socklen_t len = sizeof(sock);
139
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800140 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200141 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther3b879812010-05-01 15:32:32 +0800142 vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200143 con->cfg ? con->cfg->nr : -1,
144 con->cfg ? con->cfg->lac : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200145 con->authenticated, con->write_queue.bfd.fd,
146 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800147 }
148
149 return CMD_SUCCESS;
150}
151
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800152DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
153 SHOW_STR "Display the MGCP status for a given BSC")
154{
155 struct bsc_connection *con;
156 int nr = atoi(argv[0]);
157 int i;
158
159 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
160 if (!con->cfg)
161 continue;
162 if (con->cfg->nr != nr)
163 continue;
164
165 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
166 for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i)
167 vty_out(vty, " Endpoint 0x%x %s%s", i,
168 con->endpoint_status[i] == 0 ? "free" : "allocated",
169 VTY_NEWLINE);
170 break;
171 }
172
173 return CMD_SUCCESS;
174}
175
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800176DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
177 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800178{
179 struct bsc_config *conf;
180 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
181 vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
182 conf->token, conf->lac, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800183 if (conf->acc_lst_name)
184 vty_out(vty, " access-list: %s%s",
185 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800186 vty_out(vty, " paging forbidden: %d%s",
187 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800188 if (conf->description)
189 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
190 else
191 vty_out(vty, " No description.%s", VTY_NEWLINE);
192
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800193 }
194
195 return CMD_SUCCESS;
196}
197
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800198static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
199{
200 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
201 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
202 counter_get(nat->stats.sccp.conn),
203 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
204 vty_out(vty, " MSC Connections %lu%s",
205 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800206 vty_out(vty, " MSC Connected: %d%s",
207 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800208 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
209 counter_get(nat->stats.bsc.reconn),
210 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
211}
212
213static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
214{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800215 int connected = 0;
216 struct bsc_connection *con;
217
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800218 vty_out(vty, " BSC lac: %d nr: %d%s",
219 conf->lac, conf->nr, VTY_NEWLINE);
220 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800221
222 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
223 if (con->cfg != conf)
224 continue;
225 connected = 1;
226 break;
227 }
228
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800229 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800230}
231
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200232DEFUN(show_stats,
233 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800234 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800235 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200236{
237 struct bsc_config *conf;
238
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800239 int nr = -1;
240
241 if (argc == 1)
242 nr = atoi(argv[0]);
243
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800244 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200245 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800246 if (argc == 1 && nr != conf->nr)
247 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800248 dump_stat_bsc(vty, conf);
249 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800250
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800251 return CMD_SUCCESS;
252}
253
254DEFUN(show_stats_lac,
255 show_stats_lac_cmd,
256 "show statistics-by-lac <0-65535>",
257 SHOW_STR "Display network statistics by lac\n"
258 "The lac of the BSC\n")
259{
260 int lac;
261 struct bsc_config *conf;
262
263 lac = atoi(argv[0]);
264
265 dump_stat_total(vty, _nat);
266 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
267 if (conf->lac != lac)
268 continue;
269 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200270 }
271
272 return CMD_SUCCESS;
273}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800274
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800275DEFUN(show_msc,
276 show_msc_cmd,
277 "show msc connection",
278 SHOW_STR "Show the status of the MSC connection.")
279{
280 if (!_nat->msc_con) {
281 vty_out(vty, "The MSC is not yet configured.\n");
282 return CMD_WARNING;
283 }
284
285 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
286 _nat->msc_con->ip, _nat->msc_con->port,
287 _nat->msc_con->is_connected, VTY_NEWLINE);
288 return CMD_SUCCESS;
289}
290
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800291DEFUN(close_bsc,
292 close_bsc_cmd,
293 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800294 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800295{
296 struct bsc_connection *bsc;
297 int bsc_nr = atoi(argv[0]);
298
299 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
300 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
301 continue;
302 bsc_close_connection(bsc);
303 break;
304 }
305
306 return CMD_SUCCESS;
307}
308
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800309DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
310{
311 vty->index = _nat;
312 vty->node = NAT_NODE;
313
314 return CMD_SUCCESS;
315}
316
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800317DEFUN(cfg_nat_msc_ip,
318 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800319 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800320 "Set the IP address of the MSC.")
321{
322 bsc_nat_set_msc_ip(_nat, argv[0]);
323 return CMD_SUCCESS;
324}
325
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200326DEFUN(cfg_nat_msc_port,
327 cfg_nat_msc_port_cmd,
328 "msc port <1-65500>",
329 "Set the port of the MSC.")
330{
331 _nat->msc_port = atoi(argv[0]);
332 return CMD_SUCCESS;
333}
334
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800335DEFUN(cfg_nat_auth_time,
336 cfg_nat_auth_time_cmd,
337 "timeout auth <1-256>",
338 "The time to wait for an auth response.")
339{
340 _nat->auth_timeout = atoi(argv[0]);
341 return CMD_SUCCESS;
342}
343
344DEFUN(cfg_nat_ping_time,
345 cfg_nat_ping_time_cmd,
346 "timeout ping NR",
347 "Send a ping every NR seconds. Negative to disable.")
348{
349 _nat->ping_timeout = atoi(argv[0]);
350 return CMD_SUCCESS;
351}
352
353DEFUN(cfg_nat_pong_time,
354 cfg_nat_pong_time_cmd,
355 "timeout pong NR",
356 "Wait NR seconds for the PONG response. Should be smaller than ping.")
357{
358 _nat->pong_timeout = atoi(argv[0]);
359 return CMD_SUCCESS;
360}
361
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800362DEFUN(cfg_nat_token, cfg_nat_token_cmd,
363 "token TOKEN",
364 "Set a token for the NAT")
365{
366 if (_nat->token)
367 talloc_free(_nat->token);
368 _nat->token = talloc_strdup(_nat, argv[0]);
369 return CMD_SUCCESS;
370}
371
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800372DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
373 "ip-dscp <0-255>",
374 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800375{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800376 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800377 return CMD_SUCCESS;
378}
379
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800380ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
381 "ip-tos <0-255>",
382 "Use ip-dscp in the future.\n" "Set the DSCP\n")
383
384
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800385DEFUN(cfg_nat_acc_lst_name,
386 cfg_nat_acc_lst_name_cmd,
387 "access-list-name NAME",
388 "Set the name of the access list to use.\n"
389 "The name of the to be used access list.")
390{
391 if (_nat->acc_lst_name)
392 talloc_free(_nat->acc_lst_name);
393 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
394 return CMD_SUCCESS;
395}
396
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800397/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800398DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800399{
400 int bsc_nr = atoi(argv[0]);
401 struct bsc_config *bsc;
402
403 if (bsc_nr > _nat->num_bsc) {
404 vty_out(vty, "%% The next unused BSC number is %u%s",
405 _nat->num_bsc, VTY_NEWLINE);
406 return CMD_WARNING;
407 } else if (bsc_nr == _nat->num_bsc) {
408 /* allocate a new one */
409 bsc = bsc_config_alloc(_nat, "unknown", 0);
410 } else
411 bsc = bsc_config_num(_nat, bsc_nr);
412
413 if (!bsc)
414 return CMD_WARNING;
415
416 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800417 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800418
419 return CMD_SUCCESS;
420}
421
422DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
423{
424 struct bsc_config *conf = vty->index;
425
426 if (conf->token)
427 talloc_free(conf->token);
428 conf->token = talloc_strdup(conf, argv[0]);
429 return CMD_SUCCESS;
430}
431
432DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800433 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800434{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200435 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800436 struct bsc_config *conf = vty->index;
437
438 int lac = atoi(argv[0]);
439
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800440 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
441 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
442 lac, VTY_NEWLINE);
443 return CMD_WARNING;
444 }
445
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200446 /* verify that the LACs are unique */
447 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
448 if (tmp->lac == lac) {
449 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
450 return CMD_ERR_INCOMPLETE;
451 }
452 }
453
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800454 conf->lac = lac;
455
456 return CMD_SUCCESS;
457}
458
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800459DEFUN(cfg_lst_imsi_allow,
460 cfg_lst_imsi_allow_cmd,
461 "access-list NAME imsi-allow [REGEXP]",
462 "Allow IMSIs matching the REGEXP\n"
463 "The name of the access-list\n"
464 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200465{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800466 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800467 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200468
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800469 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800470 if (!acc)
471 return CMD_WARNING;
472
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800473 entry = bsc_nat_acc_lst_entry_create(acc);
474 if (!entry)
475 return CMD_WARNING;
476
477 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200478 return CMD_SUCCESS;
479}
480
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800481DEFUN(cfg_lst_imsi_deny,
482 cfg_lst_imsi_deny_cmd,
483 "access-list NAME imsi-deny [REGEXP]",
484 "Allow IMSIs matching the REGEXP\n"
485 "The name of the access-list\n"
486 "The regexp of to be denied IMSIs\n")
487{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800488 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800489 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800490
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800491 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800492 if (!acc)
493 return CMD_WARNING;
494
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800495 entry = bsc_nat_acc_lst_entry_create(acc);
496 if (!entry)
497 return CMD_WARNING;
498
499 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800500 return CMD_SUCCESS;
501}
502
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800503/* naming to follow Zebra... */
504DEFUN(cfg_lst_no,
505 cfg_lst_no_cmd,
506 "no access-list NAME",
507 NO_STR "Remove an access-list by name\n"
508 "The access-list to remove\n")
509{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800510 struct bsc_nat_acc_lst *acc;
511 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800512 if (!acc)
513 return CMD_WARNING;
514
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800515 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800516 return CMD_SUCCESS;
517}
518
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800519DEFUN(cfg_bsc_acc_lst_name,
520 cfg_bsc_acc_lst_name_cmd,
521 "access-list-name NAME",
522 "Set the name of the access list to use.\n"
523 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200524{
525 struct bsc_config *conf = vty->index;
526
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800527 if (conf->acc_lst_name)
528 talloc_free(conf->acc_lst_name);
529 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200530 return CMD_SUCCESS;
531}
532
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800533DEFUN(cfg_bsc_paging,
534 cfg_bsc_paging_cmd,
535 "paging forbidden (0|1)",
536 "Forbid sending PAGING REQUESTS to the BSC.")
537{
538 struct bsc_config *conf = vty->index;
539
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800540 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800541 conf->forbid_paging = 1;
542 else
543 conf->forbid_paging = 0;
544
545 return CMD_SUCCESS;
546}
547
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800548DEFUN(cfg_bsc_desc,
549 cfg_bsc_desc_cmd,
550 "description DESC",
551 "Provide a description for the given BSC.")
552{
553 struct bsc_config *conf = vty->index;
554
555 if (conf->description)
556 talloc_free(conf->description);
557 conf->description = talloc_strdup(conf, argv[0]);
558 return CMD_SUCCESS;
559}
560
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800561DEFUN(test_regex, test_regex_cmd,
562 "test regex PATTERN STRING",
563 "Check if the string is matching the current pattern.")
564{
565 regex_t reg;
566 char *str = NULL;
567
568 memset(&reg, 0, sizeof(reg));
569 bsc_parse_reg(_nat, &reg, &str, 1, argv);
570
571 vty_out(vty, "String matches allow pattern: %d%s",
572 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
573
574 talloc_free(str);
575 regfree(&reg);
576 return CMD_SUCCESS;
577}
578
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800579int bsc_nat_vty_init(struct bsc_nat *nat)
580{
581 _nat = nat;
582
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800583 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800584 install_element_ve(&show_sccp_cmd);
585 install_element_ve(&show_bsc_cmd);
586 install_element_ve(&show_bsc_cfg_cmd);
587 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800588 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800589 install_element_ve(&close_bsc_cmd);
590 install_element_ve(&show_msc_cmd);
591 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800592 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200593
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800594 /* nat group */
595 install_element(CONFIG_NODE, &cfg_nat_cmd);
596 install_node(&nat_node, config_write_nat);
597 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800598 install_element(NAT_NODE, &ournode_exit_cmd);
599 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800600 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200601 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800602 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
603 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
604 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800605 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800606 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800607 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800608 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
609
610 /* access-list */
611 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
612 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800613 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800614
615 /* BSC subgroups */
616 install_element(NAT_NODE, &cfg_bsc_cmd);
617 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800618 install_default(NAT_BSC_NODE);
619 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
620 install_element(NAT_BSC_NODE, &ournode_end_cmd);
621 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
622 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
623 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
624 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
625 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800626
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800627 mgcp_vty_init();
628
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800629 return 0;
630}
631
632
633/* called by the telnet interface... we have our own init above */
634void bsc_vty_init()
635{}