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 | { |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 54 | struct bsc_nat_access_list *lst; |
| 55 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 56 | vty_out(vty, "nat%s", 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 | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 65 | if (_nat->acc_lst_name) |
| 66 | vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE); |
| 67 | |
| 68 | llist_for_each_entry(lst, &_nat->access_lists, list) { |
| 69 | if (lst->imsi_allow) |
| 70 | vty_out(vty, " access-list %s imsi-allow %s%s", |
| 71 | lst->name, lst->imsi_allow, VTY_NEWLINE); |
| 72 | if (lst->imsi_deny) |
| 73 | vty_out(vty, " access-list %s imsi-deny %s%s", |
| 74 | lst->name, lst->imsi_deny, VTY_NEWLINE); |
| 75 | } |
| 76 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 77 | return CMD_SUCCESS; |
| 78 | } |
| 79 | |
| 80 | static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc) |
| 81 | { |
| 82 | vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE); |
| 83 | vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | d1278c1 | 2010-04-16 16:52:20 +0200 | [diff] [blame] | 84 | vty_out(vty, " location_area_code %u%s", bsc->lac, VTY_NEWLINE); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 85 | 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] | 86 | if (bsc->description) |
| 87 | vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 88 | if (bsc->acc_lst_name) |
| 89 | vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static int config_write_bsc(struct vty *vty) |
| 93 | { |
| 94 | struct bsc_config *bsc; |
| 95 | |
| 96 | llist_for_each_entry(bsc, &_nat->bsc_configs, entry) |
| 97 | config_write_bsc_single(vty, bsc); |
| 98 | return CMD_SUCCESS; |
| 99 | } |
| 100 | |
| 101 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 102 | DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", |
| 103 | SHOW_STR "Display information about current SCCP connections") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 104 | { |
| 105 | struct sccp_connections *con; |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 106 | 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] | 107 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 108 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 109 | 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] | 110 | con->bsc->cfg ? con->bsc->cfg->nr : -1, |
| 111 | con->bsc->cfg ? con->bsc->cfg->lac : -1, |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 112 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 113 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 4bd2294 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 114 | con->has_remote_ref, |
| 115 | sccp_src_ref_to_int(&con->remote_ref), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 116 | con->msc_timeslot, con->bsc_timeslot, |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 117 | bsc_con_type_to_string(con->con_type), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 118 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | return CMD_SUCCESS; |
| 122 | } |
| 123 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 124 | DEFUN(show_bsc, show_bsc_cmd, "show bsc connections", |
| 125 | SHOW_STR "Display information about current BSCs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 126 | { |
| 127 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 128 | struct sockaddr_in sock; |
| 129 | socklen_t len = sizeof(sock); |
| 130 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 131 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 132 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | 3b87981 | 2010-05-01 15:32:32 +0800 | [diff] [blame] | 133 | 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] | 134 | con->cfg ? con->cfg->nr : -1, |
| 135 | con->cfg ? con->cfg->lac : -1, |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 136 | con->authenticated, con->write_queue.bfd.fd, |
| 137 | inet_ntoa(sock.sin_addr), VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | return CMD_SUCCESS; |
| 141 | } |
| 142 | |
Holger Hans Peter Freyther | ab7539c | 2010-04-22 13:36:46 +0800 | [diff] [blame] | 143 | DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config", |
| 144 | SHOW_STR "Display information about known BSC configs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 145 | { |
| 146 | struct bsc_config *conf; |
| 147 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
| 148 | vty_out(vty, "BSC token: '%s' lac: %u nr: %u%s", |
| 149 | conf->token, conf->lac, conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 150 | if (conf->acc_lst_name) |
| 151 | vty_out(vty, " access-list: %s%s", |
| 152 | conf->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 153 | vty_out(vty, " paging forbidden: %d%s", |
| 154 | conf->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 155 | if (conf->description) |
| 156 | vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE); |
| 157 | else |
| 158 | vty_out(vty, " No description.%s", VTY_NEWLINE); |
| 159 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | return CMD_SUCCESS; |
| 163 | } |
| 164 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 165 | DEFUN(show_stats, |
| 166 | show_stats_cmd, |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 167 | "show statistics [NR]", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 168 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 169 | { |
| 170 | struct bsc_config *conf; |
| 171 | |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 172 | int nr = -1; |
| 173 | |
| 174 | if (argc == 1) |
| 175 | nr = atoi(argv[0]); |
| 176 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 177 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 178 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 179 | counter_get(_nat->stats.sccp.conn), |
| 180 | counter_get(_nat->stats.sccp.calls), VTY_NEWLINE); |
| 181 | vty_out(vty, " MSC Connections %lu%s", |
| 182 | counter_get(_nat->stats.msc.reconn), VTY_NEWLINE); |
| 183 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 184 | counter_get(_nat->stats.bsc.reconn), |
| 185 | counter_get(_nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 186 | |
| 187 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 188 | if (argc == 1 && nr != conf->nr) |
| 189 | continue; |
| 190 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 191 | vty_out(vty, " BSC lac: %d nr: %d%s", |
| 192 | conf->lac, conf->nr, VTY_NEWLINE); |
| 193 | vty_out(vty, " SCCP Connnections %lu total, %lu calls%s", |
| 194 | counter_get(conf->stats.sccp.conn), |
| 195 | counter_get(conf->stats.sccp.calls), VTY_NEWLINE); |
| 196 | vty_out(vty, " BSC Connections %lu total%s", |
| 197 | counter_get(conf->stats.net.reconn), VTY_NEWLINE); |
| 198 | } |
| 199 | |
| 200 | return CMD_SUCCESS; |
| 201 | } |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 202 | |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 203 | DEFUN(show_msc, |
| 204 | show_msc_cmd, |
| 205 | "show msc connection", |
| 206 | SHOW_STR "Show the status of the MSC connection.") |
| 207 | { |
| 208 | if (!_nat->msc_con) { |
| 209 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 210 | return CMD_WARNING; |
| 211 | } |
| 212 | |
| 213 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 214 | _nat->msc_con->ip, _nat->msc_con->port, |
| 215 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 216 | return CMD_SUCCESS; |
| 217 | } |
| 218 | |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 219 | DEFUN(close_bsc, |
| 220 | close_bsc_cmd, |
| 221 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 222 | "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] | 223 | { |
| 224 | struct bsc_connection *bsc; |
| 225 | int bsc_nr = atoi(argv[0]); |
| 226 | |
| 227 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 228 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 229 | continue; |
| 230 | bsc_close_connection(bsc); |
| 231 | break; |
| 232 | } |
| 233 | |
| 234 | return CMD_SUCCESS; |
| 235 | } |
| 236 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 237 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 238 | { |
| 239 | vty->index = _nat; |
| 240 | vty->node = NAT_NODE; |
| 241 | |
| 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 | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 300 | DEFUN(cfg_nat_bsc_ip_tos, cfg_nat_bsc_ip_tos_cmd, |
| 301 | "ip-tos <0-255>", |
| 302 | "Set the IP_TOS for the BSCs to use\n" "Set the IP_TOS attribute") |
| 303 | { |
| 304 | _nat->bsc_ip_tos = atoi(argv[0]); |
| 305 | return CMD_SUCCESS; |
| 306 | } |
| 307 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 308 | DEFUN(cfg_nat_acc_lst_name, |
| 309 | cfg_nat_acc_lst_name_cmd, |
| 310 | "access-list-name NAME", |
| 311 | "Set the name of the access list to use.\n" |
| 312 | "The name of the to be used access list.") |
| 313 | { |
| 314 | if (_nat->acc_lst_name) |
| 315 | talloc_free(_nat->acc_lst_name); |
| 316 | _nat->acc_lst_name = talloc_strdup(_nat, argv[0]); |
| 317 | return CMD_SUCCESS; |
| 318 | } |
| 319 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 320 | /* per BSC configuration */ |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 321 | 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] | 322 | { |
| 323 | int bsc_nr = atoi(argv[0]); |
| 324 | struct bsc_config *bsc; |
| 325 | |
| 326 | if (bsc_nr > _nat->num_bsc) { |
| 327 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 328 | _nat->num_bsc, VTY_NEWLINE); |
| 329 | return CMD_WARNING; |
| 330 | } else if (bsc_nr == _nat->num_bsc) { |
| 331 | /* allocate a new one */ |
| 332 | bsc = bsc_config_alloc(_nat, "unknown", 0); |
| 333 | } else |
| 334 | bsc = bsc_config_num(_nat, bsc_nr); |
| 335 | |
| 336 | if (!bsc) |
| 337 | return CMD_WARNING; |
| 338 | |
| 339 | vty->index = bsc; |
| 340 | vty->node = BSC_NODE; |
| 341 | |
| 342 | return CMD_SUCCESS; |
| 343 | } |
| 344 | |
| 345 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 346 | { |
| 347 | struct bsc_config *conf = vty->index; |
| 348 | |
| 349 | if (conf->token) |
| 350 | talloc_free(conf->token); |
| 351 | conf->token = talloc_strdup(conf, argv[0]); |
| 352 | return CMD_SUCCESS; |
| 353 | } |
| 354 | |
| 355 | 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] | 356 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 357 | { |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 358 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 359 | struct bsc_config *conf = vty->index; |
| 360 | |
| 361 | int lac = atoi(argv[0]); |
| 362 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 363 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 364 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 365 | lac, VTY_NEWLINE); |
| 366 | return CMD_WARNING; |
| 367 | } |
| 368 | |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 369 | /* verify that the LACs are unique */ |
| 370 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
| 371 | if (tmp->lac == lac) { |
| 372 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 373 | return CMD_ERR_INCOMPLETE; |
| 374 | } |
| 375 | } |
| 376 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 377 | conf->lac = lac; |
| 378 | |
| 379 | return CMD_SUCCESS; |
| 380 | } |
| 381 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 382 | DEFUN(cfg_lst_imsi_allow, |
| 383 | cfg_lst_imsi_allow_cmd, |
| 384 | "access-list NAME imsi-allow [REGEXP]", |
| 385 | "Allow IMSIs matching the REGEXP\n" |
| 386 | "The name of the access-list\n" |
| 387 | "The regexp of allowed IMSIs\n") |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 388 | { |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 389 | struct bsc_nat_access_list *acc; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 390 | |
Holger Hans Peter Freyther | 86c4dc3 | 2010-06-03 01:34:20 +0800 | [diff] [blame^] | 391 | acc = bsc_nat_accs_list_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 392 | if (!acc) |
| 393 | return CMD_WARNING; |
| 394 | |
| 395 | bsc_parse_reg(acc, &acc->imsi_allow_re, &acc->imsi_allow, argc, argv); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 396 | return CMD_SUCCESS; |
| 397 | } |
| 398 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 399 | DEFUN(cfg_lst_imsi_deny, |
| 400 | cfg_lst_imsi_deny_cmd, |
| 401 | "access-list NAME imsi-deny [REGEXP]", |
| 402 | "Allow IMSIs matching the REGEXP\n" |
| 403 | "The name of the access-list\n" |
| 404 | "The regexp of to be denied IMSIs\n") |
| 405 | { |
| 406 | struct bsc_nat_access_list *acc; |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 407 | |
Holger Hans Peter Freyther | 86c4dc3 | 2010-06-03 01:34:20 +0800 | [diff] [blame^] | 408 | acc = bsc_nat_accs_list_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 409 | if (!acc) |
| 410 | return CMD_WARNING; |
| 411 | |
| 412 | bsc_parse_reg(acc, &acc->imsi_deny_re, &acc->imsi_deny, argc, argv); |
| 413 | return CMD_SUCCESS; |
| 414 | } |
| 415 | |
| 416 | DEFUN(cfg_bsc_acc_lst_name, |
| 417 | cfg_bsc_acc_lst_name_cmd, |
| 418 | "access-list-name NAME", |
| 419 | "Set the name of the access list to use.\n" |
| 420 | "The name of the to be used access list.") |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 421 | { |
| 422 | struct bsc_config *conf = vty->index; |
| 423 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 424 | if (conf->acc_lst_name) |
| 425 | talloc_free(conf->acc_lst_name); |
| 426 | conf->acc_lst_name = talloc_strdup(conf, argv[0]); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 427 | return CMD_SUCCESS; |
| 428 | } |
| 429 | |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 430 | DEFUN(cfg_bsc_paging, |
| 431 | cfg_bsc_paging_cmd, |
| 432 | "paging forbidden (0|1)", |
| 433 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 434 | { |
| 435 | struct bsc_config *conf = vty->index; |
| 436 | |
Holger Hans Peter Freyther | 834f1df | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 437 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 438 | conf->forbid_paging = 1; |
| 439 | else |
| 440 | conf->forbid_paging = 0; |
| 441 | |
| 442 | return CMD_SUCCESS; |
| 443 | } |
| 444 | |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 445 | DEFUN(cfg_bsc_desc, |
| 446 | cfg_bsc_desc_cmd, |
| 447 | "description DESC", |
| 448 | "Provide a description for the given BSC.") |
| 449 | { |
| 450 | struct bsc_config *conf = vty->index; |
| 451 | |
| 452 | if (conf->description) |
| 453 | talloc_free(conf->description); |
| 454 | conf->description = talloc_strdup(conf, argv[0]); |
| 455 | return CMD_SUCCESS; |
| 456 | } |
| 457 | |
Holger Hans Peter Freyther | 52c4ba0 | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 458 | DEFUN(test_regex, test_regex_cmd, |
| 459 | "test regex PATTERN STRING", |
| 460 | "Check if the string is matching the current pattern.") |
| 461 | { |
| 462 | regex_t reg; |
| 463 | char *str = NULL; |
| 464 | |
| 465 | memset(®, 0, sizeof(reg)); |
| 466 | bsc_parse_reg(_nat, ®, &str, 1, argv); |
| 467 | |
| 468 | vty_out(vty, "String matches allow pattern: %d%s", |
| 469 | regexec(®, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE); |
| 470 | |
| 471 | talloc_free(str); |
| 472 | regfree(®); |
| 473 | return CMD_SUCCESS; |
| 474 | } |
| 475 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 476 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 477 | { |
| 478 | _nat = nat; |
| 479 | |
| 480 | cmd_init(1); |
| 481 | vty_init(); |
| 482 | |
| 483 | /* show commands */ |
| 484 | install_element(VIEW_NODE, &show_sccp_cmd); |
| 485 | install_element(VIEW_NODE, &show_bsc_cmd); |
| 486 | install_element(VIEW_NODE, &show_bsc_cfg_cmd); |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 487 | install_element(VIEW_NODE, &show_stats_cmd); |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 488 | install_element(VIEW_NODE, &close_bsc_cmd); |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 489 | install_element(VIEW_NODE, &show_msc_cmd); |
Holger Hans Peter Freyther | 52c4ba0 | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 490 | install_element(VIEW_NODE, &test_regex_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 491 | |
Holger Hans Peter Freyther | 5f291d5 | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 492 | openbsc_vty_add_cmds(); |
| 493 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 494 | /* nat group */ |
| 495 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 496 | install_node(&nat_node, config_write_nat); |
| 497 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 498 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 499 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 500 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 501 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 502 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 503 | install_element(NAT_NODE, &cfg_nat_token_cmd); |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 504 | install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 505 | install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd); |
| 506 | |
| 507 | /* access-list */ |
| 508 | install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd); |
| 509 | install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 510 | |
| 511 | /* BSC subgroups */ |
| 512 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 513 | install_node(&bsc_node, config_write_bsc); |
| 514 | install_default(BSC_NODE); |
| 515 | install_element(BSC_NODE, &cfg_bsc_token_cmd); |
| 516 | install_element(BSC_NODE, &cfg_bsc_lac_cmd); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 517 | install_element(BSC_NODE, &cfg_bsc_paging_cmd); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 518 | install_element(BSC_NODE, &cfg_bsc_desc_cmd); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 519 | install_element(NAT_NODE, &cfg_bsc_acc_lst_name_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 520 | |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 521 | mgcp_vty_init(); |
| 522 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 523 | return 0; |
| 524 | } |
| 525 | |
| 526 | |
| 527 | /* called by the telnet interface... we have our own init above */ |
| 528 | void bsc_vty_init() |
| 529 | {} |