blob: 761c299477718ef61d1b7d911455bc28cafc862c [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
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +08009 * (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
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080018 *
19 */
20
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +080021#include <openbsc/vty.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080022#include <openbsc/bsc_nat.h>
Holger Hans Peter Freytherc2b31ed2010-07-31 05:17:17 +080023#include <openbsc/bsc_nat_sccp.h>
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +080024#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080025#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +080026#include <openbsc/mgcp.h>
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +020027#include <openbsc/vty.h>
Holger Hans Peter Freyther6c45f2e2010-06-15 19:06:18 +080028
29#include <osmocore/talloc.h>
Holger Hans Peter Freytherb2c38eb2010-06-17 18:16:00 +080030#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +080031#include <osmocore/utils.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);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +020080 if (_nat->ussd_lst_name)
81 vty_out(vty, " ussd-list-name %s%s", _nat->ussd_lst_name, VTY_NEWLINE);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +020082 if (_nat->ussd_query)
83 vty_out(vty, " ussd-query %s%s", _nat->ussd_query, VTY_NEWLINE);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +020084 if (_nat->ussd_token)
85 vty_out(vty, " ussd-token %s%s", _nat->ussd_token, VTY_NEWLINE);
86 if (_nat->ussd_local)
87 vty_out(vty, " ussd-local-ip %s%s", _nat->ussd_local, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080088
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +020089 if (_nat->num_rewr_name)
90 vty_out(vty, " number-rewrite %s%s", _nat->num_rewr_name, VTY_NEWLINE);
91
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080092 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080093 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080094 }
95
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080096 return CMD_SUCCESS;
97}
98
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +080099static void dump_lac(struct vty *vty, struct bsc_config *cfg)
100{
101 struct bsc_lac_entry *lac;
102 llist_for_each_entry(lac, &cfg->lac_list, entry)
103 vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE);
104}
105
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800106static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
107{
108 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
109 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800110 dump_lac(vty, bsc);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800111 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800112 if (bsc->description)
113 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800114 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +0800115 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100116 vty_out(vty, " max-endpoints %d%s", bsc->max_endpoints, VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800117}
118
119static int config_write_bsc(struct vty *vty)
120{
121 struct bsc_config *bsc;
122
123 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
124 config_write_bsc_single(vty, bsc);
125 return CMD_SUCCESS;
126}
127
128
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800129DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
130 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800131{
132 struct sccp_connections *con;
Holger Hans Peter Freyther85804a82010-09-15 19:01:31 +0800133 vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800134
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800135 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800136 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 +0200137 con->bsc->cfg ? con->bsc->cfg->nr : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800138 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200139 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800140 con->has_remote_ref,
141 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800142 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800143 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200144 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800145 }
146
147 return CMD_SUCCESS;
148}
149
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800150DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
151 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800152{
153 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200154 struct sockaddr_in sock;
155 socklen_t len = sizeof(sock);
156
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800157 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200158 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800159 vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200160 con->cfg ? con->cfg->nr : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200161 con->authenticated, con->write_queue.bfd.fd,
162 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800163 }
164
165 return CMD_SUCCESS;
166}
167
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800168DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
169 SHOW_STR "Display the MGCP status for a given BSC")
170{
171 struct bsc_connection *con;
172 int nr = atoi(argv[0]);
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100173 int i, j, endp;
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800174
175 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100176 int max;
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800177 if (!con->cfg)
178 continue;
179 if (con->cfg->nr != nr)
180 continue;
181
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100182 /* this bsc has no audio endpoints yet */
183 if (!con->_endpoint_status)
184 continue;
185
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800186 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100187 max = bsc_mgcp_nr_multiplexes(con->max_endpoints);
188 for (i = 0; i < max; ++i) {
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100189 for (j = 0; j < 32; ++j) {
190 endp = mgcp_timeslot_to_endpoint(i, j);
191 vty_out(vty, " Endpoint 0x%x %s%s", endp,
192 con->_endpoint_status[endp] == 0
193 ? "free" : "allocated",
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800194 VTY_NEWLINE);
Holger Hans Peter Freythera9e93312011-02-26 11:38:00 +0100195 }
196 }
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800197 break;
198 }
199
200 return CMD_SUCCESS;
201}
202
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800203DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
204 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800205{
206 struct bsc_config *conf;
207 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800208 vty_out(vty, "BSC token: '%s' nr: %u%s",
209 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800210 if (conf->acc_lst_name)
211 vty_out(vty, " access-list: %s%s",
212 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800213 vty_out(vty, " paging forbidden: %d%s",
214 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800215 if (conf->description)
216 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
217 else
218 vty_out(vty, " No description.%s", VTY_NEWLINE);
219
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800220 }
221
222 return CMD_SUCCESS;
223}
224
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800225static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
226{
227 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
228 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
229 counter_get(nat->stats.sccp.conn),
230 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
231 vty_out(vty, " MSC Connections %lu%s",
232 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800233 vty_out(vty, " MSC Connected: %d%s",
234 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800235 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
236 counter_get(nat->stats.bsc.reconn),
237 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
238}
239
240static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
241{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800242 int connected = 0;
243 struct bsc_connection *con;
244
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800245 vty_out(vty, " BSC nr: %d%s",
246 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800247 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800248
249 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
250 if (con->cfg != conf)
251 continue;
252 connected = 1;
253 break;
254 }
255
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800256 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800257}
258
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200259DEFUN(show_stats,
260 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800261 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800262 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200263{
264 struct bsc_config *conf;
265
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800266 int nr = -1;
267
268 if (argc == 1)
269 nr = atoi(argv[0]);
270
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800271 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200272 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800273 if (argc == 1 && nr != conf->nr)
274 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800275 dump_stat_bsc(vty, conf);
276 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800277
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800278 return CMD_SUCCESS;
279}
280
281DEFUN(show_stats_lac,
282 show_stats_lac_cmd,
283 "show statistics-by-lac <0-65535>",
284 SHOW_STR "Display network statistics by lac\n"
285 "The lac of the BSC\n")
286{
287 int lac;
288 struct bsc_config *conf;
289
290 lac = atoi(argv[0]);
291
292 dump_stat_total(vty, _nat);
293 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800294 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800295 continue;
296 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200297 }
298
299 return CMD_SUCCESS;
300}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800301
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800302DEFUN(show_msc,
303 show_msc_cmd,
304 "show msc connection",
305 SHOW_STR "Show the status of the MSC connection.")
306{
307 if (!_nat->msc_con) {
308 vty_out(vty, "The MSC is not yet configured.\n");
309 return CMD_WARNING;
310 }
311
312 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
313 _nat->msc_con->ip, _nat->msc_con->port,
314 _nat->msc_con->is_connected, VTY_NEWLINE);
315 return CMD_SUCCESS;
316}
317
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800318DEFUN(close_bsc,
319 close_bsc_cmd,
320 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800321 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800322{
323 struct bsc_connection *bsc;
324 int bsc_nr = atoi(argv[0]);
325
326 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
327 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
328 continue;
329 bsc_close_connection(bsc);
330 break;
331 }
332
333 return CMD_SUCCESS;
334}
335
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800336DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
337{
338 vty->index = _nat;
339 vty->node = NAT_NODE;
340
341 return CMD_SUCCESS;
342}
343
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800344DEFUN(cfg_nat_msc_ip,
345 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800346 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800347 "Set the IP address of the MSC.")
348{
349 bsc_nat_set_msc_ip(_nat, argv[0]);
350 return CMD_SUCCESS;
351}
352
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200353DEFUN(cfg_nat_msc_port,
354 cfg_nat_msc_port_cmd,
355 "msc port <1-65500>",
356 "Set the port of the MSC.")
357{
358 _nat->msc_port = atoi(argv[0]);
359 return CMD_SUCCESS;
360}
361
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800362DEFUN(cfg_nat_auth_time,
363 cfg_nat_auth_time_cmd,
364 "timeout auth <1-256>",
365 "The time to wait for an auth response.")
366{
367 _nat->auth_timeout = atoi(argv[0]);
368 return CMD_SUCCESS;
369}
370
371DEFUN(cfg_nat_ping_time,
372 cfg_nat_ping_time_cmd,
373 "timeout ping NR",
374 "Send a ping every NR seconds. Negative to disable.")
375{
376 _nat->ping_timeout = atoi(argv[0]);
377 return CMD_SUCCESS;
378}
379
380DEFUN(cfg_nat_pong_time,
381 cfg_nat_pong_time_cmd,
382 "timeout pong NR",
383 "Wait NR seconds for the PONG response. Should be smaller than ping.")
384{
385 _nat->pong_timeout = atoi(argv[0]);
386 return CMD_SUCCESS;
387}
388
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800389DEFUN(cfg_nat_token, cfg_nat_token_cmd,
390 "token TOKEN",
391 "Set a token for the NAT")
392{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200393 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800394 return CMD_SUCCESS;
395}
396
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800397DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
398 "ip-dscp <0-255>",
399 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800400{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800401 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800402 return CMD_SUCCESS;
403}
404
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800405ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
406 "ip-tos <0-255>",
407 "Use ip-dscp in the future.\n" "Set the DSCP\n")
408
409
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800410DEFUN(cfg_nat_acc_lst_name,
411 cfg_nat_acc_lst_name_cmd,
412 "access-list-name NAME",
413 "Set the name of the access list to use.\n"
414 "The name of the to be used access list.")
415{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200416 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800417 return CMD_SUCCESS;
418}
419
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200420DEFUN(cfg_nat_number_rewrite,
421 cfg_nat_number_rewrite_cmd,
422 "number-rewrite FILENAME",
423 "Set the file with rewriting rules.\n" "Filename")
424{
425 bsc_replace_string(_nat, &_nat->num_rewr_name, argv[0]);
426 if (_nat->num_rewr_name) {
427 if (_nat->num_rewr)
428 talloc_free(_nat->num_rewr);
429 _nat->num_rewr = msg_entry_parse(_nat, _nat->num_rewr_name);
430 return _nat->num_rewr == NULL ? CMD_WARNING : CMD_SUCCESS;
431 } else {
432 if (_nat->num_rewr)
433 talloc_free(_nat->num_rewr);
434 _nat->num_rewr = NULL;
435 return CMD_SUCCESS;
436 }
437}
438
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200439DEFUN(cfg_nat_ussd_lst_name,
440 cfg_nat_ussd_lst_name_cmd,
441 "ussd-list-name NAME",
442 "Set the name of the access list to check for IMSIs for USSD message\n"
443 "The name of the access list for HLR USSD handling")
444{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200445 bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200446 return CMD_SUCCESS;
447}
448
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200449DEFUN(cfg_nat_ussd_query,
450 cfg_nat_ussd_query_cmd,
451 "ussd-query QUERY",
452 "Set the USSD query to match with the ussd-list-name\n"
453 "The query to match")
454{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200455 bsc_replace_string(_nat, &_nat->ussd_query, argv[0]);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200456 return CMD_SUCCESS;
457}
458
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200459DEFUN(cfg_nat_ussd_token,
460 cfg_nat_ussd_token_cmd,
461 "ussd-token TOKEN",
462 "Set the token used to identify the USSD module\n" "Secret key\n")
463{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200464 bsc_replace_string(_nat, &_nat->ussd_token, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200465 return CMD_SUCCESS;
466}
467
468DEFUN(cfg_nat_ussd_local,
469 cfg_nat_ussd_local_cmd,
470 "ussd-local-ip A.B.C.D",
471 "Set the IP to listen for the USSD Provider\n" "IP Address\n")
472{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200473 bsc_replace_string(_nat, &_nat->ussd_local, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200474 return CMD_SUCCESS;
475}
476
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800477/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800478DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800479{
480 int bsc_nr = atoi(argv[0]);
481 struct bsc_config *bsc;
482
483 if (bsc_nr > _nat->num_bsc) {
484 vty_out(vty, "%% The next unused BSC number is %u%s",
485 _nat->num_bsc, VTY_NEWLINE);
486 return CMD_WARNING;
487 } else if (bsc_nr == _nat->num_bsc) {
488 /* allocate a new one */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800489 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800490 } else
491 bsc = bsc_config_num(_nat, bsc_nr);
492
493 if (!bsc)
494 return CMD_WARNING;
495
496 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800497 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800498
499 return CMD_SUCCESS;
500}
501
502DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
503{
504 struct bsc_config *conf = vty->index;
505
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200506 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800507 return CMD_SUCCESS;
508}
509
510DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800511 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800512{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200513 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800514 struct bsc_config *conf = vty->index;
515
516 int lac = atoi(argv[0]);
517
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800518 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
519 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
520 lac, VTY_NEWLINE);
521 return CMD_WARNING;
522 }
523
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200524 /* verify that the LACs are unique */
525 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800526 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200527 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
528 return CMD_ERR_INCOMPLETE;
529 }
530 }
531
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800532 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800533
534 return CMD_SUCCESS;
535}
536
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800537DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
538 "no location_area_code <0-65535>",
539 NO_STR "Set the Location Area Code (LAC) of this BSC")
540{
541 int lac = atoi(argv[0]);
542 struct bsc_config *conf = vty->index;
543
544 bsc_config_del_lac(conf, lac);
545 return CMD_SUCCESS;
546}
547
548
549
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800550DEFUN(cfg_lst_imsi_allow,
551 cfg_lst_imsi_allow_cmd,
552 "access-list NAME imsi-allow [REGEXP]",
553 "Allow IMSIs matching the REGEXP\n"
554 "The name of the access-list\n"
555 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200556{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800557 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800558 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200559
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800560 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800561 if (!acc)
562 return CMD_WARNING;
563
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800564 entry = bsc_nat_acc_lst_entry_create(acc);
565 if (!entry)
566 return CMD_WARNING;
567
568 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200569 return CMD_SUCCESS;
570}
571
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800572DEFUN(cfg_lst_imsi_deny,
573 cfg_lst_imsi_deny_cmd,
574 "access-list NAME imsi-deny [REGEXP]",
575 "Allow IMSIs matching the REGEXP\n"
576 "The name of the access-list\n"
577 "The regexp of to be denied IMSIs\n")
578{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800579 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800580 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800581
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800582 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800583 if (!acc)
584 return CMD_WARNING;
585
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800586 entry = bsc_nat_acc_lst_entry_create(acc);
587 if (!entry)
588 return CMD_WARNING;
589
590 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800591 return CMD_SUCCESS;
592}
593
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800594/* naming to follow Zebra... */
595DEFUN(cfg_lst_no,
596 cfg_lst_no_cmd,
597 "no access-list NAME",
598 NO_STR "Remove an access-list by name\n"
599 "The access-list to remove\n")
600{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800601 struct bsc_nat_acc_lst *acc;
602 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800603 if (!acc)
604 return CMD_WARNING;
605
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800606 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800607 return CMD_SUCCESS;
608}
609
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800610DEFUN(show_acc_lst,
611 show_acc_lst_cmd,
612 "show access-list NAME",
613 SHOW_STR "The name of the access list\n")
614{
615 struct bsc_nat_acc_lst *acc;
616 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
617 if (!acc)
618 return CMD_WARNING;
619
620 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
621 vty_out_rate_ctr_group(vty, " ", acc->stats);
622
623 return CMD_SUCCESS;
624}
625
626
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800627DEFUN(cfg_bsc_acc_lst_name,
628 cfg_bsc_acc_lst_name_cmd,
629 "access-list-name NAME",
630 "Set the name of the access list to use.\n"
631 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200632{
633 struct bsc_config *conf = vty->index;
634
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200635 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200636 return CMD_SUCCESS;
637}
638
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100639DEFUN(cfg_bsc_max_endps, cfg_bsc_max_endps_cmd,
640 "max-endpoints <1-1024>",
641 "Highest endpoint to use (exclusively)\n" "Number of ports\n")
Holger Hans Peter Freyther7b07b2d2011-02-25 20:38:15 +0100642{
643 struct bsc_config *conf = vty->index;
644
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100645 conf->max_endpoints = atoi(argv[0]);
Holger Hans Peter Freyther7b07b2d2011-02-25 20:38:15 +0100646 return CMD_SUCCESS;
647}
648
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800649DEFUN(cfg_bsc_paging,
650 cfg_bsc_paging_cmd,
651 "paging forbidden (0|1)",
652 "Forbid sending PAGING REQUESTS to the BSC.")
653{
654 struct bsc_config *conf = vty->index;
655
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800656 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800657 conf->forbid_paging = 1;
658 else
659 conf->forbid_paging = 0;
660
661 return CMD_SUCCESS;
662}
663
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800664DEFUN(cfg_bsc_desc,
665 cfg_bsc_desc_cmd,
666 "description DESC",
667 "Provide a description for the given BSC.")
668{
669 struct bsc_config *conf = vty->index;
670
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200671 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800672 return CMD_SUCCESS;
673}
674
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800675DEFUN(test_regex, test_regex_cmd,
676 "test regex PATTERN STRING",
677 "Check if the string is matching the current pattern.")
678{
679 regex_t reg;
680 char *str = NULL;
681
682 memset(&reg, 0, sizeof(reg));
683 bsc_parse_reg(_nat, &reg, &str, 1, argv);
684
685 vty_out(vty, "String matches allow pattern: %d%s",
686 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
687
688 talloc_free(str);
689 regfree(&reg);
690 return CMD_SUCCESS;
691}
692
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800693int bsc_nat_vty_init(struct bsc_nat *nat)
694{
695 _nat = nat;
696
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800697 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800698 install_element_ve(&show_sccp_cmd);
699 install_element_ve(&show_bsc_cmd);
700 install_element_ve(&show_bsc_cfg_cmd);
701 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800702 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800703 install_element_ve(&close_bsc_cmd);
704 install_element_ve(&show_msc_cmd);
705 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800706 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800707 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200708
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800709 /* nat group */
710 install_element(CONFIG_NODE, &cfg_nat_cmd);
711 install_node(&nat_node, config_write_nat);
712 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800713 install_element(NAT_NODE, &ournode_exit_cmd);
714 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800715 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200716 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800717 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
718 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
719 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800720 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800721 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800722 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800723 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200724 install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200725 install_element(NAT_NODE, &cfg_nat_ussd_query_cmd);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200726 install_element(NAT_NODE, &cfg_nat_ussd_token_cmd);
727 install_element(NAT_NODE, &cfg_nat_ussd_local_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800728
729 /* access-list */
730 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
731 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800732 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800733
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200734 /* number rewriting */
735 install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd);
736
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800737 /* BSC subgroups */
738 install_element(NAT_NODE, &cfg_bsc_cmd);
739 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800740 install_default(NAT_BSC_NODE);
741 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
742 install_element(NAT_BSC_NODE, &ournode_end_cmd);
743 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
744 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800745 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800746 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
747 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
748 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9ec030d2011-02-27 11:04:27 +0100749 install_element(NAT_BSC_NODE, &cfg_bsc_max_endps_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800750
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800751 mgcp_vty_init();
752
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800753 return 0;
754}
755
756
757/* called by the telnet interface... we have our own init above */
Holger Hans Peter Freyther6c79a682011-02-24 14:33:09 +0100758int bsc_vty_init(void)
759{
760 return 0;
761}