blob: c4d77f14f19b0ed624ad30a29ab66390843fa8e5 [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);
181 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
182 counter_get(nat->stats.bsc.reconn),
183 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
184}
185
186static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
187{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800188 int connected = 0;
189 struct bsc_connection *con;
190
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800191 vty_out(vty, " BSC lac: %d nr: %d%s",
192 conf->lac, conf->nr, VTY_NEWLINE);
193 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800194
195 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
196 if (con->cfg != conf)
197 continue;
198 connected = 1;
199 break;
200 }
201
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800202 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800203}
204
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200205DEFUN(show_stats,
206 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800207 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800208 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200209{
210 struct bsc_config *conf;
211
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800212 int nr = -1;
213
214 if (argc == 1)
215 nr = atoi(argv[0]);
216
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800217 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200218 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800219 if (argc == 1 && nr != conf->nr)
220 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800221 dump_stat_bsc(vty, conf);
222 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800223
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800224 return CMD_SUCCESS;
225}
226
227DEFUN(show_stats_lac,
228 show_stats_lac_cmd,
229 "show statistics-by-lac <0-65535>",
230 SHOW_STR "Display network statistics by lac\n"
231 "The lac of the BSC\n")
232{
233 int lac;
234 struct bsc_config *conf;
235
236 lac = atoi(argv[0]);
237
238 dump_stat_total(vty, _nat);
239 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
240 if (conf->lac != lac)
241 continue;
242 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200243 }
244
245 return CMD_SUCCESS;
246}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800247
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800248DEFUN(show_msc,
249 show_msc_cmd,
250 "show msc connection",
251 SHOW_STR "Show the status of the MSC connection.")
252{
253 if (!_nat->msc_con) {
254 vty_out(vty, "The MSC is not yet configured.\n");
255 return CMD_WARNING;
256 }
257
258 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
259 _nat->msc_con->ip, _nat->msc_con->port,
260 _nat->msc_con->is_connected, VTY_NEWLINE);
261 return CMD_SUCCESS;
262}
263
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800264DEFUN(close_bsc,
265 close_bsc_cmd,
266 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800267 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800268{
269 struct bsc_connection *bsc;
270 int bsc_nr = atoi(argv[0]);
271
272 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
273 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
274 continue;
275 bsc_close_connection(bsc);
276 break;
277 }
278
279 return CMD_SUCCESS;
280}
281
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800282DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
283{
284 vty->index = _nat;
285 vty->node = NAT_NODE;
286
287 return CMD_SUCCESS;
288}
289
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800290DEFUN(cfg_nat_msc_ip,
291 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800292 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800293 "Set the IP address of the MSC.")
294{
295 bsc_nat_set_msc_ip(_nat, argv[0]);
296 return CMD_SUCCESS;
297}
298
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200299DEFUN(cfg_nat_msc_port,
300 cfg_nat_msc_port_cmd,
301 "msc port <1-65500>",
302 "Set the port of the MSC.")
303{
304 _nat->msc_port = atoi(argv[0]);
305 return CMD_SUCCESS;
306}
307
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800308DEFUN(cfg_nat_auth_time,
309 cfg_nat_auth_time_cmd,
310 "timeout auth <1-256>",
311 "The time to wait for an auth response.")
312{
313 _nat->auth_timeout = atoi(argv[0]);
314 return CMD_SUCCESS;
315}
316
317DEFUN(cfg_nat_ping_time,
318 cfg_nat_ping_time_cmd,
319 "timeout ping NR",
320 "Send a ping every NR seconds. Negative to disable.")
321{
322 _nat->ping_timeout = atoi(argv[0]);
323 return CMD_SUCCESS;
324}
325
326DEFUN(cfg_nat_pong_time,
327 cfg_nat_pong_time_cmd,
328 "timeout pong NR",
329 "Wait NR seconds for the PONG response. Should be smaller than ping.")
330{
331 _nat->pong_timeout = atoi(argv[0]);
332 return CMD_SUCCESS;
333}
334
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800335DEFUN(cfg_nat_token, cfg_nat_token_cmd,
336 "token TOKEN",
337 "Set a token for the NAT")
338{
339 if (_nat->token)
340 talloc_free(_nat->token);
341 _nat->token = talloc_strdup(_nat, argv[0]);
342 return CMD_SUCCESS;
343}
344
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800345DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
346 "ip-dscp <0-255>",
347 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800348{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800349 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800350 return CMD_SUCCESS;
351}
352
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800353ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
354 "ip-tos <0-255>",
355 "Use ip-dscp in the future.\n" "Set the DSCP\n")
356
357
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800358DEFUN(cfg_nat_acc_lst_name,
359 cfg_nat_acc_lst_name_cmd,
360 "access-list-name NAME",
361 "Set the name of the access list to use.\n"
362 "The name of the to be used access list.")
363{
364 if (_nat->acc_lst_name)
365 talloc_free(_nat->acc_lst_name);
366 _nat->acc_lst_name = talloc_strdup(_nat, argv[0]);
367 return CMD_SUCCESS;
368}
369
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800370/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800371DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800372{
373 int bsc_nr = atoi(argv[0]);
374 struct bsc_config *bsc;
375
376 if (bsc_nr > _nat->num_bsc) {
377 vty_out(vty, "%% The next unused BSC number is %u%s",
378 _nat->num_bsc, VTY_NEWLINE);
379 return CMD_WARNING;
380 } else if (bsc_nr == _nat->num_bsc) {
381 /* allocate a new one */
382 bsc = bsc_config_alloc(_nat, "unknown", 0);
383 } else
384 bsc = bsc_config_num(_nat, bsc_nr);
385
386 if (!bsc)
387 return CMD_WARNING;
388
389 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800390 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800391
392 return CMD_SUCCESS;
393}
394
395DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
396{
397 struct bsc_config *conf = vty->index;
398
399 if (conf->token)
400 talloc_free(conf->token);
401 conf->token = talloc_strdup(conf, argv[0]);
402 return CMD_SUCCESS;
403}
404
405DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800406 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800407{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200408 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800409 struct bsc_config *conf = vty->index;
410
411 int lac = atoi(argv[0]);
412
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800413 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
414 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
415 lac, VTY_NEWLINE);
416 return CMD_WARNING;
417 }
418
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200419 /* verify that the LACs are unique */
420 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
421 if (tmp->lac == lac) {
422 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
423 return CMD_ERR_INCOMPLETE;
424 }
425 }
426
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800427 conf->lac = lac;
428
429 return CMD_SUCCESS;
430}
431
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800432DEFUN(cfg_lst_imsi_allow,
433 cfg_lst_imsi_allow_cmd,
434 "access-list NAME imsi-allow [REGEXP]",
435 "Allow IMSIs matching the REGEXP\n"
436 "The name of the access-list\n"
437 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200438{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800439 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800440 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200441
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800442 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800443 if (!acc)
444 return CMD_WARNING;
445
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800446 entry = bsc_nat_acc_lst_entry_create(acc);
447 if (!entry)
448 return CMD_WARNING;
449
450 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200451 return CMD_SUCCESS;
452}
453
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800454DEFUN(cfg_lst_imsi_deny,
455 cfg_lst_imsi_deny_cmd,
456 "access-list NAME imsi-deny [REGEXP]",
457 "Allow IMSIs matching the REGEXP\n"
458 "The name of the access-list\n"
459 "The regexp of to be denied IMSIs\n")
460{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800461 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800462 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800463
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800464 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800465 if (!acc)
466 return CMD_WARNING;
467
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800468 entry = bsc_nat_acc_lst_entry_create(acc);
469 if (!entry)
470 return CMD_WARNING;
471
472 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800473 return CMD_SUCCESS;
474}
475
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800476/* naming to follow Zebra... */
477DEFUN(cfg_lst_no,
478 cfg_lst_no_cmd,
479 "no access-list NAME",
480 NO_STR "Remove an access-list by name\n"
481 "The access-list to remove\n")
482{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800483 struct bsc_nat_acc_lst *acc;
484 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800485 if (!acc)
486 return CMD_WARNING;
487
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800488 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800489 return CMD_SUCCESS;
490}
491
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800492DEFUN(cfg_bsc_acc_lst_name,
493 cfg_bsc_acc_lst_name_cmd,
494 "access-list-name NAME",
495 "Set the name of the access list to use.\n"
496 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200497{
498 struct bsc_config *conf = vty->index;
499
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800500 if (conf->acc_lst_name)
501 talloc_free(conf->acc_lst_name);
502 conf->acc_lst_name = talloc_strdup(conf, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200503 return CMD_SUCCESS;
504}
505
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800506DEFUN(cfg_bsc_paging,
507 cfg_bsc_paging_cmd,
508 "paging forbidden (0|1)",
509 "Forbid sending PAGING REQUESTS to the BSC.")
510{
511 struct bsc_config *conf = vty->index;
512
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800513 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800514 conf->forbid_paging = 1;
515 else
516 conf->forbid_paging = 0;
517
518 return CMD_SUCCESS;
519}
520
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800521DEFUN(cfg_bsc_desc,
522 cfg_bsc_desc_cmd,
523 "description DESC",
524 "Provide a description for the given BSC.")
525{
526 struct bsc_config *conf = vty->index;
527
528 if (conf->description)
529 talloc_free(conf->description);
530 conf->description = talloc_strdup(conf, argv[0]);
531 return CMD_SUCCESS;
532}
533
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800534DEFUN(test_regex, test_regex_cmd,
535 "test regex PATTERN STRING",
536 "Check if the string is matching the current pattern.")
537{
538 regex_t reg;
539 char *str = NULL;
540
541 memset(&reg, 0, sizeof(reg));
542 bsc_parse_reg(_nat, &reg, &str, 1, argv);
543
544 vty_out(vty, "String matches allow pattern: %d%s",
545 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
546
547 talloc_free(str);
548 regfree(&reg);
549 return CMD_SUCCESS;
550}
551
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800552int bsc_nat_vty_init(struct bsc_nat *nat)
553{
554 _nat = nat;
555
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800556 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800557 install_element_ve(&show_sccp_cmd);
558 install_element_ve(&show_bsc_cmd);
559 install_element_ve(&show_bsc_cfg_cmd);
560 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800561 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800562 install_element_ve(&close_bsc_cmd);
563 install_element_ve(&show_msc_cmd);
564 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200565
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800566 /* nat group */
567 install_element(CONFIG_NODE, &cfg_nat_cmd);
568 install_node(&nat_node, config_write_nat);
569 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800570 install_element(NAT_NODE, &ournode_exit_cmd);
571 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800572 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200573 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800574 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
575 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
576 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800577 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800578 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800579 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800580 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
581
582 /* access-list */
583 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
584 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800585 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800586
587 /* BSC subgroups */
588 install_element(NAT_NODE, &cfg_bsc_cmd);
589 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800590 install_default(NAT_BSC_NODE);
591 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
592 install_element(NAT_BSC_NODE, &ournode_end_cmd);
593 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
594 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
595 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
596 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
597 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800598
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800599 mgcp_vty_init();
600
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800601 return 0;
602}
603
604
605/* called by the telnet interface... we have our own init above */
606void bsc_vty_init()
607{}