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