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", |
| 118 | get_value_string(keep_modes, g_cfg->keep_tlli_infos), |
| 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); |
| 424 | g_cfg->keep_tlli_infos = val; |
| 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) { |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 456 | struct gbproxy_tlli_info *tlli_info; |
| 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 | |
| 461 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) { |
| 462 | time_t age = now - tlli_info->timestamp; |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 463 | int stored_msgs = 0; |
| 464 | struct llist_head *iter; |
| 465 | llist_for_each(iter, &tlli_info->stored_msgs) |
| 466 | stored_msgs++; |
| 467 | |
Jacob Erlbeck | 155dc9c | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 468 | if (tlli_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 | 155dc9c | 2014-09-11 14:57:03 +0200 | [diff] [blame] | 471 | tlli_info->imsi, |
| 472 | tlli_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", |
| 477 | tlli_info->tlli.current, mi_buf, (int)age); |
| 478 | |
| 479 | if (stored_msgs) |
| 480 | vty_out(vty, ", STORED %d", stored_msgs); |
| 481 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 482 | if (tlli_info->is_deregistered) |
| 483 | vty_out(vty, ", DE-REGISTERED"); |
| 484 | |
Jacob Erlbeck | 675481c | 2014-09-02 14:09:01 +0200 | [diff] [blame] | 485 | vty_out(vty, "%s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | return CMD_SUCCESS; |
| 489 | } |
| 490 | |
| 491 | DEFUN(delete_gb_bvci, delete_gb_bvci_cmd, |
| 492 | "delete-gbproxy-peer <0-65534> bvci <2-65534>", |
| 493 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 494 | "NSEI number\n" |
| 495 | "Only delete peer with a matching BVCI\n" |
| 496 | "BVCI number\n") |
| 497 | { |
| 498 | const uint16_t nsei = atoi(argv[0]); |
| 499 | const uint16_t bvci = atoi(argv[1]); |
| 500 | int counter; |
| 501 | |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 502 | counter = gbproxy_cleanup_peers(g_cfg, nsei, bvci); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 503 | |
| 504 | if (counter == 0) { |
| 505 | vty_out(vty, "BVC not found%s", VTY_NEWLINE); |
| 506 | return CMD_WARNING; |
| 507 | } |
| 508 | |
| 509 | return CMD_SUCCESS; |
| 510 | } |
| 511 | |
| 512 | DEFUN(delete_gb_nsei, delete_gb_nsei_cmd, |
| 513 | "delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]", |
| 514 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 515 | "NSEI number\n" |
| 516 | "Only delete BSSGP connections (BVC)\n" |
| 517 | "Only delete dynamic NS connections (NS-VC)\n" |
| 518 | "Delete BVC and dynamic NS connections\n" |
| 519 | "Show what would be deleted instead of actually deleting\n" |
| 520 | ) |
| 521 | { |
| 522 | const uint16_t nsei = atoi(argv[0]); |
| 523 | const char *mode = argv[1]; |
| 524 | int dry_run = argc > 2; |
| 525 | int delete_bvc = 0; |
| 526 | int delete_nsvc = 0; |
| 527 | int counter; |
| 528 | |
| 529 | if (strcmp(mode, "only-bvc") == 0) |
| 530 | delete_bvc = 1; |
| 531 | else if (strcmp(mode, "only-nsvc") == 0) |
| 532 | delete_nsvc = 1; |
| 533 | else |
| 534 | delete_bvc = delete_nsvc = 1; |
| 535 | |
| 536 | if (delete_bvc) { |
| 537 | if (!dry_run) |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 538 | counter = gbproxy_cleanup_peers(g_cfg, nsei, 0); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 539 | else { |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 540 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 541 | counter = 0; |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 542 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 543 | if (peer->nsei != nsei) |
| 544 | continue; |
| 545 | |
| 546 | vty_out(vty, "BVC: "); |
| 547 | gbprox_vty_print_peer(vty, peer); |
| 548 | counter += 1; |
| 549 | } |
| 550 | } |
| 551 | vty_out(vty, "%sDeleted %d BVC%s", |
| 552 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 553 | } |
| 554 | |
| 555 | if (delete_nsvc) { |
Holger Hans Peter Freyther | 7d9c1df | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 556 | struct gprs_ns_inst *nsi = g_cfg->nsi; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 557 | struct gprs_nsvc *nsvc, *nsvc2; |
| 558 | |
| 559 | counter = 0; |
| 560 | llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) { |
| 561 | if (nsvc->nsei != nsei) |
| 562 | continue; |
| 563 | if (nsvc->persistent) |
| 564 | continue; |
| 565 | |
| 566 | if (!dry_run) |
| 567 | gprs_nsvc_delete(nsvc); |
| 568 | else |
| 569 | vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, " |
| 570 | "remote %s%s", |
| 571 | nsvc->nsei, nsvc->nsvci, |
| 572 | gprs_ns_ll_str(nsvc), VTY_NEWLINE); |
| 573 | counter += 1; |
| 574 | } |
| 575 | vty_out(vty, "%sDeleted %d NS-VC%s", |
| 576 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 577 | } |
| 578 | |
| 579 | return CMD_SUCCESS; |
| 580 | } |
| 581 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 582 | #define GBPROXY_DELETE_TLLI_STR \ |
| 583 | "Delete a GBProxy TLLI entry by NSEI and identification\nNSEI number\n" |
| 584 | |
| 585 | DEFUN(delete_gb_tlli_by_id, delete_gb_tlli_by_id_cmd, |
| 586 | "delete-gbproxy-tlli <0-65534> (tlli|imsi) IDENT", |
| 587 | GBPROXY_DELETE_TLLI_STR |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 588 | "Delete entries with a matching TLLI (hex)\n" |
| 589 | "Delete entries with a matching IMSI\n" |
| 590 | "Identification to match\n") |
| 591 | { |
| 592 | const uint16_t nsei = atoi(argv[0]); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 593 | enum {MATCH_TLLI = 't', MATCH_IMSI = 'i'} match; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 594 | uint32_t tlli = 0; |
| 595 | const char *imsi = NULL; |
Holger Hans Peter Freyther | d64bf22 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 596 | struct gbproxy_peer *peer = 0; |
| 597 | struct gbproxy_tlli_info *tlli_info, *nxt; |
| 598 | struct gbproxy_patch_state *state; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 599 | char mi_buf[200]; |
| 600 | int found = 0; |
| 601 | |
| 602 | match = argv[1][0]; |
| 603 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 604 | if (match == MATCH_TLLI) |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 605 | tlli = strtoll(argv[2], NULL, 16); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 606 | else |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 607 | imsi = argv[2]; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 608 | |
| 609 | peer = gbproxy_peer_by_nsei(g_cfg, nsei); |
| 610 | if (!peer) { |
| 611 | vty_out(vty, "Didn't find peer with NSEI %d%s", |
| 612 | nsei, VTY_NEWLINE); |
| 613 | return CMD_WARNING; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 614 | } |
| 615 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 616 | state = &peer->patch_state; |
| 617 | |
| 618 | llist_for_each_entry_safe(tlli_info, nxt, &state->enabled_tllis, list) { |
| 619 | if (match == MATCH_TLLI) { |
| 620 | if (tlli_info->tlli.current != tlli) |
| 621 | continue; |
| 622 | } else { |
| 623 | mi_buf[0] = '\0'; |
| 624 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
| 625 | tlli_info->imsi, |
| 626 | tlli_info->imsi_len); |
| 627 | |
| 628 | if (strcmp(mi_buf, imsi) != 0) |
| 629 | continue; |
| 630 | } |
| 631 | |
| 632 | vty_out(vty, "Deleting TLLI %08x%s", tlli_info->tlli.current, |
| 633 | VTY_NEWLINE); |
| 634 | gbproxy_delete_tlli(peer, tlli_info); |
| 635 | found += 1; |
| 636 | } |
| 637 | |
| 638 | if (!found && argc >= 2) { |
| 639 | vty_out(vty, "Didn't find TLLI entry with %s %s%s", |
| 640 | argv[1], argv[2], VTY_NEWLINE); |
| 641 | } |
| 642 | |
| 643 | return CMD_SUCCESS; |
| 644 | } |
| 645 | |
| 646 | DEFUN(delete_gb_tlli, delete_gb_tlli_cmd, |
| 647 | "delete-gbproxy-tlli <0-65534> (stale|de-registered)", |
| 648 | GBPROXY_DELETE_TLLI_STR |
| 649 | "Delete stale entries\n" |
| 650 | "Delete de-registered entries\n") |
| 651 | { |
| 652 | const uint16_t nsei = atoi(argv[0]); |
| 653 | enum {MATCH_STALE = 's', MATCH_DEREGISTERED = 'd'} match; |
| 654 | struct gbproxy_peer *peer = 0; |
| 655 | struct gbproxy_tlli_info *tlli_info, *nxt; |
| 656 | struct gbproxy_patch_state *state; |
| 657 | int found = 0; |
| 658 | |
| 659 | match = argv[1][0]; |
| 660 | |
Jacob Erlbeck | 040fabc | 2014-08-21 10:01:30 +0200 | [diff] [blame] | 661 | peer = gbproxy_peer_by_nsei(g_cfg, nsei); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 662 | if (!peer) { |
| 663 | vty_out(vty, "Didn't find peer with NSEI %d%s", |
| 664 | nsei, VTY_NEWLINE); |
| 665 | return CMD_WARNING; |
| 666 | } |
| 667 | |
| 668 | state = &peer->patch_state; |
| 669 | |
| 670 | if (match == MATCH_STALE) { |
Jacob Erlbeck | cf11e93 | 2014-08-19 12:21:01 +0200 | [diff] [blame] | 671 | found = gbproxy_remove_stale_tllis(peer, time(NULL)); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 672 | if (found) |
| 673 | vty_out(vty, "Deleted %d stale TLLI%s%s", |
| 674 | found, found == 1 ? "" : "s", VTY_NEWLINE); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 675 | } else { |
| 676 | llist_for_each_entry_safe(tlli_info, nxt, |
| 677 | &state->enabled_tllis, list) { |
| 678 | if (!tlli_info->is_deregistered) |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 679 | continue; |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 680 | |
| 681 | gbproxy_delete_tlli(peer, tlli_info); |
| 682 | found += 1; |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 683 | } |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 684 | } |
| 685 | |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 686 | if (found) |
| 687 | vty_out(vty, "Deleted %d %s TLLI%s%s", |
| 688 | found, argv[1], found == 1 ? "" : "s", VTY_NEWLINE); |
Holger Hans Peter Freyther | 5eaf1a2 | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 689 | |
| 690 | return CMD_SUCCESS; |
| 691 | } |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 692 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 693 | int gbproxy_vty_init(void) |
| 694 | { |
Harald Welte | c91af6a | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 695 | install_element_ve(&show_gbproxy_cmd); |
Jacob Erlbeck | eb2705a | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 696 | install_element_ve(&show_gbproxy_tllis_cmd); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 697 | |
Jacob Erlbeck | 7fee972 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 698 | install_element(ENABLE_NODE, &delete_gb_bvci_cmd); |
| 699 | install_element(ENABLE_NODE, &delete_gb_nsei_cmd); |
Jacob Erlbeck | 26faff1 | 2014-09-16 08:56:26 +0200 | [diff] [blame] | 700 | install_element(ENABLE_NODE, &delete_gb_tlli_by_id_cmd); |
Jacob Erlbeck | eb2705a | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 701 | install_element(ENABLE_NODE, &delete_gb_tlli_cmd); |
Holger Hans Peter Freyther | 2ea8812 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 702 | |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 703 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 704 | install_node(&gbproxy_node, config_write_gbproxy); |
Jacob Erlbeck | f414e85 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 705 | vty_install_default(GBPROXY_NODE); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 706 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 707 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd); |
| 708 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 709 | install_element(GBPROXY_NODE, &cfg_gbproxy_match_imsi_cmd); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 710 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 711 | install_element(GBPROXY_NODE, &cfg_gbproxy_secondary_sgsn_cmd); |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 712 | install_element(GBPROXY_NODE, &cfg_gbproxy_patch_ptmsi_cmd); |
Jacob Erlbeck | 4c0f698 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 713 | install_element(GBPROXY_NODE, &cfg_gbproxy_acquire_imsi_cmd); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 714 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_age_cmd); |
| 715 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_len_cmd); |
Jacob Erlbeck | f9038d9 | 2014-09-12 15:09:56 +0200 | [diff] [blame] | 716 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_keep_mode_cmd); |
Jacob Erlbeck | 2504bc4 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 717 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd); |
| 718 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 719 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_match_imsi_cmd); |
Jacob Erlbeck | 5620c6d | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 720 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd); |
Jacob Erlbeck | b443d1f | 2014-09-02 13:57:19 +0200 | [diff] [blame] | 721 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_secondary_sgsn_cmd); |
Jacob Erlbeck | 480d718 | 2014-08-18 14:54:37 +0200 | [diff] [blame] | 722 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_patch_ptmsi_cmd); |
Jacob Erlbeck | 4c0f698 | 2014-08-22 17:10:01 +0200 | [diff] [blame] | 723 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_acquire_imsi_cmd); |
Jacob Erlbeck | 4303763 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 724 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_age_cmd); |
| 725 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_len_cmd); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 726 | |
| 727 | return 0; |
| 728 | } |
| 729 | |
| 730 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 731 | { |
| 732 | int rc; |
| 733 | |
| 734 | g_cfg = cfg; |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 735 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | a167efb | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 736 | if (rc < 0) { |
| 737 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 738 | return rc; |
| 739 | } |
| 740 | |
| 741 | return 0; |
| 742 | } |
| 743 | |