blob: cfa5473cc992cdda1d9bc21be9ae9bd43eaeee25 [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 Freytheraad82ce2010-05-11 19:07:39 +080024#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080025#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +080026#include <openbsc/mgcp.h>
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +020027#include <openbsc/vty.h>
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080028
29#include <osmocore/talloc.h>
Holger Hans Peter Freytherb2c38eb2010-06-17 18:16:00 +080030#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080031
32#include <sccp/sccp.h>
33
34#include <stdlib.h>
35
36static struct bsc_nat *_nat;
37
38static struct cmd_node nat_node = {
39 NAT_NODE,
40 "%s(nat)#",
41 1,
42};
43
44static struct cmd_node bsc_node = {
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080045 NAT_BSC_NODE,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080046 "%s(bsc)#",
47 1,
48};
49
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080050static void write_acc_lst(struct vty *vty, struct bsc_nat_acc_lst *lst)
51{
52 struct bsc_nat_acc_lst_entry *entry;
53
54 llist_for_each_entry(entry, &lst->fltr_list, list) {
55 if (entry->imsi_allow)
56 vty_out(vty, " access-list %s imsi-allow %s%s",
57 lst->name, entry->imsi_allow, VTY_NEWLINE);
58 if (entry->imsi_deny)
59 vty_out(vty, " access-list %s imsi-deny %s%s",
60 lst->name, entry->imsi_deny, VTY_NEWLINE);
61 }
62}
63
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080064static int config_write_nat(struct vty *vty)
65{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +080066 struct bsc_nat_acc_lst *lst;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080067
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080068 vty_out(vty, "nat%s", VTY_NEWLINE);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +080069 vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +020070 vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +080071 vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE);
72 vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE);
73 vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +080074 if (_nat->token)
75 vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +080076 vty_out(vty, " ip-tos %d%s", _nat->bsc_ip_tos, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080077 if (_nat->acc_lst_name)
78 vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE);
79
80 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080081 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080082 }
83
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080084 return CMD_SUCCESS;
85}
86
87static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
88{
89 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
90 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freytherd1278c12010-04-16 16:52:20 +020091 vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +080092 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +080093 if (bsc->description)
94 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080095 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +080096 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080097}
98
99static int config_write_bsc(struct vty *vty)
100{
101 struct bsc_config *bsc;
102
103 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
104 config_write_bsc_single(vty, bsc);
105 return CMD_SUCCESS;
106}
107
108
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800109DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
110 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800111{
112 struct sccp_connections *con;
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800113 vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800114
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800115 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800116 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 +0200117 con->bsc->cfg ? con->bsc->cfg->nr : -1,
118 con->bsc->cfg ? con->bsc->cfg->lac : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800119 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200120 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800121 con->has_remote_ref,
122 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200123 con->msc_timeslot, con->bsc_timeslot,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800124 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200125 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800126 }
127
128 return CMD_SUCCESS;
129}
130
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800131DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
132 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800133{
134 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200135 struct sockaddr_in sock;
136 socklen_t len = sizeof(sock);
137
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800138 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200139 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther3b879812010-05-01 15:32:32 +0800140 vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200141 con->cfg ? con->cfg->nr : -1,
142 con->cfg ? con->cfg->lac : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200143 con->authenticated, con->write_queue.bfd.fd,
144 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800145 }
146
147 return CMD_SUCCESS;
148}
149
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800150DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
151 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800152{
153 struct bsc_config *conf;
154 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
155 vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
156 conf->token, conf->lac, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800157 if (conf->acc_lst_name)
158 vty_out(vty, " access-list: %s%s",
159 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800160 vty_out(vty, " paging forbidden: %d%s",
161 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800162 if (conf->description)
163 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
164 else
165 vty_out(vty, " No description.%s", VTY_NEWLINE);
166
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800167 }
168
169 return CMD_SUCCESS;
170}
171
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800172static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
173{
174 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
175 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
176 counter_get(nat->stats.sccp.conn),
177 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
178 vty_out(vty, " MSC Connections %lu%s",
179 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
180 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
181 counter_get(nat->stats.bsc.reconn),
182 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
183}
184
185static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
186{
187 vty_out(vty, " BSC lac: %d nr: %d%s",
188 conf->lac, conf->nr, VTY_NEWLINE);
189 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
190}
191
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200192DEFUN(show_stats,
193 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800194 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800195 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200196{
197 struct bsc_config *conf;
198
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800199 int nr = -1;
200
201 if (argc == 1)
202 nr = atoi(argv[0]);
203
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800204 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200205 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800206 if (argc == 1 && nr != conf->nr)
207 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800208 dump_stat_bsc(vty, conf);
209 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800210
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800211 return CMD_SUCCESS;
212}
213
214DEFUN(show_stats_lac,
215 show_stats_lac_cmd,
216 "show statistics-by-lac <0-65535>",
217 SHOW_STR "Display network statistics by lac\n"
218 "The lac of the BSC\n")
219{
220 int lac;
221 struct bsc_config *conf;
222
223 lac = atoi(argv[0]);
224
225 dump_stat_total(vty, _nat);
226 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
227 if (conf->lac != lac)
228 continue;
229 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200230 }
231
232 return CMD_SUCCESS;
233}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800234
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800235DEFUN(show_msc,
236 show_msc_cmd,
237 "show msc connection",
238 SHOW_STR "Show the status of the MSC connection.")
239{
240 if (!_nat->msc_con) {
241 vty_out(vty, "The MSC is not yet configured.\n");
242 return CMD_WARNING;
243 }
244
245 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
246 _nat->msc_con->ip, _nat->msc_con->port,
247 _nat->msc_con->is_connected, VTY_NEWLINE);
248 return CMD_SUCCESS;
249}
250
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800251DEFUN(close_bsc,
252 close_bsc_cmd,
253 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800254 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800255{
256 struct bsc_connection *bsc;
257 int bsc_nr = atoi(argv[0]);
258
259 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
260 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
261 continue;
262 bsc_close_connection(bsc);
263 break;
264 }
265
266 return CMD_SUCCESS;
267}
268
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800269DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
270{
271 vty->index = _nat;
272 vty->node = NAT_NODE;
273
274 return CMD_SUCCESS;
275}
276
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800277DEFUN(cfg_nat_msc_ip,
278 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800279 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800280 "Set the IP address of the MSC.")
281{
282 bsc_nat_set_msc_ip(_nat, argv[0]);
283 return CMD_SUCCESS;
284}
285
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200286DEFUN(cfg_nat_msc_port,
287 cfg_nat_msc_port_cmd,
288 "msc port <1-65500>",
289 "Set the port of the MSC.")
290{
291 _nat->msc_port = atoi(argv[0]);
292 return CMD_SUCCESS;
293}
294
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800295DEFUN(cfg_nat_auth_time,
296 cfg_nat_auth_time_cmd,
297 "timeout auth <1-256>",
298 "The time to wait for an auth response.")
299{
300 _nat->auth_timeout = atoi(argv[0]);
301 return CMD_SUCCESS;
302}
303
304DEFUN(cfg_nat_ping_time,
305 cfg_nat_ping_time_cmd,
306 "timeout ping NR",
307 "Send a ping every NR seconds. Negative to disable.")
308{
309 _nat->ping_timeout = atoi(argv[0]);
310 return CMD_SUCCESS;
311}
312
313DEFUN(cfg_nat_pong_time,
314 cfg_nat_pong_time_cmd,
315 "timeout pong NR",
316 "Wait NR seconds for the PONG response. Should be smaller than ping.")
317{
318 _nat->pong_timeout = atoi(argv[0]);
319 return CMD_SUCCESS;
320}
321
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800322DEFUN(cfg_nat_token, cfg_nat_token_cmd,
323 "token TOKEN",
324 "Set a token for the NAT")
325{
326 if (_nat->token)
327 talloc_free(_nat->token);
328 _nat->token = talloc_strdup(_nat, argv[0]);
329 return CMD_SUCCESS;
330}
331
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800332DEFUN(cfg_nat_bsc_ip_tos, cfg_nat_bsc_ip_tos_cmd,
333 "ip-tos <0-255>",
334 "Set the IP_TOS for the BSCs to use\n" "Set the IP_TOS attribute")
335{
336 _nat->bsc_ip_tos = atoi(argv[0]);
337 return CMD_SUCCESS;
338}
339
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800340DEFUN(cfg_nat_acc_lst_name,
341 cfg_nat_acc_lst_name_cmd,
342 "access-list-name NAME",
343 "Set the name of the access list to use.\n"
344 "The name of the to be used access list.")
345{
346 if (_nat->acc_lst_name)
347 talloc_free(_nat->acc_lst_name);
348 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
349 return CMD_SUCCESS;
350}
351
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800352/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800353DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800354{
355 int bsc_nr = atoi(argv[0]);
356 struct bsc_config *bsc;
357
358 if (bsc_nr > _nat->num_bsc) {
359 vty_out(vty, "%% The next unused BSC number is %u%s",
360 _nat->num_bsc, VTY_NEWLINE);
361 return CMD_WARNING;
362 } else if (bsc_nr == _nat->num_bsc) {
363 /* allocate a new one */
364 bsc = bsc_config_alloc(_nat, "unknown", 0);
365 } else
366 bsc = bsc_config_num(_nat, bsc_nr);
367
368 if (!bsc)
369 return CMD_WARNING;
370
371 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800372 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800373
374 return CMD_SUCCESS;
375}
376
377DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
378{
379 struct bsc_config *conf = vty->index;
380
381 if (conf->token)
382 talloc_free(conf->token);
383 conf->token = talloc_strdup(conf, argv[0]);
384 return CMD_SUCCESS;
385}
386
387DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800388 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800389{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200390 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800391 struct bsc_config *conf = vty->index;
392
393 int lac = atoi(argv[0]);
394
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800395 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
396 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
397 lac, VTY_NEWLINE);
398 return CMD_WARNING;
399 }
400
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200401 /* verify that the LACs are unique */
402 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
403 if (tmp->lac == lac) {
404 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
405 return CMD_ERR_INCOMPLETE;
406 }
407 }
408
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800409 conf->lac = lac;
410
411 return CMD_SUCCESS;
412}
413
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800414DEFUN(cfg_lst_imsi_allow,
415 cfg_lst_imsi_allow_cmd,
416 "access-list NAME imsi-allow [REGEXP]",
417 "Allow IMSIs matching the REGEXP\n"
418 "The name of the access-list\n"
419 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200420{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800421 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800422 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200423
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800424 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800425 if (!acc)
426 return CMD_WARNING;
427
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800428 entry = bsc_nat_acc_lst_entry_create(acc);
429 if (!entry)
430 return CMD_WARNING;
431
432 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200433 return CMD_SUCCESS;
434}
435
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800436DEFUN(cfg_lst_imsi_deny,
437 cfg_lst_imsi_deny_cmd,
438 "access-list NAME imsi-deny [REGEXP]",
439 "Allow IMSIs matching the REGEXP\n"
440 "The name of the access-list\n"
441 "The regexp of to be denied IMSIs\n")
442{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800443 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800444 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800445
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800446 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800447 if (!acc)
448 return CMD_WARNING;
449
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800450 entry = bsc_nat_acc_lst_entry_create(acc);
451 if (!entry)
452 return CMD_WARNING;
453
454 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800455 return CMD_SUCCESS;
456}
457
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800458/* naming to follow Zebra... */
459DEFUN(cfg_lst_no,
460 cfg_lst_no_cmd,
461 "no access-list NAME",
462 NO_STR "Remove an access-list by name\n"
463 "The access-list to remove\n")
464{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800465 struct bsc_nat_acc_lst *acc;
466 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800467 if (!acc)
468 return CMD_WARNING;
469
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800470 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800471 return CMD_SUCCESS;
472}
473
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800474DEFUN(cfg_bsc_acc_lst_name,
475 cfg_bsc_acc_lst_name_cmd,
476 "access-list-name NAME",
477 "Set the name of the access list to use.\n"
478 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200479{
480 struct bsc_config *conf = vty->index;
481
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800482 if (conf->acc_lst_name)
483 talloc_free(conf->acc_lst_name);
484 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200485 return CMD_SUCCESS;
486}
487
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800488DEFUN(cfg_bsc_paging,
489 cfg_bsc_paging_cmd,
490 "paging forbidden (0|1)",
491 "Forbid sending PAGING REQUESTS to the BSC.")
492{
493 struct bsc_config *conf = vty->index;
494
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800495 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800496 conf->forbid_paging = 1;
497 else
498 conf->forbid_paging = 0;
499
500 return CMD_SUCCESS;
501}
502
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800503DEFUN(cfg_bsc_desc,
504 cfg_bsc_desc_cmd,
505 "description DESC",
506 "Provide a description for the given BSC.")
507{
508 struct bsc_config *conf = vty->index;
509
510 if (conf->description)
511 talloc_free(conf->description);
512 conf->description = talloc_strdup(conf, argv[0]);
513 return CMD_SUCCESS;
514}
515
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800516DEFUN(test_regex, test_regex_cmd,
517 "test regex PATTERN STRING",
518 "Check if the string is matching the current pattern.")
519{
520 regex_t reg;
521 char *str = NULL;
522
523 memset(&reg, 0, sizeof(reg));
524 bsc_parse_reg(_nat, &reg, &str, 1, argv);
525
526 vty_out(vty, "String matches allow pattern: %d%s",
527 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
528
529 talloc_free(str);
530 regfree(&reg);
531 return CMD_SUCCESS;
532}
533
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800534int bsc_nat_vty_init(struct bsc_nat *nat)
535{
536 _nat = nat;
537
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800538 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800539 install_element_ve(&show_sccp_cmd);
540 install_element_ve(&show_bsc_cmd);
541 install_element_ve(&show_bsc_cfg_cmd);
542 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800543 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800544 install_element_ve(&close_bsc_cmd);
545 install_element_ve(&show_msc_cmd);
546 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200547
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800548 /* nat group */
549 install_element(CONFIG_NODE, &cfg_nat_cmd);
550 install_node(&nat_node, config_write_nat);
551 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800552 install_element(NAT_NODE, &ournode_exit_cmd);
553 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800554 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200555 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800556 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
557 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
558 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800559 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800560 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800561 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
562
563 /* access-list */
564 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
565 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800566 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800567
568 /* BSC subgroups */
569 install_element(NAT_NODE, &cfg_bsc_cmd);
570 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800571 install_default(NAT_BSC_NODE);
572 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
573 install_element(NAT_BSC_NODE, &ournode_end_cmd);
574 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
575 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
576 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
577 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
578 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800579
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800580 mgcp_vty_init();
581
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800582 return 0;
583}
584
585
586/* called by the telnet interface... we have our own init above */
587void bsc_vty_init()
588{}