Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 1 | /* 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 | |
| 22 | #include <vty/command.h> |
| 23 | #include <vty/buffer.h> |
| 24 | #include <vty/vty.h> |
| 25 | |
| 26 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 27 | #include <openbsc/bsc_msc.h> |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 28 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 29 | #include <openbsc/mgcp.h> |
Holger Hans Peter Freyther | 5f291d5 | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 30 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 6c45f2e | 2010-06-15 19:06:18 +0800 | [diff] [blame] | 31 | |
| 32 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 33 | |
| 34 | #include <sccp/sccp.h> |
| 35 | |
| 36 | #include <stdlib.h> |
| 37 | |
| 38 | static struct bsc_nat *_nat; |
| 39 | |
| 40 | static struct cmd_node nat_node = { |
| 41 | NAT_NODE, |
| 42 | "%s(nat)#", |
| 43 | 1, |
| 44 | }; |
| 45 | |
| 46 | static struct cmd_node bsc_node = { |
| 47 | BSC_NODE, |
| 48 | "%s(bsc)#", |
| 49 | 1, |
| 50 | }; |
| 51 | |
| 52 | static int config_write_nat(struct vty *vty) |
| 53 | { |
| 54 | vty_out(vty, "nat%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 55 | if (_nat->imsi_deny) |
Holger Hans Peter Freyther | 3df0233 | 2010-05-14 23:06:09 +0800 | [diff] [blame] | 56 | vty_out(vty, " imsi deny %s%s", _nat->imsi_deny, VTY_NEWLINE); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 57 | vty_out(vty, " msc ip %s%s", _nat->msc_ip, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 58 | vty_out(vty, " msc port %d%s", _nat->msc_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 59 | vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE); |
| 60 | vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE); |
| 61 | vty_out(vty, " timeout pong %d%s", _nat->pong_timeout, VTY_NEWLINE); |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 62 | if (_nat->token) |
| 63 | vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame^] | 64 | vty_out(vty, " ip-tos %d%s", _nat->bsc_ip_tos, VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 65 | return CMD_SUCCESS; |
| 66 | } |
| 67 | |
| 68 | static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc) |
| 69 | { |
| 70 | vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE); |
| 71 | vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | d1278c1 | 2010-04-16 16:52:20 +0200 | [diff] [blame] | 72 | vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 73 | if (bsc->imsi_allow) |
| 74 | vty_out(vty, " imsi allow %s%s", bsc->imsi_allow, VTY_NEWLINE); |
| 75 | if (bsc->imsi_deny) |
| 76 | vty_out(vty, " imsi deny %s%s", bsc->imsi_deny, VTY_NEWLINE); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 77 | vty_out(vty, " paging forbidden %d%s", bsc->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 78 | if (bsc->description) |
| 79 | vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static int config_write_bsc(struct vty *vty) |
| 83 | { |
| 84 | struct bsc_config *bsc; |
| 85 | |
| 86 | llist_for_each_entry(bsc, &_nat->bsc_configs, entry) |
| 87 | config_write_bsc_single(vty, bsc); |
| 88 | return CMD_SUCCESS; |
| 89 | } |
| 90 | |
| 91 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 92 | DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", |
| 93 | SHOW_STR "Display information about current SCCP connections") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 94 | { |
| 95 | struct sccp_connections *con; |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 96 | vty_out(vty, "Listing all opening SCCP connections%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 4bd2294 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 97 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 98 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 99 | vty_out(vty, "For BSC Nr: %d lac: %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 Freyther | 47dd494 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 100 | con->bsc->cfg ? con->bsc->cfg->nr : -1, |
| 101 | con->bsc->cfg ? con->bsc->cfg->lac : -1, |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 102 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 103 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 4bd2294 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 104 | con->has_remote_ref, |
| 105 | sccp_src_ref_to_int(&con->remote_ref), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 106 | con->msc_timeslot, con->bsc_timeslot, |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 107 | bsc_con_type_to_string(con->con_type), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 108 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | return CMD_SUCCESS; |
| 112 | } |
| 113 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 114 | DEFUN(show_bsc, show_bsc_cmd, "show bsc connections", |
| 115 | SHOW_STR "Display information about current BSCs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 116 | { |
| 117 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 118 | struct sockaddr_in sock; |
| 119 | socklen_t len = sizeof(sock); |
| 120 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 121 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 122 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | 3b87981 | 2010-05-01 15:32:32 +0800 | [diff] [blame] | 123 | vty_out(vty, "BSC nr: %d lac: %d auth: %d fd: %d peername: %s%s", |
Holger Hans Peter Freyther | 47dd494 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 124 | con->cfg ? con->cfg->nr : -1, |
| 125 | con->cfg ? con->cfg->lac : -1, |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 126 | con->authenticated, con->write_queue.bfd.fd, |
| 127 | inet_ntoa(sock.sin_addr), VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | return CMD_SUCCESS; |
| 131 | } |
| 132 | |
Holger Hans Peter Freyther | ab7539c | 2010-04-22 13:36:46 +0800 | [diff] [blame] | 133 | DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config", |
| 134 | SHOW_STR "Display information about known BSC configs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 135 | { |
| 136 | struct bsc_config *conf; |
| 137 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
| 138 | vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s", |
| 139 | conf->token, conf->lac, conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 140 | vty_out(vty, " imsi_allow: '%s' imsi_deny: '%s'%s", |
| 141 | conf->imsi_allow ? conf->imsi_allow: "any", |
| 142 | conf->imsi_deny ? conf->imsi_deny : "none", |
| 143 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 144 | vty_out(vty, " paging forbidden: %d%s", |
| 145 | conf->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 146 | if (conf->description) |
| 147 | vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE); |
| 148 | else |
| 149 | vty_out(vty, " No description.%s", VTY_NEWLINE); |
| 150 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | return CMD_SUCCESS; |
| 154 | } |
| 155 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 156 | DEFUN(show_stats, |
| 157 | show_stats_cmd, |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 158 | "show statistics [NR]", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 159 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 160 | { |
| 161 | struct bsc_config *conf; |
| 162 | |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 163 | int nr = -1; |
| 164 | |
| 165 | if (argc == 1) |
| 166 | nr = atoi(argv[0]); |
| 167 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 168 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 169 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 170 | counter_get(_nat->stats.sccp.conn), |
| 171 | counter_get(_nat->stats.sccp.calls), VTY_NEWLINE); |
| 172 | vty_out(vty, " MSC Connections %lu%s", |
| 173 | counter_get(_nat->stats.msc.reconn), VTY_NEWLINE); |
| 174 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 175 | counter_get(_nat->stats.bsc.reconn), |
| 176 | counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 177 | |
| 178 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 179 | if (argc == 1 && nr != conf->nr) |
| 180 | continue; |
| 181 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 182 | vty_out(vty, " BSC lac: %d nr: %d%s", |
| 183 | conf->lac, conf->nr, VTY_NEWLINE); |
| 184 | vty_out(vty, " SCCP Connnections %lu total, %lu calls%s", |
| 185 | counter_get(conf->stats.sccp.conn), |
| 186 | counter_get(conf->stats.sccp.calls), VTY_NEWLINE); |
| 187 | vty_out(vty, " BSC Connections %lu total%s", |
| 188 | counter_get(conf->stats.net.reconn), VTY_NEWLINE); |
| 189 | } |
| 190 | |
| 191 | return CMD_SUCCESS; |
| 192 | } |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 193 | |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 194 | DEFUN(show_msc, |
| 195 | show_msc_cmd, |
| 196 | "show msc connection", |
| 197 | SHOW_STR "Show the status of the MSC connection.") |
| 198 | { |
| 199 | if (!_nat->msc_con) { |
| 200 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 201 | return CMD_WARNING; |
| 202 | } |
| 203 | |
| 204 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 205 | _nat->msc_con->ip, _nat->msc_con->port, |
| 206 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 207 | return CMD_SUCCESS; |
| 208 | } |
| 209 | |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 210 | DEFUN(close_bsc, |
| 211 | close_bsc_cmd, |
| 212 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 213 | "Close the connection with the BSC identified by the config number.") |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 214 | { |
| 215 | struct bsc_connection *bsc; |
| 216 | int bsc_nr = atoi(argv[0]); |
| 217 | |
| 218 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 219 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 220 | continue; |
| 221 | bsc_close_connection(bsc); |
| 222 | break; |
| 223 | } |
| 224 | |
| 225 | return CMD_SUCCESS; |
| 226 | } |
| 227 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 228 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 229 | { |
| 230 | vty->index = _nat; |
| 231 | vty->node = NAT_NODE; |
| 232 | |
| 233 | return CMD_SUCCESS; |
| 234 | } |
| 235 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 236 | DEFUN(cfg_nat_imsi_deny, |
| 237 | cfg_nat_imsi_deny_cmd, |
| 238 | "imsi deny [REGEXP]", |
| 239 | "Deny matching IMSIs to talk to the MSC. " |
| 240 | "The defualt is to not deny.") |
| 241 | { |
Holger Hans Peter Freyther | 12dc89a | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 242 | bsc_parse_reg(_nat, &_nat->imsi_deny_re, &_nat->imsi_deny, argc, argv); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 243 | return CMD_SUCCESS; |
| 244 | } |
| 245 | |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 246 | DEFUN(cfg_nat_msc_ip, |
| 247 | cfg_nat_msc_ip_cmd, |
Holger Hans Peter Freyther | d8b8206 | 2010-05-14 02:36:42 +0800 | [diff] [blame] | 248 | "msc ip A.B.C.D", |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 249 | "Set the IP address of the MSC.") |
| 250 | { |
| 251 | bsc_nat_set_msc_ip(_nat, argv[0]); |
| 252 | return CMD_SUCCESS; |
| 253 | } |
| 254 | |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 255 | DEFUN(cfg_nat_msc_port, |
| 256 | cfg_nat_msc_port_cmd, |
| 257 | "msc port <1-65500>", |
| 258 | "Set the port of the MSC.") |
| 259 | { |
| 260 | _nat->msc_port = atoi(argv[0]); |
| 261 | return CMD_SUCCESS; |
| 262 | } |
| 263 | |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 264 | DEFUN(cfg_nat_auth_time, |
| 265 | cfg_nat_auth_time_cmd, |
| 266 | "timeout auth <1-256>", |
| 267 | "The time to wait for an auth response.") |
| 268 | { |
| 269 | _nat->auth_timeout = atoi(argv[0]); |
| 270 | return CMD_SUCCESS; |
| 271 | } |
| 272 | |
| 273 | DEFUN(cfg_nat_ping_time, |
| 274 | cfg_nat_ping_time_cmd, |
| 275 | "timeout ping NR", |
| 276 | "Send a ping every NR seconds. Negative to disable.") |
| 277 | { |
| 278 | _nat->ping_timeout = atoi(argv[0]); |
| 279 | return CMD_SUCCESS; |
| 280 | } |
| 281 | |
| 282 | DEFUN(cfg_nat_pong_time, |
| 283 | cfg_nat_pong_time_cmd, |
| 284 | "timeout pong NR", |
| 285 | "Wait NR seconds for the PONG response. Should be smaller than ping.") |
| 286 | { |
| 287 | _nat->pong_timeout = atoi(argv[0]); |
| 288 | return CMD_SUCCESS; |
| 289 | } |
| 290 | |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 291 | DEFUN(cfg_nat_token, cfg_nat_token_cmd, |
| 292 | "token TOKEN", |
| 293 | "Set a token for the NAT") |
| 294 | { |
| 295 | if (_nat->token) |
| 296 | talloc_free(_nat->token); |
| 297 | _nat->token = talloc_strdup(_nat, argv[0]); |
| 298 | return CMD_SUCCESS; |
| 299 | } |
| 300 | |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame^] | 301 | DEFUN(cfg_nat_bsc_ip_tos, cfg_nat_bsc_ip_tos_cmd, |
| 302 | "ip-tos <0-255>", |
| 303 | "Set the IP_TOS for the BSCs to use\n" "Set the IP_TOS attribute") |
| 304 | { |
| 305 | _nat->bsc_ip_tos = atoi(argv[0]); |
| 306 | return CMD_SUCCESS; |
| 307 | } |
| 308 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 309 | /* per BSC configuration */ |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 310 | DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 311 | { |
| 312 | int bsc_nr = atoi(argv[0]); |
| 313 | struct bsc_config *bsc; |
| 314 | |
| 315 | if (bsc_nr > _nat->num_bsc) { |
| 316 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 317 | _nat->num_bsc, VTY_NEWLINE); |
| 318 | return CMD_WARNING; |
| 319 | } else if (bsc_nr == _nat->num_bsc) { |
| 320 | /* allocate a new one */ |
| 321 | bsc = bsc_config_alloc(_nat, "unknown", 0); |
| 322 | } else |
| 323 | bsc = bsc_config_num(_nat, bsc_nr); |
| 324 | |
| 325 | if (!bsc) |
| 326 | return CMD_WARNING; |
| 327 | |
| 328 | vty->index = bsc; |
| 329 | vty->node = BSC_NODE; |
| 330 | |
| 331 | return CMD_SUCCESS; |
| 332 | } |
| 333 | |
| 334 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 335 | { |
| 336 | struct bsc_config *conf = vty->index; |
| 337 | |
| 338 | if (conf->token) |
| 339 | talloc_free(conf->token); |
| 340 | conf->token = talloc_strdup(conf, argv[0]); |
| 341 | return CMD_SUCCESS; |
| 342 | } |
| 343 | |
| 344 | DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 345 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 346 | { |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 347 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 348 | struct bsc_config *conf = vty->index; |
| 349 | |
| 350 | int lac = atoi(argv[0]); |
| 351 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 352 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 353 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 354 | lac, VTY_NEWLINE); |
| 355 | return CMD_WARNING; |
| 356 | } |
| 357 | |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 358 | /* verify that the LACs are unique */ |
| 359 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
| 360 | if (tmp->lac == lac) { |
| 361 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 362 | return CMD_ERR_INCOMPLETE; |
| 363 | } |
| 364 | } |
| 365 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 366 | conf->lac = lac; |
| 367 | |
| 368 | return CMD_SUCCESS; |
| 369 | } |
| 370 | |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 371 | DEFUN(cfg_bsc_imsi_allow, |
| 372 | cfg_bsc_imsi_allow_cmd, |
| 373 | "imsi allow [REGEXP]", |
| 374 | "Allow IMSIs with the following network to talk to the MSC." |
| 375 | "The default is to allow everyone)") |
| 376 | { |
| 377 | struct bsc_config *conf = vty->index; |
| 378 | |
Holger Hans Peter Freyther | 12dc89a | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 379 | bsc_parse_reg(conf, &conf->imsi_allow_re, &conf->imsi_allow, argc, argv); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 380 | return CMD_SUCCESS; |
| 381 | } |
| 382 | |
| 383 | DEFUN(cfg_bsc_imsi_deny, |
| 384 | cfg_bsc_imsi_deny_cmd, |
| 385 | "imsi deny [REGEXP]", |
| 386 | "Deny IMSIs with the following network to talk to the MSC." |
| 387 | "The default is to not deny anyone.)") |
| 388 | { |
| 389 | struct bsc_config *conf = vty->index; |
| 390 | |
Holger Hans Peter Freyther | 12dc89a | 2010-05-14 18:38:29 +0800 | [diff] [blame] | 391 | bsc_parse_reg(conf, &conf->imsi_deny_re, &conf->imsi_deny, argc, argv); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 392 | return CMD_SUCCESS; |
| 393 | } |
| 394 | |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 395 | DEFUN(cfg_bsc_paging, |
| 396 | cfg_bsc_paging_cmd, |
| 397 | "paging forbidden (0|1)", |
| 398 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 399 | { |
| 400 | struct bsc_config *conf = vty->index; |
| 401 | |
Holger Hans Peter Freyther | 834f1df | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 402 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 403 | conf->forbid_paging = 1; |
| 404 | else |
| 405 | conf->forbid_paging = 0; |
| 406 | |
| 407 | return CMD_SUCCESS; |
| 408 | } |
| 409 | |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 410 | DEFUN(cfg_bsc_desc, |
| 411 | cfg_bsc_desc_cmd, |
| 412 | "description DESC", |
| 413 | "Provide a description for the given BSC.") |
| 414 | { |
| 415 | struct bsc_config *conf = vty->index; |
| 416 | |
| 417 | if (conf->description) |
| 418 | talloc_free(conf->description); |
| 419 | conf->description = talloc_strdup(conf, argv[0]); |
| 420 | return CMD_SUCCESS; |
| 421 | } |
| 422 | |
Holger Hans Peter Freyther | 52c4ba0 | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 423 | DEFUN(test_regex, test_regex_cmd, |
| 424 | "test regex PATTERN STRING", |
| 425 | "Check if the string is matching the current pattern.") |
| 426 | { |
| 427 | regex_t reg; |
| 428 | char *str = NULL; |
| 429 | |
| 430 | memset(®, 0, sizeof(reg)); |
| 431 | bsc_parse_reg(_nat, ®, &str, 1, argv); |
| 432 | |
| 433 | vty_out(vty, "String matches allow pattern: %d%s", |
| 434 | regexec(®, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE); |
| 435 | |
| 436 | talloc_free(str); |
| 437 | regfree(®); |
| 438 | return CMD_SUCCESS; |
| 439 | } |
| 440 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 441 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 442 | { |
| 443 | _nat = nat; |
| 444 | |
| 445 | cmd_init(1); |
| 446 | vty_init(); |
| 447 | |
| 448 | /* show commands */ |
| 449 | install_element(VIEW_NODE, &show_sccp_cmd); |
| 450 | install_element(VIEW_NODE, &show_bsc_cmd); |
| 451 | install_element(VIEW_NODE, &show_bsc_cfg_cmd); |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 452 | install_element(VIEW_NODE, &show_stats_cmd); |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 453 | install_element(VIEW_NODE, &close_bsc_cmd); |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 454 | install_element(VIEW_NODE, &show_msc_cmd); |
Holger Hans Peter Freyther | 52c4ba0 | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 455 | install_element(VIEW_NODE, &test_regex_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 456 | |
Holger Hans Peter Freyther | 5f291d5 | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 457 | openbsc_vty_add_cmds(); |
| 458 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 459 | /* nat group */ |
| 460 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 461 | install_node(&nat_node, config_write_nat); |
| 462 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 463 | install_element(NAT_NODE, &cfg_nat_imsi_deny_cmd); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 464 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 465 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 466 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 467 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 468 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 469 | install_element(NAT_NODE, &cfg_nat_token_cmd); |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame^] | 470 | install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 471 | |
| 472 | /* BSC subgroups */ |
| 473 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 474 | install_node(&bsc_node, config_write_bsc); |
| 475 | install_default(BSC_NODE); |
| 476 | install_element(BSC_NODE, &cfg_bsc_token_cmd); |
| 477 | install_element(BSC_NODE, &cfg_bsc_lac_cmd); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 478 | install_element(BSC_NODE, &cfg_bsc_imsi_allow_cmd); |
| 479 | install_element(BSC_NODE, &cfg_bsc_imsi_deny_cmd); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 480 | install_element(BSC_NODE, &cfg_bsc_paging_cmd); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 481 | install_element(BSC_NODE, &cfg_bsc_desc_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 482 | |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 483 | mgcp_vty_init(); |
| 484 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 485 | return 0; |
| 486 | } |
| 487 | |
| 488 | |
| 489 | /* called by the telnet interface... we have our own init above */ |
| 490 | void bsc_vty_init() |
| 491 | {} |