blob: 940ebfdf22774736e789bbb7804dda9965261c11 [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 Freytherc1578bc2010-10-11 10:06:39 +020083 if (_nat->ussd_query)
84 vty_out(vty, " ussd-query %s%s", _nat->ussd_query, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080085
86 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080087 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080088 }
89
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080090 return CMD_SUCCESS;
91}
92
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +080093static void dump_lac(struct vty *vty, struct bsc_config *cfg)
94{
95 struct bsc_lac_entry *lac;
96 llist_for_each_entry(lac, &cfg->lac_list, entry)
97 vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE);
98}
99
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800100static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
101{
102 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
103 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800104 dump_lac(vty, bsc);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800105 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800106 if (bsc->description)
107 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800108 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +0800109 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800110}
111
112static int config_write_bsc(struct vty *vty)
113{
114 struct bsc_config *bsc;
115
116 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
117 config_write_bsc_single(vty, bsc);
118 return CMD_SUCCESS;
119}
120
121
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800122DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
123 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800124{
125 struct sccp_connections *con;
Holger Hans Peter Freyther85804a82010-09-15 19:01:31 +0800126 vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800127
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800128 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800129 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 +0200130 con->bsc->cfg ? con->bsc->cfg->nr : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800131 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200132 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800133 con->has_remote_ref,
134 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800135 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800136 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200137 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800138 }
139
140 return CMD_SUCCESS;
141}
142
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800143DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
144 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800145{
146 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200147 struct sockaddr_in sock;
148 socklen_t len = sizeof(sock);
149
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800150 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200151 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800152 vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200153 con->cfg ? con->cfg->nr : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200154 con->authenticated, con->write_queue.bfd.fd,
155 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800156 }
157
158 return CMD_SUCCESS;
159}
160
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800161DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
162 SHOW_STR "Display the MGCP status for a given BSC")
163{
164 struct bsc_connection *con;
165 int nr = atoi(argv[0]);
166 int i;
167
168 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
169 if (!con->cfg)
170 continue;
171 if (con->cfg->nr != nr)
172 continue;
173
174 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
175 for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i)
176 vty_out(vty, " Endpoint 0x%x %s%s", i,
177 con->endpoint_status[i] == 0 ? "free" : "allocated",
178 VTY_NEWLINE);
179 break;
180 }
181
182 return CMD_SUCCESS;
183}
184
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800185DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
186 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800187{
188 struct bsc_config *conf;
189 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800190 vty_out(vty, "BSC token: '%s' nr: %u%s",
191 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800192 if (conf->acc_lst_name)
193 vty_out(vty, " access-list: %s%s",
194 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800195 vty_out(vty, " paging forbidden: %d%s",
196 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800197 if (conf->description)
198 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
199 else
200 vty_out(vty, " No description.%s", VTY_NEWLINE);
201
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800202 }
203
204 return CMD_SUCCESS;
205}
206
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800207static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
208{
209 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
210 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
211 counter_get(nat->stats.sccp.conn),
212 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
213 vty_out(vty, " MSC Connections %lu%s",
214 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800215 vty_out(vty, " MSC Connected: %d%s",
216 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800217 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
218 counter_get(nat->stats.bsc.reconn),
219 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
220}
221
222static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
223{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800224 int connected = 0;
225 struct bsc_connection *con;
226
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800227 vty_out(vty, " BSC nr: %d%s",
228 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800229 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800230
231 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
232 if (con->cfg != conf)
233 continue;
234 connected = 1;
235 break;
236 }
237
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800238 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800239}
240
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200241DEFUN(show_stats,
242 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800243 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800244 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200245{
246 struct bsc_config *conf;
247
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800248 int nr = -1;
249
250 if (argc == 1)
251 nr = atoi(argv[0]);
252
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800253 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200254 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800255 if (argc == 1 && nr != conf->nr)
256 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800257 dump_stat_bsc(vty, conf);
258 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800259
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800260 return CMD_SUCCESS;
261}
262
263DEFUN(show_stats_lac,
264 show_stats_lac_cmd,
265 "show statistics-by-lac <0-65535>",
266 SHOW_STR "Display network statistics by lac\n"
267 "The lac of the BSC\n")
268{
269 int lac;
270 struct bsc_config *conf;
271
272 lac = atoi(argv[0]);
273
274 dump_stat_total(vty, _nat);
275 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800276 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800277 continue;
278 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200279 }
280
281 return CMD_SUCCESS;
282}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800283
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800284DEFUN(show_msc,
285 show_msc_cmd,
286 "show msc connection",
287 SHOW_STR "Show the status of the MSC connection.")
288{
289 if (!_nat->msc_con) {
290 vty_out(vty, "The MSC is not yet configured.\n");
291 return CMD_WARNING;
292 }
293
294 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
295 _nat->msc_con->ip, _nat->msc_con->port,
296 _nat->msc_con->is_connected, VTY_NEWLINE);
297 return CMD_SUCCESS;
298}
299
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800300DEFUN(close_bsc,
301 close_bsc_cmd,
302 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800303 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800304{
305 struct bsc_connection *bsc;
306 int bsc_nr = atoi(argv[0]);
307
308 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
309 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
310 continue;
311 bsc_close_connection(bsc);
312 break;
313 }
314
315 return CMD_SUCCESS;
316}
317
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800318DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
319{
320 vty->index = _nat;
321 vty->node = NAT_NODE;
322
323 return CMD_SUCCESS;
324}
325
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800326DEFUN(cfg_nat_msc_ip,
327 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800328 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800329 "Set the IP address of the MSC.")
330{
331 bsc_nat_set_msc_ip(_nat, argv[0]);
332 return CMD_SUCCESS;
333}
334
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200335DEFUN(cfg_nat_msc_port,
336 cfg_nat_msc_port_cmd,
337 "msc port <1-65500>",
338 "Set the port of the MSC.")
339{
340 _nat->msc_port = atoi(argv[0]);
341 return CMD_SUCCESS;
342}
343
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800344DEFUN(cfg_nat_auth_time,
345 cfg_nat_auth_time_cmd,
346 "timeout auth <1-256>",
347 "The time to wait for an auth response.")
348{
349 _nat->auth_timeout = atoi(argv[0]);
350 return CMD_SUCCESS;
351}
352
353DEFUN(cfg_nat_ping_time,
354 cfg_nat_ping_time_cmd,
355 "timeout ping NR",
356 "Send a ping every NR seconds. Negative to disable.")
357{
358 _nat->ping_timeout = atoi(argv[0]);
359 return CMD_SUCCESS;
360}
361
362DEFUN(cfg_nat_pong_time,
363 cfg_nat_pong_time_cmd,
364 "timeout pong NR",
365 "Wait NR seconds for the PONG response. Should be smaller than ping.")
366{
367 _nat->pong_timeout = atoi(argv[0]);
368 return CMD_SUCCESS;
369}
370
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800371DEFUN(cfg_nat_token, cfg_nat_token_cmd,
372 "token TOKEN",
373 "Set a token for the NAT")
374{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200375 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800376 return CMD_SUCCESS;
377}
378
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800379DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
380 "ip-dscp <0-255>",
381 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800382{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800383 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800384 return CMD_SUCCESS;
385}
386
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800387ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
388 "ip-tos <0-255>",
389 "Use ip-dscp in the future.\n" "Set the DSCP\n")
390
391
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800392DEFUN(cfg_nat_acc_lst_name,
393 cfg_nat_acc_lst_name_cmd,
394 "access-list-name NAME",
395 "Set the name of the access list to use.\n"
396 "The name of the to be used access list.")
397{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200398 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800399 return CMD_SUCCESS;
400}
401
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200402DEFUN(cfg_nat_ussd_lst_name,
403 cfg_nat_ussd_lst_name_cmd,
404 "ussd-list-name NAME",
405 "Set the name of the access list to check for IMSIs for USSD message\n"
406 "The name of the access list for HLR USSD handling")
407{
408 if (_nat->ussd_lst_name)
409 talloc_free(_nat->ussd_lst_name);
410 _nat->ussd_lst_name = talloc_strdup(_nat, argv[0]);
411 return CMD_SUCCESS;
412}
413
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200414DEFUN(cfg_nat_ussd_query,
415 cfg_nat_ussd_query_cmd,
416 "ussd-query QUERY",
417 "Set the USSD query to match with the ussd-list-name\n"
418 "The query to match")
419{
420 if (_nat->ussd_query)
421 talloc_free(_nat->ussd_query);
422 _nat->ussd_query = talloc_strdup(_nat, argv[0]);
423 return CMD_SUCCESS;
424}
425
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800426/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800427DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800428{
429 int bsc_nr = atoi(argv[0]);
430 struct bsc_config *bsc;
431
432 if (bsc_nr > _nat->num_bsc) {
433 vty_out(vty, "%% The next unused BSC number is %u%s",
434 _nat->num_bsc, VTY_NEWLINE);
435 return CMD_WARNING;
436 } else if (bsc_nr == _nat->num_bsc) {
437 /* allocate a new one */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800438 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800439 } else
440 bsc = bsc_config_num(_nat, bsc_nr);
441
442 if (!bsc)
443 return CMD_WARNING;
444
445 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800446 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800447
448 return CMD_SUCCESS;
449}
450
451DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
452{
453 struct bsc_config *conf = vty->index;
454
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200455 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800456 return CMD_SUCCESS;
457}
458
459DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800460 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800461{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200462 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800463 struct bsc_config *conf = vty->index;
464
465 int lac = atoi(argv[0]);
466
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800467 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
468 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
469 lac, VTY_NEWLINE);
470 return CMD_WARNING;
471 }
472
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200473 /* verify that the LACs are unique */
474 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800475 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200476 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
477 return CMD_ERR_INCOMPLETE;
478 }
479 }
480
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800481 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800482
483 return CMD_SUCCESS;
484}
485
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800486DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
487 "no location_area_code <0-65535>",
488 NO_STR "Set the Location Area Code (LAC) of this BSC")
489{
490 int lac = atoi(argv[0]);
491 struct bsc_config *conf = vty->index;
492
493 bsc_config_del_lac(conf, lac);
494 return CMD_SUCCESS;
495}
496
497
498
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800499DEFUN(cfg_lst_imsi_allow,
500 cfg_lst_imsi_allow_cmd,
501 "access-list NAME imsi-allow [REGEXP]",
502 "Allow IMSIs matching the REGEXP\n"
503 "The name of the access-list\n"
504 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200505{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800506 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800507 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200508
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800509 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800510 if (!acc)
511 return CMD_WARNING;
512
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800513 entry = bsc_nat_acc_lst_entry_create(acc);
514 if (!entry)
515 return CMD_WARNING;
516
517 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200518 return CMD_SUCCESS;
519}
520
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800521DEFUN(cfg_lst_imsi_deny,
522 cfg_lst_imsi_deny_cmd,
523 "access-list NAME imsi-deny [REGEXP]",
524 "Allow IMSIs matching the REGEXP\n"
525 "The name of the access-list\n"
526 "The regexp of to be denied IMSIs\n")
527{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800528 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800529 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800530
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800531 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800532 if (!acc)
533 return CMD_WARNING;
534
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800535 entry = bsc_nat_acc_lst_entry_create(acc);
536 if (!entry)
537 return CMD_WARNING;
538
539 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800540 return CMD_SUCCESS;
541}
542
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800543/* naming to follow Zebra... */
544DEFUN(cfg_lst_no,
545 cfg_lst_no_cmd,
546 "no access-list NAME",
547 NO_STR "Remove an access-list by name\n"
548 "The access-list to remove\n")
549{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800550 struct bsc_nat_acc_lst *acc;
551 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800552 if (!acc)
553 return CMD_WARNING;
554
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800555 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800556 return CMD_SUCCESS;
557}
558
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800559DEFUN(show_acc_lst,
560 show_acc_lst_cmd,
561 "show access-list NAME",
562 SHOW_STR "The name of the access list\n")
563{
564 struct bsc_nat_acc_lst *acc;
565 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
566 if (!acc)
567 return CMD_WARNING;
568
569 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
570 vty_out_rate_ctr_group(vty, " ", acc->stats);
571
572 return CMD_SUCCESS;
573}
574
575
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800576DEFUN(cfg_bsc_acc_lst_name,
577 cfg_bsc_acc_lst_name_cmd,
578 "access-list-name NAME",
579 "Set the name of the access list to use.\n"
580 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200581{
582 struct bsc_config *conf = vty->index;
583
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200584 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200585 return CMD_SUCCESS;
586}
587
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800588DEFUN(cfg_bsc_paging,
589 cfg_bsc_paging_cmd,
590 "paging forbidden (0|1)",
591 "Forbid sending PAGING REQUESTS to the BSC.")
592{
593 struct bsc_config *conf = vty->index;
594
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800595 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800596 conf->forbid_paging = 1;
597 else
598 conf->forbid_paging = 0;
599
600 return CMD_SUCCESS;
601}
602
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800603DEFUN(cfg_bsc_desc,
604 cfg_bsc_desc_cmd,
605 "description DESC",
606 "Provide a description for the given BSC.")
607{
608 struct bsc_config *conf = vty->index;
609
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200610 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800611 return CMD_SUCCESS;
612}
613
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800614DEFUN(test_regex, test_regex_cmd,
615 "test regex PATTERN STRING",
616 "Check if the string is matching the current pattern.")
617{
618 regex_t reg;
619 char *str = NULL;
620
621 memset(&reg, 0, sizeof(reg));
622 bsc_parse_reg(_nat, &reg, &str, 1, argv);
623
624 vty_out(vty, "String matches allow pattern: %d%s",
625 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
626
627 talloc_free(str);
628 regfree(&reg);
629 return CMD_SUCCESS;
630}
631
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800632int bsc_nat_vty_init(struct bsc_nat *nat)
633{
634 _nat = nat;
635
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800636 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800637 install_element_ve(&show_sccp_cmd);
638 install_element_ve(&show_bsc_cmd);
639 install_element_ve(&show_bsc_cfg_cmd);
640 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800641 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800642 install_element_ve(&close_bsc_cmd);
643 install_element_ve(&show_msc_cmd);
644 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800645 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800646 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200647
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800648 /* nat group */
649 install_element(CONFIG_NODE, &cfg_nat_cmd);
650 install_node(&nat_node, config_write_nat);
651 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800652 install_element(NAT_NODE, &ournode_exit_cmd);
653 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800654 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200655 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800656 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
657 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
658 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800659 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800660 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800661 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800662 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200663 install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200664 install_element(NAT_NODE, &cfg_nat_ussd_query_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800665
666 /* access-list */
667 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
668 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800669 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800670
671 /* BSC subgroups */
672 install_element(NAT_NODE, &cfg_bsc_cmd);
673 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800674 install_default(NAT_BSC_NODE);
675 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
676 install_element(NAT_BSC_NODE, &ournode_end_cmd);
677 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
678 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800679 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800680 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
681 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
682 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800683
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800684 mgcp_vty_init();
685
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800686 return 0;
687}
688
689
690/* called by the telnet interface... we have our own init above */
691void bsc_vty_init()
692{}