blob: d8af1c23f6588a1065a5c1258f42d99163a4586b [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 Freyther9a85ef32010-06-15 18:46:11 +080032
Harald Welted5db12c2010-08-03 15:11:51 +020033#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080034
35#include <stdlib.h>
36
37static struct bsc_nat *_nat;
38
39static struct cmd_node nat_node = {
40 NAT_NODE,
41 "%s(nat)#",
42 1,
43};
44
45static struct cmd_node bsc_node = {
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080046 NAT_BSC_NODE,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080047 "%s(bsc)#",
48 1,
49};
50
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080051static void write_acc_lst(struct vty *vty, struct bsc_nat_acc_lst *lst)
52{
53 struct bsc_nat_acc_lst_entry *entry;
54
55 llist_for_each_entry(entry, &lst->fltr_list, list) {
56 if (entry->imsi_allow)
57 vty_out(vty, " access-list %s imsi-allow %s%s",
58 lst->name, entry->imsi_allow, VTY_NEWLINE);
59 if (entry->imsi_deny)
60 vty_out(vty, " access-list %s imsi-deny %s%s",
61 lst->name, entry->imsi_deny, VTY_NEWLINE);
62 }
63}
64
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080065static int config_write_nat(struct vty *vty)
66{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +080067 struct bsc_nat_acc_lst *lst;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080068
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080069 vty_out(vty, "nat%s", VTY_NEWLINE);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +080070 vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +020071 vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +080072 vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE);
73 vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE);
74 vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +080075 if (_nat->token)
76 vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +080077 vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080078 if (_nat->acc_lst_name)
79 vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE);
80
81 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080082 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080083 }
84
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080085 return CMD_SUCCESS;
86}
87
88static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
89{
90 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
91 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freytherd1278c12010-04-16 16:52:20 +020092 vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +080093 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +080094 if (bsc->description)
95 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080096 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +080097 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080098}
99
100static int config_write_bsc(struct vty *vty)
101{
102 struct bsc_config *bsc;
103
104 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
105 config_write_bsc_single(vty, bsc);
106 return CMD_SUCCESS;
107}
108
109
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800110DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
111 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800112{
113 struct sccp_connections *con;
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800114 vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800115
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800116 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800117 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 +0200118 con->bsc->cfg ? con->bsc->cfg->nr : -1,
119 con->bsc->cfg ? con->bsc->cfg->lac : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800120 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200121 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800122 con->has_remote_ref,
123 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200124 con->msc_timeslot, con->bsc_timeslot,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800125 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200126 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800127 }
128
129 return CMD_SUCCESS;
130}
131
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800132DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
133 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800134{
135 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200136 struct sockaddr_in sock;
137 socklen_t len = sizeof(sock);
138
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800139 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200140 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther3b879812010-05-01 15:32:32 +0800141 vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200142 con->cfg ? con->cfg->nr : -1,
143 con->cfg ? con->cfg->lac : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200144 con->authenticated, con->write_queue.bfd.fd,
145 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800146 }
147
148 return CMD_SUCCESS;
149}
150
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800151DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
152 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800153{
154 struct bsc_config *conf;
155 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
156 vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s",
157 conf->token, conf->lac, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800158 if (conf->acc_lst_name)
159 vty_out(vty, " access-list: %s%s",
160 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800161 vty_out(vty, " paging forbidden: %d%s",
162 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800163 if (conf->description)
164 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
165 else
166 vty_out(vty, " No description.%s", VTY_NEWLINE);
167
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800168 }
169
170 return CMD_SUCCESS;
171}
172
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800173static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
174{
175 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
176 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
177 counter_get(nat->stats.sccp.conn),
178 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
179 vty_out(vty, " MSC Connections %lu%s",
180 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800181 vty_out(vty, " MSC Connected: %d%s",
182 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800183 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
184 counter_get(nat->stats.bsc.reconn),
185 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
186}
187
188static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
189{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800190 int connected = 0;
191 struct bsc_connection *con;
192
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800193 vty_out(vty, " BSC lac: %d nr: %d%s",
194 conf->lac, conf->nr, VTY_NEWLINE);
195 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800196
197 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
198 if (con->cfg != conf)
199 continue;
200 connected = 1;
201 break;
202 }
203
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800204 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800205}
206
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200207DEFUN(show_stats,
208 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800209 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800210 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200211{
212 struct bsc_config *conf;
213
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800214 int nr = -1;
215
216 if (argc == 1)
217 nr = atoi(argv[0]);
218
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800219 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200220 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800221 if (argc == 1 && nr != conf->nr)
222 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800223 dump_stat_bsc(vty, conf);
224 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800225
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800226 return CMD_SUCCESS;
227}
228
229DEFUN(show_stats_lac,
230 show_stats_lac_cmd,
231 "show statistics-by-lac <0-65535>",
232 SHOW_STR "Display network statistics by lac\n"
233 "The lac of the BSC\n")
234{
235 int lac;
236 struct bsc_config *conf;
237
238 lac = atoi(argv[0]);
239
240 dump_stat_total(vty, _nat);
241 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
242 if (conf->lac != lac)
243 continue;
244 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200245 }
246
247 return CMD_SUCCESS;
248}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800249
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800250DEFUN(show_msc,
251 show_msc_cmd,
252 "show msc connection",
253 SHOW_STR "Show the status of the MSC connection.")
254{
255 if (!_nat->msc_con) {
256 vty_out(vty, "The MSC is not yet configured.\n");
257 return CMD_WARNING;
258 }
259
260 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
261 _nat->msc_con->ip, _nat->msc_con->port,
262 _nat->msc_con->is_connected, VTY_NEWLINE);
263 return CMD_SUCCESS;
264}
265
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800266DEFUN(close_bsc,
267 close_bsc_cmd,
268 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800269 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800270{
271 struct bsc_connection *bsc;
272 int bsc_nr = atoi(argv[0]);
273
274 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
275 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
276 continue;
277 bsc_close_connection(bsc);
278 break;
279 }
280
281 return CMD_SUCCESS;
282}
283
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800284DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
285{
286 vty->index = _nat;
287 vty->node = NAT_NODE;
288
289 return CMD_SUCCESS;
290}
291
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800292DEFUN(cfg_nat_msc_ip,
293 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800294 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800295 "Set the IP address of the MSC.")
296{
297 bsc_nat_set_msc_ip(_nat, argv[0]);
298 return CMD_SUCCESS;
299}
300
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200301DEFUN(cfg_nat_msc_port,
302 cfg_nat_msc_port_cmd,
303 "msc port <1-65500>",
304 "Set the port of the MSC.")
305{
306 _nat->msc_port = atoi(argv[0]);
307 return CMD_SUCCESS;
308}
309
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800310DEFUN(cfg_nat_auth_time,
311 cfg_nat_auth_time_cmd,
312 "timeout auth <1-256>",
313 "The time to wait for an auth response.")
314{
315 _nat->auth_timeout = atoi(argv[0]);
316 return CMD_SUCCESS;
317}
318
319DEFUN(cfg_nat_ping_time,
320 cfg_nat_ping_time_cmd,
321 "timeout ping NR",
322 "Send a ping every NR seconds. Negative to disable.")
323{
324 _nat->ping_timeout = atoi(argv[0]);
325 return CMD_SUCCESS;
326}
327
328DEFUN(cfg_nat_pong_time,
329 cfg_nat_pong_time_cmd,
330 "timeout pong NR",
331 "Wait NR seconds for the PONG response. Should be smaller than ping.")
332{
333 _nat->pong_timeout = atoi(argv[0]);
334 return CMD_SUCCESS;
335}
336
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800337DEFUN(cfg_nat_token, cfg_nat_token_cmd,
338 "token TOKEN",
339 "Set a token for the NAT")
340{
341 if (_nat->token)
342 talloc_free(_nat->token);
343 _nat->token = talloc_strdup(_nat, argv[0]);
344 return CMD_SUCCESS;
345}
346
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800347DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
348 "ip-dscp <0-255>",
349 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800350{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800351 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800352 return CMD_SUCCESS;
353}
354
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800355ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
356 "ip-tos <0-255>",
357 "Use ip-dscp in the future.\n" "Set the DSCP\n")
358
359
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800360DEFUN(cfg_nat_acc_lst_name,
361 cfg_nat_acc_lst_name_cmd,
362 "access-list-name NAME",
363 "Set the name of the access list to use.\n"
364 "The name of the to be used access list.")
365{
366 if (_nat->acc_lst_name)
367 talloc_free(_nat->acc_lst_name);
368 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
369 return CMD_SUCCESS;
370}
371
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800372/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800373DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800374{
375 int bsc_nr = atoi(argv[0]);
376 struct bsc_config *bsc;
377
378 if (bsc_nr > _nat->num_bsc) {
379 vty_out(vty, "%% The next unused BSC number is %u%s",
380 _nat->num_bsc, VTY_NEWLINE);
381 return CMD_WARNING;
382 } else if (bsc_nr == _nat->num_bsc) {
383 /* allocate a new one */
384 bsc = bsc_config_alloc(_nat, "unknown", 0);
385 } else
386 bsc = bsc_config_num(_nat, bsc_nr);
387
388 if (!bsc)
389 return CMD_WARNING;
390
391 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800392 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800393
394 return CMD_SUCCESS;
395}
396
397DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
398{
399 struct bsc_config *conf = vty->index;
400
401 if (conf->token)
402 talloc_free(conf->token);
403 conf->token = talloc_strdup(conf, argv[0]);
404 return CMD_SUCCESS;
405}
406
407DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800408 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800409{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200410 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800411 struct bsc_config *conf = vty->index;
412
413 int lac = atoi(argv[0]);
414
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800415 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
416 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
417 lac, VTY_NEWLINE);
418 return CMD_WARNING;
419 }
420
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200421 /* verify that the LACs are unique */
422 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
423 if (tmp->lac == lac) {
424 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
425 return CMD_ERR_INCOMPLETE;
426 }
427 }
428
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800429 conf->lac = lac;
430
431 return CMD_SUCCESS;
432}
433
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800434DEFUN(cfg_lst_imsi_allow,
435 cfg_lst_imsi_allow_cmd,
436 "access-list NAME imsi-allow [REGEXP]",
437 "Allow IMSIs matching the REGEXP\n"
438 "The name of the access-list\n"
439 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200440{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800441 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800442 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200443
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800444 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800445 if (!acc)
446 return CMD_WARNING;
447
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800448 entry = bsc_nat_acc_lst_entry_create(acc);
449 if (!entry)
450 return CMD_WARNING;
451
452 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200453 return CMD_SUCCESS;
454}
455
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800456DEFUN(cfg_lst_imsi_deny,
457 cfg_lst_imsi_deny_cmd,
458 "access-list NAME imsi-deny [REGEXP]",
459 "Allow IMSIs matching the REGEXP\n"
460 "The name of the access-list\n"
461 "The regexp of to be denied IMSIs\n")
462{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800463 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800464 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800465
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800466 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800467 if (!acc)
468 return CMD_WARNING;
469
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800470 entry = bsc_nat_acc_lst_entry_create(acc);
471 if (!entry)
472 return CMD_WARNING;
473
474 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800475 return CMD_SUCCESS;
476}
477
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800478/* naming to follow Zebra... */
479DEFUN(cfg_lst_no,
480 cfg_lst_no_cmd,
481 "no access-list NAME",
482 NO_STR "Remove an access-list by name\n"
483 "The access-list to remove\n")
484{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800485 struct bsc_nat_acc_lst *acc;
486 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800487 if (!acc)
488 return CMD_WARNING;
489
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800490 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800491 return CMD_SUCCESS;
492}
493
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800494DEFUN(cfg_bsc_acc_lst_name,
495 cfg_bsc_acc_lst_name_cmd,
496 "access-list-name NAME",
497 "Set the name of the access list to use.\n"
498 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200499{
500 struct bsc_config *conf = vty->index;
501
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800502 if (conf->acc_lst_name)
503 talloc_free(conf->acc_lst_name);
504 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200505 return CMD_SUCCESS;
506}
507
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800508DEFUN(cfg_bsc_paging,
509 cfg_bsc_paging_cmd,
510 "paging forbidden (0|1)",
511 "Forbid sending PAGING REQUESTS to the BSC.")
512{
513 struct bsc_config *conf = vty->index;
514
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800515 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800516 conf->forbid_paging = 1;
517 else
518 conf->forbid_paging = 0;
519
520 return CMD_SUCCESS;
521}
522
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800523DEFUN(cfg_bsc_desc,
524 cfg_bsc_desc_cmd,
525 "description DESC",
526 "Provide a description for the given BSC.")
527{
528 struct bsc_config *conf = vty->index;
529
530 if (conf->description)
531 talloc_free(conf->description);
532 conf->description = talloc_strdup(conf, argv[0]);
533 return CMD_SUCCESS;
534}
535
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800536DEFUN(test_regex, test_regex_cmd,
537 "test regex PATTERN STRING",
538 "Check if the string is matching the current pattern.")
539{
540 regex_t reg;
541 char *str = NULL;
542
543 memset(&reg, 0, sizeof(reg));
544 bsc_parse_reg(_nat, &reg, &str, 1, argv);
545
546 vty_out(vty, "String matches allow pattern: %d%s",
547 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
548
549 talloc_free(str);
550 regfree(&reg);
551 return CMD_SUCCESS;
552}
553
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800554int bsc_nat_vty_init(struct bsc_nat *nat)
555{
556 _nat = nat;
557
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800558 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800559 install_element_ve(&show_sccp_cmd);
560 install_element_ve(&show_bsc_cmd);
561 install_element_ve(&show_bsc_cfg_cmd);
562 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800563 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800564 install_element_ve(&close_bsc_cmd);
565 install_element_ve(&show_msc_cmd);
566 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200567
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800568 /* nat group */
569 install_element(CONFIG_NODE, &cfg_nat_cmd);
570 install_node(&nat_node, config_write_nat);
571 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800572 install_element(NAT_NODE, &ournode_exit_cmd);
573 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800574 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200575 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800576 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
577 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
578 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800579 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800580 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800581 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800582 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
583
584 /* access-list */
585 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
586 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800587 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800588
589 /* BSC subgroups */
590 install_element(NAT_NODE, &cfg_bsc_cmd);
591 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800592 install_default(NAT_BSC_NODE);
593 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
594 install_element(NAT_BSC_NODE, &ournode_end_cmd);
595 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
596 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
597 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
598 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
599 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800600
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800601 mgcp_vty_init();
602
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800603 return 0;
604}
605
606
607/* called by the telnet interface... we have our own init above */
608void bsc_vty_init()
609{}