blob: af7e94c6779eb541ef75f06832a8cd875bdea79e [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 Freythere393f272010-10-12 18:25:52 +020085 if (_nat->ussd_token)
86 vty_out(vty, " ussd-token %s%s", _nat->ussd_token, VTY_NEWLINE);
87 if (_nat->ussd_local)
88 vty_out(vty, " ussd-local-ip %s%s", _nat->ussd_local, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080089
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +020090 if (_nat->num_rewr_name)
91 vty_out(vty, " number-rewrite %s%s", _nat->num_rewr_name, VTY_NEWLINE);
92
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080093 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +080094 write_acc_lst(vty, lst);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +080095 }
96
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +080097 return CMD_SUCCESS;
98}
99
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800100static void dump_lac(struct vty *vty, struct bsc_config *cfg)
101{
102 struct bsc_lac_entry *lac;
103 llist_for_each_entry(lac, &cfg->lac_list, entry)
104 vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE);
105}
106
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800107static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
108{
109 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
110 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800111 dump_lac(vty, bsc);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800112 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800113 if (bsc->description)
114 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800115 if (bsc->acc_lst_name)
Holger Hans Peter Freyther27d36de2010-06-08 11:18:26 +0800116 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, 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]);
173 int i;
174
175 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
176 if (!con->cfg)
177 continue;
178 if (con->cfg->nr != nr)
179 continue;
180
181 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
182 for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i)
183 vty_out(vty, " Endpoint 0x%x %s%s", i,
184 con->endpoint_status[i] == 0 ? "free" : "allocated",
185 VTY_NEWLINE);
186 break;
187 }
188
189 return CMD_SUCCESS;
190}
191
Holger Hans Peter Freytherab7539c2010-04-22 13:36:46 +0800192DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
193 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800194{
195 struct bsc_config *conf;
196 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800197 vty_out(vty, "BSC token: '%s' nr: %u%s",
198 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800199 if (conf->acc_lst_name)
200 vty_out(vty, " access-list: %s%s",
201 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800202 vty_out(vty, " paging forbidden: %d%s",
203 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800204 if (conf->description)
205 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
206 else
207 vty_out(vty, " No description.%s", VTY_NEWLINE);
208
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800209 }
210
211 return CMD_SUCCESS;
212}
213
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800214static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
215{
216 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
217 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
218 counter_get(nat->stats.sccp.conn),
219 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
220 vty_out(vty, " MSC Connections %lu%s",
221 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freythercbfd0982010-08-04 02:34:10 +0800222 vty_out(vty, " MSC Connected: %d%s",
223 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800224 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
225 counter_get(nat->stats.bsc.reconn),
226 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
227}
228
229static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
230{
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800231 int connected = 0;
232 struct bsc_connection *con;
233
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800234 vty_out(vty, " BSC nr: %d%s",
235 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800236 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freytherf21e4532010-07-22 20:37:35 +0800237
238 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
239 if (con->cfg != conf)
240 continue;
241 connected = 1;
242 break;
243 }
244
Holger Hans Peter Freyther03a0ad02010-08-04 02:29:03 +0800245 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800246}
247
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200248DEFUN(show_stats,
249 show_stats_cmd,
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800250 "show statistics [NR]",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800251 SHOW_STR "Display network statistics")
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200252{
253 struct bsc_config *conf;
254
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800255 int nr = -1;
256
257 if (argc == 1)
258 nr = atoi(argv[0]);
259
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800260 dump_stat_total(vty, _nat);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200261 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800262 if (argc == 1 && nr != conf->nr)
263 continue;
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800264 dump_stat_bsc(vty, conf);
265 }
Holger Hans Peter Freyther314191d2010-05-02 18:59:24 +0800266
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800267 return CMD_SUCCESS;
268}
269
270DEFUN(show_stats_lac,
271 show_stats_lac_cmd,
272 "show statistics-by-lac <0-65535>",
273 SHOW_STR "Display network statistics by lac\n"
274 "The lac of the BSC\n")
275{
276 int lac;
277 struct bsc_config *conf;
278
279 lac = atoi(argv[0]);
280
281 dump_stat_total(vty, _nat);
282 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800283 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800284 continue;
285 dump_stat_bsc(vty, conf);
Holger Hans Peter Freytherbcfebb22010-04-12 12:33:27 +0200286 }
287
288 return CMD_SUCCESS;
289}
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800290
Holger Hans Peter Freytheraad82ce2010-05-11 19:07:39 +0800291DEFUN(show_msc,
292 show_msc_cmd,
293 "show msc connection",
294 SHOW_STR "Show the status of the MSC connection.")
295{
296 if (!_nat->msc_con) {
297 vty_out(vty, "The MSC is not yet configured.\n");
298 return CMD_WARNING;
299 }
300
301 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
302 _nat->msc_con->ip, _nat->msc_con->port,
303 _nat->msc_con->is_connected, VTY_NEWLINE);
304 return CMD_SUCCESS;
305}
306
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800307DEFUN(close_bsc,
308 close_bsc_cmd,
309 "close bsc connection BSC_NR",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800310 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther2f9dcf02010-04-27 13:21:39 +0800311{
312 struct bsc_connection *bsc;
313 int bsc_nr = atoi(argv[0]);
314
315 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
316 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
317 continue;
318 bsc_close_connection(bsc);
319 break;
320 }
321
322 return CMD_SUCCESS;
323}
324
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800325DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
326{
327 vty->index = _nat;
328 vty->node = NAT_NODE;
329
330 return CMD_SUCCESS;
331}
332
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800333DEFUN(cfg_nat_msc_ip,
334 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherd8b82062010-05-14 02:36:42 +0800335 "msc ip A.B.C.D",
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800336 "Set the IP address of the MSC.")
337{
338 bsc_nat_set_msc_ip(_nat, argv[0]);
339 return CMD_SUCCESS;
340}
341
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200342DEFUN(cfg_nat_msc_port,
343 cfg_nat_msc_port_cmd,
344 "msc port <1-65500>",
345 "Set the port of the MSC.")
346{
347 _nat->msc_port = atoi(argv[0]);
348 return CMD_SUCCESS;
349}
350
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800351DEFUN(cfg_nat_auth_time,
352 cfg_nat_auth_time_cmd,
353 "timeout auth <1-256>",
354 "The time to wait for an auth response.")
355{
356 _nat->auth_timeout = atoi(argv[0]);
357 return CMD_SUCCESS;
358}
359
360DEFUN(cfg_nat_ping_time,
361 cfg_nat_ping_time_cmd,
362 "timeout ping NR",
363 "Send a ping every NR seconds. Negative to disable.")
364{
365 _nat->ping_timeout = atoi(argv[0]);
366 return CMD_SUCCESS;
367}
368
369DEFUN(cfg_nat_pong_time,
370 cfg_nat_pong_time_cmd,
371 "timeout pong NR",
372 "Wait NR seconds for the PONG response. Should be smaller than ping.")
373{
374 _nat->pong_timeout = atoi(argv[0]);
375 return CMD_SUCCESS;
376}
377
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800378DEFUN(cfg_nat_token, cfg_nat_token_cmd,
379 "token TOKEN",
380 "Set a token for the NAT")
381{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200382 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800383 return CMD_SUCCESS;
384}
385
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800386DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
387 "ip-dscp <0-255>",
388 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800389{
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800390 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800391 return CMD_SUCCESS;
392}
393
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800394ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
395 "ip-tos <0-255>",
396 "Use ip-dscp in the future.\n" "Set the DSCP\n")
397
398
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800399DEFUN(cfg_nat_acc_lst_name,
400 cfg_nat_acc_lst_name_cmd,
401 "access-list-name NAME",
402 "Set the name of the access list to use.\n"
403 "The name of the to be used access list.")
404{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200405 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800406 return CMD_SUCCESS;
407}
408
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200409DEFUN(cfg_nat_number_rewrite,
410 cfg_nat_number_rewrite_cmd,
411 "number-rewrite FILENAME",
412 "Set the file with rewriting rules.\n" "Filename")
413{
414 bsc_replace_string(_nat, &_nat->num_rewr_name, argv[0]);
415 if (_nat->num_rewr_name) {
416 if (_nat->num_rewr)
417 talloc_free(_nat->num_rewr);
418 _nat->num_rewr = msg_entry_parse(_nat, _nat->num_rewr_name);
419 return _nat->num_rewr == NULL ? CMD_WARNING : CMD_SUCCESS;
420 } else {
421 if (_nat->num_rewr)
422 talloc_free(_nat->num_rewr);
423 _nat->num_rewr = NULL;
424 return CMD_SUCCESS;
425 }
426}
427
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200428DEFUN(cfg_nat_ussd_lst_name,
429 cfg_nat_ussd_lst_name_cmd,
430 "ussd-list-name NAME",
431 "Set the name of the access list to check for IMSIs for USSD message\n"
432 "The name of the access list for HLR USSD handling")
433{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200434 bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200435 return CMD_SUCCESS;
436}
437
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200438DEFUN(cfg_nat_ussd_query,
439 cfg_nat_ussd_query_cmd,
440 "ussd-query QUERY",
441 "Set the USSD query to match with the ussd-list-name\n"
442 "The query to match")
443{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200444 bsc_replace_string(_nat, &_nat->ussd_query, argv[0]);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200445 return CMD_SUCCESS;
446}
447
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200448DEFUN(cfg_nat_ussd_token,
449 cfg_nat_ussd_token_cmd,
450 "ussd-token TOKEN",
451 "Set the token used to identify the USSD module\n" "Secret key\n")
452{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200453 bsc_replace_string(_nat, &_nat->ussd_token, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200454 return CMD_SUCCESS;
455}
456
457DEFUN(cfg_nat_ussd_local,
458 cfg_nat_ussd_local_cmd,
459 "ussd-local-ip A.B.C.D",
460 "Set the IP to listen for the USSD Provider\n" "IP Address\n")
461{
Holger Hans Peter Freyther64b12922010-10-12 21:31:02 +0200462 bsc_replace_string(_nat, &_nat->ussd_local, argv[0]);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200463 return CMD_SUCCESS;
464}
465
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800466/* per BSC configuration */
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800467DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800468{
469 int bsc_nr = atoi(argv[0]);
470 struct bsc_config *bsc;
471
472 if (bsc_nr > _nat->num_bsc) {
473 vty_out(vty, "%% The next unused BSC number is %u%s",
474 _nat->num_bsc, VTY_NEWLINE);
475 return CMD_WARNING;
476 } else if (bsc_nr == _nat->num_bsc) {
477 /* allocate a new one */
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800478 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800479 } else
480 bsc = bsc_config_num(_nat, bsc_nr);
481
482 if (!bsc)
483 return CMD_WARNING;
484
485 vty->index = bsc;
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800486 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800487
488 return CMD_SUCCESS;
489}
490
491DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
492{
493 struct bsc_config *conf = vty->index;
494
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200495 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800496 return CMD_SUCCESS;
497}
498
499DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherb9af2fa2010-04-27 15:35:14 +0800500 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800501{
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200502 struct bsc_config *tmp;
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800503 struct bsc_config *conf = vty->index;
504
505 int lac = atoi(argv[0]);
506
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800507 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
508 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
509 lac, VTY_NEWLINE);
510 return CMD_WARNING;
511 }
512
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200513 /* verify that the LACs are unique */
514 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800515 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther39ee8772010-03-30 06:08:56 +0200516 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
517 return CMD_ERR_INCOMPLETE;
518 }
519 }
520
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800521 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800522
523 return CMD_SUCCESS;
524}
525
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800526DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
527 "no location_area_code <0-65535>",
528 NO_STR "Set the Location Area Code (LAC) of this BSC")
529{
530 int lac = atoi(argv[0]);
531 struct bsc_config *conf = vty->index;
532
533 bsc_config_del_lac(conf, lac);
534 return CMD_SUCCESS;
535}
536
537
538
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800539DEFUN(cfg_lst_imsi_allow,
540 cfg_lst_imsi_allow_cmd,
541 "access-list NAME imsi-allow [REGEXP]",
542 "Allow IMSIs matching the REGEXP\n"
543 "The name of the access-list\n"
544 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200545{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800546 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800547 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200548
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800549 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800550 if (!acc)
551 return CMD_WARNING;
552
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800553 entry = bsc_nat_acc_lst_entry_create(acc);
554 if (!entry)
555 return CMD_WARNING;
556
557 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200558 return CMD_SUCCESS;
559}
560
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800561DEFUN(cfg_lst_imsi_deny,
562 cfg_lst_imsi_deny_cmd,
563 "access-list NAME imsi-deny [REGEXP]",
564 "Allow IMSIs matching the REGEXP\n"
565 "The name of the access-list\n"
566 "The regexp of to be denied IMSIs\n")
567{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800568 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800569 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800570
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800571 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800572 if (!acc)
573 return CMD_WARNING;
574
Holger Hans Peter Freytherd77c8172010-06-08 10:53:39 +0800575 entry = bsc_nat_acc_lst_entry_create(acc);
576 if (!entry)
577 return CMD_WARNING;
578
579 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800580 return CMD_SUCCESS;
581}
582
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800583/* naming to follow Zebra... */
584DEFUN(cfg_lst_no,
585 cfg_lst_no_cmd,
586 "no access-list NAME",
587 NO_STR "Remove an access-list by name\n"
588 "The access-list to remove\n")
589{
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800590 struct bsc_nat_acc_lst *acc;
591 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800592 if (!acc)
593 return CMD_WARNING;
594
Holger Hans Peter Freyther29c67032010-06-08 10:14:44 +0800595 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800596 return CMD_SUCCESS;
597}
598
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800599DEFUN(show_acc_lst,
600 show_acc_lst_cmd,
601 "show access-list NAME",
602 SHOW_STR "The name of the access list\n")
603{
604 struct bsc_nat_acc_lst *acc;
605 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
606 if (!acc)
607 return CMD_WARNING;
608
609 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
610 vty_out_rate_ctr_group(vty, " ", acc->stats);
611
612 return CMD_SUCCESS;
613}
614
615
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800616DEFUN(cfg_bsc_acc_lst_name,
617 cfg_bsc_acc_lst_name_cmd,
618 "access-list-name NAME",
619 "Set the name of the access list to use.\n"
620 "The name of the to be used access list.")
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200621{
622 struct bsc_config *conf = vty->index;
623
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200624 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freytherc16cf272010-04-13 09:24:37 +0200625 return CMD_SUCCESS;
626}
627
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800628DEFUN(cfg_bsc_paging,
629 cfg_bsc_paging_cmd,
630 "paging forbidden (0|1)",
631 "Forbid sending PAGING REQUESTS to the BSC.")
632{
633 struct bsc_config *conf = vty->index;
634
Holger Hans Peter Freyther834f1df2010-04-21 20:07:07 +0800635 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther62e58432010-04-21 19:05:14 +0800636 conf->forbid_paging = 1;
637 else
638 conf->forbid_paging = 0;
639
640 return CMD_SUCCESS;
641}
642
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800643DEFUN(cfg_bsc_desc,
644 cfg_bsc_desc_cmd,
645 "description DESC",
646 "Provide a description for the given BSC.")
647{
648 struct bsc_config *conf = vty->index;
649
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200650 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freytherb6061012010-05-14 22:06:28 +0800651 return CMD_SUCCESS;
652}
653
Holger Hans Peter Freyther52c4ba02010-05-14 23:43:12 +0800654DEFUN(test_regex, test_regex_cmd,
655 "test regex PATTERN STRING",
656 "Check if the string is matching the current pattern.")
657{
658 regex_t reg;
659 char *str = NULL;
660
661 memset(&reg, 0, sizeof(reg));
662 bsc_parse_reg(_nat, &reg, &str, 1, argv);
663
664 vty_out(vty, "String matches allow pattern: %d%s",
665 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
666
667 talloc_free(str);
668 regfree(&reg);
669 return CMD_SUCCESS;
670}
671
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800672int bsc_nat_vty_init(struct bsc_nat *nat)
673{
674 _nat = nat;
675
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800676 /* show commands */
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800677 install_element_ve(&show_sccp_cmd);
678 install_element_ve(&show_bsc_cmd);
679 install_element_ve(&show_bsc_cfg_cmd);
680 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freytherc95cfda2010-07-22 20:26:10 +0800681 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther1398f132010-06-15 20:14:08 +0800682 install_element_ve(&close_bsc_cmd);
683 install_element_ve(&show_msc_cmd);
684 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther0d8330c2010-08-28 18:33:34 +0800685 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther520c1f12010-09-25 16:25:47 +0800686 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freyther5f291d52010-04-06 12:01:15 +0200687
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800688 /* nat group */
689 install_element(CONFIG_NODE, &cfg_nat_cmd);
690 install_node(&nat_node, config_write_nat);
691 install_default(NAT_NODE);
Holger Hans Peter Freyther9c786972010-06-17 14:39:15 +0800692 install_element(NAT_NODE, &ournode_exit_cmd);
693 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freythera88742c2010-06-15 18:51:04 +0800694 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freyther81395532010-04-17 07:48:45 +0200695 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytherda35a8d2010-05-05 16:57:38 +0800696 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
697 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
698 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freythere635dab2010-05-15 00:14:58 +0800699 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freyther6b771072010-07-27 19:21:53 +0800700 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther078321a2010-05-31 10:36:35 +0800701 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800702 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
Holger Hans Peter Freytherd1effd82010-10-10 17:29:20 +0200703 install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd);
Holger Hans Peter Freytherc1578bc2010-10-11 10:06:39 +0200704 install_element(NAT_NODE, &cfg_nat_ussd_query_cmd);
Holger Hans Peter Freythere393f272010-10-12 18:25:52 +0200705 install_element(NAT_NODE, &cfg_nat_ussd_token_cmd);
706 install_element(NAT_NODE, &cfg_nat_ussd_local_cmd);
Holger Hans Peter Freyther8affef52010-06-01 01:03:13 +0800707
708 /* access-list */
709 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
710 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freythere4900a02010-06-03 01:44:05 +0800711 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800712
Holger Hans Peter Freyther76424392010-10-21 10:59:54 +0200713 /* number rewriting */
714 install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd);
715
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800716 /* BSC subgroups */
717 install_element(NAT_NODE, &cfg_bsc_cmd);
718 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800719 install_default(NAT_BSC_NODE);
720 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
721 install_element(NAT_BSC_NODE, &ournode_end_cmd);
722 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
723 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther0bd60f32010-10-08 22:08:29 +0800724 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freyther7b4a53d2010-06-17 14:42:20 +0800725 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
726 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
727 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800728
Holger Hans Peter Freytherf7d33352010-06-15 18:50:26 +0800729 mgcp_vty_init();
730
Holger Hans Peter Freyther9a85ef32010-06-15 18:46:11 +0800731 return 0;
732}
733
734
735/* called by the telnet interface... we have our own init above */
736void bsc_vty_init()
737{}