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