Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 1 | /* OpenBSC NAT interface to quagga VTY */ |
Holger Hans Peter Freyther | 9a9b3d1 | 2011-04-01 17:32:21 +0200 | [diff] [blame] | 2 | /* (C) 2010-2011 by Holger Hans Peter Freyther |
| 3 | * (C) 2010-2011 by On-Waves |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 4 | * All Rights Reserved |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 0e3e88e | 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 | 5e54788 | 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 | 0e3e88e | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 15 | * |
Harald Welte | 0e3e88e | 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 | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Holger Hans Peter Freyther | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 21 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 22 | #include <openbsc/bsc_nat.h> |
Holger Hans Peter Freyther | 4a9dd3b | 2010-07-31 05:17:17 +0800 | [diff] [blame] | 23 | #include <openbsc/bsc_nat_sccp.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 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 29 | #include <osmocom/core/talloc.h> |
| 30 | #include <osmocom/core/rate_ctr.h> |
| 31 | #include <osmocom/core/utils.h> |
Pablo Neira Ayuso | 36ad9a4 | 2011-03-09 13:36:32 +0100 | [diff] [blame] | 32 | #include <osmocom/vty/logging.h> |
Pablo Neira Ayuso | 3d31c3a | 2011-03-28 19:35:00 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/misc.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 34 | |
Harald Welte | 90e5eae | 2010-08-03 15:11:51 +0200 | [diff] [blame] | 35 | #include <osmocom/sccp/sccp.h> |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 36 | |
| 37 | #include <stdlib.h> |
| 38 | |
| 39 | static struct bsc_nat *_nat; |
| 40 | |
| 41 | static struct cmd_node nat_node = { |
| 42 | NAT_NODE, |
| 43 | "%s(nat)#", |
| 44 | 1, |
| 45 | }; |
| 46 | |
| 47 | static struct cmd_node bsc_node = { |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 48 | NAT_BSC_NODE, |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 49 | "%s(bsc)#", |
| 50 | 1, |
| 51 | }; |
| 52 | |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 53 | static void write_acc_lst(struct vty *vty, struct bsc_nat_acc_lst *lst) |
| 54 | { |
| 55 | struct bsc_nat_acc_lst_entry *entry; |
| 56 | |
| 57 | llist_for_each_entry(entry, &lst->fltr_list, list) { |
| 58 | if (entry->imsi_allow) |
| 59 | vty_out(vty, " access-list %s imsi-allow %s%s", |
| 60 | lst->name, entry->imsi_allow, VTY_NEWLINE); |
| 61 | if (entry->imsi_deny) |
| 62 | vty_out(vty, " access-list %s imsi-deny %s%s", |
| 63 | lst->name, entry->imsi_deny, VTY_NEWLINE); |
| 64 | } |
| 65 | } |
| 66 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 67 | static int config_write_nat(struct vty *vty) |
| 68 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 69 | struct bsc_nat_acc_lst *lst; |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 70 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 71 | vty_out(vty, "nat%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 72 | 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] | 73 | 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] | 74 | vty_out(vty, " timeout auth %d%s", _nat->auth_timeout, VTY_NEWLINE); |
| 75 | vty_out(vty, " timeout ping %d%s", _nat->ping_timeout, VTY_NEWLINE); |
| 76 | 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] | 77 | if (_nat->token) |
| 78 | vty_out(vty, " token %s%s", _nat->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 79 | 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] | 80 | if (_nat->acc_lst_name) |
| 81 | vty_out(vty, " access-list-name %s%s", _nat->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | de021be | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 82 | if (_nat->ussd_lst_name) |
| 83 | vty_out(vty, " ussd-list-name %s%s", _nat->ussd_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | daf5417 | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 84 | if (_nat->ussd_query) |
| 85 | vty_out(vty, " ussd-query %s%s", _nat->ussd_query, VTY_NEWLINE); |
Holger Hans Peter Freyther | 552fc16 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 86 | if (_nat->ussd_token) |
| 87 | vty_out(vty, " ussd-token %s%s", _nat->ussd_token, VTY_NEWLINE); |
| 88 | if (_nat->ussd_local) |
| 89 | vty_out(vty, " ussd-local-ip %s%s", _nat->ussd_local, VTY_NEWLINE); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 90 | |
Holger Hans Peter Freyther | 2945ee9 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 91 | if (_nat->num_rewr_name) |
| 92 | vty_out(vty, " number-rewrite %s%s", _nat->num_rewr_name, VTY_NEWLINE); |
| 93 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 94 | llist_for_each_entry(lst, &_nat->access_lists, list) { |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 95 | write_acc_lst(vty, lst); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 96 | } |
| 97 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 98 | return CMD_SUCCESS; |
| 99 | } |
| 100 | |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 101 | static void dump_lac(struct vty *vty, struct bsc_config *cfg) |
| 102 | { |
| 103 | struct bsc_lac_entry *lac; |
| 104 | llist_for_each_entry(lac, &cfg->lac_list, entry) |
| 105 | vty_out(vty, " location_area_code %u%s", lac->lac, VTY_NEWLINE); |
| 106 | } |
| 107 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 108 | static void config_write_bsc_single(struct vty *vty, struct bsc_config *bsc) |
| 109 | { |
| 110 | vty_out(vty, " bsc %u%s", bsc->nr, VTY_NEWLINE); |
| 111 | vty_out(vty, " token %s%s", bsc->token, VTY_NEWLINE); |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 112 | dump_lac(vty, bsc); |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 113 | 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] | 114 | if (bsc->description) |
| 115 | vty_out(vty, " description %s%s", bsc->description, VTY_NEWLINE); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 116 | if (bsc->acc_lst_name) |
Holger Hans Peter Freyther | 409a370 | 2010-06-08 11:18:26 +0800 | [diff] [blame] | 117 | vty_out(vty, " access-list-name %s%s", bsc->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 118 | vty_out(vty, " max-endpoints %d%s", bsc->max_endpoints, VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static int config_write_bsc(struct vty *vty) |
| 122 | { |
| 123 | struct bsc_config *bsc; |
| 124 | |
| 125 | llist_for_each_entry(bsc, &_nat->bsc_configs, entry) |
| 126 | config_write_bsc_single(vty, bsc); |
| 127 | return CMD_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | |
Holger Hans Peter Freyther | 17f8c95 | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 131 | DEFUN(show_sccp, show_sccp_cmd, "show sccp connections", |
| 132 | SHOW_STR "Display information about current SCCP connections") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 133 | { |
| 134 | struct sccp_connections *con; |
Holger Hans Peter Freyther | c3fd3b7 | 2010-09-15 19:01:31 +0800 | [diff] [blame] | 135 | vty_out(vty, "Listing all open SCCP connections%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 136 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 137 | llist_for_each_entry(con, &_nat->sccp_connections, list_entry) { |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 138 | 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 | bfcf519 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 139 | con->bsc->cfg ? con->bsc->cfg->nr : -1, |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 140 | sccp_src_ref_to_int(&con->real_ref), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 141 | sccp_src_ref_to_int(&con->patched_ref), |
Holger Hans Peter Freyther | 0a3a853 | 2010-04-27 13:11:18 +0800 | [diff] [blame] | 142 | con->has_remote_ref, |
| 143 | sccp_src_ref_to_int(&con->remote_ref), |
Holger Hans Peter Freyther | 7089d53 | 2010-08-28 16:08:39 +0800 | [diff] [blame] | 144 | con->msc_endp, con->bsc_endp, |
Holger Hans Peter Freyther | 8e69f0c | 2010-05-16 02:06:11 +0800 | [diff] [blame] | 145 | bsc_con_type_to_string(con->con_type), |
Holger Hans Peter Freyther | 32aba23 | 2010-04-05 10:10:33 +0200 | [diff] [blame] | 146 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | return CMD_SUCCESS; |
| 150 | } |
| 151 | |
Holger Hans Peter Freyther | 17f8c95 | 2010-04-19 16:06:43 +0800 | [diff] [blame] | 152 | DEFUN(show_bsc, show_bsc_cmd, "show bsc connections", |
| 153 | SHOW_STR "Display information about current BSCs") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 154 | { |
| 155 | struct bsc_connection *con; |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 156 | struct sockaddr_in sock; |
| 157 | socklen_t len = sizeof(sock); |
| 158 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 159 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 160 | getpeername(con->write_queue.bfd.fd, (struct sockaddr *) &sock, &len); |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 161 | vty_out(vty, "BSC nr: %d auth: %d fd: %d peername: %s%s", |
Holger Hans Peter Freyther | bfcf519 | 2010-04-06 15:11:34 +0200 | [diff] [blame] | 162 | con->cfg ? con->cfg->nr : -1, |
Holger Hans Peter Freyther | 9e53e97 | 2010-04-08 10:35:20 +0200 | [diff] [blame] | 163 | con->authenticated, con->write_queue.bfd.fd, |
| 164 | inet_ntoa(sock.sin_addr), VTY_NEWLINE); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | return CMD_SUCCESS; |
| 168 | } |
| 169 | |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 170 | DEFUN(show_bsc_mgcp, show_bsc_mgcp_cmd, "show bsc mgcp NR", |
| 171 | SHOW_STR "Display the MGCP status for a given BSC") |
| 172 | { |
| 173 | struct bsc_connection *con; |
| 174 | int nr = atoi(argv[0]); |
Holger Hans Peter Freyther | 473b38a | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 175 | int i, j, endp; |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 176 | |
| 177 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 178 | int max; |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 179 | if (!con->cfg) |
| 180 | continue; |
| 181 | if (con->cfg->nr != nr) |
| 182 | continue; |
| 183 | |
Holger Hans Peter Freyther | 9575164 | 2011-02-25 17:09:07 +0100 | [diff] [blame] | 184 | /* this bsc has no audio endpoints yet */ |
| 185 | if (!con->_endpoint_status) |
| 186 | continue; |
| 187 | |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 188 | vty_out(vty, "MGCP Status for %d%s", con->cfg->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 189 | max = bsc_mgcp_nr_multiplexes(con->max_endpoints); |
| 190 | for (i = 0; i < max; ++i) { |
Holger Hans Peter Freyther | 473b38a | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 191 | for (j = 0; j < 32; ++j) { |
| 192 | endp = mgcp_timeslot_to_endpoint(i, j); |
| 193 | vty_out(vty, " Endpoint 0x%x %s%s", endp, |
| 194 | con->_endpoint_status[endp] == 0 |
| 195 | ? "free" : "allocated", |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 196 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 473b38a | 2011-02-26 11:38:00 +0100 | [diff] [blame] | 197 | } |
| 198 | } |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 199 | break; |
| 200 | } |
| 201 | |
| 202 | return CMD_SUCCESS; |
| 203 | } |
| 204 | |
Holger Hans Peter Freyther | 936aed7 | 2010-04-22 13:36:46 +0800 | [diff] [blame] | 205 | DEFUN(show_bsc_cfg, show_bsc_cfg_cmd, "show bsc config", |
| 206 | SHOW_STR "Display information about known BSC configs") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 207 | { |
| 208 | struct bsc_config *conf; |
| 209 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 210 | vty_out(vty, "BSC token: '%s' nr: %u%s", |
| 211 | conf->token, conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 212 | if (conf->acc_lst_name) |
| 213 | vty_out(vty, " access-list: %s%s", |
| 214 | conf->acc_lst_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 215 | vty_out(vty, " paging forbidden: %d%s", |
| 216 | conf->forbid_paging, VTY_NEWLINE); |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 217 | if (conf->description) |
| 218 | vty_out(vty, " description: %s%s", conf->description, VTY_NEWLINE); |
| 219 | else |
| 220 | vty_out(vty, " No description.%s", VTY_NEWLINE); |
| 221 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | return CMD_SUCCESS; |
| 225 | } |
| 226 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 227 | static void dump_stat_total(struct vty *vty, struct bsc_nat *nat) |
| 228 | { |
| 229 | vty_out(vty, "NAT statistics%s", VTY_NEWLINE); |
| 230 | vty_out(vty, " SCCP Connections %lu total, %lu calls%s", |
| 231 | counter_get(nat->stats.sccp.conn), |
| 232 | counter_get(nat->stats.sccp.calls), VTY_NEWLINE); |
| 233 | vty_out(vty, " MSC Connections %lu%s", |
| 234 | counter_get(nat->stats.msc.reconn), VTY_NEWLINE); |
Holger Hans Peter Freyther | 9ecec6d | 2010-08-04 02:34:10 +0800 | [diff] [blame] | 235 | vty_out(vty, " MSC Connected: %d%s", |
| 236 | nat->msc_con->is_connected, VTY_NEWLINE); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 237 | vty_out(vty, " BSC Connections %lu total, %lu auth failed.%s", |
| 238 | counter_get(nat->stats.bsc.reconn), |
| 239 | counter_get(nat->stats.bsc.auth_fail), VTY_NEWLINE); |
| 240 | } |
| 241 | |
| 242 | static void dump_stat_bsc(struct vty *vty, struct bsc_config *conf) |
| 243 | { |
Holger Hans Peter Freyther | e410758 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 244 | int connected = 0; |
| 245 | struct bsc_connection *con; |
| 246 | |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 247 | vty_out(vty, " BSC nr: %d%s", |
| 248 | conf->nr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 249 | vty_out_rate_ctr_group(vty, " ", conf->stats.ctrg); |
Holger Hans Peter Freyther | e410758 | 2010-07-22 20:37:35 +0800 | [diff] [blame] | 250 | |
| 251 | llist_for_each_entry(con, &conf->nat->bsc_connections, list_entry) { |
| 252 | if (con->cfg != conf) |
| 253 | continue; |
| 254 | connected = 1; |
| 255 | break; |
| 256 | } |
| 257 | |
Holger Hans Peter Freyther | 869f117 | 2010-08-04 02:29:03 +0800 | [diff] [blame] | 258 | vty_out(vty, " Connected: %d%s", connected, VTY_NEWLINE); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 259 | } |
| 260 | |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 261 | DEFUN(show_stats, |
| 262 | show_stats_cmd, |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 263 | "show statistics [NR]", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 264 | SHOW_STR "Display network statistics") |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 265 | { |
| 266 | struct bsc_config *conf; |
| 267 | |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 268 | int nr = -1; |
| 269 | |
| 270 | if (argc == 1) |
| 271 | nr = atoi(argv[0]); |
| 272 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 273 | dump_stat_total(vty, _nat); |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 274 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 275 | if (argc == 1 && nr != conf->nr) |
| 276 | continue; |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 277 | dump_stat_bsc(vty, conf); |
| 278 | } |
Holger Hans Peter Freyther | 44d534c | 2010-05-02 18:59:24 +0800 | [diff] [blame] | 279 | |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 280 | return CMD_SUCCESS; |
| 281 | } |
| 282 | |
| 283 | DEFUN(show_stats_lac, |
| 284 | show_stats_lac_cmd, |
| 285 | "show statistics-by-lac <0-65535>", |
| 286 | SHOW_STR "Display network statistics by lac\n" |
| 287 | "The lac of the BSC\n") |
| 288 | { |
| 289 | int lac; |
| 290 | struct bsc_config *conf; |
| 291 | |
| 292 | lac = atoi(argv[0]); |
| 293 | |
| 294 | dump_stat_total(vty, _nat); |
| 295 | llist_for_each_entry(conf, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 296 | if (!bsc_config_handles_lac(conf, lac)) |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 297 | continue; |
| 298 | dump_stat_bsc(vty, conf); |
Holger Hans Peter Freyther | 02e1c7d | 2010-04-12 12:33:27 +0200 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | return CMD_SUCCESS; |
| 302 | } |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 303 | |
Holger Hans Peter Freyther | 8e2e0ac | 2010-05-11 19:07:39 +0800 | [diff] [blame] | 304 | DEFUN(show_msc, |
| 305 | show_msc_cmd, |
| 306 | "show msc connection", |
| 307 | SHOW_STR "Show the status of the MSC connection.") |
| 308 | { |
| 309 | if (!_nat->msc_con) { |
| 310 | vty_out(vty, "The MSC is not yet configured.\n"); |
| 311 | return CMD_WARNING; |
| 312 | } |
| 313 | |
| 314 | vty_out(vty, "MSC on %s:%d is connected: %d%s\n", |
| 315 | _nat->msc_con->ip, _nat->msc_con->port, |
| 316 | _nat->msc_con->is_connected, VTY_NEWLINE); |
| 317 | return CMD_SUCCESS; |
| 318 | } |
| 319 | |
Holger Hans Peter Freyther | 1512dc2 | 2010-04-27 13:21:39 +0800 | [diff] [blame] | 320 | DEFUN(close_bsc, |
| 321 | close_bsc_cmd, |
| 322 | "close bsc connection BSC_NR", |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 323 | "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] | 324 | { |
| 325 | struct bsc_connection *bsc; |
| 326 | int bsc_nr = atoi(argv[0]); |
| 327 | |
| 328 | llist_for_each_entry(bsc, &_nat->bsc_connections, list_entry) { |
| 329 | if (!bsc->cfg || bsc->cfg->nr != bsc_nr) |
| 330 | continue; |
| 331 | bsc_close_connection(bsc); |
| 332 | break; |
| 333 | } |
| 334 | |
| 335 | return CMD_SUCCESS; |
| 336 | } |
| 337 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 338 | DEFUN(cfg_nat, cfg_nat_cmd, "nat", "Configute the NAT") |
| 339 | { |
| 340 | vty->index = _nat; |
| 341 | vty->node = NAT_NODE; |
| 342 | |
| 343 | return CMD_SUCCESS; |
| 344 | } |
| 345 | |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 346 | DEFUN(cfg_nat_msc_ip, |
| 347 | cfg_nat_msc_ip_cmd, |
Holger Hans Peter Freyther | f7cd800 | 2010-05-14 02:36:42 +0800 | [diff] [blame] | 348 | "msc ip A.B.C.D", |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 349 | "Set the IP address of the MSC.") |
| 350 | { |
| 351 | bsc_nat_set_msc_ip(_nat, argv[0]); |
| 352 | return CMD_SUCCESS; |
| 353 | } |
| 354 | |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 355 | DEFUN(cfg_nat_msc_port, |
| 356 | cfg_nat_msc_port_cmd, |
| 357 | "msc port <1-65500>", |
| 358 | "Set the port of the MSC.") |
| 359 | { |
| 360 | _nat->msc_port = atoi(argv[0]); |
| 361 | return CMD_SUCCESS; |
| 362 | } |
| 363 | |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 364 | DEFUN(cfg_nat_auth_time, |
| 365 | cfg_nat_auth_time_cmd, |
| 366 | "timeout auth <1-256>", |
| 367 | "The time to wait for an auth response.") |
| 368 | { |
| 369 | _nat->auth_timeout = atoi(argv[0]); |
| 370 | return CMD_SUCCESS; |
| 371 | } |
| 372 | |
| 373 | DEFUN(cfg_nat_ping_time, |
| 374 | cfg_nat_ping_time_cmd, |
| 375 | "timeout ping NR", |
| 376 | "Send a ping every NR seconds. Negative to disable.") |
| 377 | { |
| 378 | _nat->ping_timeout = atoi(argv[0]); |
| 379 | return CMD_SUCCESS; |
| 380 | } |
| 381 | |
| 382 | DEFUN(cfg_nat_pong_time, |
| 383 | cfg_nat_pong_time_cmd, |
| 384 | "timeout pong NR", |
| 385 | "Wait NR seconds for the PONG response. Should be smaller than ping.") |
| 386 | { |
| 387 | _nat->pong_timeout = atoi(argv[0]); |
| 388 | return CMD_SUCCESS; |
| 389 | } |
| 390 | |
Holger Hans Peter Freyther | 6e88b17 | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 391 | DEFUN(cfg_nat_token, cfg_nat_token_cmd, |
| 392 | "token TOKEN", |
| 393 | "Set a token for the NAT") |
| 394 | { |
Holger Hans Peter Freyther | 7c831f6 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 395 | bsc_replace_string(_nat, &_nat->token, argv[0]); |
Holger Hans Peter Freyther | 6e88b17 | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 396 | return CMD_SUCCESS; |
| 397 | } |
| 398 | |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 399 | DEFUN(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_dscp_cmd, |
| 400 | "ip-dscp <0-255>", |
| 401 | "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] | 402 | { |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 403 | _nat->bsc_ip_dscp = atoi(argv[0]); |
Holger Hans Peter Freyther | 9d42d32 | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 404 | return CMD_SUCCESS; |
| 405 | } |
| 406 | |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 407 | ALIAS_DEPRECATED(cfg_nat_bsc_ip_dscp, cfg_nat_bsc_ip_tos_cmd, |
| 408 | "ip-tos <0-255>", |
| 409 | "Use ip-dscp in the future.\n" "Set the DSCP\n") |
| 410 | |
| 411 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 412 | DEFUN(cfg_nat_acc_lst_name, |
| 413 | cfg_nat_acc_lst_name_cmd, |
| 414 | "access-list-name NAME", |
| 415 | "Set the name of the access list to use.\n" |
| 416 | "The name of the to be used access list.") |
| 417 | { |
Holger Hans Peter Freyther | 7c831f6 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 418 | bsc_replace_string(_nat, &_nat->acc_lst_name, argv[0]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 419 | return CMD_SUCCESS; |
| 420 | } |
| 421 | |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 422 | DEFUN(cfg_nat_no_acc_lst_name, |
| 423 | cfg_nat_no_acc_lst_name_cmd, |
| 424 | "no access-list-name", |
| 425 | NO_STR "Remove the access list from the NAT.\n") |
| 426 | { |
| 427 | if (_nat->acc_lst_name) { |
| 428 | talloc_free(_nat->acc_lst_name); |
| 429 | _nat->acc_lst_name = NULL; |
| 430 | } |
| 431 | |
Holger Hans Peter Freyther | 6fab8a3 | 2011-04-01 16:22:51 +0200 | [diff] [blame] | 432 | return CMD_SUCCESS; |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 433 | } |
| 434 | |
Holger Hans Peter Freyther | 2945ee9 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 435 | DEFUN(cfg_nat_number_rewrite, |
| 436 | cfg_nat_number_rewrite_cmd, |
| 437 | "number-rewrite FILENAME", |
| 438 | "Set the file with rewriting rules.\n" "Filename") |
| 439 | { |
| 440 | bsc_replace_string(_nat, &_nat->num_rewr_name, argv[0]); |
| 441 | if (_nat->num_rewr_name) { |
| 442 | if (_nat->num_rewr) |
| 443 | talloc_free(_nat->num_rewr); |
| 444 | _nat->num_rewr = msg_entry_parse(_nat, _nat->num_rewr_name); |
| 445 | return _nat->num_rewr == NULL ? CMD_WARNING : CMD_SUCCESS; |
| 446 | } else { |
| 447 | if (_nat->num_rewr) |
| 448 | talloc_free(_nat->num_rewr); |
| 449 | _nat->num_rewr = NULL; |
| 450 | return CMD_SUCCESS; |
| 451 | } |
| 452 | } |
| 453 | |
Holger Hans Peter Freyther | de021be | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 454 | DEFUN(cfg_nat_ussd_lst_name, |
| 455 | cfg_nat_ussd_lst_name_cmd, |
| 456 | "ussd-list-name NAME", |
| 457 | "Set the name of the access list to check for IMSIs for USSD message\n" |
| 458 | "The name of the access list for HLR USSD handling") |
| 459 | { |
Holger Hans Peter Freyther | 18625ac | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 460 | bsc_replace_string(_nat, &_nat->ussd_lst_name, argv[0]); |
Holger Hans Peter Freyther | de021be | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 461 | return CMD_SUCCESS; |
| 462 | } |
| 463 | |
Holger Hans Peter Freyther | daf5417 | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 464 | DEFUN(cfg_nat_ussd_query, |
| 465 | cfg_nat_ussd_query_cmd, |
Holger Hans Peter Freyther | 9a9b3d1 | 2011-04-01 17:32:21 +0200 | [diff] [blame] | 466 | "ussd-query REGEXP", |
Holger Hans Peter Freyther | daf5417 | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 467 | "Set the USSD query to match with the ussd-list-name\n" |
| 468 | "The query to match") |
| 469 | { |
Holger Hans Peter Freyther | dd7e85b | 2011-04-04 19:19:26 +0200 | [diff] [blame] | 470 | if (bsc_parse_reg(_nat, &_nat->ussd_query_re, &_nat->ussd_query, argc, argv) != 0) |
| 471 | return CMD_WARNING; |
Holger Hans Peter Freyther | daf5417 | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 472 | return CMD_SUCCESS; |
| 473 | } |
| 474 | |
Holger Hans Peter Freyther | 552fc16 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 475 | DEFUN(cfg_nat_ussd_token, |
| 476 | cfg_nat_ussd_token_cmd, |
| 477 | "ussd-token TOKEN", |
| 478 | "Set the token used to identify the USSD module\n" "Secret key\n") |
| 479 | { |
Holger Hans Peter Freyther | 18625ac | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 480 | bsc_replace_string(_nat, &_nat->ussd_token, argv[0]); |
Holger Hans Peter Freyther | 552fc16 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 481 | return CMD_SUCCESS; |
| 482 | } |
| 483 | |
| 484 | DEFUN(cfg_nat_ussd_local, |
| 485 | cfg_nat_ussd_local_cmd, |
| 486 | "ussd-local-ip A.B.C.D", |
| 487 | "Set the IP to listen for the USSD Provider\n" "IP Address\n") |
| 488 | { |
Holger Hans Peter Freyther | 18625ac | 2010-10-12 21:31:02 +0200 | [diff] [blame] | 489 | bsc_replace_string(_nat, &_nat->ussd_local, argv[0]); |
Holger Hans Peter Freyther | 552fc16 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 490 | return CMD_SUCCESS; |
| 491 | } |
| 492 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 493 | /* per BSC configuration */ |
Holger Hans Peter Freyther | dbdd30f | 2010-04-27 15:35:14 +0800 | [diff] [blame] | 494 | 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] | 495 | { |
| 496 | int bsc_nr = atoi(argv[0]); |
| 497 | struct bsc_config *bsc; |
| 498 | |
| 499 | if (bsc_nr > _nat->num_bsc) { |
| 500 | vty_out(vty, "%% The next unused BSC number is %u%s", |
| 501 | _nat->num_bsc, VTY_NEWLINE); |
| 502 | return CMD_WARNING; |
| 503 | } else if (bsc_nr == _nat->num_bsc) { |
| 504 | /* allocate a new one */ |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 505 | bsc = bsc_config_alloc(_nat, "unknown"); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 506 | } else |
| 507 | bsc = bsc_config_num(_nat, bsc_nr); |
| 508 | |
| 509 | if (!bsc) |
| 510 | return CMD_WARNING; |
| 511 | |
| 512 | vty->index = bsc; |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 513 | vty->node = NAT_BSC_NODE; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 514 | |
| 515 | return CMD_SUCCESS; |
| 516 | } |
| 517 | |
| 518 | DEFUN(cfg_bsc_token, cfg_bsc_token_cmd, "token TOKEN", "Set the token") |
| 519 | { |
| 520 | struct bsc_config *conf = vty->index; |
| 521 | |
Holger Hans Peter Freyther | 7c831f6 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 522 | bsc_replace_string(conf, &conf->token, argv[0]); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 523 | return CMD_SUCCESS; |
| 524 | } |
| 525 | |
| 526 | 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] | 527 | "Set the Location Area Code (LAC) of this BSC") |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 528 | { |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 529 | struct bsc_config *tmp; |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 530 | struct bsc_config *conf = vty->index; |
| 531 | |
| 532 | int lac = atoi(argv[0]); |
| 533 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 534 | if (lac == GSM_LAC_RESERVED_DETACHED || lac == GSM_LAC_RESERVED_ALL_BTS) { |
| 535 | vty_out(vty, "%% LAC %d is reserved by GSM 04.08%s", |
| 536 | lac, VTY_NEWLINE); |
| 537 | return CMD_WARNING; |
| 538 | } |
| 539 | |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 540 | /* verify that the LACs are unique */ |
| 541 | llist_for_each_entry(tmp, &_nat->bsc_configs, entry) { |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 542 | if (bsc_config_handles_lac(tmp, lac)) { |
Holger Hans Peter Freyther | 435a5c1 | 2010-03-30 06:08:56 +0200 | [diff] [blame] | 543 | vty_out(vty, "%% LAC %d is already used.%s", lac, VTY_NEWLINE); |
| 544 | return CMD_ERR_INCOMPLETE; |
| 545 | } |
| 546 | } |
| 547 | |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 548 | bsc_config_add_lac(conf, lac); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 549 | |
| 550 | return CMD_SUCCESS; |
| 551 | } |
| 552 | |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 553 | DEFUN(cfg_bsc_no_lac, cfg_bsc_no_lac_cmd, |
| 554 | "no location_area_code <0-65535>", |
| 555 | NO_STR "Set the Location Area Code (LAC) of this BSC") |
| 556 | { |
| 557 | int lac = atoi(argv[0]); |
| 558 | struct bsc_config *conf = vty->index; |
| 559 | |
| 560 | bsc_config_del_lac(conf, lac); |
| 561 | return CMD_SUCCESS; |
| 562 | } |
| 563 | |
| 564 | |
| 565 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 566 | DEFUN(cfg_lst_imsi_allow, |
| 567 | cfg_lst_imsi_allow_cmd, |
| 568 | "access-list NAME imsi-allow [REGEXP]", |
Holger Hans Peter Freyther | 5901e09 | 2011-04-13 20:58:14 +0200 | [diff] [blame] | 569 | "Add the regexp to the allowed list\n" |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 570 | "The name of the access-list\n" |
| 571 | "The regexp of allowed IMSIs\n") |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 572 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 573 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 574 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 575 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 576 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 577 | if (!acc) |
| 578 | return CMD_WARNING; |
| 579 | |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 580 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 581 | if (!entry) |
| 582 | return CMD_WARNING; |
| 583 | |
Holger Hans Peter Freyther | dd7e85b | 2011-04-04 19:19:26 +0200 | [diff] [blame] | 584 | if (bsc_parse_reg(acc, &entry->imsi_allow_re, &entry->imsi_allow, argc - 1, &argv[1]) != 0) |
| 585 | return CMD_WARNING; |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 586 | return CMD_SUCCESS; |
| 587 | } |
| 588 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 589 | DEFUN(cfg_lst_imsi_deny, |
| 590 | cfg_lst_imsi_deny_cmd, |
| 591 | "access-list NAME imsi-deny [REGEXP]", |
Holger Hans Peter Freyther | 5901e09 | 2011-04-13 20:58:14 +0200 | [diff] [blame] | 592 | "Add the regexp to the deny list\n" |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 593 | "The name of the access-list\n" |
| 594 | "The regexp of to be denied IMSIs\n") |
| 595 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 596 | struct bsc_nat_acc_lst *acc; |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 597 | struct bsc_nat_acc_lst_entry *entry; |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 598 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 599 | acc = bsc_nat_acc_lst_get(_nat, argv[0]); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 600 | if (!acc) |
| 601 | return CMD_WARNING; |
| 602 | |
Holger Hans Peter Freyther | 8eb4589 | 2010-06-08 10:53:39 +0800 | [diff] [blame] | 603 | entry = bsc_nat_acc_lst_entry_create(acc); |
| 604 | if (!entry) |
| 605 | return CMD_WARNING; |
| 606 | |
Holger Hans Peter Freyther | dd7e85b | 2011-04-04 19:19:26 +0200 | [diff] [blame] | 607 | if (bsc_parse_reg(acc, &entry->imsi_deny_re, &entry->imsi_deny, argc - 1, &argv[1]) != 0) |
| 608 | return CMD_WARNING; |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 609 | return CMD_SUCCESS; |
| 610 | } |
| 611 | |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 612 | /* naming to follow Zebra... */ |
| 613 | DEFUN(cfg_lst_no, |
| 614 | cfg_lst_no_cmd, |
| 615 | "no access-list NAME", |
| 616 | NO_STR "Remove an access-list by name\n" |
| 617 | "The access-list to remove\n") |
| 618 | { |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 619 | struct bsc_nat_acc_lst *acc; |
| 620 | acc = bsc_nat_acc_lst_find(_nat, argv[0]); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 621 | if (!acc) |
| 622 | return CMD_WARNING; |
| 623 | |
Holger Hans Peter Freyther | b604471 | 2010-06-08 10:14:44 +0800 | [diff] [blame] | 624 | bsc_nat_acc_lst_delete(acc); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 625 | return CMD_SUCCESS; |
| 626 | } |
| 627 | |
Holger Hans Peter Freyther | 1279967 | 2010-09-25 16:25:47 +0800 | [diff] [blame] | 628 | DEFUN(show_acc_lst, |
| 629 | show_acc_lst_cmd, |
| 630 | "show access-list NAME", |
| 631 | SHOW_STR "The name of the access list\n") |
| 632 | { |
| 633 | struct bsc_nat_acc_lst *acc; |
| 634 | acc = bsc_nat_acc_lst_find(_nat, argv[0]); |
| 635 | if (!acc) |
| 636 | return CMD_WARNING; |
| 637 | |
| 638 | vty_out(vty, "access-list %s%s", acc->name, VTY_NEWLINE); |
| 639 | vty_out_rate_ctr_group(vty, " ", acc->stats); |
| 640 | |
| 641 | return CMD_SUCCESS; |
| 642 | } |
| 643 | |
| 644 | |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 645 | DEFUN(cfg_bsc_acc_lst_name, |
| 646 | cfg_bsc_acc_lst_name_cmd, |
| 647 | "access-list-name NAME", |
| 648 | "Set the name of the access list to use.\n" |
| 649 | "The name of the to be used access list.") |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 650 | { |
| 651 | struct bsc_config *conf = vty->index; |
| 652 | |
Holger Hans Peter Freyther | 7c831f6 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 653 | bsc_replace_string(conf, &conf->acc_lst_name, argv[0]); |
Holger Hans Peter Freyther | 4b6da56 | 2010-04-13 09:24:37 +0200 | [diff] [blame] | 654 | return CMD_SUCCESS; |
| 655 | } |
| 656 | |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 657 | DEFUN(cfg_bsc_no_acc_lst_name, |
| 658 | cfg_bsc_no_acc_lst_name_cmd, |
| 659 | "no access-list-name", |
Holger Hans Peter Freyther | 5901e09 | 2011-04-13 20:58:14 +0200 | [diff] [blame] | 660 | NO_STR "Do not use an access-list for the BSC.\n") |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 661 | { |
| 662 | struct bsc_config *conf = vty->index; |
| 663 | |
| 664 | if (conf->acc_lst_name) { |
| 665 | talloc_free(conf->acc_lst_name); |
| 666 | conf->acc_lst_name = NULL; |
| 667 | } |
| 668 | |
| 669 | return CMD_SUCCESS; |
| 670 | } |
| 671 | |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 672 | DEFUN(cfg_bsc_max_endps, cfg_bsc_max_endps_cmd, |
| 673 | "max-endpoints <1-1024>", |
| 674 | "Highest endpoint to use (exclusively)\n" "Number of ports\n") |
Holger Hans Peter Freyther | ef9d138 | 2011-02-25 20:38:15 +0100 | [diff] [blame] | 675 | { |
| 676 | struct bsc_config *conf = vty->index; |
| 677 | |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 678 | conf->max_endpoints = atoi(argv[0]); |
Holger Hans Peter Freyther | ef9d138 | 2011-02-25 20:38:15 +0100 | [diff] [blame] | 679 | return CMD_SUCCESS; |
| 680 | } |
| 681 | |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 682 | DEFUN(cfg_bsc_paging, |
| 683 | cfg_bsc_paging_cmd, |
| 684 | "paging forbidden (0|1)", |
| 685 | "Forbid sending PAGING REQUESTS to the BSC.") |
| 686 | { |
| 687 | struct bsc_config *conf = vty->index; |
| 688 | |
Holger Hans Peter Freyther | e6ac5de | 2010-04-21 20:07:07 +0800 | [diff] [blame] | 689 | if (strcmp("1", argv[0]) == 0) |
Holger Hans Peter Freyther | 7acf462 | 2010-04-21 19:05:14 +0800 | [diff] [blame] | 690 | conf->forbid_paging = 1; |
| 691 | else |
| 692 | conf->forbid_paging = 0; |
| 693 | |
| 694 | return CMD_SUCCESS; |
| 695 | } |
| 696 | |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 697 | DEFUN(cfg_bsc_desc, |
| 698 | cfg_bsc_desc_cmd, |
| 699 | "description DESC", |
| 700 | "Provide a description for the given BSC.") |
| 701 | { |
| 702 | struct bsc_config *conf = vty->index; |
| 703 | |
Holger Hans Peter Freyther | 7c831f6 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 704 | bsc_replace_string(conf, &conf->description, argv[0]); |
Holger Hans Peter Freyther | 6f00907 | 2010-05-14 22:06:28 +0800 | [diff] [blame] | 705 | return CMD_SUCCESS; |
| 706 | } |
| 707 | |
Holger Hans Peter Freyther | 6ad646a | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 708 | DEFUN(test_regex, test_regex_cmd, |
| 709 | "test regex PATTERN STRING", |
| 710 | "Check if the string is matching the current pattern.") |
| 711 | { |
| 712 | regex_t reg; |
| 713 | char *str = NULL; |
| 714 | |
| 715 | memset(®, 0, sizeof(reg)); |
Holger Hans Peter Freyther | dd7e85b | 2011-04-04 19:19:26 +0200 | [diff] [blame] | 716 | if (bsc_parse_reg(_nat, ®, &str, 1, argv) != 0) |
| 717 | return CMD_WARNING; |
Holger Hans Peter Freyther | 6ad646a | 2010-05-14 23:43:12 +0800 | [diff] [blame] | 718 | |
| 719 | vty_out(vty, "String matches allow pattern: %d%s", |
| 720 | regexec(®, argv[1], 0, NULL, 0) == 0, VTY_NEWLINE); |
| 721 | |
| 722 | talloc_free(str); |
| 723 | regfree(®); |
| 724 | return CMD_SUCCESS; |
| 725 | } |
| 726 | |
Holger Hans Peter Freyther | 086c9cd | 2011-02-28 01:07:13 +0100 | [diff] [blame] | 727 | DEFUN(set_last_endp, set_last_endp_cmd, |
| 728 | "set bsc last-used-endpoint <0-9999999999> <0-1024>", |
| 729 | "Set a value\n" "Operate on a BSC\n" |
| 730 | "Last used endpoint for an assignment\n" "BSC configuration number\n" |
| 731 | "Endpoint number used\n") |
| 732 | { |
| 733 | struct bsc_connection *con; |
| 734 | int nr = atoi(argv[0]); |
| 735 | int endp = atoi(argv[1]); |
| 736 | |
| 737 | |
| 738 | llist_for_each_entry(con, &_nat->bsc_connections, list_entry) { |
| 739 | if (!con->cfg) |
| 740 | continue; |
| 741 | if (con->cfg->nr != nr) |
| 742 | continue; |
| 743 | |
| 744 | con->last_endpoint = endp; |
| 745 | vty_out(vty, "Updated the last endpoint for %d to %d.%s", |
| 746 | con->cfg->nr, con->last_endpoint, VTY_NEWLINE); |
| 747 | } |
| 748 | |
| 749 | return CMD_SUCCESS; |
| 750 | } |
| 751 | |
Holger Hans Peter Freyther | 013dd14 | 2011-04-23 23:55:14 +0200 | [diff] [blame] | 752 | DEFUN(block_new_conn, block_new_conn_cmd, |
| 753 | "nat-block (block|unblock)", |
| 754 | "Block the NAT for new connections\n" |
| 755 | "Block\n" "Unblock\n") |
| 756 | { |
| 757 | _nat->blocked = argv[0][0] == 'b'; |
| 758 | vty_out(vty, "%%Going to %s the NAT.%s", |
| 759 | _nat->blocked ? "block" : "unblock", VTY_NEWLINE); |
| 760 | return CMD_SUCCESS; |
| 761 | } |
| 762 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 763 | int bsc_nat_vty_init(struct bsc_nat *nat) |
| 764 | { |
| 765 | _nat = nat; |
| 766 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 767 | /* show commands */ |
Holger Hans Peter Freyther | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 768 | install_element_ve(&show_sccp_cmd); |
| 769 | install_element_ve(&show_bsc_cmd); |
| 770 | install_element_ve(&show_bsc_cfg_cmd); |
| 771 | install_element_ve(&show_stats_cmd); |
Holger Hans Peter Freyther | 032e45b | 2010-07-22 20:26:10 +0800 | [diff] [blame] | 772 | install_element_ve(&show_stats_lac_cmd); |
Holger Hans Peter Freyther | 4fcedba | 2010-06-15 20:14:08 +0800 | [diff] [blame] | 773 | install_element_ve(&close_bsc_cmd); |
| 774 | install_element_ve(&show_msc_cmd); |
| 775 | install_element_ve(&test_regex_cmd); |
Holger Hans Peter Freyther | 8c61f79 | 2010-08-28 18:33:34 +0800 | [diff] [blame] | 776 | install_element_ve(&show_bsc_mgcp_cmd); |
Holger Hans Peter Freyther | 1279967 | 2010-09-25 16:25:47 +0800 | [diff] [blame] | 777 | install_element_ve(&show_acc_lst_cmd); |
Holger Hans Peter Freyther | b372fad | 2010-04-06 12:01:15 +0200 | [diff] [blame] | 778 | |
Holger Hans Peter Freyther | 086c9cd | 2011-02-28 01:07:13 +0100 | [diff] [blame] | 779 | install_element(ENABLE_NODE, &set_last_endp_cmd); |
Holger Hans Peter Freyther | 013dd14 | 2011-04-23 23:55:14 +0200 | [diff] [blame] | 780 | install_element(ENABLE_NODE, &block_new_conn_cmd); |
Holger Hans Peter Freyther | 086c9cd | 2011-02-28 01:07:13 +0100 | [diff] [blame] | 781 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 782 | /* nat group */ |
| 783 | install_element(CONFIG_NODE, &cfg_nat_cmd); |
| 784 | install_node(&nat_node, config_write_nat); |
| 785 | install_default(NAT_NODE); |
Holger Hans Peter Freyther | b4b5205 | 2010-06-17 14:39:15 +0800 | [diff] [blame] | 786 | install_element(NAT_NODE, &ournode_exit_cmd); |
| 787 | install_element(NAT_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | 9226d70 | 2010-06-15 18:51:04 +0800 | [diff] [blame] | 788 | install_element(NAT_NODE, &cfg_nat_msc_ip_cmd); |
Holger Hans Peter Freyther | bace202 | 2010-04-17 07:48:45 +0200 | [diff] [blame] | 789 | install_element(NAT_NODE, &cfg_nat_msc_port_cmd); |
Holger Hans Peter Freyther | acd3078 | 2010-05-05 16:57:38 +0800 | [diff] [blame] | 790 | install_element(NAT_NODE, &cfg_nat_auth_time_cmd); |
| 791 | install_element(NAT_NODE, &cfg_nat_ping_time_cmd); |
| 792 | install_element(NAT_NODE, &cfg_nat_pong_time_cmd); |
Holger Hans Peter Freyther | 6e88b17 | 2010-05-15 00:14:58 +0800 | [diff] [blame] | 793 | install_element(NAT_NODE, &cfg_nat_token_cmd); |
Holger Hans Peter Freyther | f0374a5 | 2010-07-27 19:21:53 +0800 | [diff] [blame] | 794 | install_element(NAT_NODE, &cfg_nat_bsc_ip_dscp_cmd); |
Holger Hans Peter Freyther | 9d42d32 | 2010-05-31 10:36:35 +0800 | [diff] [blame] | 795 | install_element(NAT_NODE, &cfg_nat_bsc_ip_tos_cmd); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 796 | install_element(NAT_NODE, &cfg_nat_acc_lst_name_cmd); |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 797 | install_element(NAT_NODE, &cfg_nat_no_acc_lst_name_cmd); |
Holger Hans Peter Freyther | de021be | 2010-10-10 17:29:20 +0200 | [diff] [blame] | 798 | install_element(NAT_NODE, &cfg_nat_ussd_lst_name_cmd); |
Holger Hans Peter Freyther | daf5417 | 2010-10-11 10:06:39 +0200 | [diff] [blame] | 799 | install_element(NAT_NODE, &cfg_nat_ussd_query_cmd); |
Holger Hans Peter Freyther | 552fc16 | 2010-10-12 18:25:52 +0200 | [diff] [blame] | 800 | install_element(NAT_NODE, &cfg_nat_ussd_token_cmd); |
| 801 | install_element(NAT_NODE, &cfg_nat_ussd_local_cmd); |
Holger Hans Peter Freyther | 67b6d52 | 2010-06-01 01:03:13 +0800 | [diff] [blame] | 802 | |
| 803 | /* access-list */ |
| 804 | install_element(NAT_NODE, &cfg_lst_imsi_allow_cmd); |
| 805 | install_element(NAT_NODE, &cfg_lst_imsi_deny_cmd); |
Holger Hans Peter Freyther | 704b350 | 2010-06-03 01:44:05 +0800 | [diff] [blame] | 806 | install_element(NAT_NODE, &cfg_lst_no_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 807 | |
Holger Hans Peter Freyther | 2945ee9 | 2010-10-21 10:59:54 +0200 | [diff] [blame] | 808 | /* number rewriting */ |
| 809 | install_element(NAT_NODE, &cfg_nat_number_rewrite_cmd); |
| 810 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 811 | /* BSC subgroups */ |
| 812 | install_element(NAT_NODE, &cfg_bsc_cmd); |
| 813 | install_node(&bsc_node, config_write_bsc); |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 814 | install_default(NAT_BSC_NODE); |
| 815 | install_element(NAT_BSC_NODE, &ournode_exit_cmd); |
| 816 | install_element(NAT_BSC_NODE, &ournode_end_cmd); |
| 817 | install_element(NAT_BSC_NODE, &cfg_bsc_token_cmd); |
| 818 | install_element(NAT_BSC_NODE, &cfg_bsc_lac_cmd); |
Holger Hans Peter Freyther | 1f04083 | 2010-10-08 22:08:29 +0800 | [diff] [blame] | 819 | install_element(NAT_BSC_NODE, &cfg_bsc_no_lac_cmd); |
Holger Hans Peter Freyther | a34bb3d | 2010-06-17 14:42:20 +0800 | [diff] [blame] | 820 | install_element(NAT_BSC_NODE, &cfg_bsc_paging_cmd); |
| 821 | install_element(NAT_BSC_NODE, &cfg_bsc_desc_cmd); |
| 822 | install_element(NAT_BSC_NODE, &cfg_bsc_acc_lst_name_cmd); |
Holger Hans Peter Freyther | de3f525 | 2011-03-29 17:14:34 +0200 | [diff] [blame] | 823 | install_element(NAT_BSC_NODE, &cfg_bsc_no_acc_lst_name_cmd); |
Holger Hans Peter Freyther | b28f5a0 | 2011-02-27 11:04:27 +0100 | [diff] [blame] | 824 | install_element(NAT_BSC_NODE, &cfg_bsc_max_endps_cmd); |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 825 | |
Holger Hans Peter Freyther | 3660e4d | 2010-06-15 18:50:26 +0800 | [diff] [blame] | 826 | mgcp_vty_init(); |
| 827 | |
Holger Hans Peter Freyther | 5e54788 | 2010-06-15 18:46:11 +0800 | [diff] [blame] | 828 | return 0; |
| 829 | } |
| 830 | |
| 831 | |
| 832 | /* called by the telnet interface... we have our own init above */ |
Pablo Neira Ayuso | 36ad9a4 | 2011-03-09 13:36:32 +0100 | [diff] [blame] | 833 | int bsc_vty_init(const struct log_info *cat) |
Holger Hans Peter Freyther | 53730f6 | 2011-02-24 14:33:09 +0100 | [diff] [blame] | 834 | { |
Pablo Neira Ayuso | 36ad9a4 | 2011-03-09 13:36:32 +0100 | [diff] [blame] | 835 | logging_vty_add_cmds(cat); |
Holger Hans Peter Freyther | 53730f6 | 2011-02-24 14:33:09 +0100 | [diff] [blame] | 836 | return 0; |
| 837 | } |