blob: de58bba07eb79e6a9ffa43580cf36886024e2d21 [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 Freyther0d8330c2010-08-28 18:33:34 +080032#include <osmocore/utils.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080033
Harald Welted5db12c2010-08-03 15:11:51 +020034#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080035
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 = {
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +080047 NAT_BSC_NODE,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080048 "%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 Freyther6b771072010-07-27 19:21:53 +080078 vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, 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);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +020081 if (_nat->ussd_lst_name)
82 vty_out(vty, " ussd-list-name %s%s", _nat->ussd_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080083
84 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080085 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080086 }
87
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080088 return CMD_SUCCESS;
89}
90
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +080091static void dump_lac(struct vty *vty, struct bsc_config *cfg)
92{
93 struct bsc_lac_entry *lac;
94 llist_for_each_entry(lac, &cfg->lac_list, entry)
95 vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE);
96}
97
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080098static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
99{
100 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
101 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800102 dump_lac(vty, bsc);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800103 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800104 if (bsc->description)
105 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800106 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +0800107 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800108}
109
110static int config_write_bsc(struct vty *vty)
111{
112 struct bsc_config *bsc;
113
114 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
115 config_write_bsc_single(vty, bsc);
116 return CMD_SUCCESS;
117}
118
119
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800120DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
121 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800122{
123 struct sccp_connections *con;
Holger Hans Peter Freyther85804a82010-09-15 19:01:31 +0800124 vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800125
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800126 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800127 vty_out(vty, "For BSC Nr: %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 +0200128 con->bsc->cfg ? con->bsc->cfg->nr : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800129 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200130 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800131 con->has_remote_ref,
132 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800133 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800134 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200135 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800136 }
137
138 return CMD_SUCCESS;
139}
140
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800141DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
142 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800143{
144 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200145 struct sockaddr_in sock;
146 socklen_t len = sizeof(sock);
147
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800148 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200149 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800150 vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200151 con->cfg ? con->cfg->nr : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200152 con->authenticated, con->write_queue.bfd.fd,
153 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800154 }
155
156 return CMD_SUCCESS;
157}
158
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800159DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
160 SHOW_STR "Display the MGCP status for a given BSC")
161{
162 struct bsc_connection *con;
163 int nr = atoi(argv[0]);
164 int i;
165
166 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
167 if (!con->cfg)
168 continue;
169 if (con->cfg->nr != nr)
170 continue;
171
172 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
173 for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i)
174 vty_out(vty, " Endpoint 0x%x %s%s", i,
175 con->endpoint_status[i] == 0 ? "free" : "allocated",
176 VTY_NEWLINE);
177 break;
178 }
179
180 return CMD_SUCCESS;
181}
182
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800183DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
184 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800185{
186 struct bsc_config *conf;
187 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800188 vty_out(vty, "BSC token: '%s' nr: %u%s",
189 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800190 if (conf->acc_lst_name)
191 vty_out(vty, " access-list: %s%s",
192 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800193 vty_out(vty, " paging forbidden: %d%s",
194 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800195 if (conf->description)
196 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
197 else
198 vty_out(vty, " No description.%s", VTY_NEWLINE);
199
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800200 }
201
202 return CMD_SUCCESS;
203}
204
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800205static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
206{
207 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
208 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
209 counter_get(nat->stats.sccp.conn),
210 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
211 vty_out(vty, " MSC Connections %lu%s",
212 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800213 vty_out(vty, " MSC Connected: %d%s",
214 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800215 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
216 counter_get(nat->stats.bsc.reconn),
217 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
218}
219
220static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
221{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800222 int connected = 0;
223 struct bsc_connection *con;
224
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800225 vty_out(vty, " BSC nr: %d%s",
226 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800227 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800228
229 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
230 if (con->cfg != conf)
231 continue;
232 connected = 1;
233 break;
234 }
235
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800236 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800237}
238
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200239DEFUN(show_stats,
240 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800241 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800242 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200243{
244 struct bsc_config *conf;
245
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800246 int nr = -1;
247
248 if (argc == 1)
249 nr = atoi(argv[0]);
250
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800251 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200252 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800253 if (argc == 1 && nr != conf->nr)
254 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800255 dump_stat_bsc(vty, conf);
256 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800257
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800258 return CMD_SUCCESS;
259}
260
261DEFUN(show_stats_lac,
262 show_stats_lac_cmd,
263 "show statistics-by-lac <0-65535>",
264 SHOW_STR "Display network statistics by lac\n"
265 "The lac of the BSC\n")
266{
267 int lac;
268 struct bsc_config *conf;
269
270 lac = atoi(argv[0]);
271
272 dump_stat_total(vty, _nat);
273 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800274 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800275 continue;
276 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200277 }
278
279 return CMD_SUCCESS;
280}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800281
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800282DEFUN(show_msc,
283 show_msc_cmd,
284 "show msc connection",
285 SHOW_STR "Show the status of the MSC connection.")
286{
287 if (!_nat->msc_con) {
288 vty_out(vty, "The MSC is not yet configured.\n");
289 return CMD_WARNING;
290 }
291
292 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
293 _nat->msc_con->ip, _nat->msc_con->port,
294 _nat->msc_con->is_connected, VTY_NEWLINE);
295 return CMD_SUCCESS;
296}
297
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800298DEFUN(close_bsc,
299 close_bsc_cmd,
300 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800301 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800302{
303 struct bsc_connection *bsc;
304 int bsc_nr = atoi(argv[0]);
305
306 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
307 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
308 continue;
309 bsc_close_connection(bsc);
310 break;
311 }
312
313 return CMD_SUCCESS;
314}
315
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800316DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
317{
318 vty->index = _nat;
319 vty->node = NAT_NODE;
320
321 return CMD_SUCCESS;
322}
323
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800324DEFUN(cfg_nat_msc_ip,
325 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800326 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800327 "Set the IP address of the MSC.")
328{
329 bsc_nat_set_msc_ip(_nat, argv[0]);
330 return CMD_SUCCESS;
331}
332
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200333DEFUN(cfg_nat_msc_port,
334 cfg_nat_msc_port_cmd,
335 "msc port <1-65500>",
336 "Set the port of the MSC.")
337{
338 _nat->msc_port = atoi(argv[0]);
339 return CMD_SUCCESS;
340}
341
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800342DEFUN(cfg_nat_auth_time,
343 cfg_nat_auth_time_cmd,
344 "timeout auth <1-256>",
345 "The time to wait for an auth response.")
346{
347 _nat->auth_timeout = atoi(argv[0]);
348 return CMD_SUCCESS;
349}
350
351DEFUN(cfg_nat_ping_time,
352 cfg_nat_ping_time_cmd,
353 "timeout ping NR",
354 "Send a ping every NR seconds. Negative to disable.")
355{
356 _nat->ping_timeout = atoi(argv[0]);
357 return CMD_SUCCESS;
358}
359
360DEFUN(cfg_nat_pong_time,
361 cfg_nat_pong_time_cmd,
362 "timeout pong NR",
363 "Wait NR seconds for the PONG response. Should be smaller than ping.")
364{
365 _nat->pong_timeout = atoi(argv[0]);
366 return CMD_SUCCESS;
367}
368
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800369DEFUN(cfg_nat_token, cfg_nat_token_cmd,
370 "token TOKEN",
371 "Set a token for the NAT")
372{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200373 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800374 return CMD_SUCCESS;
375}
376
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800377DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
378 "ip-dscp <0-255>",
379 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800380{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800381 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800382 return CMD_SUCCESS;
383}
384
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800385ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
386 "ip-tos <0-255>",
387 "Use ip-dscp in the future.\n" "Set the DSCP\n")
388
389
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800390DEFUN(cfg_nat_acc_lst_name,
391 cfg_nat_acc_lst_name_cmd,
392 "access-list-name NAME",
393 "Set the name of the access list to use.\n"
394 "The name of the to be used access list.")
395{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200396 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800397 return CMD_SUCCESS;
398}
399
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200400DEFUN(cfg_nat_ussd_lst_name,
401 cfg_nat_ussd_lst_name_cmd,
402 "ussd-list-name NAME",
403 "Set the name of the access list to check for IMSIs for USSD message\n"
404 "The name of the access list for HLR USSD handling")
405{
406 if (_nat->ussd_lst_name)
407 talloc_free(_nat->ussd_lst_name);
408 _nat->ussd_lst_name = talloc_strdup(_nat, argv[0]);
409 return CMD_SUCCESS;
410}
411
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800412/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800413DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800414{
415 int bsc_nr = atoi(argv[0]);
416 struct bsc_config *bsc;
417
418 if (bsc_nr > _nat->num_bsc) {
419 vty_out(vty, "%% The next unused BSC number is %u%s",
420 _nat->num_bsc, VTY_NEWLINE);
421 return CMD_WARNING;
422 } else if (bsc_nr == _nat->num_bsc) {
423 /* allocate a new one */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800424 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800425 } else
426 bsc = bsc_config_num(_nat, bsc_nr);
427
428 if (!bsc)
429 return CMD_WARNING;
430
431 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800432 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800433
434 return CMD_SUCCESS;
435}
436
437DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
438{
439 struct bsc_config *conf = vty->index;
440
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200441 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800442 return CMD_SUCCESS;
443}
444
445DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800446 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800447{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200448 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800449 struct bsc_config *conf = vty->index;
450
451 int lac = atoi(argv[0]);
452
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800453 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
454 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
455 lac, VTY_NEWLINE);
456 return CMD_WARNING;
457 }
458
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200459 /* verify that the LACs are unique */
460 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800461 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200462 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
463 return CMD_ERR_INCOMPLETE;
464 }
465 }
466
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800467 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800468
469 return CMD_SUCCESS;
470}
471
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800472DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
473 "no location_area_code <0-65535>",
474 NO_STR "Set the Location Area Code (LAC) of this BSC")
475{
476 int lac = atoi(argv[0]);
477 struct bsc_config *conf = vty->index;
478
479 bsc_config_del_lac(conf, lac);
480 return CMD_SUCCESS;
481}
482
483
484
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800485DEFUN(cfg_lst_imsi_allow,
486 cfg_lst_imsi_allow_cmd,
487 "access-list NAME imsi-allow [REGEXP]",
488 "Allow IMSIs matching the REGEXP\n"
489 "The name of the access-list\n"
490 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200491{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800492 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800493 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200494
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800495 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800496 if (!acc)
497 return CMD_WARNING;
498
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800499 entry = bsc_nat_acc_lst_entry_create(acc);
500 if (!entry)
501 return CMD_WARNING;
502
503 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200504 return CMD_SUCCESS;
505}
506
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800507DEFUN(cfg_lst_imsi_deny,
508 cfg_lst_imsi_deny_cmd,
509 "access-list NAME imsi-deny [REGEXP]",
510 "Allow IMSIs matching the REGEXP\n"
511 "The name of the access-list\n"
512 "The regexp of to be denied IMSIs\n")
513{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800514 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800515 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800516
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800517 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800518 if (!acc)
519 return CMD_WARNING;
520
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800521 entry = bsc_nat_acc_lst_entry_create(acc);
522 if (!entry)
523 return CMD_WARNING;
524
525 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800526 return CMD_SUCCESS;
527}
528
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800529/* naming to follow Zebra... */
530DEFUN(cfg_lst_no,
531 cfg_lst_no_cmd,
532 "no access-list NAME",
533 NO_STR "Remove an access-list by name\n"
534 "The access-list to remove\n")
535{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800536 struct bsc_nat_acc_lst *acc;
537 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800538 if (!acc)
539 return CMD_WARNING;
540
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800541 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800542 return CMD_SUCCESS;
543}
544
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800545DEFUN(show_acc_lst,
546 show_acc_lst_cmd,
547 "show access-list NAME",
548 SHOW_STR "The name of the access list\n")
549{
550 struct bsc_nat_acc_lst *acc;
551 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
552 if (!acc)
553 return CMD_WARNING;
554
555 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
556 vty_out_rate_ctr_group(vty, " ", acc->stats);
557
558 return CMD_SUCCESS;
559}
560
561
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800562DEFUN(cfg_bsc_acc_lst_name,
563 cfg_bsc_acc_lst_name_cmd,
564 "access-list-name NAME",
565 "Set the name of the access list to use.\n"
566 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200567{
568 struct bsc_config *conf = vty->index;
569
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200570 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200571 return CMD_SUCCESS;
572}
573
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800574DEFUN(cfg_bsc_paging,
575 cfg_bsc_paging_cmd,
576 "paging forbidden (0|1)",
577 "Forbid sending PAGING REQUESTS to the BSC.")
578{
579 struct bsc_config *conf = vty->index;
580
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800581 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800582 conf->forbid_paging = 1;
583 else
584 conf->forbid_paging = 0;
585
586 return CMD_SUCCESS;
587}
588
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800589DEFUN(cfg_bsc_desc,
590 cfg_bsc_desc_cmd,
591 "description DESC",
592 "Provide a description for the given BSC.")
593{
594 struct bsc_config *conf = vty->index;
595
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200596 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800597 return CMD_SUCCESS;
598}
599
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800600DEFUN(test_regex, test_regex_cmd,
601 "test regex PATTERN STRING",
602 "Check if the string is matching the current pattern.")
603{
604 regex_t reg;
605 char *str = NULL;
606
607 memset(&reg, 0, sizeof(reg));
608 bsc_parse_reg(_nat, &reg, &str, 1, argv);
609
610 vty_out(vty, "String matches allow pattern: %d%s",
611 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
612
613 talloc_free(str);
614 regfree(&reg);
615 return CMD_SUCCESS;
616}
617
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800618int bsc_nat_vty_init(struct bsc_nat *nat)
619{
620 _nat = nat;
621
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800622 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800623 install_element_ve(&show_sccp_cmd);
624 install_element_ve(&show_bsc_cmd);
625 install_element_ve(&show_bsc_cfg_cmd);
626 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800627 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800628 install_element_ve(&close_bsc_cmd);
629 install_element_ve(&show_msc_cmd);
630 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800631 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800632 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200633
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800634 /* nat group */
635 install_element(CONFIG_NODE, &cfg_nat_cmd);
636 install_node(&nat_node, config_write_nat);
637 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800638 install_element(NAT_NODE, &ournode_exit_cmd);
639 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800640 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200641 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800642 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
643 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
644 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800645 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800646 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800647 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800648 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200649 install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800650
651 /* access-list */
652 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
653 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800654 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800655
656 /* BSC subgroups */
657 install_element(NAT_NODE, &cfg_bsc_cmd);
658 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800659 install_default(NAT_BSC_NODE);
660 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
661 install_element(NAT_BSC_NODE, &ournode_end_cmd);
662 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
663 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800664 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800665 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
666 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
667 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800668
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800669 mgcp_vty_init();
670
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800671 return 0;
672}
673
674
675/* called by the telnet interface... we have our own init above */
676void bsc_vty_init()
677{}