blob: 9822e5c5708f1786ab13fa280fc720b7dbcc83a8 [file] [log] [blame]
Holger Hans Peter Freyther5e547882010-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 Freyther4fcedba2010-06-15 20:14:08 +080022#include <openbsc/vty.h>
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080023#include <openbsc/bsc_nat.h>
Holger Hans Peter Freyther4a9dd3b2010-07-31 05:17:17 +080024#include <openbsc/bsc_nat_sccp.h>
Holger Hans Peter Freyther8e2e0ac2010-05-11 19:07:39 +080025#include <openbsc/bsc_msc.h>
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080026#include <openbsc/gsm_04_08.h>
Holger Hans Peter Freyther3660e4d2010-06-15 18:50:26 +080027#include <openbsc/mgcp.h>
Holger Hans Peter Freytherb372fad2010-04-06 12:01:15 +020028#include <openbsc/vty.h>
Holger Hans Peter Freyther3b960892010-06-15 19:06:18 +080029
30#include <osmocore/talloc.h>
Holger Hans Peter Freytherccefba62010-06-17 18:16:00 +080031#include <osmocore/rate_ctr.h>
Holger Hans Peter Freyther8c61f792010-08-28 18:33:34 +080032#include <osmocore/utils.h>
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080033
Harald Welte90e5eae2010-08-03 15:11:51 +020034#include <osmocom/sccp/sccp.h>
Holger Hans Peter Freyther5e547882010-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 Freythera34bb3d2010-06-17 14:42:20 +080047 NAT_BSC_NODE,
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080048 "%s(bsc)#",
49 1,
50};
51
Holger Hans Peter Freyther8eb45892010-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 Freyther5e547882010-06-15 18:46:11 +080066static int config_write_nat(struct vty *vty)
67{
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +080068 struct bsc_nat_acc_lst *lst;
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +080069
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080070 vty_out(vty, "nat%s", VTY_NEWLINE);
Holger Hans Peter Freyther9226d702010-06-15 18:51:04 +080071 vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE);
Holger Hans Peter Freytherbace2022010-04-17 07:48:45 +020072 vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE);
Holger Hans Peter Freytheracd30782010-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 Freyther6e88b172010-05-15 00:14:58 +080076 if (_nat->token)
77 vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE);
Holger Hans Peter Freytherf0374a52010-07-27 19:21:53 +080078 vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, VTY_NEWLINE);
Holger Hans Peter Freyther67b6d522010-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);
81
82 llist_for_each_entry(lst, &_nat->access_lists, list) {
Holger Hans Peter Freyther8eb45892010-06-08 10:53:39 +080083 write_acc_lst(vty, lst);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +080084 }
85
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080086 return CMD_SUCCESS;
87}
88
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +080089static void dump_lac(struct vty *vty, struct bsc_config *cfg)
90{
91 struct bsc_lac_entry *lac;
92 llist_for_each_entry(lac, &cfg->lac_list, entry)
93 vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE);
94}
95
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +080096static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc)
97{
98 vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE);
99 vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE);
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800100 dump_lac(vty, bsc);
Holger Hans Peter Freyther7acf4622010-04-21 19:05:14 +0800101 vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freyther6f009072010-05-14 22:06:28 +0800102 if (bsc->description)
103 vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800104 if (bsc->acc_lst_name)
Holger Hans Peter Freyther409a3702010-06-08 11:18:26 +0800105 vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800106}
107
108static int config_write_bsc(struct vty *vty)
109{
110 struct bsc_config *bsc;
111
112 llist_for_each_entry(bsc, &_nat->bsc_configs, entry)
113 config_write_bsc_single(vty, bsc);
114 return CMD_SUCCESS;
115}
116
117
Holger Hans Peter Freyther17f8c952010-04-19 16:06:43 +0800118DEFUN(show_sccp, show_sccp_cmd, "show sccp connections",
119 SHOW_STR "Display information about current SCCP connections")
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800120{
121 struct sccp_connections *con;
Holger Hans Peter Freytherc3fd3b72010-09-15 19:01:31 +0800122 vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE);
Holger Hans Peter Freyther0a3a8532010-04-27 13:11:18 +0800123
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800124 llist_for_each_entry(con, &_nat->sccp_connections, list_entry) {
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800125 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 Freytherbfcf5192010-04-06 15:11:34 +0200126 con->bsc->cfg ? con->bsc->cfg->nr : -1,
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800127 sccp_src_ref_to_int(&con->real_ref),
Holger Hans Peter Freyther32aba232010-04-05 10:10:33 +0200128 sccp_src_ref_to_int(&con->patched_ref),
Holger Hans Peter Freyther0a3a8532010-04-27 13:11:18 +0800129 con->has_remote_ref,
130 sccp_src_ref_to_int(&con->remote_ref),
Holger Hans Peter Freyther7089d532010-08-28 16:08:39 +0800131 con->msc_endp, con->bsc_endp,
Holger Hans Peter Freyther8e69f0c2010-05-16 02:06:11 +0800132 bsc_con_type_to_string(con->con_type),
Holger Hans Peter Freyther32aba232010-04-05 10:10:33 +0200133 VTY_NEWLINE);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800134 }
135
136 return CMD_SUCCESS;
137}
138
Holger Hans Peter Freyther17f8c952010-04-19 16:06:43 +0800139DEFUN(show_bsc, show_bsc_cmd, "show bsc connections",
140 SHOW_STR "Display information about current BSCs")
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800141{
142 struct bsc_connection *con;
Holger Hans Peter Freyther9e53e972010-04-08 10:35:20 +0200143 struct sockaddr_in sock;
144 socklen_t len = sizeof(sock);
145
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800146 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
Holger Hans Peter Freyther9e53e972010-04-08 10:35:20 +0200147 getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len);
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800148 vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s",
Holger Hans Peter Freytherbfcf5192010-04-06 15:11:34 +0200149 con->cfg ? con->cfg->nr : -1,
Holger Hans Peter Freyther9e53e972010-04-08 10:35:20 +0200150 con->authenticated, con->write_queue.bfd.fd,
151 inet_ntoa(sock.sin_addr), VTY_NEWLINE);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800152 }
153
154 return CMD_SUCCESS;
155}
156
Holger Hans Peter Freyther8c61f792010-08-28 18:33:34 +0800157DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR",
158 SHOW_STR "Display the MGCP status for a given BSC")
159{
160 struct bsc_connection *con;
161 int nr = atoi(argv[0]);
162 int i;
163
164 llist_for_each_entry(con, &_nat->bsc_connections, list_entry) {
165 if (!con->cfg)
166 continue;
167 if (con->cfg->nr != nr)
168 continue;
169
170 vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE);
171 for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i)
172 vty_out(vty, " Endpoint 0x%x %s%s", i,
173 con->endpoint_status[i] == 0 ? "free" : "allocated",
174 VTY_NEWLINE);
175 break;
176 }
177
178 return CMD_SUCCESS;
179}
180
Holger Hans Peter Freyther936aed72010-04-22 13:36:46 +0800181DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config",
182 SHOW_STR "Display information about known BSC configs")
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800183{
184 struct bsc_config *conf;
185 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800186 vty_out(vty, "BSC token: '%s' nr: %u%s",
187 conf->token, conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800188 if (conf->acc_lst_name)
189 vty_out(vty, " access-list: %s%s",
190 conf->acc_lst_name, VTY_NEWLINE);
Holger Hans Peter Freyther7acf4622010-04-21 19:05:14 +0800191 vty_out(vty, " paging forbidden: %d%s",
192 conf->forbid_paging, VTY_NEWLINE);
Holger Hans Peter Freyther6f009072010-05-14 22:06:28 +0800193 if (conf->description)
194 vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE);
195 else
196 vty_out(vty, " No description.%s", VTY_NEWLINE);
197
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800198 }
199
200 return CMD_SUCCESS;
201}
202
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800203static void dump_stat_total(struct vty *vty, struct bsc_nat *nat)
204{
205 vty_out(vty, "NAT statistics%s", VTY_NEWLINE);
206 vty_out(vty, " SCCP Connections %lu total, %lu calls%s",
207 counter_get(nat->stats.sccp.conn),
208 counter_get(nat->stats.sccp.calls), VTY_NEWLINE);
209 vty_out(vty, " MSC Connections %lu%s",
210 counter_get(nat->stats.msc.reconn), VTY_NEWLINE);
Holger Hans Peter Freyther9ecec6d2010-08-04 02:34:10 +0800211 vty_out(vty, " MSC Connected: %d%s",
212 nat->msc_con->is_connected, VTY_NEWLINE);
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800213 vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s",
214 counter_get(nat->stats.bsc.reconn),
215 counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE);
216}
217
218static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf)
219{
Holger Hans Peter Freythere4107582010-07-22 20:37:35 +0800220 int connected = 0;
221 struct bsc_connection *con;
222
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800223 vty_out(vty, " BSC nr: %d%s",
224 conf->nr, VTY_NEWLINE);
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800225 vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg);
Holger Hans Peter Freythere4107582010-07-22 20:37:35 +0800226
227 llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) {
228 if (con->cfg != conf)
229 continue;
230 connected = 1;
231 break;
232 }
233
Holger Hans Peter Freyther869f1172010-08-04 02:29:03 +0800234 vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE);
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800235}
236
Holger Hans Peter Freyther02e1c7d2010-04-12 12:33:27 +0200237DEFUN(show_stats,
238 show_stats_cmd,
Holger Hans Peter Freyther44d534c2010-05-02 18:59:24 +0800239 "show statistics [NR]",
Holger Hans Peter Freytherdbdd30f2010-04-27 15:35:14 +0800240 SHOW_STR "Display network statistics")
Holger Hans Peter Freyther02e1c7d2010-04-12 12:33:27 +0200241{
242 struct bsc_config *conf;
243
Holger Hans Peter Freyther44d534c2010-05-02 18:59:24 +0800244 int nr = -1;
245
246 if (argc == 1)
247 nr = atoi(argv[0]);
248
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800249 dump_stat_total(vty, _nat);
Holger Hans Peter Freyther02e1c7d2010-04-12 12:33:27 +0200250 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther44d534c2010-05-02 18:59:24 +0800251 if (argc == 1 && nr != conf->nr)
252 continue;
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800253 dump_stat_bsc(vty, conf);
254 }
Holger Hans Peter Freyther44d534c2010-05-02 18:59:24 +0800255
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800256 return CMD_SUCCESS;
257}
258
259DEFUN(show_stats_lac,
260 show_stats_lac_cmd,
261 "show statistics-by-lac <0-65535>",
262 SHOW_STR "Display network statistics by lac\n"
263 "The lac of the BSC\n")
264{
265 int lac;
266 struct bsc_config *conf;
267
268 lac = atoi(argv[0]);
269
270 dump_stat_total(vty, _nat);
271 llist_for_each_entry(conf, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800272 if (!bsc_config_handles_lac(conf, lac))
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800273 continue;
274 dump_stat_bsc(vty, conf);
Holger Hans Peter Freyther02e1c7d2010-04-12 12:33:27 +0200275 }
276
277 return CMD_SUCCESS;
278}
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800279
Holger Hans Peter Freyther8e2e0ac2010-05-11 19:07:39 +0800280DEFUN(show_msc,
281 show_msc_cmd,
282 "show msc connection",
283 SHOW_STR "Show the status of the MSC connection.")
284{
285 if (!_nat->msc_con) {
286 vty_out(vty, "The MSC is not yet configured.\n");
287 return CMD_WARNING;
288 }
289
290 vty_out(vty, "MSC on %s:%d is connected: %d%s\n",
291 _nat->msc_con->ip, _nat->msc_con->port,
292 _nat->msc_con->is_connected, VTY_NEWLINE);
293 return CMD_SUCCESS;
294}
295
Holger Hans Peter Freyther1512dc22010-04-27 13:21:39 +0800296DEFUN(close_bsc,
297 close_bsc_cmd,
298 "close bsc connection BSC_NR",
Holger Hans Peter Freytherdbdd30f2010-04-27 15:35:14 +0800299 "Close the connection with the BSC identified by the config number.")
Holger Hans Peter Freyther1512dc22010-04-27 13:21:39 +0800300{
301 struct bsc_connection *bsc;
302 int bsc_nr = atoi(argv[0]);
303
304 llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) {
305 if (!bsc->cfg || bsc->cfg->nr != bsc_nr)
306 continue;
307 bsc_close_connection(bsc);
308 break;
309 }
310
311 return CMD_SUCCESS;
312}
313
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800314DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT")
315{
316 vty->index = _nat;
317 vty->node = NAT_NODE;
318
319 return CMD_SUCCESS;
320}
321
Holger Hans Peter Freyther9226d702010-06-15 18:51:04 +0800322DEFUN(cfg_nat_msc_ip,
323 cfg_nat_msc_ip_cmd,
Holger Hans Peter Freytherf7cd8002010-05-14 02:36:42 +0800324 "msc ip A.B.C.D",
Holger Hans Peter Freyther9226d702010-06-15 18:51:04 +0800325 "Set the IP address of the MSC.")
326{
327 bsc_nat_set_msc_ip(_nat, argv[0]);
328 return CMD_SUCCESS;
329}
330
Holger Hans Peter Freytherbace2022010-04-17 07:48:45 +0200331DEFUN(cfg_nat_msc_port,
332 cfg_nat_msc_port_cmd,
333 "msc port <1-65500>",
334 "Set the port of the MSC.")
335{
336 _nat->msc_port = atoi(argv[0]);
337 return CMD_SUCCESS;
338}
339
Holger Hans Peter Freytheracd30782010-05-05 16:57:38 +0800340DEFUN(cfg_nat_auth_time,
341 cfg_nat_auth_time_cmd,
342 "timeout auth <1-256>",
343 "The time to wait for an auth response.")
344{
345 _nat->auth_timeout = atoi(argv[0]);
346 return CMD_SUCCESS;
347}
348
349DEFUN(cfg_nat_ping_time,
350 cfg_nat_ping_time_cmd,
351 "timeout ping NR",
352 "Send a ping every NR seconds. Negative to disable.")
353{
354 _nat->ping_timeout = atoi(argv[0]);
355 return CMD_SUCCESS;
356}
357
358DEFUN(cfg_nat_pong_time,
359 cfg_nat_pong_time_cmd,
360 "timeout pong NR",
361 "Wait NR seconds for the PONG response. Should be smaller than ping.")
362{
363 _nat->pong_timeout = atoi(argv[0]);
364 return CMD_SUCCESS;
365}
366
Holger Hans Peter Freyther6e88b172010-05-15 00:14:58 +0800367DEFUN(cfg_nat_token, cfg_nat_token_cmd,
368 "token TOKEN",
369 "Set a token for the NAT")
370{
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200371 bsc_replace_string(_nat, &_nat->token, argv[0]);
Holger Hans Peter Freyther6e88b172010-05-15 00:14:58 +0800372 return CMD_SUCCESS;
373}
374
Holger Hans Peter Freytherf0374a52010-07-27 19:21:53 +0800375DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd,
376 "ip-dscp <0-255>",
377 "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute")
Holger Hans Peter Freyther9d42d322010-05-31 10:36:35 +0800378{
Holger Hans Peter Freytherf0374a52010-07-27 19:21:53 +0800379 _nat->bsc_ip_dscp = atoi(argv[0]);
Holger Hans Peter Freyther9d42d322010-05-31 10:36:35 +0800380 return CMD_SUCCESS;
381}
382
Holger Hans Peter Freytherf0374a52010-07-27 19:21:53 +0800383ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd,
384 "ip-tos <0-255>",
385 "Use ip-dscp in the future.\n" "Set the DSCP\n")
386
387
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800388DEFUN(cfg_nat_acc_lst_name,
389 cfg_nat_acc_lst_name_cmd,
390 "access-list-name NAME",
391 "Set the name of the access list to use.\n"
392 "The name of the to be used access list.")
393{
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200394 bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800395 return CMD_SUCCESS;
396}
397
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800398/* per BSC configuration */
Holger Hans Peter Freytherdbdd30f2010-04-27 15:35:14 +0800399DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure")
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800400{
401 int bsc_nr = atoi(argv[0]);
402 struct bsc_config *bsc;
403
404 if (bsc_nr > _nat->num_bsc) {
405 vty_out(vty, "%% The next unused BSC number is %u%s",
406 _nat->num_bsc, VTY_NEWLINE);
407 return CMD_WARNING;
408 } else if (bsc_nr == _nat->num_bsc) {
409 /* allocate a new one */
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800410 bsc = bsc_config_alloc(_nat, "unknown");
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800411 } else
412 bsc = bsc_config_num(_nat, bsc_nr);
413
414 if (!bsc)
415 return CMD_WARNING;
416
417 vty->index = bsc;
Holger Hans Peter Freythera34bb3d2010-06-17 14:42:20 +0800418 vty->node = NAT_BSC_NODE;
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800419
420 return CMD_SUCCESS;
421}
422
423DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token")
424{
425 struct bsc_config *conf = vty->index;
426
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200427 bsc_replace_string(conf, &conf->token, argv[0]);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800428 return CMD_SUCCESS;
429}
430
431DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>",
Holger Hans Peter Freytherdbdd30f2010-04-27 15:35:14 +0800432 "Set the Location Area Code (LAC) of this BSC")
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800433{
Holger Hans Peter Freyther435a5c12010-03-30 06:08:56 +0200434 struct bsc_config *tmp;
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800435 struct bsc_config *conf = vty->index;
436
437 int lac = atoi(argv[0]);
438
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800439 if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) {
440 vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s",
441 lac, VTY_NEWLINE);
442 return CMD_WARNING;
443 }
444
Holger Hans Peter Freyther435a5c12010-03-30 06:08:56 +0200445 /* verify that the LACs are unique */
446 llist_for_each_entry(tmp, &_nat->bsc_configs, entry) {
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800447 if (bsc_config_handles_lac(tmp, lac)) {
Holger Hans Peter Freyther435a5c12010-03-30 06:08:56 +0200448 vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE);
449 return CMD_ERR_INCOMPLETE;
450 }
451 }
452
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800453 bsc_config_add_lac(conf, lac);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800454
455 return CMD_SUCCESS;
456}
457
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800458DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd,
459 "no location_area_code <0-65535>",
460 NO_STR "Set the Location Area Code (LAC) of this BSC")
461{
462 int lac = atoi(argv[0]);
463 struct bsc_config *conf = vty->index;
464
465 bsc_config_del_lac(conf, lac);
466 return CMD_SUCCESS;
467}
468
469
470
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800471DEFUN(cfg_lst_imsi_allow,
472 cfg_lst_imsi_allow_cmd,
473 "access-list NAME imsi-allow [REGEXP]",
474 "Allow IMSIs matching the REGEXP\n"
475 "The name of the access-list\n"
476 "The regexp of allowed IMSIs\n")
Holger Hans Peter Freyther4b6da562010-04-13 09:24:37 +0200477{
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800478 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freyther8eb45892010-06-08 10:53:39 +0800479 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther4b6da562010-04-13 09:24:37 +0200480
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800481 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800482 if (!acc)
483 return CMD_WARNING;
484
Holger Hans Peter Freyther8eb45892010-06-08 10:53:39 +0800485 entry = bsc_nat_acc_lst_entry_create(acc);
486 if (!entry)
487 return CMD_WARNING;
488
489 bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]);
Holger Hans Peter Freyther4b6da562010-04-13 09:24:37 +0200490 return CMD_SUCCESS;
491}
492
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800493DEFUN(cfg_lst_imsi_deny,
494 cfg_lst_imsi_deny_cmd,
495 "access-list NAME imsi-deny [REGEXP]",
496 "Allow IMSIs matching the REGEXP\n"
497 "The name of the access-list\n"
498 "The regexp of to be denied IMSIs\n")
499{
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800500 struct bsc_nat_acc_lst *acc;
Holger Hans Peter Freyther8eb45892010-06-08 10:53:39 +0800501 struct bsc_nat_acc_lst_entry *entry;
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800502
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800503 acc = bsc_nat_acc_lst_get(_nat, argv[0]);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800504 if (!acc)
505 return CMD_WARNING;
506
Holger Hans Peter Freyther8eb45892010-06-08 10:53:39 +0800507 entry = bsc_nat_acc_lst_entry_create(acc);
508 if (!entry)
509 return CMD_WARNING;
510
511 bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800512 return CMD_SUCCESS;
513}
514
Holger Hans Peter Freyther704b3502010-06-03 01:44:05 +0800515/* naming to follow Zebra... */
516DEFUN(cfg_lst_no,
517 cfg_lst_no_cmd,
518 "no access-list NAME",
519 NO_STR "Remove an access-list by name\n"
520 "The access-list to remove\n")
521{
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800522 struct bsc_nat_acc_lst *acc;
523 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
Holger Hans Peter Freyther704b3502010-06-03 01:44:05 +0800524 if (!acc)
525 return CMD_WARNING;
526
Holger Hans Peter Freytherb6044712010-06-08 10:14:44 +0800527 bsc_nat_acc_lst_delete(acc);
Holger Hans Peter Freyther704b3502010-06-03 01:44:05 +0800528 return CMD_SUCCESS;
529}
530
Holger Hans Peter Freyther12799672010-09-25 16:25:47 +0800531DEFUN(show_acc_lst,
532 show_acc_lst_cmd,
533 "show access-list NAME",
534 SHOW_STR "The name of the access list\n")
535{
536 struct bsc_nat_acc_lst *acc;
537 acc = bsc_nat_acc_lst_find(_nat, argv[0]);
538 if (!acc)
539 return CMD_WARNING;
540
541 vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE);
542 vty_out_rate_ctr_group(vty, " ", acc->stats);
543
544 return CMD_SUCCESS;
545}
546
547
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800548DEFUN(cfg_bsc_acc_lst_name,
549 cfg_bsc_acc_lst_name_cmd,
550 "access-list-name NAME",
551 "Set the name of the access list to use.\n"
552 "The name of the to be used access list.")
Holger Hans Peter Freyther4b6da562010-04-13 09:24:37 +0200553{
554 struct bsc_config *conf = vty->index;
555
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200556 bsc_replace_string(conf, &conf->acc_lst_name, argv[0]);
Holger Hans Peter Freyther4b6da562010-04-13 09:24:37 +0200557 return CMD_SUCCESS;
558}
559
Holger Hans Peter Freyther7acf4622010-04-21 19:05:14 +0800560DEFUN(cfg_bsc_paging,
561 cfg_bsc_paging_cmd,
562 "paging forbidden (0|1)",
563 "Forbid sending PAGING REQUESTS to the BSC.")
564{
565 struct bsc_config *conf = vty->index;
566
Holger Hans Peter Freythere6ac5de2010-04-21 20:07:07 +0800567 if (strcmp("1", argv[0]) == 0)
Holger Hans Peter Freyther7acf4622010-04-21 19:05:14 +0800568 conf->forbid_paging = 1;
569 else
570 conf->forbid_paging = 0;
571
572 return CMD_SUCCESS;
573}
574
Holger Hans Peter Freyther6f009072010-05-14 22:06:28 +0800575DEFUN(cfg_bsc_desc,
576 cfg_bsc_desc_cmd,
577 "description DESC",
578 "Provide a description for the given BSC.")
579{
580 struct bsc_config *conf = vty->index;
581
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200582 bsc_replace_string(conf, &conf->description, argv[0]);
Holger Hans Peter Freyther6f009072010-05-14 22:06:28 +0800583 return CMD_SUCCESS;
584}
585
Holger Hans Peter Freyther6ad646a2010-05-14 23:43:12 +0800586DEFUN(test_regex, test_regex_cmd,
587 "test regex PATTERN STRING",
588 "Check if the string is matching the current pattern.")
589{
590 regex_t reg;
591 char *str = NULL;
592
593 memset(&reg, 0, sizeof(reg));
594 bsc_parse_reg(_nat, &reg, &str, 1, argv);
595
596 vty_out(vty, "String matches allow pattern: %d%s",
597 regexec(&reg, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE);
598
599 talloc_free(str);
600 regfree(&reg);
601 return CMD_SUCCESS;
602}
603
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800604int bsc_nat_vty_init(struct bsc_nat *nat)
605{
606 _nat = nat;
607
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800608 /* show commands */
Holger Hans Peter Freyther4fcedba2010-06-15 20:14:08 +0800609 install_element_ve(&show_sccp_cmd);
610 install_element_ve(&show_bsc_cmd);
611 install_element_ve(&show_bsc_cfg_cmd);
612 install_element_ve(&show_stats_cmd);
Holger Hans Peter Freyther032e45b2010-07-22 20:26:10 +0800613 install_element_ve(&show_stats_lac_cmd);
Holger Hans Peter Freyther4fcedba2010-06-15 20:14:08 +0800614 install_element_ve(&close_bsc_cmd);
615 install_element_ve(&show_msc_cmd);
616 install_element_ve(&test_regex_cmd);
Holger Hans Peter Freyther8c61f792010-08-28 18:33:34 +0800617 install_element_ve(&show_bsc_mgcp_cmd);
Holger Hans Peter Freyther12799672010-09-25 16:25:47 +0800618 install_element_ve(&show_acc_lst_cmd);
Holger Hans Peter Freytherb372fad2010-04-06 12:01:15 +0200619
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800620 /* nat group */
621 install_element(CONFIG_NODE, &cfg_nat_cmd);
622 install_node(&nat_node, config_write_nat);
623 install_default(NAT_NODE);
Holger Hans Peter Freytherb4b52052010-06-17 14:39:15 +0800624 install_element(NAT_NODE, &ournode_exit_cmd);
625 install_element(NAT_NODE, &ournode_end_cmd);
Holger Hans Peter Freyther9226d702010-06-15 18:51:04 +0800626 install_element(NAT_NODE, &cfg_nat_msc_ip_cmd);
Holger Hans Peter Freytherbace2022010-04-17 07:48:45 +0200627 install_element(NAT_NODE, &cfg_nat_msc_port_cmd);
Holger Hans Peter Freytheracd30782010-05-05 16:57:38 +0800628 install_element(NAT_NODE, &cfg_nat_auth_time_cmd);
629 install_element(NAT_NODE, &cfg_nat_ping_time_cmd);
630 install_element(NAT_NODE, &cfg_nat_pong_time_cmd);
Holger Hans Peter Freyther6e88b172010-05-15 00:14:58 +0800631 install_element(NAT_NODE, &cfg_nat_token_cmd);
Holger Hans Peter Freytherf0374a52010-07-27 19:21:53 +0800632 install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd);
Holger Hans Peter Freyther9d42d322010-05-31 10:36:35 +0800633 install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd);
Holger Hans Peter Freyther67b6d522010-06-01 01:03:13 +0800634 install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd);
635
636 /* access-list */
637 install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd);
638 install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd);
Holger Hans Peter Freyther704b3502010-06-03 01:44:05 +0800639 install_element(NAT_NODE, &cfg_lst_no_cmd);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800640
641 /* BSC subgroups */
642 install_element(NAT_NODE, &cfg_bsc_cmd);
643 install_node(&bsc_node, config_write_bsc);
Holger Hans Peter Freythera34bb3d2010-06-17 14:42:20 +0800644 install_default(NAT_BSC_NODE);
645 install_element(NAT_BSC_NODE, &ournode_exit_cmd);
646 install_element(NAT_BSC_NODE, &ournode_end_cmd);
647 install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd);
648 install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd);
Holger Hans Peter Freyther1f040832010-10-08 22:08:29 +0800649 install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd);
Holger Hans Peter Freythera34bb3d2010-06-17 14:42:20 +0800650 install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd);
651 install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd);
652 install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd);
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800653
Holger Hans Peter Freyther3660e4d2010-06-15 18:50:26 +0800654 mgcp_vty_init();
655
Holger Hans Peter Freyther5e547882010-06-15 18:46:11 +0800656 return 0;
657}
658
659
660/* called by the telnet interface... we have our own init above */
661void bsc_vty_init()
662{}