blob: 01bee7489411f51539e7ecc6ecfc8e0c875fba3b [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 Freyther9a85ef32010-06-15 18:46:11 +0800116}
117
118static int config_write_bsc(struct vty *vty)
119{
120 struct bsc_config *bsc;
121
122 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
123 config_write_bsc_single(vty, bsc);
124 return CMD_SUCCESS;
125}
126
127
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800128DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
129 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800130{
131 struct sccp_connections *con;
Holger Hans Peter Freyther85804a82010-09-15 19:01:31 +0800132 vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800133
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800134 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800135 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 +0200136 con->bsc->cfg ? con->bsc->cfg->nr : -1,
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800137 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200138 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther4bd22942010-04-27 13:11:18 +0800139 con->has_remote_ref,
140 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freytherf4b34392010-08-28 16:08:39 +0800141 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther234d3122010-05-16 02:06:11 +0800142 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32d34362010-04-05 10:10:33 +0200143 VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800144 }
145
146 return CMD_SUCCESS;
147}
148
Holger Hans Peter Freyther01a0b1b2010-04-19 16:06:43 +0800149DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
150 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800151{
152 struct bsc_connection *con;
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200153 struct sockaddr_in sock;
154 socklen_t len = sizeof(sock);
155
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800156 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200157 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800158 vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freyther47dd4942010-04-06 15:11:34 +0200159 con->cfg ? con->cfg->nr : -1,
Holger Hans Peter Freyther870663a2010-04-08 10:35:20 +0200160 con->authenticated, con->write_queue.bfd.fd,
161 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800162 }
163
164 return CMD_SUCCESS;
165}
166
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800167DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
168 SHOW_STR "Display the MGCP status for a given BSC")
169{
170 struct bsc_connection *con;
171 int nr = atoi(argv[0]);
172 int i;
173
174 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100175 int endpoints;
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800176 if (!con->cfg)
177 continue;
178 if (con->cfg->nr != nr)
179 continue;
180
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100181 /* this bsc has no audio endpoints yet */
182 if (!con->_endpoint_status)
183 continue;
184
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800185 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100186 endpoints = 31 * con->cfg->number_multiplexes;
187 for (i = 1; i <= endpoints; ++i)
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800188 vty_out(vty, " Endpoint 0x%x %s%s", i,
Holger Hans Peter Freythered500e32011-02-25 17:09:07 +0100189 con->_endpoint_status[i] == 0 ? "free" : "allocated",
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800190 VTY_NEWLINE);
191 break;
192 }
193
194 return CMD_SUCCESS;
195}
196
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800197DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
198 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800199{
200 struct bsc_config *conf;
201 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800202 vty_out(vty, "BSC token: '%s' nr: %u%s",
203 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800204 if (conf->acc_lst_name)
205 vty_out(vty, " access-list: %s%s",
206 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800207 vty_out(vty, " paging forbidden: %d%s",
208 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800209 if (conf->description)
210 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
211 else
212 vty_out(vty, " No description.%s", VTY_NEWLINE);
213
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800214 }
215
216 return CMD_SUCCESS;
217}
218
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800219static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
220{
221 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
222 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
223 counter_get(nat->stats.sccp.conn),
224 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
225 vty_out(vty, " MSC Connections %lu%s",
226 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800227 vty_out(vty, " MSC Connected: %d%s",
228 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800229 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
230 counter_get(nat->stats.bsc.reconn),
231 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
232}
233
234static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
235{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800236 int connected = 0;
237 struct bsc_connection *con;
238
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800239 vty_out(vty, " BSC nr: %d%s",
240 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800241 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800242
243 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
244 if (con->cfg != conf)
245 continue;
246 connected = 1;
247 break;
248 }
249
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800250 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800251}
252
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200253DEFUN(show_stats,
254 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800255 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800256 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200257{
258 struct bsc_config *conf;
259
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800260 int nr = -1;
261
262 if (argc == 1)
263 nr = atoi(argv[0]);
264
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800265 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200266 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800267 if (argc == 1 && nr != conf->nr)
268 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800269 dump_stat_bsc(vty, conf);
270 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800271
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800272 return CMD_SUCCESS;
273}
274
275DEFUN(show_stats_lac,
276 show_stats_lac_cmd,
277 "show statistics-by-lac <0-65535>",
278 SHOW_STR "Display network statistics by lac\n"
279 "The lac of the BSC\n")
280{
281 int lac;
282 struct bsc_config *conf;
283
284 lac = atoi(argv[0]);
285
286 dump_stat_total(vty, _nat);
287 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800288 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800289 continue;
290 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200291 }
292
293 return CMD_SUCCESS;
294}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800295
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800296DEFUN(show_msc,
297 show_msc_cmd,
298 "show msc connection",
299 SHOW_STR "Show the status of the MSC connection.")
300{
301 if (!_nat->msc_con) {
302 vty_out(vty, "The MSC is not yet configured.\n");
303 return CMD_WARNING;
304 }
305
306 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
307 _nat->msc_con->ip, _nat->msc_con->port,
308 _nat->msc_con->is_connected, VTY_NEWLINE);
309 return CMD_SUCCESS;
310}
311
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800312DEFUN(close_bsc,
313 close_bsc_cmd,
314 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800315 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800316{
317 struct bsc_connection *bsc;
318 int bsc_nr = atoi(argv[0]);
319
320 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
321 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
322 continue;
323 bsc_close_connection(bsc);
324 break;
325 }
326
327 return CMD_SUCCESS;
328}
329
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800330DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
331{
332 vty->index = _nat;
333 vty->node = NAT_NODE;
334
335 return CMD_SUCCESS;
336}
337
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800338DEFUN(cfg_nat_msc_ip,
339 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800340 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800341 "Set the IP address of the MSC.")
342{
343 bsc_nat_set_msc_ip(_nat, argv[0]);
344 return CMD_SUCCESS;
345}
346
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200347DEFUN(cfg_nat_msc_port,
348 cfg_nat_msc_port_cmd,
349 "msc port <1-65500>",
350 "Set the port of the MSC.")
351{
352 _nat->msc_port = atoi(argv[0]);
353 return CMD_SUCCESS;
354}
355
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800356DEFUN(cfg_nat_auth_time,
357 cfg_nat_auth_time_cmd,
358 "timeout auth <1-256>",
359 "The time to wait for an auth response.")
360{
361 _nat->auth_timeout = atoi(argv[0]);
362 return CMD_SUCCESS;
363}
364
365DEFUN(cfg_nat_ping_time,
366 cfg_nat_ping_time_cmd,
367 "timeout ping NR",
368 "Send a ping every NR seconds. Negative to disable.")
369{
370 _nat->ping_timeout = atoi(argv[0]);
371 return CMD_SUCCESS;
372}
373
374DEFUN(cfg_nat_pong_time,
375 cfg_nat_pong_time_cmd,
376 "timeout pong NR",
377 "Wait NR seconds for the PONG response. Should be smaller than ping.")
378{
379 _nat->pong_timeout = atoi(argv[0]);
380 return CMD_SUCCESS;
381}
382
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800383DEFUN(cfg_nat_token, cfg_nat_token_cmd,
384 "token TOKEN",
385 "Set a token for the NAT")
386{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200387 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800388 return CMD_SUCCESS;
389}
390
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800391DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
392 "ip-dscp <0-255>",
393 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800394{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800395 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800396 return CMD_SUCCESS;
397}
398
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800399ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
400 "ip-tos <0-255>",
401 "Use ip-dscp in the future.\n" "Set the DSCP\n")
402
403
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800404DEFUN(cfg_nat_acc_lst_name,
405 cfg_nat_acc_lst_name_cmd,
406 "access-list-name NAME",
407 "Set the name of the access list to use.\n"
408 "The name of the to be used access list.")
409{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200410 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800411 return CMD_SUCCESS;
412}
413
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200414DEFUN(cfg_nat_number_rewrite,
415 cfg_nat_number_rewrite_cmd,
416 "number-rewrite FILENAME",
417 "Set the file with rewriting rules.\n" "Filename")
418{
419 bsc_replace_string(_nat, &_nat->num_rewr_name, argv[0]);
420 if (_nat->num_rewr_name) {
421 if (_nat->num_rewr)
422 talloc_free(_nat->num_rewr);
423 _nat->num_rewr = msg_entry_parse(_nat, _nat->num_rewr_name);
424 return _nat->num_rewr == NULL ? CMD_WARNING : CMD_SUCCESS;
425 } else {
426 if (_nat->num_rewr)
427 talloc_free(_nat->num_rewr);
428 _nat->num_rewr = NULL;
429 return CMD_SUCCESS;
430 }
431}
432
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200433DEFUN(cfg_nat_ussd_lst_name,
434 cfg_nat_ussd_lst_name_cmd,
435 "ussd-list-name NAME",
436 "Set the name of the access list to check for IMSIs for USSD message\n"
437 "The name of the access list for HLR USSD handling")
438{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200439 bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200440 return CMD_SUCCESS;
441}
442
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200443DEFUN(cfg_nat_ussd_query,
444 cfg_nat_ussd_query_cmd,
445 "ussd-query QUERY",
446 "Set the USSD query to match with the ussd-list-name\n"
447 "The query to match")
448{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200449 bsc_replace_string(_nat, &_nat->ussd_query, argv[0]);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200450 return CMD_SUCCESS;
451}
452
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200453DEFUN(cfg_nat_ussd_token,
454 cfg_nat_ussd_token_cmd,
455 "ussd-token TOKEN",
456 "Set the token used to identify the USSD module\n" "Secret key\n")
457{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200458 bsc_replace_string(_nat, &_nat->ussd_token, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200459 return CMD_SUCCESS;
460}
461
462DEFUN(cfg_nat_ussd_local,
463 cfg_nat_ussd_local_cmd,
464 "ussd-local-ip A.B.C.D",
465 "Set the IP to listen for the USSD Provider\n" "IP Address\n")
466{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200467 bsc_replace_string(_nat, &_nat->ussd_local, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200468 return CMD_SUCCESS;
469}
470
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800471/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800472DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800473{
474 int bsc_nr = atoi(argv[0]);
475 struct bsc_config *bsc;
476
477 if (bsc_nr > _nat->num_bsc) {
478 vty_out(vty, "%% The next unused BSC number is %u%s",
479 _nat->num_bsc, VTY_NEWLINE);
480 return CMD_WARNING;
481 } else if (bsc_nr == _nat->num_bsc) {
482 /* allocate a new one */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800483 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800484 } else
485 bsc = bsc_config_num(_nat, bsc_nr);
486
487 if (!bsc)
488 return CMD_WARNING;
489
490 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800491 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800492
493 return CMD_SUCCESS;
494}
495
496DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
497{
498 struct bsc_config *conf = vty->index;
499
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200500 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800501 return CMD_SUCCESS;
502}
503
504DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800505 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800506{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200507 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800508 struct bsc_config *conf = vty->index;
509
510 int lac = atoi(argv[0]);
511
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800512 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
513 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
514 lac, VTY_NEWLINE);
515 return CMD_WARNING;
516 }
517
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200518 /* verify that the LACs are unique */
519 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800520 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200521 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
522 return CMD_ERR_INCOMPLETE;
523 }
524 }
525
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800526 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800527
528 return CMD_SUCCESS;
529}
530
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800531DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
532 "no location_area_code <0-65535>",
533 NO_STR "Set the Location Area Code (LAC) of this BSC")
534{
535 int lac = atoi(argv[0]);
536 struct bsc_config *conf = vty->index;
537
538 bsc_config_del_lac(conf, lac);
539 return CMD_SUCCESS;
540}
541
542
543
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800544DEFUN(cfg_lst_imsi_allow,
545 cfg_lst_imsi_allow_cmd,
546 "access-list NAME imsi-allow [REGEXP]",
547 "Allow IMSIs matching the REGEXP\n"
548 "The name of the access-list\n"
549 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200550{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800551 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800552 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200553
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800554 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800555 if (!acc)
556 return CMD_WARNING;
557
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800558 entry = bsc_nat_acc_lst_entry_create(acc);
559 if (!entry)
560 return CMD_WARNING;
561
562 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200563 return CMD_SUCCESS;
564}
565
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800566DEFUN(cfg_lst_imsi_deny,
567 cfg_lst_imsi_deny_cmd,
568 "access-list NAME imsi-deny [REGEXP]",
569 "Allow IMSIs matching the REGEXP\n"
570 "The name of the access-list\n"
571 "The regexp of to be denied IMSIs\n")
572{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800573 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800574 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800575
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800576 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800577 if (!acc)
578 return CMD_WARNING;
579
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800580 entry = bsc_nat_acc_lst_entry_create(acc);
581 if (!entry)
582 return CMD_WARNING;
583
584 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800585 return CMD_SUCCESS;
586}
587
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800588/* naming to follow Zebra... */
589DEFUN(cfg_lst_no,
590 cfg_lst_no_cmd,
591 "no access-list NAME",
592 NO_STR "Remove an access-list by name\n"
593 "The access-list to remove\n")
594{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800595 struct bsc_nat_acc_lst *acc;
596 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800597 if (!acc)
598 return CMD_WARNING;
599
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800600 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800601 return CMD_SUCCESS;
602}
603
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800604DEFUN(show_acc_lst,
605 show_acc_lst_cmd,
606 "show access-list NAME",
607 SHOW_STR "The name of the access list\n")
608{
609 struct bsc_nat_acc_lst *acc;
610 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
611 if (!acc)
612 return CMD_WARNING;
613
614 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
615 vty_out_rate_ctr_group(vty, " ", acc->stats);
616
617 return CMD_SUCCESS;
618}
619
620
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800621DEFUN(cfg_bsc_acc_lst_name,
622 cfg_bsc_acc_lst_name_cmd,
623 "access-list-name NAME",
624 "Set the name of the access list to use.\n"
625 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200626{
627 struct bsc_config *conf = vty->index;
628
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200629 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200630 return CMD_SUCCESS;
631}
632
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800633DEFUN(cfg_bsc_paging,
634 cfg_bsc_paging_cmd,
635 "paging forbidden (0|1)",
636 "Forbid sending PAGING REQUESTS to the BSC.")
637{
638 struct bsc_config *conf = vty->index;
639
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800640 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800641 conf->forbid_paging = 1;
642 else
643 conf->forbid_paging = 0;
644
645 return CMD_SUCCESS;
646}
647
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800648DEFUN(cfg_bsc_desc,
649 cfg_bsc_desc_cmd,
650 "description DESC",
651 "Provide a description for the given BSC.")
652{
653 struct bsc_config *conf = vty->index;
654
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200655 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800656 return CMD_SUCCESS;
657}
658
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800659DEFUN(test_regex, test_regex_cmd,
660 "test regex PATTERN STRING",
661 "Check if the string is matching the current pattern.")
662{
663 regex_t reg;
664 char *str = NULL;
665
666 memset(&reg, 0, sizeof(reg));
667 bsc_parse_reg(_nat, &reg, &str, 1, argv);
668
669 vty_out(vty, "String matches allow pattern: %d%s",
670 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
671
672 talloc_free(str);
673 regfree(&reg);
674 return CMD_SUCCESS;
675}
676
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800677int bsc_nat_vty_init(struct bsc_nat *nat)
678{
679 _nat = nat;
680
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800681 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800682 install_element_ve(&show_sccp_cmd);
683 install_element_ve(&show_bsc_cmd);
684 install_element_ve(&show_bsc_cfg_cmd);
685 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800686 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800687 install_element_ve(&close_bsc_cmd);
688 install_element_ve(&show_msc_cmd);
689 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800690 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800691 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200692
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800693 /* nat group */
694 install_element(CONFIG_NODE, &cfg_nat_cmd);
695 install_node(&nat_node, config_write_nat);
696 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800697 install_element(NAT_NODE, &ournode_exit_cmd);
698 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800699 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200700 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800701 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
702 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
703 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800704 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800705 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800706 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800707 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200708 install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200709 install_element(NAT_NODE, &cfg_nat_ussd_query_cmd);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200710 install_element(NAT_NODE, &cfg_nat_ussd_token_cmd);
711 install_element(NAT_NODE, &cfg_nat_ussd_local_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800712
713 /* access-list */
714 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
715 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800716 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800717
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200718 /* number rewriting */
719 install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd);
720
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800721 /* BSC subgroups */
722 install_element(NAT_NODE, &cfg_bsc_cmd);
723 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800724 install_default(NAT_BSC_NODE);
725 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
726 install_element(NAT_BSC_NODE, &ournode_end_cmd);
727 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
728 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800729 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800730 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
731 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
732 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800733
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800734 mgcp_vty_init();
735
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800736 return 0;
737}
738
739
740/* called by the telnet interface... we have our own init above */
Holger Hans Peter Freyther6c79a682011-02-24 14:33:09 +0100741int bsc_vty_init(void)
742{
743 return 0;
744}