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