blob: 66c45f602c430b043a7cc8930fac532b3733fc4f [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 Freyther9a85ef32010-06-15 18:46:11 +080030
31#include <sccp/sccp.h>
32
33#include <stdlib.h>
34
35static struct bsc_nat *_nat;
36
37static struct cmd_node nat_node = {
38 NAT_NODE,
39 "%s(nat)#",
40 1,
41};
42
43static struct cmd_node bsc_node = {
44 BSC_NODE,
45 "%s(bsc)#",
46 1,
47};
48
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080049static void write_acc_lst(struct vty *vty, struct bsc_nat_acc_lst *lst)
50{
51 struct bsc_nat_acc_lst_entry *entry;
52
53 llist_for_each_entry(entry, &lst->fltr_list, list) {
54 if (entry->imsi_allow)
55 vty_out(vty, " access-list %s imsi-allow %s%s",
56 lst->name, entry->imsi_allow, VTY_NEWLINE);
57 if (entry->imsi_deny)
58 vty_out(vty, " access-list %s imsi-deny %s%s",
59 lst->name, entry->imsi_deny, VTY_NEWLINE);
60 }
61}
62
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080063static int config_write_nat(struct vty *vty)
64{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +080065 struct bsc_nat_acc_lst *lst;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080066
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080067 vty_out(vty, "nat%s", VTY_NEWLINE);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +080068 vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +020069 vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +080070 vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE);
71 vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE);
72 vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +080073 if (_nat->token)
74 vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +080075 vty_out(vty, " ip-tos %d%s", _nat->bsc_ip_tos, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080076 if (_nat->acc_lst_name)
77 vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE);
78
79 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080080 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080081 }
82
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080083 return CMD_SUCCESS;
84}
85
86static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
87{
88 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
89 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freytherd1278c12010-04-16 16:52:20 +020090 vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +080091 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +080092 if (bsc->description)
93 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080094 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +080095 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080096}
97
98static int config_write_bsc(struct vty *vty)
99{
100 struct bsc_config *bsc;
101
102 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
103 config_write_bsc_single(vty, bsc);
104 return CMD_SUCCESS;
105}
106
107
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800108DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
109 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800110{
111 struct sccp_connections *con;
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800112 vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800113
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800114 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800115 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 +0200116 con->bsc->cfg ? con->bsc->cfg->nr : -1,
117 con->bsc->cfg ? con->bsc->cfg->lac : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800118 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200119 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800120 con->has_remote_ref,
121 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200122 con->msc_timeslot, con->bsc_timeslot,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800123 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200124 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800125 }
126
127 return CMD_SUCCESS;
128}
129
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800130DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
131 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800132{
133 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200134 struct sockaddr_in sock;
135 socklen_t len = sizeof(sock);
136
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800137 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200138 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther3b879812010-05-01 15:32:32 +0800139 vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200140 con->cfg ? con->cfg->nr : -1,
141 con->cfg ? con->cfg->lac : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200142 con->authenticated, con->write_queue.bfd.fd,
143 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800144 }
145
146 return CMD_SUCCESS;
147}
148
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800149DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
150 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800151{
152 struct bsc_config *conf;
153 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
154 vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
155 conf->token, conf->lac, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800156 if (conf->acc_lst_name)
157 vty_out(vty, " access-list: %s%s",
158 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800159 vty_out(vty, " paging forbidden: %d%s",
160 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800161 if (conf->description)
162 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
163 else
164 vty_out(vty, " No description.%s", VTY_NEWLINE);
165
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800166 }
167
168 return CMD_SUCCESS;
169}
170
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200171DEFUN(show_stats,
172 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800173 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800174 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200175{
176 struct bsc_config *conf;
177
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800178 int nr = -1;
179
180 if (argc == 1)
181 nr = atoi(argv[0]);
182
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200183 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
184 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
185 counter_get(_nat->stats.sccp.conn),
186 counter_get(_nat->stats.sccp.calls), VTY_NEWLINE);
187 vty_out(vty, " MSC Connections %lu%s",
188 counter_get(_nat->stats.msc.reconn), VTY_NEWLINE);
189 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
190 counter_get(_nat->stats.bsc.reconn),
191 counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE);
192
193 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800194 if (argc == 1 && nr != conf->nr)
195 continue;
196
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200197 vty_out(vty, " BSC lac: %d nr: %d%s",
198 conf->lac, conf->nr, VTY_NEWLINE);
199 vty_out(vty, " SCCP Connnections %lu total, %lu calls%s",
200 counter_get(conf->stats.sccp.conn),
201 counter_get(conf->stats.sccp.calls), VTY_NEWLINE);
202 vty_out(vty, " BSC Connections %lu total%s",
203 counter_get(conf->stats.net.reconn), VTY_NEWLINE);
204 }
205
206 return CMD_SUCCESS;
207}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800208
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800209DEFUN(show_msc,
210 show_msc_cmd,
211 "show msc connection",
212 SHOW_STR "Show the status of the MSC connection.")
213{
214 if (!_nat->msc_con) {
215 vty_out(vty, "The MSC is not yet configured.\n");
216 return CMD_WARNING;
217 }
218
219 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
220 _nat->msc_con->ip, _nat->msc_con->port,
221 _nat->msc_con->is_connected, VTY_NEWLINE);
222 return CMD_SUCCESS;
223}
224
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800225DEFUN(close_bsc,
226 close_bsc_cmd,
227 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800228 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800229{
230 struct bsc_connection *bsc;
231 int bsc_nr = atoi(argv[0]);
232
233 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
234 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
235 continue;
236 bsc_close_connection(bsc);
237 break;
238 }
239
240 return CMD_SUCCESS;
241}
242
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800243DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
244{
245 vty->index = _nat;
246 vty->node = NAT_NODE;
247
248 return CMD_SUCCESS;
249}
250
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800251DEFUN(cfg_nat_msc_ip,
252 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800253 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800254 "Set the IP address of the MSC.")
255{
256 bsc_nat_set_msc_ip(_nat, argv[0]);
257 return CMD_SUCCESS;
258}
259
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200260DEFUN(cfg_nat_msc_port,
261 cfg_nat_msc_port_cmd,
262 "msc port <1-65500>",
263 "Set the port of the MSC.")
264{
265 _nat->msc_port = atoi(argv[0]);
266 return CMD_SUCCESS;
267}
268
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800269DEFUN(cfg_nat_auth_time,
270 cfg_nat_auth_time_cmd,
271 "timeout auth <1-256>",
272 "The time to wait for an auth response.")
273{
274 _nat->auth_timeout = atoi(argv[0]);
275 return CMD_SUCCESS;
276}
277
278DEFUN(cfg_nat_ping_time,
279 cfg_nat_ping_time_cmd,
280 "timeout ping NR",
281 "Send a ping every NR seconds. Negative to disable.")
282{
283 _nat->ping_timeout = atoi(argv[0]);
284 return CMD_SUCCESS;
285}
286
287DEFUN(cfg_nat_pong_time,
288 cfg_nat_pong_time_cmd,
289 "timeout pong NR",
290 "Wait NR seconds for the PONG response. Should be smaller than ping.")
291{
292 _nat->pong_timeout = atoi(argv[0]);
293 return CMD_SUCCESS;
294}
295
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800296DEFUN(cfg_nat_token, cfg_nat_token_cmd,
297 "token TOKEN",
298 "Set a token for the NAT")
299{
300 if (_nat->token)
301 talloc_free(_nat->token);
302 _nat->token = talloc_strdup(_nat, argv[0]);
303 return CMD_SUCCESS;
304}
305
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800306DEFUN(cfg_nat_bsc_ip_tos, cfg_nat_bsc_ip_tos_cmd,
307 "ip-tos <0-255>",
308 "Set the IP_TOS for the BSCs to use\n" "Set the IP_TOS attribute")
309{
310 _nat->bsc_ip_tos = atoi(argv[0]);
311 return CMD_SUCCESS;
312}
313
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800314DEFUN(cfg_nat_acc_lst_name,
315 cfg_nat_acc_lst_name_cmd,
316 "access-list-name NAME",
317 "Set the name of the access list to use.\n"
318 "The name of the to be used access list.")
319{
320 if (_nat->acc_lst_name)
321 talloc_free(_nat->acc_lst_name);
322 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
323 return CMD_SUCCESS;
324}
325
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800326/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800327DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800328{
329 int bsc_nr = atoi(argv[0]);
330 struct bsc_config *bsc;
331
332 if (bsc_nr > _nat->num_bsc) {
333 vty_out(vty, "%% The next unused BSC number is %u%s",
334 _nat->num_bsc, VTY_NEWLINE);
335 return CMD_WARNING;
336 } else if (bsc_nr == _nat->num_bsc) {
337 /* allocate a new one */
338 bsc = bsc_config_alloc(_nat, "unknown", 0);
339 } else
340 bsc = bsc_config_num(_nat, bsc_nr);
341
342 if (!bsc)
343 return CMD_WARNING;
344
345 vty->index = bsc;
346 vty->node = BSC_NODE;
347
348 return CMD_SUCCESS;
349}
350
351DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
352{
353 struct bsc_config *conf = vty->index;
354
355 if (conf->token)
356 talloc_free(conf->token);
357 conf->token = talloc_strdup(conf, argv[0]);
358 return CMD_SUCCESS;
359}
360
361DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800362 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800363{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200364 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800365 struct bsc_config *conf = vty->index;
366
367 int lac = atoi(argv[0]);
368
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800369 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
370 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
371 lac, VTY_NEWLINE);
372 return CMD_WARNING;
373 }
374
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200375 /* verify that the LACs are unique */
376 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
377 if (tmp->lac == lac) {
378 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
379 return CMD_ERR_INCOMPLETE;
380 }
381 }
382
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800383 conf->lac = lac;
384
385 return CMD_SUCCESS;
386}
387
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800388DEFUN(cfg_lst_imsi_allow,
389 cfg_lst_imsi_allow_cmd,
390 "access-list NAME imsi-allow [REGEXP]",
391 "Allow IMSIs matching the REGEXP\n"
392 "The name of the access-list\n"
393 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200394{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800395 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800396 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200397
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800398 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800399 if (!acc)
400 return CMD_WARNING;
401
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800402 entry = bsc_nat_acc_lst_entry_create(acc);
403 if (!entry)
404 return CMD_WARNING;
405
406 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200407 return CMD_SUCCESS;
408}
409
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800410DEFUN(cfg_lst_imsi_deny,
411 cfg_lst_imsi_deny_cmd,
412 "access-list NAME imsi-deny [REGEXP]",
413 "Allow IMSIs matching the REGEXP\n"
414 "The name of the access-list\n"
415 "The regexp of to be denied IMSIs\n")
416{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800417 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800418 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800419
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800420 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800421 if (!acc)
422 return CMD_WARNING;
423
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800424 entry = bsc_nat_acc_lst_entry_create(acc);
425 if (!entry)
426 return CMD_WARNING;
427
428 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800429 return CMD_SUCCESS;
430}
431
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800432/* naming to follow Zebra... */
433DEFUN(cfg_lst_no,
434 cfg_lst_no_cmd,
435 "no access-list NAME",
436 NO_STR "Remove an access-list by name\n"
437 "The access-list to remove\n")
438{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800439 struct bsc_nat_acc_lst *acc;
440 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800441 if (!acc)
442 return CMD_WARNING;
443
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800444 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800445 return CMD_SUCCESS;
446}
447
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800448DEFUN(cfg_bsc_acc_lst_name,
449 cfg_bsc_acc_lst_name_cmd,
450 "access-list-name NAME",
451 "Set the name of the access list to use.\n"
452 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200453{
454 struct bsc_config *conf = vty->index;
455
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800456 if (conf->acc_lst_name)
457 talloc_free(conf->acc_lst_name);
458 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200459 return CMD_SUCCESS;
460}
461
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800462DEFUN(cfg_bsc_paging,
463 cfg_bsc_paging_cmd,
464 "paging forbidden (0|1)",
465 "Forbid sending PAGING REQUESTS to the BSC.")
466{
467 struct bsc_config *conf = vty->index;
468
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800469 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800470 conf->forbid_paging = 1;
471 else
472 conf->forbid_paging = 0;
473
474 return CMD_SUCCESS;
475}
476
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800477DEFUN(cfg_bsc_desc,
478 cfg_bsc_desc_cmd,
479 "description DESC",
480 "Provide a description for the given BSC.")
481{
482 struct bsc_config *conf = vty->index;
483
484 if (conf->description)
485 talloc_free(conf->description);
486 conf->description = talloc_strdup(conf, argv[0]);
487 return CMD_SUCCESS;
488}
489
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800490DEFUN(test_regex, test_regex_cmd,
491 "test regex PATTERN STRING",
492 "Check if the string is matching the current pattern.")
493{
494 regex_t reg;
495 char *str = NULL;
496
497 memset(&reg, 0, sizeof(reg));
498 bsc_parse_reg(_nat, &reg, &str, 1, argv);
499
500 vty_out(vty, "String matches allow pattern: %d%s",
501 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
502
503 talloc_free(str);
504 regfree(&reg);
505 return CMD_SUCCESS;
506}
507
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800508int bsc_nat_vty_init(struct bsc_nat *nat)
509{
510 _nat = nat;
511
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800512 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800513 install_element_ve(&show_sccp_cmd);
514 install_element_ve(&show_bsc_cmd);
515 install_element_ve(&show_bsc_cfg_cmd);
516 install_element_ve(&show_stats_cmd);
517 install_element_ve(&close_bsc_cmd);
518 install_element_ve(&show_msc_cmd);
519 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200520
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800521 /* nat group */
522 install_element(CONFIG_NODE, &cfg_nat_cmd);
523 install_node(&nat_node, config_write_nat);
524 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800525 install_element(NAT_NODE, &ournode_exit_cmd);
526 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800527 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200528 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800529 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
530 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
531 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800532 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800533 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800534 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
535
536 /* access-list */
537 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
538 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800539 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800540
541 /* BSC subgroups */
542 install_element(NAT_NODE, &cfg_bsc_cmd);
543 install_node(&bsc_node, config_write_bsc);
544 install_default(BSC_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800545 install_element(BSC_NODE, &ournode_exit_cmd);
546 install_element(BSC_NODE, &ournode_end_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800547 install_element(BSC_NODE, &cfg_bsc_token_cmd);
548 install_element(BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800549 install_element(BSC_NODE, &cfg_bsc_paging_cmd);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800550 install_element(BSC_NODE, &cfg_bsc_desc_cmd);
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +0800551 install_element(BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800552
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800553 mgcp_vty_init();
554
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800555 return 0;
556}
557
558
559/* called by the telnet interface... we have our own init above */
560void bsc_vty_init()
561{}