Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 1 | /* |
| 2 | * (C) 2010 by Harald Welte <laforge@gnumonks.org> |
| 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 | 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 |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [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. |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [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/>. |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 21 | #include <sys/socket.h> |
| 22 | #include <netinet/in.h> |
| 23 | #include <arpa/inet.h> |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 24 | #include <string.h> |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 25 | #include <time.h> |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 26 | |
Pablo Neira Ayuso | dd5fff4 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 28 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 29 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 30 | #include <openbsc/gsm_04_08.h> |
Harald Welte | cfb6b28 | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 31 | #include <osmocom/gprs/gprs_ns.h> |
| 32 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 33 | #include <openbsc/debug.h> |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 34 | #include <openbsc/gb_proxy.h> |
Holger Hans Peter Freyther | 8ac3a72 | 2014-08-04 11:52:52 +0200 | [diff] [blame] | 35 | #include <openbsc/gprs_utils.h> |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 36 | #include <openbsc/vty.h> |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 37 | |
Harald Welte | bd9591f | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 38 | #include <osmocom/vty/command.h> |
| 39 | #include <osmocom/vty/vty.h> |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 40 | #include <osmocom/vty/misc.h> |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 41 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 42 | static struct gbproxy_config *g_cfg = NULL; |
| 43 | |
| 44 | /* |
| 45 | * vty code for mgcp below |
| 46 | */ |
Harald Welte | 323e4f6 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 47 | static struct cmd_node gbproxy_node = { |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 48 | GBPROXY_NODE, |
Harald Welte | 45362bb | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 49 | "%s(config-gbproxy)# ", |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 50 | 1, |
| 51 | }; |
| 52 | |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 53 | static const struct value_string keep_modes[] = { |
| 54 | {GBPROX_KEEP_NEVER, "never"}, |
| 55 | {GBPROX_KEEP_REATTACH, "re-attach"}, |
| 56 | {GBPROX_KEEP_IDENTIFIED, "identified"}, |
| 57 | {GBPROX_KEEP_ALWAYS, "always"}, |
| 58 | {0, NULL} |
| 59 | }; |
| 60 | |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 61 | static void gbprox_vty_print_peer(struct vty *vty, struct gbproxy_peer *peer) |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 62 | { |
| 63 | struct gprs_ra_id raid; |
| 64 | gsm48_parse_ra(&raid, peer->ra); |
| 65 | |
| 66 | vty_out(vty, "NSEI %5u, PTP-BVCI %5u, " |
| 67 | "RAI %u-%u-%u-%u", |
| 68 | peer->nsei, peer->bvci, |
| 69 | raid.mcc, raid.mnc, raid.lac, raid.rac); |
| 70 | if (peer->blocked) |
| 71 | vty_out(vty, " [BVC-BLOCKED]"); |
| 72 | |
| 73 | vty_out(vty, "%s", VTY_NEWLINE); |
| 74 | } |
| 75 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 76 | static int config_write_gbproxy(struct vty *vty) |
| 77 | { |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 78 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 79 | |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 80 | vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei, |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 81 | VTY_NEWLINE); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 82 | |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 83 | if (g_cfg->core_mcc > 0) |
| 84 | vty_out(vty, " core-mobile-country-code %d%s", |
| 85 | g_cfg->core_mcc, VTY_NEWLINE); |
| 86 | if (g_cfg->core_mnc > 0) |
| 87 | vty_out(vty, " core-mobile-network-code %d%s", |
| 88 | g_cfg->core_mnc, VTY_NEWLINE); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 89 | |
| 90 | if (g_cfg->match_re) |
| 91 | vty_out(vty, " match-imsi %s%s", |
| 92 | g_cfg->match_re, VTY_NEWLINE); |
| 93 | |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 94 | if (g_cfg->core_apn != NULL) { |
| 95 | if (g_cfg->core_apn_size > 0) { |
| 96 | char str[500] = {0}; |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 97 | vty_out(vty, " core-access-point-name %s%s", |
Holger Hans Peter Freyther | 8ac3a72 | 2014-08-04 11:52:52 +0200 | [diff] [blame] | 98 | gprs_apn_to_str(str, g_cfg->core_apn, |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 99 | g_cfg->core_apn_size), |
| 100 | VTY_NEWLINE); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 101 | } else { |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 102 | vty_out(vty, " core-access-point-name none%s", |
| 103 | VTY_NEWLINE); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 104 | } |
| 105 | } |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 106 | |
Jacob Erlbeck | a862193 | 2014-08-28 13:47:53 +0200 | [diff] [blame] | 107 | if (g_cfg->route_to_sgsn2) |
| 108 | vty_out(vty, " secondary-sgsn nsei %u%s", g_cfg->nsip_sgsn2_nsei, |
| 109 | VTY_NEWLINE); |
| 110 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 111 | if (g_cfg->tlli_max_age > 0) |
| 112 | vty_out(vty, " tlli-list max-age %d%s", |
| 113 | g_cfg->tlli_max_age, VTY_NEWLINE); |
| 114 | if (g_cfg->tlli_max_len > 0) |
| 115 | vty_out(vty, " tlli-list max-length %d%s", |
| 116 | g_cfg->tlli_max_len, VTY_NEWLINE); |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 117 | vty_out(vty, " tlli-list keep-mode %s%s", |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 118 | get_value_string(keep_modes, g_cfg->keep_link_infos), |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 119 | VTY_NEWLINE); |
| 120 | |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 121 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 122 | return CMD_SUCCESS; |
| 123 | } |
| 124 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 125 | DEFUN(cfg_gbproxy, |
| 126 | cfg_gbproxy_cmd, |
| 127 | "gbproxy", |
| 128 | "Configure the Gb proxy") |
| 129 | { |
| 130 | vty->node = GBPROXY_NODE; |
| 131 | return CMD_SUCCESS; |
| 132 | } |
| 133 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 134 | DEFUN(cfg_nsip_sgsn_nsei, |
| 135 | cfg_nsip_sgsn_nsei_cmd, |
Harald Welte | 31f0a23 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 136 | "sgsn nsei <0-65534>", |
Holger Hans Peter Freyther | 812d87a | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 137 | "SGSN information\n" |
| 138 | "NSEI to be used in the connection with the SGSN\n" |
| 139 | "The NSEI\n") |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 140 | { |
| 141 | unsigned int port = atoi(argv[0]); |
| 142 | |
| 143 | g_cfg->nsip_sgsn_nsei = port; |
| 144 | return CMD_SUCCESS; |
| 145 | } |
| 146 | |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 147 | #define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n" |
| 148 | |
| 149 | DEFUN(cfg_gbproxy_core_mnc, |
| 150 | cfg_gbproxy_core_mnc_cmd, |
| 151 | "core-mobile-network-code <1-999>", |
| 152 | GBPROXY_CORE_MNC_STR "NCC value\n") |
| 153 | { |
| 154 | g_cfg->core_mnc = atoi(argv[0]); |
| 155 | return CMD_SUCCESS; |
| 156 | } |
| 157 | |
| 158 | DEFUN(cfg_gbproxy_no_core_mnc, |
| 159 | cfg_gbproxy_no_core_mnc_cmd, |
| 160 | "no core-mobile-network-code", |
| 161 | NO_STR GBPROXY_CORE_MNC_STR) |
| 162 | { |
| 163 | g_cfg->core_mnc = 0; |
| 164 | return CMD_SUCCESS; |
| 165 | } |
| 166 | |
| 167 | #define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n" |
| 168 | |
| 169 | DEFUN(cfg_gbproxy_core_mcc, |
| 170 | cfg_gbproxy_core_mcc_cmd, |
| 171 | "core-mobile-country-code <1-999>", |
| 172 | GBPROXY_CORE_MCC_STR "MCC value\n") |
| 173 | { |
| 174 | g_cfg->core_mcc = atoi(argv[0]); |
| 175 | return CMD_SUCCESS; |
| 176 | } |
| 177 | |
| 178 | DEFUN(cfg_gbproxy_no_core_mcc, |
| 179 | cfg_gbproxy_no_core_mcc_cmd, |
| 180 | "no core-mobile-country-code", |
| 181 | NO_STR GBPROXY_CORE_MCC_STR) |
| 182 | { |
| 183 | g_cfg->core_mcc = 0; |
| 184 | return CMD_SUCCESS; |
| 185 | } |
| 186 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 187 | #define GBPROXY_MATCH_IMSI_STR "Restrict DTAP patching to certain IMSIs\n" |
| 188 | |
| 189 | DEFUN(cfg_gbproxy_match_imsi, |
| 190 | cfg_gbproxy_match_imsi_cmd, |
| 191 | "match-imsi .REGEXP", |
| 192 | GBPROXY_MATCH_IMSI_STR |
| 193 | "Regular expression for the match\n") |
| 194 | { |
| 195 | const char *filter = argv[0]; |
| 196 | const char *err_msg = NULL; |
| 197 | |
| 198 | if (gbproxy_set_patch_filter(g_cfg, filter, &err_msg) != 0) { |
| 199 | vty_out(vty, "Match expression invalid: %s%s", |
| 200 | err_msg, VTY_NEWLINE); |
| 201 | return CMD_WARNING; |
| 202 | } |
| 203 | talloc_free(g_cfg->match_re); |
| 204 | /* TODO: replace NULL */ |
| 205 | g_cfg->match_re = talloc_strdup(NULL, filter); |
| 206 | |
| 207 | g_cfg->acquire_imsi = 1; |
| 208 | |
| 209 | return CMD_SUCCESS; |
| 210 | } |
| 211 | |
| 212 | DEFUN(cfg_gbproxy_no_match_imsi, |
| 213 | cfg_gbproxy_no_match_imsi_cmd, |
| 214 | "no match-imsi", |
| 215 | NO_STR GBPROXY_MATCH_IMSI_STR) |
| 216 | { |
| 217 | gbproxy_clear_patch_filter(g_cfg); |
| 218 | |
| 219 | talloc_free(g_cfg->match_re); |
| 220 | g_cfg->match_re = NULL; |
| 221 | |
| 222 | g_cfg->acquire_imsi = 0; |
| 223 | |
| 224 | return CMD_SUCCESS; |
| 225 | } |
| 226 | |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 227 | #define GBPROXY_CORE_APN_STR "Use this access point name (APN) for the backbone\n" |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 228 | #define GBPROXY_CORE_APN_ARG_STR "Replace APN by this string\n" "Remove APN\n" |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 229 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 230 | static int set_core_apn(struct vty *vty, const char *apn) |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 231 | { |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 232 | int apn_len; |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 233 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 234 | if (!apn) { |
| 235 | talloc_free(g_cfg->core_apn); |
| 236 | g_cfg->core_apn = NULL; |
| 237 | g_cfg->core_apn_size = 0; |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 238 | return CMD_SUCCESS; |
| 239 | } |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 240 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 241 | apn_len = strlen(apn); |
| 242 | |
| 243 | if (apn_len >= 100) { |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 244 | vty_out(vty, "APN string too long (max 99 chars)%s", |
| 245 | VTY_NEWLINE); |
| 246 | return CMD_WARNING; |
| 247 | } |
| 248 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 249 | if (apn_len == 0) { |
| 250 | talloc_free(g_cfg->core_apn); |
| 251 | /* TODO: replace NULL */ |
| 252 | g_cfg->core_apn = talloc_zero_size(NULL, 2); |
| 253 | g_cfg->core_apn_size = 0; |
| 254 | } else { |
| 255 | /* TODO: replace NULL */ |
| 256 | g_cfg->core_apn = |
| 257 | talloc_realloc_size(NULL, g_cfg->core_apn, apn_len + 1); |
| 258 | g_cfg->core_apn_size = |
Holger Hans Peter Freyther | 2d10ad1 | 2014-08-04 14:22:13 +0200 | [diff] [blame] | 259 | gprs_str_to_apn(g_cfg->core_apn, apn_len + 1, apn); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 260 | } |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 261 | |
| 262 | return CMD_SUCCESS; |
| 263 | } |
| 264 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 265 | DEFUN(cfg_gbproxy_core_apn, |
| 266 | cfg_gbproxy_core_apn_cmd, |
| 267 | "core-access-point-name (APN|none)", |
| 268 | GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR) |
| 269 | { |
| 270 | if (strcmp(argv[0], "none") == 0) |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 271 | return set_core_apn(vty, ""); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 272 | else |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 273 | return set_core_apn(vty, argv[0]); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 274 | } |
| 275 | |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 276 | DEFUN(cfg_gbproxy_no_core_apn, |
| 277 | cfg_gbproxy_no_core_apn_cmd, |
| 278 | "no core-access-point-name", |
| 279 | NO_STR GBPROXY_CORE_APN_STR) |
| 280 | { |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 281 | return set_core_apn(vty, NULL); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 282 | } |
| 283 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 284 | /* TODO: Remove the patch-ptmsi command, since P-TMSI patching is enabled |
| 285 | * automatically when needed. This command is only left for manual testing |
| 286 | * (e.g. doing P-TMSI patching without using a secondary SGSN) |
| 287 | */ |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 288 | #define GBPROXY_PATCH_PTMSI_STR "Patch P-TMSI/TLLI\n" |
| 289 | |
| 290 | DEFUN(cfg_gbproxy_patch_ptmsi, |
| 291 | cfg_gbproxy_patch_ptmsi_cmd, |
| 292 | "patch-ptmsi", |
| 293 | GBPROXY_PATCH_PTMSI_STR) |
| 294 | { |
| 295 | g_cfg->patch_ptmsi = 1; |
| 296 | |
| 297 | return CMD_SUCCESS; |
| 298 | } |
| 299 | |
| 300 | DEFUN(cfg_gbproxy_no_patch_ptmsi, |
| 301 | cfg_gbproxy_no_patch_ptmsi_cmd, |
| 302 | "no patch-ptmsi", |
| 303 | NO_STR GBPROXY_PATCH_PTMSI_STR) |
| 304 | { |
| 305 | g_cfg->patch_ptmsi = 0; |
| 306 | |
| 307 | return CMD_SUCCESS; |
| 308 | } |
| 309 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 310 | /* TODO: Remove the acquire-imsi command, since that feature is enabled |
| 311 | * automatically when IMSI matching is enabled. This command is only left for |
| 312 | * manual testing (e.g. doing IMSI acquisition without IMSI based patching) |
| 313 | */ |
Jacob Erlbeck | 4c0f698 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 314 | #define GBPROXY_ACQUIRE_IMSI_STR "Acquire the IMSI before establishing a LLC connection (Experimental)\n" |
| 315 | |
| 316 | DEFUN(cfg_gbproxy_acquire_imsi, |
| 317 | cfg_gbproxy_acquire_imsi_cmd, |
| 318 | "acquire-imsi", |
| 319 | GBPROXY_ACQUIRE_IMSI_STR) |
| 320 | { |
| 321 | g_cfg->acquire_imsi = 1; |
| 322 | |
| 323 | return CMD_SUCCESS; |
| 324 | } |
| 325 | |
| 326 | DEFUN(cfg_gbproxy_no_acquire_imsi, |
| 327 | cfg_gbproxy_no_acquire_imsi_cmd, |
| 328 | "no acquire-imsi", |
| 329 | NO_STR GBPROXY_ACQUIRE_IMSI_STR) |
| 330 | { |
| 331 | g_cfg->acquire_imsi = 0; |
| 332 | |
| 333 | return CMD_SUCCESS; |
| 334 | } |
| 335 | |
Jacob Erlbeck | 3803e9b | 2014-08-26 14:47:15 +0200 | [diff] [blame] | 336 | #define GBPROXY_SECOND_SGSN_STR "Route matching LLC connections to a second SGSN (Experimental)\n" |
| 337 | |
| 338 | DEFUN(cfg_gbproxy_secondary_sgsn, |
| 339 | cfg_gbproxy_secondary_sgsn_cmd, |
| 340 | "secondary-sgsn nsei <0-65534>", |
| 341 | GBPROXY_SECOND_SGSN_STR |
| 342 | "NSEI to be used in the connection with the SGSN\n" |
| 343 | "The NSEI\n") |
| 344 | { |
| 345 | g_cfg->route_to_sgsn2 = 1; |
| 346 | g_cfg->nsip_sgsn2_nsei = atoi(argv[0]); |
| 347 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 348 | g_cfg->patch_ptmsi = 1; |
| 349 | |
Jacob Erlbeck | 3803e9b | 2014-08-26 14:47:15 +0200 | [diff] [blame] | 350 | return CMD_SUCCESS; |
| 351 | } |
| 352 | |
| 353 | DEFUN(cfg_gbproxy_no_secondary_sgsn, |
| 354 | cfg_gbproxy_no_secondary_sgsn_cmd, |
| 355 | "no secondary-sgsn", |
| 356 | NO_STR GBPROXY_SECOND_SGSN_STR) |
| 357 | { |
| 358 | g_cfg->route_to_sgsn2 = 0; |
| 359 | g_cfg->nsip_sgsn2_nsei = 0xFFFF; |
| 360 | |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 361 | g_cfg->patch_ptmsi = 0; |
| 362 | |
Jacob Erlbeck | 3803e9b | 2014-08-26 14:47:15 +0200 | [diff] [blame] | 363 | return CMD_SUCCESS; |
| 364 | } |
| 365 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 366 | #define GBPROXY_TLLI_LIST_STR "Set TLLI list parameters\n" |
| 367 | #define GBPROXY_MAX_AGE_STR "Limit maximum age\n" |
| 368 | |
| 369 | DEFUN(cfg_gbproxy_tlli_list_max_age, |
| 370 | cfg_gbproxy_tlli_list_max_age_cmd, |
| 371 | "tlli-list max-age <1-999999>", |
| 372 | GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR |
| 373 | "Maximum age in seconds\n") |
| 374 | { |
| 375 | g_cfg->tlli_max_age = atoi(argv[0]); |
| 376 | |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 377 | return CMD_SUCCESS; |
| 378 | } |
| 379 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 380 | DEFUN(cfg_gbproxy_tlli_list_no_max_age, |
| 381 | cfg_gbproxy_tlli_list_no_max_age_cmd, |
| 382 | "no tlli-list max-age", |
| 383 | NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR) |
| 384 | { |
| 385 | g_cfg->tlli_max_age = 0; |
| 386 | |
| 387 | return CMD_SUCCESS; |
| 388 | } |
| 389 | |
| 390 | #define GBPROXY_MAX_LEN_STR "Limit list length\n" |
| 391 | |
| 392 | DEFUN(cfg_gbproxy_tlli_list_max_len, |
| 393 | cfg_gbproxy_tlli_list_max_len_cmd, |
| 394 | "tlli-list max-length <1-99999>", |
| 395 | GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR |
| 396 | "Maximum number of TLLIs in the list\n") |
| 397 | { |
| 398 | g_cfg->tlli_max_len = atoi(argv[0]); |
| 399 | |
| 400 | return CMD_SUCCESS; |
| 401 | } |
| 402 | |
| 403 | DEFUN(cfg_gbproxy_tlli_list_no_max_len, |
| 404 | cfg_gbproxy_tlli_list_no_max_len_cmd, |
| 405 | "no tlli-list max-length", |
| 406 | NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR) |
| 407 | { |
| 408 | g_cfg->tlli_max_len = 0; |
| 409 | |
| 410 | return CMD_SUCCESS; |
| 411 | } |
| 412 | |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 413 | DEFUN(cfg_gbproxy_tlli_list_keep_mode, |
| 414 | cfg_gbproxy_tlli_list_keep_mode_cmd, |
| 415 | "tlli-list keep-mode (never|re-attach|identified|always)", |
| 416 | GBPROXY_TLLI_LIST_STR "How to keep entries for detached TLLIs\n" |
| 417 | "Discard entry immediately after detachment\n" |
| 418 | "Keep entry if a re-attachment has be requested\n" |
| 419 | "Keep entry if it associated with an IMSI\n" |
| 420 | "Don't discard entries after detachment\n") |
| 421 | { |
| 422 | int val = get_string_value(keep_modes, argv[0]); |
| 423 | OSMO_ASSERT(val >= GBPROX_KEEP_NEVER && val <= GBPROX_KEEP_ALWAYS); |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 424 | g_cfg->keep_link_infos = val; |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 425 | |
| 426 | return CMD_SUCCESS; |
| 427 | } |
| 428 | |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 429 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 430 | DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]", |
| 431 | SHOW_STR "Display information about the Gb proxy\n" "Show statistics\n") |
| 432 | { |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 433 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 434 | int show_stats = argc >= 1; |
Jacob Erlbeck | 0727f9a | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 435 | |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 436 | if (show_stats) |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 437 | vty_out_rate_ctr_group(vty, "", g_cfg->ctrg); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 438 | |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 439 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 440 | gbprox_vty_print_peer(vty, peer); |
| 441 | |
| 442 | if (show_stats) |
| 443 | vty_out_rate_ctr_group(vty, " ", peer->ctrg); |
| 444 | } |
| 445 | return CMD_SUCCESS; |
| 446 | } |
| 447 | |
| 448 | DEFUN(show_gbproxy_tllis, show_gbproxy_tllis_cmd, "show gbproxy tllis", |
| 449 | SHOW_STR "Display information about the Gb proxy\n" "Show TLLIs\n") |
| 450 | { |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 451 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 452 | char mi_buf[200]; |
| 453 | time_t now = time(NULL); |
| 454 | |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 455 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 456 | struct gbproxy_link_info *link_info; |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 457 | struct gbproxy_patch_state *state = &peer->patch_state; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 458 | |
| 459 | gbprox_vty_print_peer(vty, peer); |
| 460 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 461 | llist_for_each_entry(link_info, &state->enabled_tllis, list) { |
| 462 | time_t age = now - link_info->timestamp; |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 463 | int stored_msgs = 0; |
| 464 | struct llist_head *iter; |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 465 | llist_for_each(iter, &link_info->stored_msgs) |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 466 | stored_msgs++; |
| 467 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 468 | if (link_info->imsi > 0) { |
Jacob Erlbeck | 9ac42ba | 2014-08-06 18:55:15 +0200 | [diff] [blame] | 469 | snprintf(mi_buf, sizeof(mi_buf), "(invalid)"); |
| 470 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 471 | link_info->imsi, |
| 472 | link_info->imsi_len); |
Jacob Erlbeck | 9ac42ba | 2014-08-06 18:55:15 +0200 | [diff] [blame] | 473 | } else { |
| 474 | snprintf(mi_buf, sizeof(mi_buf), "(none)"); |
| 475 | } |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 476 | vty_out(vty, " TLLI %08x, IMSI %s, AGE %d", |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 477 | link_info->tlli.current, mi_buf, (int)age); |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 478 | |
| 479 | if (stored_msgs) |
| 480 | vty_out(vty, ", STORED %d", stored_msgs); |
| 481 | |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 482 | if (g_cfg->route_to_sgsn2) |
| 483 | vty_out(vty, ", SGSN NSEI %d", |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 484 | link_info->sgsn_nsei); |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 485 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 486 | if (link_info->is_deregistered) |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 487 | vty_out(vty, ", DE-REGISTERED"); |
| 488 | |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 489 | vty_out(vty, "%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 490 | } |
| 491 | } |
| 492 | return CMD_SUCCESS; |
| 493 | } |
| 494 | |
| 495 | DEFUN(delete_gb_bvci, delete_gb_bvci_cmd, |
| 496 | "delete-gbproxy-peer <0-65534> bvci <2-65534>", |
| 497 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 498 | "NSEI number\n" |
| 499 | "Only delete peer with a matching BVCI\n" |
| 500 | "BVCI number\n") |
| 501 | { |
| 502 | const uint16_t nsei = atoi(argv[0]); |
| 503 | const uint16_t bvci = atoi(argv[1]); |
| 504 | int counter; |
| 505 | |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 506 | counter = gbproxy_cleanup_peers(g_cfg, nsei, bvci); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 507 | |
| 508 | if (counter == 0) { |
| 509 | vty_out(vty, "BVC not found%s", VTY_NEWLINE); |
| 510 | return CMD_WARNING; |
| 511 | } |
| 512 | |
| 513 | return CMD_SUCCESS; |
| 514 | } |
| 515 | |
| 516 | DEFUN(delete_gb_nsei, delete_gb_nsei_cmd, |
| 517 | "delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]", |
| 518 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 519 | "NSEI number\n" |
| 520 | "Only delete BSSGP connections (BVC)\n" |
| 521 | "Only delete dynamic NS connections (NS-VC)\n" |
| 522 | "Delete BVC and dynamic NS connections\n" |
| 523 | "Show what would be deleted instead of actually deleting\n" |
| 524 | ) |
| 525 | { |
| 526 | const uint16_t nsei = atoi(argv[0]); |
| 527 | const char *mode = argv[1]; |
| 528 | int dry_run = argc > 2; |
| 529 | int delete_bvc = 0; |
| 530 | int delete_nsvc = 0; |
| 531 | int counter; |
| 532 | |
| 533 | if (strcmp(mode, "only-bvc") == 0) |
| 534 | delete_bvc = 1; |
| 535 | else if (strcmp(mode, "only-nsvc") == 0) |
| 536 | delete_nsvc = 1; |
| 537 | else |
| 538 | delete_bvc = delete_nsvc = 1; |
| 539 | |
| 540 | if (delete_bvc) { |
| 541 | if (!dry_run) |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 542 | counter = gbproxy_cleanup_peers(g_cfg, nsei, 0); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 543 | else { |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 544 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 545 | counter = 0; |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 546 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 547 | if (peer->nsei != nsei) |
| 548 | continue; |
| 549 | |
| 550 | vty_out(vty, "BVC: "); |
| 551 | gbprox_vty_print_peer(vty, peer); |
| 552 | counter += 1; |
| 553 | } |
| 554 | } |
| 555 | vty_out(vty, "%sDeleted %d BVC%s", |
| 556 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 557 | } |
| 558 | |
| 559 | if (delete_nsvc) { |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 560 | struct gprs_ns_inst *nsi = g_cfg->nsi; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 561 | struct gprs_nsvc *nsvc, *nsvc2; |
| 562 | |
| 563 | counter = 0; |
| 564 | llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) { |
| 565 | if (nsvc->nsei != nsei) |
| 566 | continue; |
| 567 | if (nsvc->persistent) |
| 568 | continue; |
| 569 | |
| 570 | if (!dry_run) |
| 571 | gprs_nsvc_delete(nsvc); |
| 572 | else |
| 573 | vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, " |
| 574 | "remote %s%s", |
| 575 | nsvc->nsei, nsvc->nsvci, |
| 576 | gprs_ns_ll_str(nsvc), VTY_NEWLINE); |
| 577 | counter += 1; |
| 578 | } |
| 579 | vty_out(vty, "%sDeleted %d NS-VC%s", |
| 580 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 581 | } |
| 582 | |
| 583 | return CMD_SUCCESS; |
| 584 | } |
| 585 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 586 | #define GBPROXY_DELETE_TLLI_STR \ |
| 587 | "Delete a GBProxy TLLI entry by NSEI and identification\nNSEI number\n" |
| 588 | |
| 589 | DEFUN(delete_gb_tlli_by_id, delete_gb_tlli_by_id_cmd, |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 590 | "delete-gbproxy-tlli <0-65534> (tlli|imsi|sgsn-nsei) IDENT", |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 591 | GBPROXY_DELETE_TLLI_STR |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 592 | "Delete entries with a matching TLLI (hex)\n" |
| 593 | "Delete entries with a matching IMSI\n" |
| 594 | "Identification to match\n") |
| 595 | { |
| 596 | const uint16_t nsei = atoi(argv[0]); |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 597 | enum {MATCH_TLLI = 't', MATCH_IMSI = 'i', MATCH_SGSN = 's'} match; |
| 598 | uint32_t ident = 0; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 599 | const char *imsi = NULL; |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 600 | struct gbproxy_peer *peer = 0; |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 601 | struct gbproxy_link_info *link_info, *nxt; |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 602 | struct gbproxy_patch_state *state; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 603 | char mi_buf[200]; |
| 604 | int found = 0; |
| 605 | |
| 606 | match = argv[1][0]; |
| 607 | |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 608 | switch (match) { |
| 609 | case MATCH_TLLI: ident = strtoll(argv[2], NULL, 16); break; |
| 610 | case MATCH_IMSI: imsi = argv[2]; break; |
| 611 | case MATCH_SGSN: ident = strtoll(argv[2], NULL, 0); break; |
| 612 | }; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 613 | |
| 614 | peer = gbproxy_peer_by_nsei(g_cfg, nsei); |
| 615 | if (!peer) { |
| 616 | vty_out(vty, "Didn't find peer with NSEI %d%s", |
| 617 | nsei, VTY_NEWLINE); |
| 618 | return CMD_WARNING; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 619 | } |
| 620 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 621 | state = &peer->patch_state; |
| 622 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 623 | llist_for_each_entry_safe(link_info, nxt, &state->enabled_tllis, list) { |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 624 | switch (match) { |
| 625 | case MATCH_TLLI: |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 626 | if (link_info->tlli.current != ident) |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 627 | continue; |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 628 | break; |
| 629 | case MATCH_SGSN: |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 630 | if (link_info->sgsn_nsei != ident) |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 631 | continue; |
| 632 | break; |
| 633 | case MATCH_IMSI: |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 634 | mi_buf[0] = '\0'; |
| 635 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 636 | link_info->imsi, |
| 637 | link_info->imsi_len); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 638 | |
| 639 | if (strcmp(mi_buf, imsi) != 0) |
| 640 | continue; |
Jacob Erlbeck | d918f52 | 2014-09-17 10:56:38 +0200 | [diff] [blame] | 641 | break; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 642 | } |
| 643 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 644 | vty_out(vty, "Deleting TLLI %08x%s", link_info->tlli.current, |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 645 | VTY_NEWLINE); |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 646 | gbproxy_delete_link_info(peer, link_info); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 647 | found += 1; |
| 648 | } |
| 649 | |
| 650 | if (!found && argc >= 2) { |
| 651 | vty_out(vty, "Didn't find TLLI entry with %s %s%s", |
| 652 | argv[1], argv[2], VTY_NEWLINE); |
| 653 | } |
| 654 | |
| 655 | return CMD_SUCCESS; |
| 656 | } |
| 657 | |
| 658 | DEFUN(delete_gb_tlli, delete_gb_tlli_cmd, |
| 659 | "delete-gbproxy-tlli <0-65534> (stale|de-registered)", |
| 660 | GBPROXY_DELETE_TLLI_STR |
| 661 | "Delete stale entries\n" |
| 662 | "Delete de-registered entries\n") |
| 663 | { |
| 664 | const uint16_t nsei = atoi(argv[0]); |
| 665 | enum {MATCH_STALE = 's', MATCH_DEREGISTERED = 'd'} match; |
| 666 | struct gbproxy_peer *peer = 0; |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 667 | struct gbproxy_link_info *link_info, *nxt; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 668 | struct gbproxy_patch_state *state; |
| 669 | int found = 0; |
| 670 | |
| 671 | match = argv[1][0]; |
| 672 | |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 673 | peer = gbproxy_peer_by_nsei(g_cfg, nsei); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 674 | if (!peer) { |
| 675 | vty_out(vty, "Didn't find peer with NSEI %d%s", |
| 676 | nsei, VTY_NEWLINE); |
| 677 | return CMD_WARNING; |
| 678 | } |
| 679 | |
| 680 | state = &peer->patch_state; |
| 681 | |
| 682 | if (match == MATCH_STALE) { |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 683 | found = gbproxy_remove_stale_link_infos(peer, time(NULL)); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 684 | if (found) |
| 685 | vty_out(vty, "Deleted %d stale TLLI%s%s", |
| 686 | found, found == 1 ? "" : "s", VTY_NEWLINE); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 687 | } else { |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 688 | llist_for_each_entry_safe(link_info, nxt, |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 689 | &state->enabled_tllis, list) { |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 690 | if (!link_info->is_deregistered) |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 691 | continue; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 692 | |
Jacob Erlbeck | 2b2406a | 2014-09-19 15:07:27 +0200 | [diff] [blame^] | 693 | gbproxy_delete_link_info(peer, link_info); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 694 | found += 1; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 695 | } |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 696 | } |
| 697 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 698 | if (found) |
| 699 | vty_out(vty, "Deleted %d %s TLLI%s%s", |
| 700 | found, argv[1], found == 1 ? "" : "s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 701 | |
| 702 | return CMD_SUCCESS; |
| 703 | } |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 704 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 705 | int gbproxy_vty_init(void) |
| 706 | { |
Harald Welte | c91af6a | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 707 | install_element_ve(&show_gbproxy_cmd); |
Jacob Erlbeck | eb2705a | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 708 | install_element_ve(&show_gbproxy_tllis_cmd); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 709 | |
Jacob Erlbeck | 7fee972 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 710 | install_element(ENABLE_NODE, &delete_gb_bvci_cmd); |
| 711 | install_element(ENABLE_NODE, &delete_gb_nsei_cmd); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 712 | install_element(ENABLE_NODE, &delete_gb_tlli_by_id_cmd); |
Jacob Erlbeck | eb2705a | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 713 | install_element(ENABLE_NODE, &delete_gb_tlli_cmd); |
Holger Hans Peter Freyther | 2ea8812 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 714 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 715 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 716 | install_node(&gbproxy_node, config_write_gbproxy); |
Jacob Erlbeck | f414e85 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 717 | vty_install_default(GBPROXY_NODE); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 718 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 719 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd); |
| 720 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 721 | install_element(GBPROXY_NODE, &cfg_gbproxy_match_imsi_cmd); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 722 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 723 | install_element(GBPROXY_NODE, &cfg_gbproxy_secondary_sgsn_cmd); |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 724 | install_element(GBPROXY_NODE, &cfg_gbproxy_patch_ptmsi_cmd); |
Jacob Erlbeck | 4c0f698 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 725 | install_element(GBPROXY_NODE, &cfg_gbproxy_acquire_imsi_cmd); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 726 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_age_cmd); |
| 727 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_len_cmd); |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 728 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_keep_mode_cmd); |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 729 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd); |
| 730 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 731 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_match_imsi_cmd); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 732 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 733 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_secondary_sgsn_cmd); |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 734 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_patch_ptmsi_cmd); |
Jacob Erlbeck | 4c0f698 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 735 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_acquire_imsi_cmd); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 736 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_age_cmd); |
| 737 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_len_cmd); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 738 | |
| 739 | return 0; |
| 740 | } |
| 741 | |
| 742 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 743 | { |
| 744 | int rc; |
| 745 | |
| 746 | g_cfg = cfg; |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 747 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 748 | if (rc < 0) { |
| 749 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 750 | return rc; |
| 751 | } |
| 752 | |
| 753 | return 0; |
| 754 | } |
| 755 | |