Harald Welte | 799e0c9 | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 7 | * it under the terms of the GNU Affero General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
Harald Welte | 799e0c9 | 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 | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 14 | * GNU Affero General Public License for more details. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 15 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 16 | * You should have received a copy of the GNU Affero General Public License |
| 17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 18 | * |
| 19 | */ |
| 20 | |
Harald Welte | 799e0c9 | 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 | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 24 | #include <string.h> |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 25 | #include <time.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 26 | |
Pablo Neira Ayuso | 136f453 | 2011-03-22 16:47:59 +0100 | [diff] [blame] | 27 | #include <osmocom/core/talloc.h> |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 28 | #include <osmocom/core/rate_ctr.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 29 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 30 | #include <openbsc/gsm_04_08.h> |
Harald Welte | ea34a4e | 2012-06-16 14:59:56 +0800 | [diff] [blame] | 31 | #include <osmocom/gprs/gprs_ns.h> |
| 32 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 33 | #include <openbsc/debug.h> |
Harald Welte | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 34 | #include <openbsc/gb_proxy.h> |
Holger Hans Peter Freyther | 7127b02 | 2014-08-04 11:52:52 +0200 | [diff] [blame] | 35 | #include <openbsc/gprs_utils.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 36 | #include <openbsc/vty.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 37 | |
Harald Welte | 4b037e4 | 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 | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 40 | #include <osmocom/vty/misc.h> |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 41 | |
Harald Welte | 799e0c9 | 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 | b77c697 | 2010-05-01 11:28:43 +0200 | [diff] [blame] | 47 | static struct cmd_node gbproxy_node = { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 48 | GBPROXY_NODE, |
Harald Welte | 570ce24 | 2012-08-17 13:16:10 +0200 | [diff] [blame] | 49 | "%s(config-gbproxy)# ", |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 50 | 1, |
| 51 | }; |
| 52 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 53 | static const struct value_string patch_modes[] = { |
| 54 | {GBPROX_PATCH_DEFAULT, "default"}, |
| 55 | {GBPROX_PATCH_BSSGP, "bssgp"}, |
| 56 | {GBPROX_PATCH_LLC_ATTACH_REQ, "llc-attach-req"}, |
| 57 | {GBPROX_PATCH_LLC_ATTACH, "llc-attach"}, |
| 58 | {GBPROX_PATCH_LLC_GMM, "llc-gmm"}, |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 59 | {GBPROX_PATCH_LLC_GSM, "llc-gsm"}, |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 60 | {GBPROX_PATCH_LLC, "llc"}, |
| 61 | {0, NULL} |
| 62 | }; |
| 63 | |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 64 | static void gbprox_vty_print_peer(struct vty *vty, struct gbproxy_peer *peer) |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 65 | { |
| 66 | struct gprs_ra_id raid; |
| 67 | gsm48_parse_ra(&raid, peer->ra); |
| 68 | |
| 69 | vty_out(vty, "NSEI %5u, PTP-BVCI %5u, " |
| 70 | "RAI %u-%u-%u-%u", |
| 71 | peer->nsei, peer->bvci, |
| 72 | raid.mcc, raid.mnc, raid.lac, raid.rac); |
| 73 | if (peer->blocked) |
| 74 | vty_out(vty, " [BVC-BLOCKED]"); |
| 75 | |
| 76 | vty_out(vty, "%s", VTY_NEWLINE); |
| 77 | } |
| 78 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 79 | static int config_write_gbproxy(struct vty *vty) |
| 80 | { |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 81 | vty_out(vty, "gbproxy%s", VTY_NEWLINE); |
| 82 | |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 83 | vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei, |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 84 | VTY_NEWLINE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 85 | |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 86 | if (g_cfg->core_mcc > 0) |
| 87 | vty_out(vty, " core-mobile-country-code %d%s", |
| 88 | g_cfg->core_mcc, VTY_NEWLINE); |
| 89 | if (g_cfg->core_mnc > 0) |
| 90 | vty_out(vty, " core-mobile-network-code %d%s", |
| 91 | g_cfg->core_mnc, VTY_NEWLINE); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 92 | if (g_cfg->core_apn != NULL) { |
| 93 | if (g_cfg->core_apn_size > 0) { |
| 94 | char str[500] = {0}; |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 95 | vty_out(vty, " core-access-point-name %s", |
Holger Hans Peter Freyther | 7127b02 | 2014-08-04 11:52:52 +0200 | [diff] [blame] | 96 | gprs_apn_to_str(str, g_cfg->core_apn, |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 97 | g_cfg->core_apn_size)); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 98 | } else { |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 99 | vty_out(vty, " core-access-point-name none"); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 100 | } |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 101 | if (g_cfg->match_re) |
| 102 | vty_out(vty, " match-imsi %s%s", |
| 103 | g_cfg->match_re, VTY_NEWLINE); |
| 104 | else |
| 105 | vty_out(vty, "%s", VTY_NEWLINE); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 106 | } |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 107 | if (g_cfg->tlli_max_age > 0) |
| 108 | vty_out(vty, " tlli-list max-age %d%s", |
| 109 | g_cfg->tlli_max_age, VTY_NEWLINE); |
| 110 | if (g_cfg->tlli_max_len > 0) |
| 111 | vty_out(vty, " tlli-list max-length %d%s", |
| 112 | g_cfg->tlli_max_len, VTY_NEWLINE); |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 113 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 114 | if (g_cfg->patch_mode != GBPROX_PATCH_DEFAULT) |
| 115 | vty_out(vty, " patch-mode %s%s", |
| 116 | get_value_string(patch_modes, g_cfg->patch_mode), |
| 117 | VTY_NEWLINE); |
| 118 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 119 | return CMD_SUCCESS; |
| 120 | } |
| 121 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 122 | DEFUN(cfg_gbproxy, |
| 123 | cfg_gbproxy_cmd, |
| 124 | "gbproxy", |
| 125 | "Configure the Gb proxy") |
| 126 | { |
| 127 | vty->node = GBPROXY_NODE; |
| 128 | return CMD_SUCCESS; |
| 129 | } |
| 130 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 131 | DEFUN(cfg_nsip_sgsn_nsei, |
| 132 | cfg_nsip_sgsn_nsei_cmd, |
Harald Welte | ff3bde8 | 2010-05-19 15:09:09 +0200 | [diff] [blame] | 133 | "sgsn nsei <0-65534>", |
Holger Hans Peter Freyther | 2eb6e2c | 2011-11-05 15:14:59 +0100 | [diff] [blame] | 134 | "SGSN information\n" |
| 135 | "NSEI to be used in the connection with the SGSN\n" |
| 136 | "The NSEI\n") |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 137 | { |
| 138 | unsigned int port = atoi(argv[0]); |
| 139 | |
| 140 | g_cfg->nsip_sgsn_nsei = port; |
| 141 | return CMD_SUCCESS; |
| 142 | } |
| 143 | |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 144 | #define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n" |
| 145 | |
| 146 | DEFUN(cfg_gbproxy_core_mnc, |
| 147 | cfg_gbproxy_core_mnc_cmd, |
| 148 | "core-mobile-network-code <1-999>", |
| 149 | GBPROXY_CORE_MNC_STR "NCC value\n") |
| 150 | { |
| 151 | g_cfg->core_mnc = atoi(argv[0]); |
| 152 | return CMD_SUCCESS; |
| 153 | } |
| 154 | |
| 155 | DEFUN(cfg_gbproxy_no_core_mnc, |
| 156 | cfg_gbproxy_no_core_mnc_cmd, |
| 157 | "no core-mobile-network-code", |
| 158 | NO_STR GBPROXY_CORE_MNC_STR) |
| 159 | { |
| 160 | g_cfg->core_mnc = 0; |
| 161 | return CMD_SUCCESS; |
| 162 | } |
| 163 | |
| 164 | #define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n" |
| 165 | |
| 166 | DEFUN(cfg_gbproxy_core_mcc, |
| 167 | cfg_gbproxy_core_mcc_cmd, |
| 168 | "core-mobile-country-code <1-999>", |
| 169 | GBPROXY_CORE_MCC_STR "MCC value\n") |
| 170 | { |
| 171 | g_cfg->core_mcc = atoi(argv[0]); |
| 172 | return CMD_SUCCESS; |
| 173 | } |
| 174 | |
| 175 | DEFUN(cfg_gbproxy_no_core_mcc, |
| 176 | cfg_gbproxy_no_core_mcc_cmd, |
| 177 | "no core-mobile-country-code", |
| 178 | NO_STR GBPROXY_CORE_MCC_STR) |
| 179 | { |
| 180 | g_cfg->core_mcc = 0; |
| 181 | return CMD_SUCCESS; |
| 182 | } |
| 183 | |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 184 | #define GBPROXY_CORE_APN_STR "Use this access point name (APN) for the backbone\n" |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 185 | #define GBPROXY_CORE_APN_ARG_STR "Replace APN by this string\n" "Remove APN\n" |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 186 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 187 | static int set_core_apn(struct vty *vty, const char *apn, const char *filter) |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 188 | { |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 189 | const char *err_msg = NULL; |
| 190 | int apn_len; |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 191 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 192 | if (!apn) { |
| 193 | talloc_free(g_cfg->core_apn); |
| 194 | g_cfg->core_apn = NULL; |
| 195 | g_cfg->core_apn_size = 0; |
Holger Hans Peter Freyther | 3fa2644 | 2014-08-04 16:27:11 +0200 | [diff] [blame] | 196 | gbprox_set_patch_filter(g_cfg, NULL, NULL); |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 197 | return CMD_SUCCESS; |
| 198 | } |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 199 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 200 | apn_len = strlen(apn); |
| 201 | |
| 202 | if (apn_len >= 100) { |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 203 | vty_out(vty, "APN string too long (max 99 chars)%s", |
| 204 | VTY_NEWLINE); |
| 205 | return CMD_WARNING; |
| 206 | } |
| 207 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 208 | if (!filter) { |
Holger Hans Peter Freyther | 3fa2644 | 2014-08-04 16:27:11 +0200 | [diff] [blame] | 209 | gbprox_set_patch_filter(g_cfg, NULL, NULL); |
| 210 | } else if (gbprox_set_patch_filter(g_cfg, filter, &err_msg) != 0) { |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 211 | vty_out(vty, "Match expression invalid: %s%s", |
| 212 | err_msg, VTY_NEWLINE); |
| 213 | return CMD_WARNING; |
| 214 | } |
| 215 | |
| 216 | talloc_free(g_cfg->match_re); |
| 217 | if (filter) |
| 218 | /* TODO: replace NULL */ |
| 219 | g_cfg->match_re = talloc_strdup(NULL, filter); |
| 220 | else |
| 221 | g_cfg->match_re = NULL; |
| 222 | |
| 223 | if (apn_len == 0) { |
| 224 | talloc_free(g_cfg->core_apn); |
| 225 | /* TODO: replace NULL */ |
| 226 | g_cfg->core_apn = talloc_zero_size(NULL, 2); |
| 227 | g_cfg->core_apn_size = 0; |
| 228 | } else { |
| 229 | /* TODO: replace NULL */ |
| 230 | g_cfg->core_apn = |
| 231 | talloc_realloc_size(NULL, g_cfg->core_apn, apn_len + 1); |
| 232 | g_cfg->core_apn_size = |
Holger Hans Peter Freyther | ce1b22e | 2014-08-04 14:22:13 +0200 | [diff] [blame] | 233 | gprs_str_to_apn(g_cfg->core_apn, apn_len + 1, apn); |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 234 | } |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 235 | |
| 236 | return CMD_SUCCESS; |
| 237 | } |
| 238 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 239 | DEFUN(cfg_gbproxy_core_apn, |
| 240 | cfg_gbproxy_core_apn_cmd, |
| 241 | "core-access-point-name (APN|none)", |
| 242 | GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR) |
| 243 | { |
| 244 | if (strcmp(argv[0], "none") == 0) |
| 245 | return set_core_apn(vty, "", NULL); |
| 246 | else |
| 247 | return set_core_apn(vty, argv[0], NULL); |
| 248 | } |
| 249 | |
| 250 | DEFUN(cfg_gbproxy_core_apn_match, |
| 251 | cfg_gbproxy_core_apn_match_cmd, |
| 252 | "core-access-point-name (APN|none) match-imsi .REGEXP", |
| 253 | GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR |
| 254 | "Only modify if the IMSI matches\n" |
| 255 | "Regular expression for the match\n") |
| 256 | { |
| 257 | if (strcmp(argv[0], "none") == 0) |
| 258 | return set_core_apn(vty, "", argv[1]); |
| 259 | else |
| 260 | return set_core_apn(vty, argv[0], argv[1]); |
| 261 | } |
| 262 | |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 263 | DEFUN(cfg_gbproxy_no_core_apn, |
| 264 | cfg_gbproxy_no_core_apn_cmd, |
| 265 | "no core-access-point-name", |
| 266 | NO_STR GBPROXY_CORE_APN_STR) |
| 267 | { |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 268 | return set_core_apn(vty, NULL, NULL); |
| 269 | } |
| 270 | |
| 271 | #define GBPROXY_TLLI_LIST_STR "Set TLLI list parameters\n" |
| 272 | #define GBPROXY_MAX_AGE_STR "Limit maximum age\n" |
| 273 | |
| 274 | DEFUN(cfg_gbproxy_tlli_list_max_age, |
| 275 | cfg_gbproxy_tlli_list_max_age_cmd, |
| 276 | "tlli-list max-age <1-999999>", |
| 277 | GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR |
| 278 | "Maximum age in seconds\n") |
| 279 | { |
| 280 | g_cfg->tlli_max_age = atoi(argv[0]); |
| 281 | |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 282 | return CMD_SUCCESS; |
| 283 | } |
| 284 | |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 285 | DEFUN(cfg_gbproxy_tlli_list_no_max_age, |
| 286 | cfg_gbproxy_tlli_list_no_max_age_cmd, |
| 287 | "no tlli-list max-age", |
| 288 | NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR) |
| 289 | { |
| 290 | g_cfg->tlli_max_age = 0; |
| 291 | |
| 292 | return CMD_SUCCESS; |
| 293 | } |
| 294 | |
| 295 | #define GBPROXY_MAX_LEN_STR "Limit list length\n" |
| 296 | |
| 297 | DEFUN(cfg_gbproxy_tlli_list_max_len, |
| 298 | cfg_gbproxy_tlli_list_max_len_cmd, |
| 299 | "tlli-list max-length <1-99999>", |
| 300 | GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR |
| 301 | "Maximum number of TLLIs in the list\n") |
| 302 | { |
| 303 | g_cfg->tlli_max_len = atoi(argv[0]); |
| 304 | |
| 305 | return CMD_SUCCESS; |
| 306 | } |
| 307 | |
| 308 | DEFUN(cfg_gbproxy_tlli_list_no_max_len, |
| 309 | cfg_gbproxy_tlli_list_no_max_len_cmd, |
| 310 | "no tlli-list max-length", |
| 311 | NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR) |
| 312 | { |
| 313 | g_cfg->tlli_max_len = 0; |
| 314 | |
| 315 | return CMD_SUCCESS; |
| 316 | } |
| 317 | |
| 318 | |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 319 | DEFUN(cfg_gbproxy_patch_mode, |
| 320 | cfg_gbproxy_patch_mode_cmd, |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 321 | "patch-mode (default|bssgp|llc-attach-req|llc-attach|llc-gmm|llc-gsm|llc)", |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 322 | "Set patch mode\n" |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 323 | "Use build-in default (best effort, try to patch everything)\n" |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 324 | "Only patch BSSGP headers\n" |
| 325 | "Patch BSSGP headers and LLC Attach Request messages\n" |
| 326 | "Patch BSSGP headers and LLC Attach Request/Accept messages\n" |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 327 | "Patch BSSGP headers and LLC GMM messages\n" |
| 328 | "Patch BSSGP headers, LLC GMM, and LLC GSM messages\n" |
| 329 | "Patch BSSGP headers and all supported LLC messages\n" |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 330 | ) |
| 331 | { |
| 332 | int val = get_string_value(patch_modes, argv[0]); |
| 333 | OSMO_ASSERT(val >= 0); |
| 334 | g_cfg->patch_mode = val; |
| 335 | return CMD_SUCCESS; |
| 336 | } |
| 337 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 338 | DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]", |
| 339 | SHOW_STR "Display information about the Gb proxy\n" "Show statistics\n") |
| 340 | { |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 341 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 342 | int show_stats = argc >= 1; |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 343 | |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 344 | if (show_stats) |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 345 | vty_out_rate_ctr_group(vty, "", g_cfg->ctrg); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 346 | |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 347 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 348 | gbprox_vty_print_peer(vty, peer); |
| 349 | |
| 350 | if (show_stats) |
| 351 | vty_out_rate_ctr_group(vty, " ", peer->ctrg); |
| 352 | } |
| 353 | return CMD_SUCCESS; |
| 354 | } |
| 355 | |
| 356 | DEFUN(show_gbproxy_tllis, show_gbproxy_tllis_cmd, "show gbproxy tllis", |
| 357 | SHOW_STR "Display information about the Gb proxy\n" "Show TLLIs\n") |
| 358 | { |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 359 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 360 | char mi_buf[200]; |
| 361 | time_t now = time(NULL); |
| 362 | |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 363 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 364 | struct gbproxy_tlli_info *tlli_info; |
| 365 | struct gbproxy_patch_state *state = &peer->patch_state; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 366 | |
| 367 | gbprox_vty_print_peer(vty, peer); |
| 368 | |
| 369 | llist_for_each_entry(tlli_info, &state->enabled_tllis, list) { |
| 370 | time_t age = now - tlli_info->timestamp; |
| 371 | snprintf(mi_buf, sizeof(mi_buf), "(invalid)"); |
| 372 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
| 373 | tlli_info->mi_data, |
| 374 | tlli_info->mi_data_len); |
| 375 | vty_out(vty, " TLLI %08x, IMSI %s, AGE %d%s", |
| 376 | tlli_info->tlli, mi_buf, (int)age, |
| 377 | VTY_NEWLINE); |
| 378 | } |
| 379 | } |
| 380 | return CMD_SUCCESS; |
| 381 | } |
| 382 | |
| 383 | DEFUN(delete_gb_bvci, delete_gb_bvci_cmd, |
| 384 | "delete-gbproxy-peer <0-65534> bvci <2-65534>", |
| 385 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 386 | "NSEI number\n" |
| 387 | "Only delete peer with a matching BVCI\n" |
| 388 | "BVCI number\n") |
| 389 | { |
| 390 | const uint16_t nsei = atoi(argv[0]); |
| 391 | const uint16_t bvci = atoi(argv[1]); |
| 392 | int counter; |
| 393 | |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 394 | counter = gbprox_cleanup_peers(g_cfg, nsei, bvci); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 395 | |
| 396 | if (counter == 0) { |
| 397 | vty_out(vty, "BVC not found%s", VTY_NEWLINE); |
| 398 | return CMD_WARNING; |
| 399 | } |
| 400 | |
| 401 | return CMD_SUCCESS; |
| 402 | } |
| 403 | |
| 404 | DEFUN(delete_gb_nsei, delete_gb_nsei_cmd, |
| 405 | "delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]", |
| 406 | "Delete a GBProxy peer by NSEI and optionally BVCI\n" |
| 407 | "NSEI number\n" |
| 408 | "Only delete BSSGP connections (BVC)\n" |
| 409 | "Only delete dynamic NS connections (NS-VC)\n" |
| 410 | "Delete BVC and dynamic NS connections\n" |
| 411 | "Show what would be deleted instead of actually deleting\n" |
| 412 | ) |
| 413 | { |
| 414 | const uint16_t nsei = atoi(argv[0]); |
| 415 | const char *mode = argv[1]; |
| 416 | int dry_run = argc > 2; |
| 417 | int delete_bvc = 0; |
| 418 | int delete_nsvc = 0; |
| 419 | int counter; |
| 420 | |
| 421 | if (strcmp(mode, "only-bvc") == 0) |
| 422 | delete_bvc = 1; |
| 423 | else if (strcmp(mode, "only-nsvc") == 0) |
| 424 | delete_nsvc = 1; |
| 425 | else |
| 426 | delete_bvc = delete_nsvc = 1; |
| 427 | |
| 428 | if (delete_bvc) { |
| 429 | if (!dry_run) |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 430 | counter = gbprox_cleanup_peers(g_cfg, nsei, 0); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 431 | else { |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 432 | struct gbproxy_peer *peer; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 433 | counter = 0; |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 434 | llist_for_each_entry(peer, &g_cfg->bts_peers, list) { |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 435 | if (peer->nsei != nsei) |
| 436 | continue; |
| 437 | |
| 438 | vty_out(vty, "BVC: "); |
| 439 | gbprox_vty_print_peer(vty, peer); |
| 440 | counter += 1; |
| 441 | } |
| 442 | } |
| 443 | vty_out(vty, "%sDeleted %d BVC%s", |
| 444 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 445 | } |
| 446 | |
| 447 | if (delete_nsvc) { |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 448 | struct gprs_ns_inst *nsi = g_cfg->nsi; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 449 | struct gprs_nsvc *nsvc, *nsvc2; |
| 450 | |
| 451 | counter = 0; |
| 452 | llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) { |
| 453 | if (nsvc->nsei != nsei) |
| 454 | continue; |
| 455 | if (nsvc->persistent) |
| 456 | continue; |
| 457 | |
| 458 | if (!dry_run) |
| 459 | gprs_nsvc_delete(nsvc); |
| 460 | else |
| 461 | vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, " |
| 462 | "remote %s%s", |
| 463 | nsvc->nsei, nsvc->nsvci, |
| 464 | gprs_ns_ll_str(nsvc), VTY_NEWLINE); |
| 465 | counter += 1; |
| 466 | } |
| 467 | vty_out(vty, "%sDeleted %d NS-VC%s", |
| 468 | dry_run ? "Not " : "", counter, VTY_NEWLINE); |
| 469 | } |
| 470 | |
| 471 | return CMD_SUCCESS; |
| 472 | } |
| 473 | |
| 474 | DEFUN(delete_gb_tlli, delete_gb_tlli_cmd, |
| 475 | "delete-gbproxy-tlli <0-65534> (tlli|imsi|stale) [IDENT]", |
| 476 | "Delete a GBProxy TLLI entry by NSEI and identification\n" |
| 477 | "NSEI number\n" |
| 478 | "Delete entries with a matching TLLI (hex)\n" |
| 479 | "Delete entries with a matching IMSI\n" |
| 480 | "Identification to match\n") |
| 481 | { |
| 482 | const uint16_t nsei = atoi(argv[0]); |
| 483 | enum {MATCH_TLLI = 't', MATCH_IMSI = 'i', MATCH_STALE = 's'} match; |
| 484 | uint32_t tlli = 0; |
| 485 | const char *imsi = NULL; |
Holger Hans Peter Freyther | 1ddd9e5 | 2014-08-04 11:35:32 +0200 | [diff] [blame] | 486 | struct gbproxy_peer *peer = 0; |
| 487 | struct gbproxy_tlli_info *tlli_info, *nxt; |
| 488 | struct gbproxy_patch_state *state; |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 489 | char mi_buf[200]; |
| 490 | int found = 0; |
| 491 | |
| 492 | match = argv[1][0]; |
| 493 | |
| 494 | switch (match) { |
| 495 | case MATCH_TLLI: |
| 496 | if (argc < 2 || !argv[2][0]) { |
| 497 | vty_out(vty, "%% Missing TLLI%s", VTY_NEWLINE); |
| 498 | return CMD_WARNING; |
| 499 | } |
| 500 | tlli = strtoll(argv[2], NULL, 16); |
| 501 | break; |
| 502 | case MATCH_IMSI: |
| 503 | if (argc < 2 || !argv[2][0]) { |
| 504 | vty_out(vty, "%% Missing IMSI%s", VTY_NEWLINE); |
| 505 | return CMD_WARNING; |
| 506 | } |
| 507 | imsi = argv[2]; |
| 508 | break; |
| 509 | default: |
| 510 | break; |
| 511 | } |
| 512 | |
Holger Hans Peter Freyther | eece6277 | 2014-08-04 15:42:36 +0200 | [diff] [blame] | 513 | peer = gbprox_peer_by_nsei(g_cfg, nsei); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 514 | if (!peer) { |
| 515 | vty_out(vty, "Didn't find peer with NSEI %d%s", |
| 516 | nsei, VTY_NEWLINE); |
| 517 | return CMD_WARNING; |
| 518 | } |
| 519 | |
| 520 | state = &peer->patch_state; |
| 521 | |
| 522 | if (match == MATCH_STALE) { |
Holger Hans Peter Freyther | d4d36f2 | 2014-08-04 11:14:54 +0200 | [diff] [blame] | 523 | found = gbprox_remove_stale_tllis(peer, time(NULL)); |
Holger Hans Peter Freyther | 18739ea | 2014-08-04 11:10:09 +0200 | [diff] [blame] | 524 | if (found) |
| 525 | vty_out(vty, "Deleted %d stale TLLI%s%s", |
| 526 | found, found == 1 ? "" : "s", VTY_NEWLINE); |
| 527 | return CMD_SUCCESS; |
| 528 | } |
| 529 | |
| 530 | llist_for_each_entry_safe(tlli_info, nxt, &state->enabled_tllis, list) { |
| 531 | if (match == MATCH_TLLI && tlli_info->tlli != tlli) |
| 532 | continue; |
| 533 | |
| 534 | if (match == MATCH_IMSI) { |
| 535 | mi_buf[0] = '\0'; |
| 536 | gsm48_mi_to_string(mi_buf, sizeof(mi_buf), |
| 537 | tlli_info->mi_data, |
| 538 | tlli_info->mi_data_len); |
| 539 | |
| 540 | if (strcmp(mi_buf, imsi) != 0) |
| 541 | continue; |
| 542 | } |
| 543 | vty_out(vty, "Deleting TLLI %08x%s", tlli_info->tlli, VTY_NEWLINE); |
| 544 | gbprox_delete_tlli(peer, tlli_info); |
| 545 | found += 1; |
| 546 | } |
| 547 | |
| 548 | if (!found && argc >= 2) { |
| 549 | vty_out(vty, "Didn't find TLLI entry with %s %s%s", |
| 550 | argv[1], argv[2], VTY_NEWLINE); |
| 551 | } |
| 552 | |
| 553 | return CMD_SUCCESS; |
| 554 | } |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 555 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 556 | int gbproxy_vty_init(void) |
| 557 | { |
Harald Welte | 995a2d3 | 2010-05-12 16:50:52 +0000 | [diff] [blame] | 558 | install_element_ve(&show_gbproxy_cmd); |
Jacob Erlbeck | 7dd498d | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 559 | install_element_ve(&show_gbproxy_tllis_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 560 | |
Jacob Erlbeck | 4211d79 | 2013-10-24 12:48:23 +0200 | [diff] [blame] | 561 | install_element(ENABLE_NODE, &delete_gb_bvci_cmd); |
| 562 | install_element(ENABLE_NODE, &delete_gb_nsei_cmd); |
Jacob Erlbeck | 7dd498d | 2014-06-19 10:15:27 +0200 | [diff] [blame] | 563 | install_element(ENABLE_NODE, &delete_gb_tlli_cmd); |
Holger Hans Peter Freyther | 90267a9 | 2013-10-23 11:24:17 +0200 | [diff] [blame] | 564 | |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 565 | install_element(CONFIG_NODE, &cfg_gbproxy_cmd); |
| 566 | install_node(&gbproxy_node, config_write_gbproxy); |
Jacob Erlbeck | 36722e1 | 2013-10-29 09:30:30 +0100 | [diff] [blame] | 567 | vty_install_default(GBPROXY_NODE); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 568 | install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd); |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 569 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd); |
| 570 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 571 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd); |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 572 | install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_match_cmd); |
| 573 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_age_cmd); |
| 574 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_len_cmd); |
Jacob Erlbeck | 67a4445 | 2014-05-19 10:14:58 +0200 | [diff] [blame] | 575 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd); |
| 576 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd); |
Jacob Erlbeck | 7368528 | 2014-05-23 20:48:07 +0200 | [diff] [blame] | 577 | install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd); |
Jacob Erlbeck | 7c101d9 | 2014-06-06 18:49:23 +0200 | [diff] [blame] | 578 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_age_cmd); |
| 579 | install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_len_cmd); |
Jacob Erlbeck | 91fb680 | 2014-05-28 10:59:10 +0200 | [diff] [blame] | 580 | install_element(GBPROXY_NODE, &cfg_gbproxy_patch_mode_cmd); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg) |
| 586 | { |
| 587 | int rc; |
| 588 | |
| 589 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 590 | rc = vty_read_config_file(config_file, NULL); |
Harald Welte | 799e0c9 | 2010-04-30 21:49:24 +0200 | [diff] [blame] | 591 | if (rc < 0) { |
| 592 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 593 | return rc; |
| 594 | } |
| 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |