Holger Hans Peter Freyther | 5e54788 | 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 | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 22 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 23 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 24 | #include <openbsc/bsc_msc.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 25 | #include <openbsc/gsm_04_08.h> |
Holger Hans Peter Freyther | 3660e4d | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 26 | #include <openbsc/mgcp.h> |
Holger Hans Peter Freyther | b372fad | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 27 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 3b96089 | 2010-06-15 19:06:18 +0800 | [diff] [blame] | 28 | |
| 29 | #include <osmocore/talloc.h> |
Holger Hans Peter Freyther | ccefba6 | 2010-06-17 18:16:00 +0800 | [diff] [blame] | 30 | #include <osmocore/rate_ctr.h> |
Holger Hans Peter Freyther | 5e54788 | 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 | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 45 | NAT_BSC_NODE, |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 46 | "%s(bsc)#", |
| 47 | 1, |
| 48 | }; |
| 49 | |
Holger Hans Peter Freyther | 8eb4589 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 64 | static int config_write_nat(struct vty *vty) |
| 65 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 66 | struct bsc_nat_acc_lst *lst; |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 67 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 68 | vty_out(vty, "nat%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 9226d70 | 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 | bace202 | 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 | acd3078 | 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 | 6e88b17 | 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 | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 76 | vty_out(vty, " ip-dscp %d%s", _nat->bsc_ip_dscp, VTY_NEWLINE); |
Holger Hans Peter Freyther | 67b6d52 | 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 | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 81 | write_acc_lst(vty, lst); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 82 | } |
| 83 | |
Holger Hans Peter Freyther | 5e54788 | 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 | 085ea30 | 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 | 7acf462 | 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 | 6f00907 | 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 | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 95 | if (bsc->acc_lst_name) |
Holger Hans Peter Freyther | 409a370 | 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 | 5e54788 | 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 | 17f8c95 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 111 | { |
| 112 | struct sccp_connections *con; |
Holger Hans Peter Freyther | dbdd30f | 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 | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 114 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 115 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 8e69f0c | 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 | bfcf519 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 119 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 120 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 0a3a853 | 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 | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 123 | con->msc_timeslot, con->bsc_timeslot, |
Holger Hans Peter Freyther | 8e69f0c | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 124 | bsc_con_type_to_string(con->con_type), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 125 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | return CMD_SUCCESS; |
| 129 | } |
| 130 | |
Holger Hans Peter Freyther | 17f8c95 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 133 | { |
| 134 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 9e53e97 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 138 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 139 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | ffc051f | 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 | bfcf519 | 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 | 9e53e97 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | return CMD_SUCCESS; |
| 148 | } |
| 149 | |
Holger Hans Peter Freyther | 936aed7 | 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 | 5e54788 | 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 | 67b6d52 | 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 | 7acf462 | 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 | 6f00907 | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | return CMD_SUCCESS; |
| 170 | } |
| 171 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 172 | static void dump_stat_total(struct vty *vty, struct bsc_nat *nat) |
| 173 | { |
| 174 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 175 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 176 | counter_get(nat->stats.sccp.conn), |
| 177 | counter_get(nat->stats.sccp.calls), VTY_NEWLINE); |
| 178 | vty_out(vty, " MSC Connections %lu%s", |
| 179 | counter_get(nat->stats.msc.reconn), VTY_NEWLINE); |
| 180 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 181 | counter_get(nat->stats.bsc.reconn), |
| 182 | counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 183 | } |
| 184 | |
| 185 | static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf) |
| 186 | { |
Holger Hans Peter Freyther | e410758 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 187 | int connected = 0; |
| 188 | struct bsc_connection *con; |
| 189 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 190 | vty_out(vty, " BSC lac: %d nr: %d%s", |
| 191 | conf->lac, conf->nr, VTY_NEWLINE); |
| 192 | vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg); |
Holger Hans Peter Freyther | e410758 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 193 | |
| 194 | llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) { |
| 195 | if (con->cfg != conf) |
| 196 | continue; |
| 197 | connected = 1; |
| 198 | break; |
| 199 | } |
| 200 | |
| 201 | vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 202 | } |
| 203 | |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 204 | DEFUN(show_stats, |
| 205 | show_stats_cmd, |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 206 | "show statistics [NR]", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 207 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 208 | { |
| 209 | struct bsc_config *conf; |
| 210 | |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 211 | int nr = -1; |
| 212 | |
| 213 | if (argc == 1) |
| 214 | nr = atoi(argv[0]); |
| 215 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 216 | dump_stat_total(vty, _nat); |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 217 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 218 | if (argc == 1 && nr != conf->nr) |
| 219 | continue; |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 220 | dump_stat_bsc(vty, conf); |
| 221 | } |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 222 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 223 | return CMD_SUCCESS; |
| 224 | } |
| 225 | |
| 226 | DEFUN(show_stats_lac, |
| 227 | show_stats_lac_cmd, |
| 228 | "show statistics-by-lac <0-65535>", |
| 229 | SHOW_STR "Display network statistics by lac\n" |
| 230 | "The lac of the BSC\n") |
| 231 | { |
| 232 | int lac; |
| 233 | struct bsc_config *conf; |
| 234 | |
| 235 | lac = atoi(argv[0]); |
| 236 | |
| 237 | dump_stat_total(vty, _nat); |
| 238 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
| 239 | if (conf->lac != lac) |
| 240 | continue; |
| 241 | dump_stat_bsc(vty, conf); |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | return CMD_SUCCESS; |
| 245 | } |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 246 | |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 247 | DEFUN(show_msc, |
| 248 | show_msc_cmd, |
| 249 | "show msc connection", |
| 250 | SHOW_STR "Show the status of the MSC connection.") |
| 251 | { |
| 252 | if (!_nat->msc_con) { |
| 253 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 254 | return CMD_WARNING; |
| 255 | } |
| 256 | |
| 257 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 258 | _nat->msc_con->ip, _nat->msc_con->port, |
| 259 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 260 | return CMD_SUCCESS; |
| 261 | } |
| 262 | |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 263 | DEFUN(close_bsc, |
| 264 | close_bsc_cmd, |
| 265 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 266 | "Close the connection with the BSC identified by the config number.") |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 267 | { |
| 268 | struct bsc_connection *bsc; |
| 269 | int bsc_nr = atoi(argv[0]); |
| 270 | |
| 271 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 272 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 273 | continue; |
| 274 | bsc_close_connection(bsc); |
| 275 | break; |
| 276 | } |
| 277 | |
| 278 | return CMD_SUCCESS; |
| 279 | } |
| 280 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 281 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 282 | { |
| 283 | vty->index = _nat; |
| 284 | vty->node = NAT_NODE; |
| 285 | |
| 286 | return CMD_SUCCESS; |
| 287 | } |
| 288 | |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 289 | DEFUN(cfg_nat_msc_ip, |
| 290 | cfg_nat_msc_ip_cmd, |
Holger Hans Peter Freyther | f7cd800 | 2010-05-14 02:36:42 +0800 | [diff] [blame] | 291 | "msc ip A.B.C.D", |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 292 | "Set the IP address of the MSC.") |
| 293 | { |
| 294 | bsc_nat_set_msc_ip(_nat, argv[0]); |
| 295 | return CMD_SUCCESS; |
| 296 | } |
| 297 | |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 298 | DEFUN(cfg_nat_msc_port, |
| 299 | cfg_nat_msc_port_cmd, |
| 300 | "msc port <1-65500>", |
| 301 | "Set the port of the MSC.") |
| 302 | { |
| 303 | _nat->msc_port = atoi(argv[0]); |
| 304 | return CMD_SUCCESS; |
| 305 | } |
| 306 | |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 307 | DEFUN(cfg_nat_auth_time, |
| 308 | cfg_nat_auth_time_cmd, |
| 309 | "timeout auth <1-256>", |
| 310 | "The time to wait for an auth response.") |
| 311 | { |
| 312 | _nat->auth_timeout = atoi(argv[0]); |
| 313 | return CMD_SUCCESS; |
| 314 | } |
| 315 | |
| 316 | DEFUN(cfg_nat_ping_time, |
| 317 | cfg_nat_ping_time_cmd, |
| 318 | "timeout ping NR", |
| 319 | "Send a ping every NR seconds. Negative to disable.") |
| 320 | { |
| 321 | _nat->ping_timeout = atoi(argv[0]); |
| 322 | return CMD_SUCCESS; |
| 323 | } |
| 324 | |
| 325 | DEFUN(cfg_nat_pong_time, |
| 326 | cfg_nat_pong_time_cmd, |
| 327 | "timeout pong NR", |
| 328 | "Wait NR seconds for the PONG response. Should be smaller than ping.") |
| 329 | { |
| 330 | _nat->pong_timeout = atoi(argv[0]); |
| 331 | return CMD_SUCCESS; |
| 332 | } |
| 333 | |
Holger Hans Peter Freyther | 6e88b17 | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 334 | DEFUN(cfg_nat_token, cfg_nat_token_cmd, |
| 335 | "token TOKEN", |
| 336 | "Set a token for the NAT") |
| 337 | { |
| 338 | if (_nat->token) |
| 339 | talloc_free(_nat->token); |
| 340 | _nat->token = talloc_strdup(_nat, argv[0]); |
| 341 | return CMD_SUCCESS; |
| 342 | } |
| 343 | |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 344 | DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd, |
| 345 | "ip-dscp <0-255>", |
| 346 | "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute") |
Holger Hans Peter Freyther | 9d42d32 | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 347 | { |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 348 | _nat->bsc_ip_dscp = atoi(argv[0]); |
Holger Hans Peter Freyther | 9d42d32 | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 349 | return CMD_SUCCESS; |
| 350 | } |
| 351 | |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 352 | ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd, |
| 353 | "ip-tos <0-255>", |
| 354 | "Use ip-dscp in the future.\n" "Set the DSCP\n") |
| 355 | |
| 356 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 357 | DEFUN(cfg_nat_acc_lst_name, |
| 358 | cfg_nat_acc_lst_name_cmd, |
| 359 | "access-list-name NAME", |
| 360 | "Set the name of the access list to use.\n" |
| 361 | "The name of the to be used access list.") |
| 362 | { |
| 363 | if (_nat->acc_lst_name) |
| 364 | talloc_free(_nat->acc_lst_name); |
| 365 | _nat->acc_lst_name = talloc_strdup(_nat, argv[0]); |
| 366 | return CMD_SUCCESS; |
| 367 | } |
| 368 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 369 | /* per BSC configuration */ |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 370 | DEFUN(cfg_bsc, cfg_bsc_cmd, "bsc BSC_NR", "Select a BSC to configure") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 371 | { |
| 372 | int bsc_nr = atoi(argv[0]); |
| 373 | struct bsc_config *bsc; |
| 374 | |
| 375 | if (bsc_nr > _nat->num_bsc) { |
| 376 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 377 | _nat->num_bsc, VTY_NEWLINE); |
| 378 | return CMD_WARNING; |
| 379 | } else if (bsc_nr == _nat->num_bsc) { |
| 380 | /* allocate a new one */ |
| 381 | bsc = bsc_config_alloc(_nat, "unknown", 0); |
| 382 | } else |
| 383 | bsc = bsc_config_num(_nat, bsc_nr); |
| 384 | |
| 385 | if (!bsc) |
| 386 | return CMD_WARNING; |
| 387 | |
| 388 | vty->index = bsc; |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 389 | vty->node = NAT_BSC_NODE; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 390 | |
| 391 | return CMD_SUCCESS; |
| 392 | } |
| 393 | |
| 394 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 395 | { |
| 396 | struct bsc_config *conf = vty->index; |
| 397 | |
| 398 | if (conf->token) |
| 399 | talloc_free(conf->token); |
| 400 | conf->token = talloc_strdup(conf, argv[0]); |
| 401 | return CMD_SUCCESS; |
| 402 | } |
| 403 | |
| 404 | DEFUN(cfg_bsc_lac, cfg_bsc_lac_cmd, "location_area_code <0-65535>", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 405 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 406 | { |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 407 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 408 | struct bsc_config *conf = vty->index; |
| 409 | |
| 410 | int lac = atoi(argv[0]); |
| 411 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 412 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 413 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 414 | lac, VTY_NEWLINE); |
| 415 | return CMD_WARNING; |
| 416 | } |
| 417 | |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 418 | /* verify that the LACs are unique */ |
| 419 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
| 420 | if (tmp->lac == lac) { |
| 421 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 422 | return CMD_ERR_INCOMPLETE; |
| 423 | } |
| 424 | } |
| 425 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 426 | conf->lac = lac; |
| 427 | |
| 428 | return CMD_SUCCESS; |
| 429 | } |
| 430 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 431 | DEFUN(cfg_lst_imsi_allow, |
| 432 | cfg_lst_imsi_allow_cmd, |
| 433 | "access-list NAME imsi-allow [REGEXP]", |
| 434 | "Allow IMSIs matching the REGEXP\n" |
| 435 | "The name of the access-list\n" |
| 436 | "The regexp of allowed IMSIs\n") |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 437 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 438 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 439 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 440 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 441 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 442 | if (!acc) |
| 443 | return CMD_WARNING; |
| 444 | |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 445 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 446 | if (!entry) |
| 447 | return CMD_WARNING; |
| 448 | |
| 449 | bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 450 | return CMD_SUCCESS; |
| 451 | } |
| 452 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 453 | DEFUN(cfg_lst_imsi_deny, |
| 454 | cfg_lst_imsi_deny_cmd, |
| 455 | "access-list NAME imsi-deny [REGEXP]", |
| 456 | "Allow IMSIs matching the REGEXP\n" |
| 457 | "The name of the access-list\n" |
| 458 | "The regexp of to be denied IMSIs\n") |
| 459 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 460 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 461 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 462 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 463 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 464 | if (!acc) |
| 465 | return CMD_WARNING; |
| 466 | |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 467 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 468 | if (!entry) |
| 469 | return CMD_WARNING; |
| 470 | |
| 471 | bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 472 | return CMD_SUCCESS; |
| 473 | } |
| 474 | |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 475 | /* naming to follow Zebra... */ |
| 476 | DEFUN(cfg_lst_no, |
| 477 | cfg_lst_no_cmd, |
| 478 | "no access-list NAME", |
| 479 | NO_STR "Remove an access-list by name\n" |
| 480 | "The access-list to remove\n") |
| 481 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 482 | struct bsc_nat_acc_lst *acc; |
| 483 | acc = bsc_nat_acc_lst_find(_nat, argv[0]); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 484 | if (!acc) |
| 485 | return CMD_WARNING; |
| 486 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 487 | bsc_nat_acc_lst_delete(acc); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 488 | return CMD_SUCCESS; |
| 489 | } |
| 490 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 491 | DEFUN(cfg_bsc_acc_lst_name, |
| 492 | cfg_bsc_acc_lst_name_cmd, |
| 493 | "access-list-name NAME", |
| 494 | "Set the name of the access list to use.\n" |
| 495 | "The name of the to be used access list.") |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 496 | { |
| 497 | struct bsc_config *conf = vty->index; |
| 498 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 499 | if (conf->acc_lst_name) |
| 500 | talloc_free(conf->acc_lst_name); |
| 501 | conf->acc_lst_name = talloc_strdup(conf, argv[0]); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 502 | return CMD_SUCCESS; |
| 503 | } |
| 504 | |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 505 | DEFUN(cfg_bsc_paging, |
| 506 | cfg_bsc_paging_cmd, |
| 507 | "paging forbidden (0|1)", |
| 508 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 509 | { |
| 510 | struct bsc_config *conf = vty->index; |
| 511 | |
Holger Hans Peter Freyther | e6ac5de | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 512 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 513 | conf->forbid_paging = 1; |
| 514 | else |
| 515 | conf->forbid_paging = 0; |
| 516 | |
| 517 | return CMD_SUCCESS; |
| 518 | } |
| 519 | |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 520 | DEFUN(cfg_bsc_desc, |
| 521 | cfg_bsc_desc_cmd, |
| 522 | "description DESC", |
| 523 | "Provide a description for the given BSC.") |
| 524 | { |
| 525 | struct bsc_config *conf = vty->index; |
| 526 | |
| 527 | if (conf->description) |
| 528 | talloc_free(conf->description); |
| 529 | conf->description = talloc_strdup(conf, argv[0]); |
| 530 | return CMD_SUCCESS; |
| 531 | } |
| 532 | |
Holger Hans Peter Freyther | 6ad646a | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 533 | DEFUN(test_regex, test_regex_cmd, |
| 534 | "test regex PATTERN STRING", |
| 535 | "Check if the string is matching the current pattern.") |
| 536 | { |
| 537 | regex_t reg; |
| 538 | char *str = NULL; |
| 539 | |
| 540 | memset(®, 0, sizeof(reg)); |
| 541 | bsc_parse_reg(_nat, ®, &str, 1, argv); |
| 542 | |
| 543 | vty_out(vty, "String matches allow pattern: %d%s", |
| 544 | regexec(®, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE); |
| 545 | |
| 546 | talloc_free(str); |
| 547 | regfree(®); |
| 548 | return CMD_SUCCESS; |
| 549 | } |
| 550 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 551 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 552 | { |
| 553 | _nat = nat; |
| 554 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 555 | /* show commands */ |
Holger Hans Peter Freyther | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 556 | install_element_ve(&show_sccp_cmd); |
| 557 | install_element_ve(&show_bsc_cmd); |
| 558 | install_element_ve(&show_bsc_cfg_cmd); |
| 559 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 560 | install_element_ve(&show_stats_lac_cmd); |
Holger Hans Peter Freyther | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 561 | install_element_ve(&close_bsc_cmd); |
| 562 | install_element_ve(&show_msc_cmd); |
| 563 | install_element_ve(&test_regex_cmd); |
Holger Hans Peter Freyther | b372fad | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 564 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 565 | /* nat group */ |
| 566 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 567 | install_node(&nat_node, config_write_nat); |
| 568 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | b4b5205 | 2010-06-17 14:39:15 +0800 | [diff] [blame] | 569 | install_element(NAT_NODE, &ournode_exit_cmd); |
| 570 | install_element(NAT_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 571 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 572 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 573 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 574 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 575 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | 6e88b17 | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 576 | install_element(NAT_NODE, &cfg_nat_token_cmd); |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 577 | install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd); |
Holger Hans Peter Freyther | 9d42d32 | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 578 | install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 579 | install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd); |
| 580 | |
| 581 | /* access-list */ |
| 582 | install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd); |
| 583 | install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 584 | install_element(NAT_NODE, &cfg_lst_no_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 585 | |
| 586 | /* BSC subgroups */ |
| 587 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 588 | install_node(&bsc_node, config_write_bsc); |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 589 | install_default(NAT_BSC_NODE); |
| 590 | install_element(NAT_BSC_NODE, &ournode_exit_cmd); |
| 591 | install_element(NAT_BSC_NODE, &ournode_end_cmd); |
| 592 | install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd); |
| 593 | install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd); |
| 594 | install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd); |
| 595 | install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd); |
| 596 | install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 597 | |
Holger Hans Peter Freyther | 3660e4d | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 598 | mgcp_vty_init(); |
| 599 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 600 | return 0; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /* called by the telnet interface... we have our own init above */ |
| 605 | void bsc_vty_init() |
| 606 | {} |