blob: 22375a87a0a7f7b5b3ea239cb6303bc593b30933 [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
22#include <vty/command.h>
23#include <vty/buffer.h>
24#include <vty/vty.h>
25
26#include <openbsc/bsc_nat.h>
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +080027#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080028#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +080029#include <openbsc/mgcp.h>
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +020030#include <openbsc/vty.h>
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080031
32#include <osmocore/talloc.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080033
34#include <sccp/sccp.h>
35
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 = {
47 BSC_NODE,
48 "%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 Freyther078321a2010-05-31 10:36:35 +080078 vty_out(vty, " ip-tos %d%s", _nat->bsc_ip_tos, 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)
98 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 Freyther32d34362010-04-05 10:10:33 +0200125 con->msc_timeslot, con->bsc_timeslot,
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 Freytherab7539c2010-04-22 13:36:46 +0800152DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
153 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800154{
155 struct bsc_config *conf;
156 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
157 vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
158 conf->token, conf->lac, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800159 if (conf->acc_lst_name)
160 vty_out(vty, " access-list: %s%s",
161 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800162 vty_out(vty, " paging forbidden: %d%s",
163 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800164 if (conf->description)
165 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
166 else
167 vty_out(vty, " No description.%s", VTY_NEWLINE);
168
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800169 }
170
171 return CMD_SUCCESS;
172}
173
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200174DEFUN(show_stats,
175 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800176 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800177 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200178{
179 struct bsc_config *conf;
180
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800181 int nr = -1;
182
183 if (argc == 1)
184 nr = atoi(argv[0]);
185
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200186 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
187 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
188 counter_get(_nat->stats.sccp.conn),
189 counter_get(_nat->stats.sccp.calls), VTY_NEWLINE);
190 vty_out(vty, " MSC Connections %lu%s",
191 counter_get(_nat->stats.msc.reconn), VTY_NEWLINE);
192 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
193 counter_get(_nat->stats.bsc.reconn),
194 counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE);
195
196 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800197 if (argc == 1 && nr != conf->nr)
198 continue;
199
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200200 vty_out(vty, " BSC lac: %d nr: %d%s",
201 conf->lac, conf->nr, VTY_NEWLINE);
202 vty_out(vty, " SCCP Connnections %lu total, %lu calls%s",
203 counter_get(conf->stats.sccp.conn),
204 counter_get(conf->stats.sccp.calls), VTY_NEWLINE);
205 vty_out(vty, " BSC Connections %lu total%s",
206 counter_get(conf->stats.net.reconn), VTY_NEWLINE);
207 }
208
209 return CMD_SUCCESS;
210}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800211
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800212DEFUN(show_msc,
213 show_msc_cmd,
214 "show msc connection",
215 SHOW_STR "Show the status of the MSC connection.")
216{
217 if (!_nat->msc_con) {
218 vty_out(vty, "The MSC is not yet configured.\n");
219 return CMD_WARNING;
220 }
221
222 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
223 _nat->msc_con->ip, _nat->msc_con->port,
224 _nat->msc_con->is_connected, VTY_NEWLINE);
225 return CMD_SUCCESS;
226}
227
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800228DEFUN(close_bsc,
229 close_bsc_cmd,
230 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800231 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800232{
233 struct bsc_connection *bsc;
234 int bsc_nr = atoi(argv[0]);
235
236 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
237 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
238 continue;
239 bsc_close_connection(bsc);
240 break;
241 }
242
243 return CMD_SUCCESS;
244}
245
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800246DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
247{
248 vty->index = _nat;
249 vty->node = NAT_NODE;
250
251 return CMD_SUCCESS;
252}
253
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800254DEFUN(cfg_nat_msc_ip,
255 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800256 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800257 "Set the IP address of the MSC.")
258{
259 bsc_nat_set_msc_ip(_nat, argv[0]);
260 return CMD_SUCCESS;
261}
262
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200263DEFUN(cfg_nat_msc_port,
264 cfg_nat_msc_port_cmd,
265 "msc port <1-65500>",
266 "Set the port of the MSC.")
267{
268 _nat->msc_port = atoi(argv[0]);
269 return CMD_SUCCESS;
270}
271
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800272DEFUN(cfg_nat_auth_time,
273 cfg_nat_auth_time_cmd,
274 "timeout auth <1-256>",
275 "The time to wait for an auth response.")
276{
277 _nat->auth_timeout = atoi(argv[0]);
278 return CMD_SUCCESS;
279}
280
281DEFUN(cfg_nat_ping_time,
282 cfg_nat_ping_time_cmd,
283 "timeout ping NR",
284 "Send a ping every NR seconds. Negative to disable.")
285{
286 _nat->ping_timeout = atoi(argv[0]);
287 return CMD_SUCCESS;
288}
289
290DEFUN(cfg_nat_pong_time,
291 cfg_nat_pong_time_cmd,
292 "timeout pong NR",
293 "Wait NR seconds for the PONG response. Should be smaller than ping.")
294{
295 _nat->pong_timeout = atoi(argv[0]);
296 return CMD_SUCCESS;
297}
298
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800299DEFUN(cfg_nat_token, cfg_nat_token_cmd,
300 "token TOKEN",
301 "Set a token for the NAT")
302{
303 if (_nat->token)
304 talloc_free(_nat->token);
305 _nat->token = talloc_strdup(_nat, argv[0]);
306 return CMD_SUCCESS;
307}
308
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800309DEFUN(cfg_nat_bsc_ip_tos, cfg_nat_bsc_ip_tos_cmd,
310 "ip-tos <0-255>",
311 "Set the IP_TOS for the BSCs to use\n" "Set the IP_TOS attribute")
312{
313 _nat->bsc_ip_tos = atoi(argv[0]);
314 return CMD_SUCCESS;
315}
316
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800317DEFUN(cfg_nat_acc_lst_name,
318 cfg_nat_acc_lst_name_cmd,
319 "access-list-name NAME",
320 "Set the name of the access list to use.\n"
321 "The name of the to be used access list.")
322{
323 if (_nat->acc_lst_name)
324 talloc_free(_nat->acc_lst_name);
325 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
326 return CMD_SUCCESS;
327}
328
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800329/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800330DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800331{
332 int bsc_nr = atoi(argv[0]);
333 struct bsc_config *bsc;
334
335 if (bsc_nr > _nat->num_bsc) {
336 vty_out(vty, "%% The next unused BSC number is %u%s",
337 _nat->num_bsc, VTY_NEWLINE);
338 return CMD_WARNING;
339 } else if (bsc_nr == _nat->num_bsc) {
340 /* allocate a new one */
341 bsc = bsc_config_alloc(_nat, "unknown", 0);
342 } else
343 bsc = bsc_config_num(_nat, bsc_nr);
344
345 if (!bsc)
346 return CMD_WARNING;
347
348 vty->index = bsc;
349 vty->node = BSC_NODE;
350
351 return CMD_SUCCESS;
352}
353
354DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
355{
356 struct bsc_config *conf = vty->index;
357
358 if (conf->token)
359 talloc_free(conf->token);
360 conf->token = talloc_strdup(conf, argv[0]);
361 return CMD_SUCCESS;
362}
363
364DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800365 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800366{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200367 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800368 struct bsc_config *conf = vty->index;
369
370 int lac = atoi(argv[0]);
371
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800372 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
373 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
374 lac, VTY_NEWLINE);
375 return CMD_WARNING;
376 }
377
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200378 /* verify that the LACs are unique */
379 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
380 if (tmp->lac == lac) {
381 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
382 return CMD_ERR_INCOMPLETE;
383 }
384 }
385
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800386 conf->lac = lac;
387
388 return CMD_SUCCESS;
389}
390
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800391DEFUN(cfg_lst_imsi_allow,
392 cfg_lst_imsi_allow_cmd,
393 "access-list NAME imsi-allow [REGEXP]",
394 "Allow IMSIs matching the REGEXP\n"
395 "The name of the access-list\n"
396 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200397{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800398 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800399 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200400
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800401 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800402 if (!acc)
403 return CMD_WARNING;
404
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800405 entry = bsc_nat_acc_lst_entry_create(acc);
406 if (!entry)
407 return CMD_WARNING;
408
409 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200410 return CMD_SUCCESS;
411}
412
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800413DEFUN(cfg_lst_imsi_deny,
414 cfg_lst_imsi_deny_cmd,
415 "access-list NAME imsi-deny [REGEXP]",
416 "Allow IMSIs matching the REGEXP\n"
417 "The name of the access-list\n"
418 "The regexp of to be denied IMSIs\n")
419{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800420 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800421 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800422
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800423 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800424 if (!acc)
425 return CMD_WARNING;
426
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800427 entry = bsc_nat_acc_lst_entry_create(acc);
428 if (!entry)
429 return CMD_WARNING;
430
431 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800432 return CMD_SUCCESS;
433}
434
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800435/* naming to follow Zebra... */
436DEFUN(cfg_lst_no,
437 cfg_lst_no_cmd,
438 "no access-list NAME",
439 NO_STR "Remove an access-list by name\n"
440 "The access-list to remove\n")
441{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800442 struct bsc_nat_acc_lst *acc;
443 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800444 if (!acc)
445 return CMD_WARNING;
446
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800447 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800448 return CMD_SUCCESS;
449}
450
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800451DEFUN(cfg_bsc_acc_lst_name,
452 cfg_bsc_acc_lst_name_cmd,
453 "access-list-name NAME",
454 "Set the name of the access list to use.\n"
455 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200456{
457 struct bsc_config *conf = vty->index;
458
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800459 if (conf->acc_lst_name)
460 talloc_free(conf->acc_lst_name);
461 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200462 return CMD_SUCCESS;
463}
464
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800465DEFUN(cfg_bsc_paging,
466 cfg_bsc_paging_cmd,
467 "paging forbidden (0|1)",
468 "Forbid sending PAGING REQUESTS to the BSC.")
469{
470 struct bsc_config *conf = vty->index;
471
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800472 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800473 conf->forbid_paging = 1;
474 else
475 conf->forbid_paging = 0;
476
477 return CMD_SUCCESS;
478}
479
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800480DEFUN(cfg_bsc_desc,
481 cfg_bsc_desc_cmd,
482 "description DESC",
483 "Provide a description for the given BSC.")
484{
485 struct bsc_config *conf = vty->index;
486
487 if (conf->description)
488 talloc_free(conf->description);
489 conf->description = talloc_strdup(conf, argv[0]);
490 return CMD_SUCCESS;
491}
492
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800493DEFUN(test_regex, test_regex_cmd,
494 "test regex PATTERN STRING",
495 "Check if the string is matching the current pattern.")
496{
497 regex_t reg;
498 char *str = NULL;
499
500 memset(&reg, 0, sizeof(reg));
501 bsc_parse_reg(_nat, &reg, &str, 1, argv);
502
503 vty_out(vty, "String matches allow pattern: %d%s",
504 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
505
506 talloc_free(str);
507 regfree(&reg);
508 return CMD_SUCCESS;
509}
510
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800511int bsc_nat_vty_init(struct bsc_nat *nat)
512{
513 _nat = nat;
514
515 cmd_init(1);
516 vty_init();
517
518 /* show commands */
519 install_element(VIEW_NODE, &show_sccp_cmd);
520 install_element(VIEW_NODE, &show_bsc_cmd);
521 install_element(VIEW_NODE, &show_bsc_cfg_cmd);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200522 install_element(VIEW_NODE, &show_stats_cmd);
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800523 install_element(VIEW_NODE, &close_bsc_cmd);
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800524 install_element(VIEW_NODE, &show_msc_cmd);
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800525 install_element(VIEW_NODE, &test_regex_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800526
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200527 openbsc_vty_add_cmds();
528
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800529 /* nat group */
530 install_element(CONFIG_NODE, &cfg_nat_cmd);
531 install_node(&nat_node, config_write_nat);
532 install_default(NAT_NODE);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800533 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200534 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800535 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
536 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
537 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800538 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800539 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800540 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
541
542 /* access-list */
543 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
544 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800545 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800546
547 /* BSC subgroups */
548 install_element(NAT_NODE, &cfg_bsc_cmd);
549 install_node(&bsc_node, config_write_bsc);
550 install_default(BSC_NODE);
551 install_element(BSC_NODE, &cfg_bsc_token_cmd);
552 install_element(BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800553 install_element(BSC_NODE, &cfg_bsc_paging_cmd);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800554 install_element(BSC_NODE, &cfg_bsc_desc_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800555 install_element(NAT_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800556
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800557 mgcp_vty_init();
558
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800559 return 0;
560}
561
562
563/* called by the telnet interface... we have our own init above */
564void bsc_vty_init()
565{}