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