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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Holger Hans Peter Freyther | 1398f13 | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 21 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 22 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | c2b31ed | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 23 | #include <openbsc/bsc_nat_sccp.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 | 0d8330c | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 31 | #include <osmocore/utils.h> |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 32 | |
Harald Welte | d5db12c | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 33 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 9a85ef3 | 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 | 7b4a53d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 46 | NAT_BSC_NODE, |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 47 | "%s(bsc)#", |
| 48 | 1, |
| 49 | }; |
| 50 | |
Holger Hans Peter Freyther | d77c817 | 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 | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 65 | static int config_write_nat(struct vty *vty) |
| 66 | { |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 67 | struct bsc_nat_acc_lst *lst; |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 68 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 69 | vty_out(vty, "nat%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | a88742c | 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 | 8139553 | 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 | da35a8d | 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 | e635dab | 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 | 6b77107 | 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 | 8affef5 | 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); |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 80 | if (_nat->ussd_lst_name) |
| 81 | vty_out(vty, " ussd-list-name %s%s", _nat->ussd_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 82 | if (_nat->ussd_query) |
| 83 | vty_out(vty, " ussd-query %s%s", _nat->ussd_query, VTY_NEWLINE); |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 84 | if (_nat->ussd_token) |
| 85 | vty_out(vty, " ussd-token %s%s", _nat->ussd_token, VTY_NEWLINE); |
| 86 | if (_nat->ussd_local) |
| 87 | vty_out(vty, " ussd-local-ip %s%s", _nat->ussd_local, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 88 | |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 89 | if (_nat->num_rewr_name) |
| 90 | vty_out(vty, " number-rewrite %s%s", _nat->num_rewr_name, VTY_NEWLINE); |
| 91 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 92 | llist_for_each_entry(lst, &_nat->access_lists, list) { |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 93 | write_acc_lst(vty, lst); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 94 | } |
| 95 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 96 | return CMD_SUCCESS; |
| 97 | } |
| 98 | |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 99 | static void dump_lac(struct vty *vty, struct bsc_config *cfg) |
| 100 | { |
| 101 | struct bsc_lac_entry *lac; |
| 102 | llist_for_each_entry(lac, &cfg->lac_list, entry) |
| 103 | vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE); |
| 104 | } |
| 105 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 106 | static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc) |
| 107 | { |
| 108 | vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE); |
| 109 | vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 110 | dump_lac(vty, bsc); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 111 | 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] | 112 | if (bsc->description) |
| 113 | vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 114 | if (bsc->acc_lst_name) |
Holger Hans Peter Freyther | 27d36de | 2010-06-08 11:18:26 +0800 | [diff] [blame] | 115 | 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] | 116 | } |
| 117 | |
| 118 | static int config_write_bsc(struct vty *vty) |
| 119 | { |
| 120 | struct bsc_config *bsc; |
| 121 | |
| 122 | llist_for_each_entry(bsc, &_nat->bsc_configs, entry) |
| 123 | config_write_bsc_single(vty, bsc); |
| 124 | return CMD_SUCCESS; |
| 125 | } |
| 126 | |
| 127 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 128 | DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", |
| 129 | SHOW_STR "Display information about current SCCP connections") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 130 | { |
| 131 | struct sccp_connections *con; |
Holger Hans Peter Freyther | 85804a8 | 2010-09-15 19:01:31 +0800 | [diff] [blame] | 132 | vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 4bd2294 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 133 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 134 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 135 | vty_out(vty, "For BSC Nr: %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] | 136 | con->bsc->cfg ? con->bsc->cfg->nr : -1, |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 137 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 138 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 4bd2294 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 139 | con->has_remote_ref, |
| 140 | sccp_src_ref_to_int(&con->remote_ref), |
Holger Hans Peter Freyther | f4b3439 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 141 | con->msc_endp, con->bsc_endp, |
Holger Hans Peter Freyther | 234d312 | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 142 | bsc_con_type_to_string(con->con_type), |
Holger Hans Peter Freyther | 32d3436 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 143 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | return CMD_SUCCESS; |
| 147 | } |
| 148 | |
Holger Hans Peter Freyther | 01a0b1b | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 149 | DEFUN(show_bsc, show_bsc_cmd, "show bsc connections", |
| 150 | SHOW_STR "Display information about current BSCs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 151 | { |
| 152 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 153 | struct sockaddr_in sock; |
| 154 | socklen_t len = sizeof(sock); |
| 155 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 156 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 157 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 158 | vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s", |
Holger Hans Peter Freyther | 47dd494 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 159 | con->cfg ? con->cfg->nr : -1, |
Holger Hans Peter Freyther | 870663a | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 160 | con->authenticated, con->write_queue.bfd.fd, |
| 161 | inet_ntoa(sock.sin_addr), VTY_NEWLINE); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | return CMD_SUCCESS; |
| 165 | } |
| 166 | |
Holger Hans Peter Freyther | 0d8330c | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 167 | DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR", |
| 168 | SHOW_STR "Display the MGCP status for a given BSC") |
| 169 | { |
| 170 | struct bsc_connection *con; |
| 171 | int nr = atoi(argv[0]); |
| 172 | int i; |
| 173 | |
| 174 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
| 175 | if (!con->cfg) |
| 176 | continue; |
| 177 | if (con->cfg->nr != nr) |
| 178 | continue; |
| 179 | |
| 180 | vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE); |
| 181 | for (i = 1; i < ARRAY_SIZE(con->endpoint_status); ++i) |
| 182 | vty_out(vty, " Endpoint 0x%x %s%s", i, |
| 183 | con->endpoint_status[i] == 0 ? "free" : "allocated", |
| 184 | VTY_NEWLINE); |
| 185 | break; |
| 186 | } |
| 187 | |
| 188 | return CMD_SUCCESS; |
| 189 | } |
| 190 | |
Holger Hans Peter Freyther | ab7539c | 2010-04-22 13:36:46 +0800 | [diff] [blame] | 191 | DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config", |
| 192 | SHOW_STR "Display information about known BSC configs") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 193 | { |
| 194 | struct bsc_config *conf; |
| 195 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 196 | vty_out(vty, "BSC token: '%s' nr: %u%s", |
| 197 | conf->token, conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 198 | if (conf->acc_lst_name) |
| 199 | vty_out(vty, " access-list: %s%s", |
| 200 | conf->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 201 | vty_out(vty, " paging forbidden: %d%s", |
| 202 | conf->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 203 | if (conf->description) |
| 204 | vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE); |
| 205 | else |
| 206 | vty_out(vty, " No description.%s", VTY_NEWLINE); |
| 207 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | return CMD_SUCCESS; |
| 211 | } |
| 212 | |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 213 | static void dump_stat_total(struct vty *vty, struct bsc_nat *nat) |
| 214 | { |
| 215 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 216 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 217 | counter_get(nat->stats.sccp.conn), |
| 218 | counter_get(nat->stats.sccp.calls), VTY_NEWLINE); |
| 219 | vty_out(vty, " MSC Connections %lu%s", |
| 220 | counter_get(nat->stats.msc.reconn), VTY_NEWLINE); |
Holger Hans Peter Freyther | cbfd098 | 2010-08-04 02:34:10 +0800 | [diff] [blame] | 221 | vty_out(vty, " MSC Connected: %d%s", |
| 222 | nat->msc_con->is_connected, VTY_NEWLINE); |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 223 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 224 | counter_get(nat->stats.bsc.reconn), |
| 225 | counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 226 | } |
| 227 | |
| 228 | static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf) |
| 229 | { |
Holger Hans Peter Freyther | f21e453 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 230 | int connected = 0; |
| 231 | struct bsc_connection *con; |
| 232 | |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 233 | vty_out(vty, " BSC nr: %d%s", |
| 234 | conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 235 | vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg); |
Holger Hans Peter Freyther | f21e453 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 236 | |
| 237 | llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) { |
| 238 | if (con->cfg != conf) |
| 239 | continue; |
| 240 | connected = 1; |
| 241 | break; |
| 242 | } |
| 243 | |
Holger Hans Peter Freyther | 03a0ad0 | 2010-08-04 02:29:03 +0800 | [diff] [blame] | 244 | vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE); |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 247 | DEFUN(show_stats, |
| 248 | show_stats_cmd, |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 249 | "show statistics [NR]", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 250 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 251 | { |
| 252 | struct bsc_config *conf; |
| 253 | |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 254 | int nr = -1; |
| 255 | |
| 256 | if (argc == 1) |
| 257 | nr = atoi(argv[0]); |
| 258 | |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 259 | dump_stat_total(vty, _nat); |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 260 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 261 | if (argc == 1 && nr != conf->nr) |
| 262 | continue; |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 263 | dump_stat_bsc(vty, conf); |
| 264 | } |
Holger Hans Peter Freyther | 314191d | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 265 | |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 266 | return CMD_SUCCESS; |
| 267 | } |
| 268 | |
| 269 | DEFUN(show_stats_lac, |
| 270 | show_stats_lac_cmd, |
| 271 | "show statistics-by-lac <0-65535>", |
| 272 | SHOW_STR "Display network statistics by lac\n" |
| 273 | "The lac of the BSC\n") |
| 274 | { |
| 275 | int lac; |
| 276 | struct bsc_config *conf; |
| 277 | |
| 278 | lac = atoi(argv[0]); |
| 279 | |
| 280 | dump_stat_total(vty, _nat); |
| 281 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 282 | if (!bsc_config_handles_lac(conf, lac)) |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 283 | continue; |
| 284 | dump_stat_bsc(vty, conf); |
Holger Hans Peter Freyther | bcfebb2 | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | return CMD_SUCCESS; |
| 288 | } |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 289 | |
Holger Hans Peter Freyther | aad82ce | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 290 | DEFUN(show_msc, |
| 291 | show_msc_cmd, |
| 292 | "show msc connection", |
| 293 | SHOW_STR "Show the status of the MSC connection.") |
| 294 | { |
| 295 | if (!_nat->msc_con) { |
| 296 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 297 | return CMD_WARNING; |
| 298 | } |
| 299 | |
| 300 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 301 | _nat->msc_con->ip, _nat->msc_con->port, |
| 302 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 303 | return CMD_SUCCESS; |
| 304 | } |
| 305 | |
Holger Hans Peter Freyther | 2f9dcf0 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 306 | DEFUN(close_bsc, |
| 307 | close_bsc_cmd, |
| 308 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 309 | "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] | 310 | { |
| 311 | struct bsc_connection *bsc; |
| 312 | int bsc_nr = atoi(argv[0]); |
| 313 | |
| 314 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 315 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 316 | continue; |
| 317 | bsc_close_connection(bsc); |
| 318 | break; |
| 319 | } |
| 320 | |
| 321 | return CMD_SUCCESS; |
| 322 | } |
| 323 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 324 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 325 | { |
| 326 | vty->index = _nat; |
| 327 | vty->node = NAT_NODE; |
| 328 | |
| 329 | return CMD_SUCCESS; |
| 330 | } |
| 331 | |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 332 | DEFUN(cfg_nat_msc_ip, |
| 333 | cfg_nat_msc_ip_cmd, |
Holger Hans Peter Freyther | d8b8206 | 2010-05-14 02:36:42 +0800 | [diff] [blame] | 334 | "msc ip A.B.C.D", |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 335 | "Set the IP address of the MSC.") |
| 336 | { |
| 337 | bsc_nat_set_msc_ip(_nat, argv[0]); |
| 338 | return CMD_SUCCESS; |
| 339 | } |
| 340 | |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 341 | DEFUN(cfg_nat_msc_port, |
| 342 | cfg_nat_msc_port_cmd, |
| 343 | "msc port <1-65500>", |
| 344 | "Set the port of the MSC.") |
| 345 | { |
| 346 | _nat->msc_port = atoi(argv[0]); |
| 347 | return CMD_SUCCESS; |
| 348 | } |
| 349 | |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 350 | DEFUN(cfg_nat_auth_time, |
| 351 | cfg_nat_auth_time_cmd, |
| 352 | "timeout auth <1-256>", |
| 353 | "The time to wait for an auth response.") |
| 354 | { |
| 355 | _nat->auth_timeout = atoi(argv[0]); |
| 356 | return CMD_SUCCESS; |
| 357 | } |
| 358 | |
| 359 | DEFUN(cfg_nat_ping_time, |
| 360 | cfg_nat_ping_time_cmd, |
| 361 | "timeout ping NR", |
| 362 | "Send a ping every NR seconds. Negative to disable.") |
| 363 | { |
| 364 | _nat->ping_timeout = atoi(argv[0]); |
| 365 | return CMD_SUCCESS; |
| 366 | } |
| 367 | |
| 368 | DEFUN(cfg_nat_pong_time, |
| 369 | cfg_nat_pong_time_cmd, |
| 370 | "timeout pong NR", |
| 371 | "Wait NR seconds for the PONG response. Should be smaller than ping.") |
| 372 | { |
| 373 | _nat->pong_timeout = atoi(argv[0]); |
| 374 | return CMD_SUCCESS; |
| 375 | } |
| 376 | |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 377 | DEFUN(cfg_nat_token, cfg_nat_token_cmd, |
| 378 | "token TOKEN", |
| 379 | "Set a token for the NAT") |
| 380 | { |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 381 | bsc_replace_string(_nat, &_nat->token, argv[0]); |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 382 | return CMD_SUCCESS; |
| 383 | } |
| 384 | |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 385 | DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd, |
| 386 | "ip-dscp <0-255>", |
| 387 | "Set the IP DSCP for the BSCs to use\n" "Set the IP_TOS attribute") |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 388 | { |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 389 | _nat->bsc_ip_dscp = atoi(argv[0]); |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 390 | return CMD_SUCCESS; |
| 391 | } |
| 392 | |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 393 | ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd, |
| 394 | "ip-tos <0-255>", |
| 395 | "Use ip-dscp in the future.\n" "Set the DSCP\n") |
| 396 | |
| 397 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 398 | DEFUN(cfg_nat_acc_lst_name, |
| 399 | cfg_nat_acc_lst_name_cmd, |
| 400 | "access-list-name NAME", |
| 401 | "Set the name of the access list to use.\n" |
| 402 | "The name of the to be used access list.") |
| 403 | { |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 404 | bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 405 | return CMD_SUCCESS; |
| 406 | } |
| 407 | |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 408 | DEFUN(cfg_nat_number_rewrite, |
| 409 | cfg_nat_number_rewrite_cmd, |
| 410 | "number-rewrite FILENAME", |
| 411 | "Set the file with rewriting rules.\n" "Filename") |
| 412 | { |
| 413 | bsc_replace_string(_nat, &_nat->num_rewr_name, argv[0]); |
| 414 | if (_nat->num_rewr_name) { |
| 415 | if (_nat->num_rewr) |
| 416 | talloc_free(_nat->num_rewr); |
| 417 | _nat->num_rewr = msg_entry_parse(_nat, _nat->num_rewr_name); |
| 418 | return _nat->num_rewr == NULL ? CMD_WARNING : CMD_SUCCESS; |
| 419 | } else { |
| 420 | if (_nat->num_rewr) |
| 421 | talloc_free(_nat->num_rewr); |
| 422 | _nat->num_rewr = NULL; |
| 423 | return CMD_SUCCESS; |
| 424 | } |
| 425 | } |
| 426 | |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 427 | DEFUN(cfg_nat_ussd_lst_name, |
| 428 | cfg_nat_ussd_lst_name_cmd, |
| 429 | "ussd-list-name NAME", |
| 430 | "Set the name of the access list to check for IMSIs for USSD message\n" |
| 431 | "The name of the access list for HLR USSD handling") |
| 432 | { |
Holger Hans Peter Freyther | 64b1292 | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 433 | bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]); |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 434 | return CMD_SUCCESS; |
| 435 | } |
| 436 | |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 437 | DEFUN(cfg_nat_ussd_query, |
| 438 | cfg_nat_ussd_query_cmd, |
| 439 | "ussd-query QUERY", |
| 440 | "Set the USSD query to match with the ussd-list-name\n" |
| 441 | "The query to match") |
| 442 | { |
Holger Hans Peter Freyther | 64b1292 | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 443 | bsc_replace_string(_nat, &_nat->ussd_query, argv[0]); |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 444 | return CMD_SUCCESS; |
| 445 | } |
| 446 | |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 447 | DEFUN(cfg_nat_ussd_token, |
| 448 | cfg_nat_ussd_token_cmd, |
| 449 | "ussd-token TOKEN", |
| 450 | "Set the token used to identify the USSD module\n" "Secret key\n") |
| 451 | { |
Holger Hans Peter Freyther | 64b1292 | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 452 | bsc_replace_string(_nat, &_nat->ussd_token, argv[0]); |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 453 | return CMD_SUCCESS; |
| 454 | } |
| 455 | |
| 456 | DEFUN(cfg_nat_ussd_local, |
| 457 | cfg_nat_ussd_local_cmd, |
| 458 | "ussd-local-ip A.B.C.D", |
| 459 | "Set the IP to listen for the USSD Provider\n" "IP Address\n") |
| 460 | { |
Holger Hans Peter Freyther | 64b1292 | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 461 | bsc_replace_string(_nat, &_nat->ussd_local, argv[0]); |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 462 | return CMD_SUCCESS; |
| 463 | } |
| 464 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 465 | /* per BSC configuration */ |
Holger Hans Peter Freyther | b9af2fa | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 466 | 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] | 467 | { |
| 468 | int bsc_nr = atoi(argv[0]); |
| 469 | struct bsc_config *bsc; |
| 470 | |
| 471 | if (bsc_nr > _nat->num_bsc) { |
| 472 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 473 | _nat->num_bsc, VTY_NEWLINE); |
| 474 | return CMD_WARNING; |
| 475 | } else if (bsc_nr == _nat->num_bsc) { |
| 476 | /* allocate a new one */ |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 477 | bsc = bsc_config_alloc(_nat, "unknown"); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 478 | } else |
| 479 | bsc = bsc_config_num(_nat, bsc_nr); |
| 480 | |
| 481 | if (!bsc) |
| 482 | return CMD_WARNING; |
| 483 | |
| 484 | vty->index = bsc; |
Holger Hans Peter Freyther | 7b4a53d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 485 | vty->node = NAT_BSC_NODE; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 486 | |
| 487 | return CMD_SUCCESS; |
| 488 | } |
| 489 | |
| 490 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 491 | { |
| 492 | struct bsc_config *conf = vty->index; |
| 493 | |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 494 | bsc_replace_string(conf, &conf->token, argv[0]); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 495 | return CMD_SUCCESS; |
| 496 | } |
| 497 | |
| 498 | 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] | 499 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 500 | { |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 501 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 502 | struct bsc_config *conf = vty->index; |
| 503 | |
| 504 | int lac = atoi(argv[0]); |
| 505 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 506 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 507 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 508 | lac, VTY_NEWLINE); |
| 509 | return CMD_WARNING; |
| 510 | } |
| 511 | |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 512 | /* verify that the LACs are unique */ |
| 513 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 514 | if (bsc_config_handles_lac(tmp, lac)) { |
Holger Hans Peter Freyther | 39ee877 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 515 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 516 | return CMD_ERR_INCOMPLETE; |
| 517 | } |
| 518 | } |
| 519 | |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 520 | bsc_config_add_lac(conf, lac); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 521 | |
| 522 | return CMD_SUCCESS; |
| 523 | } |
| 524 | |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 525 | DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd, |
| 526 | "no location_area_code <0-65535>", |
| 527 | NO_STR "Set the Location Area Code (LAC) of this BSC") |
| 528 | { |
| 529 | int lac = atoi(argv[0]); |
| 530 | struct bsc_config *conf = vty->index; |
| 531 | |
| 532 | bsc_config_del_lac(conf, lac); |
| 533 | return CMD_SUCCESS; |
| 534 | } |
| 535 | |
| 536 | |
| 537 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 538 | DEFUN(cfg_lst_imsi_allow, |
| 539 | cfg_lst_imsi_allow_cmd, |
| 540 | "access-list NAME imsi-allow [REGEXP]", |
| 541 | "Allow IMSIs matching the REGEXP\n" |
| 542 | "The name of the access-list\n" |
| 543 | "The regexp of allowed IMSIs\n") |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 544 | { |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 545 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 546 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 547 | |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 548 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 549 | if (!acc) |
| 550 | return CMD_WARNING; |
| 551 | |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 552 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 553 | if (!entry) |
| 554 | return CMD_WARNING; |
| 555 | |
| 556 | 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] | 557 | return CMD_SUCCESS; |
| 558 | } |
| 559 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 560 | DEFUN(cfg_lst_imsi_deny, |
| 561 | cfg_lst_imsi_deny_cmd, |
| 562 | "access-list NAME imsi-deny [REGEXP]", |
| 563 | "Allow IMSIs matching the REGEXP\n" |
| 564 | "The name of the access-list\n" |
| 565 | "The regexp of to be denied IMSIs\n") |
| 566 | { |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 567 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 568 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 569 | |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 570 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 571 | if (!acc) |
| 572 | return CMD_WARNING; |
| 573 | |
Holger Hans Peter Freyther | d77c817 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 574 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 575 | if (!entry) |
| 576 | return CMD_WARNING; |
| 577 | |
| 578 | 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] | 579 | return CMD_SUCCESS; |
| 580 | } |
| 581 | |
Holger Hans Peter Freyther | e4900a0 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 582 | /* naming to follow Zebra... */ |
| 583 | DEFUN(cfg_lst_no, |
| 584 | cfg_lst_no_cmd, |
| 585 | "no access-list NAME", |
| 586 | NO_STR "Remove an access-list by name\n" |
| 587 | "The access-list to remove\n") |
| 588 | { |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 589 | struct bsc_nat_acc_lst *acc; |
| 590 | acc = bsc_nat_acc_lst_find(_nat, argv[0]); |
Holger Hans Peter Freyther | e4900a0 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 591 | if (!acc) |
| 592 | return CMD_WARNING; |
| 593 | |
Holger Hans Peter Freyther | 29c6703 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 594 | bsc_nat_acc_lst_delete(acc); |
Holger Hans Peter Freyther | e4900a0 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 595 | return CMD_SUCCESS; |
| 596 | } |
| 597 | |
Holger Hans Peter Freyther | 520c1f1 | 2010-09-25 16:25:47 +0800 | [diff] [blame] | 598 | DEFUN(show_acc_lst, |
| 599 | show_acc_lst_cmd, |
| 600 | "show access-list NAME", |
| 601 | SHOW_STR "The name of the access list\n") |
| 602 | { |
| 603 | struct bsc_nat_acc_lst *acc; |
| 604 | acc = bsc_nat_acc_lst_find(_nat, argv[0]); |
| 605 | if (!acc) |
| 606 | return CMD_WARNING; |
| 607 | |
| 608 | vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE); |
| 609 | vty_out_rate_ctr_group(vty, " ", acc->stats); |
| 610 | |
| 611 | return CMD_SUCCESS; |
| 612 | } |
| 613 | |
| 614 | |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 615 | DEFUN(cfg_bsc_acc_lst_name, |
| 616 | cfg_bsc_acc_lst_name_cmd, |
| 617 | "access-list-name NAME", |
| 618 | "Set the name of the access list to use.\n" |
| 619 | "The name of the to be used access list.") |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 620 | { |
| 621 | struct bsc_config *conf = vty->index; |
| 622 | |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 623 | bsc_replace_string(conf, &conf->acc_lst_name, argv[0]); |
Holger Hans Peter Freyther | c16cf27 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 624 | return CMD_SUCCESS; |
| 625 | } |
| 626 | |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 627 | DEFUN(cfg_bsc_paging, |
| 628 | cfg_bsc_paging_cmd, |
| 629 | "paging forbidden (0|1)", |
| 630 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 631 | { |
| 632 | struct bsc_config *conf = vty->index; |
| 633 | |
Holger Hans Peter Freyther | 834f1df | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 634 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 62e5843 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 635 | conf->forbid_paging = 1; |
| 636 | else |
| 637 | conf->forbid_paging = 0; |
| 638 | |
| 639 | return CMD_SUCCESS; |
| 640 | } |
| 641 | |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 642 | DEFUN(cfg_bsc_desc, |
| 643 | cfg_bsc_desc_cmd, |
| 644 | "description DESC", |
| 645 | "Provide a description for the given BSC.") |
| 646 | { |
| 647 | struct bsc_config *conf = vty->index; |
| 648 | |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 649 | bsc_replace_string(conf, &conf->description, argv[0]); |
Holger Hans Peter Freyther | b606101 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 650 | return CMD_SUCCESS; |
| 651 | } |
| 652 | |
Holger Hans Peter Freyther | 52c4ba0 | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 653 | DEFUN(test_regex, test_regex_cmd, |
| 654 | "test regex PATTERN STRING", |
| 655 | "Check if the string is matching the current pattern.") |
| 656 | { |
| 657 | regex_t reg; |
| 658 | char *str = NULL; |
| 659 | |
| 660 | memset(®, 0, sizeof(reg)); |
| 661 | bsc_parse_reg(_nat, ®, &str, 1, argv); |
| 662 | |
| 663 | vty_out(vty, "String matches allow pattern: %d%s", |
| 664 | regexec(®, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE); |
| 665 | |
| 666 | talloc_free(str); |
| 667 | regfree(®); |
| 668 | return CMD_SUCCESS; |
| 669 | } |
| 670 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 671 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 672 | { |
| 673 | _nat = nat; |
| 674 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 675 | /* show commands */ |
Holger Hans Peter Freyther | 1398f13 | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 676 | install_element_ve(&show_sccp_cmd); |
| 677 | install_element_ve(&show_bsc_cmd); |
| 678 | install_element_ve(&show_bsc_cfg_cmd); |
| 679 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | c95cfda | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 680 | install_element_ve(&show_stats_lac_cmd); |
Holger Hans Peter Freyther | 1398f13 | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 681 | install_element_ve(&close_bsc_cmd); |
| 682 | install_element_ve(&show_msc_cmd); |
| 683 | install_element_ve(&test_regex_cmd); |
Holger Hans Peter Freyther | 0d8330c | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 684 | install_element_ve(&show_bsc_mgcp_cmd); |
Holger Hans Peter Freyther | 520c1f1 | 2010-09-25 16:25:47 +0800 | [diff] [blame] | 685 | install_element_ve(&show_acc_lst_cmd); |
Holger Hans Peter Freyther | 5f291d5 | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 686 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 687 | /* nat group */ |
| 688 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 689 | install_node(&nat_node, config_write_nat); |
| 690 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | 9c78697 | 2010-06-17 14:39:15 +0800 | [diff] [blame] | 691 | install_element(NAT_NODE, &ournode_exit_cmd); |
| 692 | install_element(NAT_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | a88742c | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 693 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | 8139553 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 694 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | da35a8d | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 695 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 696 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 697 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | e635dab | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 698 | install_element(NAT_NODE, &cfg_nat_token_cmd); |
Holger Hans Peter Freyther | 6b77107 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 699 | install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd); |
Holger Hans Peter Freyther | 078321a | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 700 | install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 701 | install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd); |
Holger Hans Peter Freyther | d1effd8 | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 702 | install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd); |
Holger Hans Peter Freyther | c1578bc | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 703 | install_element(NAT_NODE, &cfg_nat_ussd_query_cmd); |
Holger Hans Peter Freyther | e393f27 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 704 | install_element(NAT_NODE, &cfg_nat_ussd_token_cmd); |
| 705 | install_element(NAT_NODE, &cfg_nat_ussd_local_cmd); |
Holger Hans Peter Freyther | 8affef5 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 706 | |
| 707 | /* access-list */ |
| 708 | install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd); |
| 709 | install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd); |
Holger Hans Peter Freyther | e4900a0 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 710 | install_element(NAT_NODE, &cfg_lst_no_cmd); |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 711 | |
Holger Hans Peter Freyther | 7642439 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 712 | /* number rewriting */ |
| 713 | install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd); |
| 714 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 715 | /* BSC subgroups */ |
| 716 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 717 | install_node(&bsc_node, config_write_bsc); |
Holger Hans Peter Freyther | 7b4a53d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 718 | install_default(NAT_BSC_NODE); |
| 719 | install_element(NAT_BSC_NODE, &ournode_exit_cmd); |
| 720 | install_element(NAT_BSC_NODE, &ournode_end_cmd); |
| 721 | install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd); |
| 722 | install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd); |
Holger Hans Peter Freyther | 0bd60f3 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 723 | install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd); |
Holger Hans Peter Freyther | 7b4a53d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 724 | install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd); |
| 725 | install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd); |
| 726 | 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] | 727 | |
Holger Hans Peter Freyther | f7d3335 | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 728 | mgcp_vty_init(); |
| 729 | |
Holger Hans Peter Freyther | 9a85ef3 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 730 | return 0; |
| 731 | } |
| 732 | |
| 733 | |
| 734 | /* called by the telnet interface... we have our own init above */ |
Holger Hans Peter Freyther | 6c79a68 | 2011-02-24 14:33:09 +0100 | [diff] [blame] | 735 | int bsc_vty_init(void) |
| 736 | { |
| 737 | return 0; |
| 738 | } |