blob: ee13e4cb7b4150c8bb4a576ff94fdf7f0c5f9d99 [file] [log] [blame]
Harald Welte799e0c92010-04-30 21:49:24 +02001/*
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 Welte9af6ddf2011-01-01 15:25:50 +01007 * 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 Welte799e0c92010-04-30 21:49:24 +02009 * (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 Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Harald Welte799e0c92010-04-30 21:49:24 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * 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 Welte799e0c92010-04-30 21:49:24 +020018 *
19 */
20
Harald Welte799e0c92010-04-30 21:49:24 +020021#include <sys/socket.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
Jacob Erlbeck73685282014-05-23 20:48:07 +020024#include <string.h>
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020025#include <time.h>
Harald Welte799e0c92010-04-30 21:49:24 +020026
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/talloc.h>
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020028#include <osmocom/core/rate_ctr.h>
Harald Welte799e0c92010-04-30 21:49:24 +020029
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020030#include <openbsc/gsm_04_08.h>
Harald Welteea34a4e2012-06-16 14:59:56 +080031#include <osmocom/gprs/gprs_ns.h>
32
Harald Welte799e0c92010-04-30 21:49:24 +020033#include <openbsc/debug.h>
Harald Welteb77c6972010-05-01 11:28:43 +020034#include <openbsc/gb_proxy.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020035#include <openbsc/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020036
Harald Welte4b037e42010-05-19 19:45:32 +020037#include <osmocom/vty/command.h>
38#include <osmocom/vty/vty.h>
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020039#include <osmocom/vty/misc.h>
Harald Welte799e0c92010-04-30 21:49:24 +020040
Harald Welte799e0c92010-04-30 21:49:24 +020041static struct gbproxy_config *g_cfg = NULL;
42
43/*
44 * vty code for mgcp below
45 */
Harald Welteb77c6972010-05-01 11:28:43 +020046static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020047 GBPROXY_NODE,
Harald Welte570ce242012-08-17 13:16:10 +020048 "%s(config-gbproxy)# ",
Harald Welte799e0c92010-04-30 21:49:24 +020049 1,
50};
51
Jacob Erlbeck91fb6802014-05-28 10:59:10 +020052static const struct value_string patch_modes[] = {
53 {GBPROX_PATCH_DEFAULT, "default"},
54 {GBPROX_PATCH_BSSGP, "bssgp"},
55 {GBPROX_PATCH_LLC_ATTACH_REQ, "llc-attach-req"},
56 {GBPROX_PATCH_LLC_ATTACH, "llc-attach"},
57 {GBPROX_PATCH_LLC_GMM, "llc-gmm"},
Jacob Erlbeck73685282014-05-23 20:48:07 +020058 {GBPROX_PATCH_LLC_GSM, "llc-gsm"},
Jacob Erlbeck91fb6802014-05-28 10:59:10 +020059 {GBPROX_PATCH_LLC, "llc"},
60 {0, NULL}
61};
62
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +020063static void gbprox_vty_print_peer(struct vty *vty, struct gbprox_peer *peer)
64{
65 struct gprs_ra_id raid;
66 gsm48_parse_ra(&raid, peer->ra);
67
68 vty_out(vty, "NSEI %5u, PTP-BVCI %5u, "
69 "RAI %u-%u-%u-%u",
70 peer->nsei, peer->bvci,
71 raid.mcc, raid.mnc, raid.lac, raid.rac);
72 if (peer->blocked)
73 vty_out(vty, " [BVC-BLOCKED]");
74
75 vty_out(vty, "%s", VTY_NEWLINE);
76}
77
Harald Welte799e0c92010-04-30 21:49:24 +020078static int config_write_gbproxy(struct vty *vty)
79{
Harald Welte799e0c92010-04-30 21:49:24 +020080 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
81
Harald Welteff3bde82010-05-19 15:09:09 +020082 vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020083 VTY_NEWLINE);
Harald Welte799e0c92010-04-30 21:49:24 +020084
Jacob Erlbeck67a44452014-05-19 10:14:58 +020085 if (g_cfg->core_mcc > 0)
86 vty_out(vty, " core-mobile-country-code %d%s",
87 g_cfg->core_mcc, VTY_NEWLINE);
88 if (g_cfg->core_mnc > 0)
89 vty_out(vty, " core-mobile-network-code %d%s",
90 g_cfg->core_mnc, VTY_NEWLINE);
Jacob Erlbeck73685282014-05-23 20:48:07 +020091 if (g_cfg->core_apn != NULL) {
92 if (g_cfg->core_apn_size > 0) {
93 char str[500] = {0};
Jacob Erlbeck7c101d92014-06-06 18:49:23 +020094 vty_out(vty, " core-access-point-name %s",
Jacob Erlbeck73685282014-05-23 20:48:07 +020095 gbprox_apn_to_str(str, g_cfg->core_apn,
Jacob Erlbeck7c101d92014-06-06 18:49:23 +020096 g_cfg->core_apn_size));
Jacob Erlbeck73685282014-05-23 20:48:07 +020097 } else {
Jacob Erlbeck7c101d92014-06-06 18:49:23 +020098 vty_out(vty, " core-access-point-name none");
Jacob Erlbeck73685282014-05-23 20:48:07 +020099 }
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200100 if (g_cfg->match_re)
101 vty_out(vty, " match-imsi %s%s",
102 g_cfg->match_re, VTY_NEWLINE);
103 else
104 vty_out(vty, "%s", VTY_NEWLINE);
Jacob Erlbeck73685282014-05-23 20:48:07 +0200105 }
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200106 if (g_cfg->tlli_max_age > 0)
107 vty_out(vty, " tlli-list max-age %d%s",
108 g_cfg->tlli_max_age, VTY_NEWLINE);
109 if (g_cfg->tlli_max_len > 0)
110 vty_out(vty, " tlli-list max-length %d%s",
111 g_cfg->tlli_max_len, VTY_NEWLINE);
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200112
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200113 if (g_cfg->patch_mode != GBPROX_PATCH_DEFAULT)
114 vty_out(vty, " patch-mode %s%s",
115 get_value_string(patch_modes, g_cfg->patch_mode),
116 VTY_NEWLINE);
117
Harald Welte799e0c92010-04-30 21:49:24 +0200118 return CMD_SUCCESS;
119}
120
Harald Welte799e0c92010-04-30 21:49:24 +0200121DEFUN(cfg_gbproxy,
122 cfg_gbproxy_cmd,
123 "gbproxy",
124 "Configure the Gb proxy")
125{
126 vty->node = GBPROXY_NODE;
127 return CMD_SUCCESS;
128}
129
Harald Welte799e0c92010-04-30 21:49:24 +0200130DEFUN(cfg_nsip_sgsn_nsei,
131 cfg_nsip_sgsn_nsei_cmd,
Harald Welteff3bde82010-05-19 15:09:09 +0200132 "sgsn nsei <0-65534>",
Holger Hans Peter Freyther2eb6e2c2011-11-05 15:14:59 +0100133 "SGSN information\n"
134 "NSEI to be used in the connection with the SGSN\n"
135 "The NSEI\n")
Harald Welte799e0c92010-04-30 21:49:24 +0200136{
137 unsigned int port = atoi(argv[0]);
138
139 g_cfg->nsip_sgsn_nsei = port;
140 return CMD_SUCCESS;
141}
142
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200143#define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n"
144
145DEFUN(cfg_gbproxy_core_mnc,
146 cfg_gbproxy_core_mnc_cmd,
147 "core-mobile-network-code <1-999>",
148 GBPROXY_CORE_MNC_STR "NCC value\n")
149{
150 g_cfg->core_mnc = atoi(argv[0]);
151 return CMD_SUCCESS;
152}
153
154DEFUN(cfg_gbproxy_no_core_mnc,
155 cfg_gbproxy_no_core_mnc_cmd,
156 "no core-mobile-network-code",
157 NO_STR GBPROXY_CORE_MNC_STR)
158{
159 g_cfg->core_mnc = 0;
160 return CMD_SUCCESS;
161}
162
163#define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n"
164
165DEFUN(cfg_gbproxy_core_mcc,
166 cfg_gbproxy_core_mcc_cmd,
167 "core-mobile-country-code <1-999>",
168 GBPROXY_CORE_MCC_STR "MCC value\n")
169{
170 g_cfg->core_mcc = atoi(argv[0]);
171 return CMD_SUCCESS;
172}
173
174DEFUN(cfg_gbproxy_no_core_mcc,
175 cfg_gbproxy_no_core_mcc_cmd,
176 "no core-mobile-country-code",
177 NO_STR GBPROXY_CORE_MCC_STR)
178{
179 g_cfg->core_mcc = 0;
180 return CMD_SUCCESS;
181}
182
Jacob Erlbeck73685282014-05-23 20:48:07 +0200183#define GBPROXY_CORE_APN_STR "Use this access point name (APN) for the backbone\n"
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200184#define GBPROXY_CORE_APN_ARG_STR "Replace APN by this string\n" "Remove APN\n"
Jacob Erlbeck73685282014-05-23 20:48:07 +0200185
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200186static int set_core_apn(struct vty *vty, const char *apn, const char *filter)
Jacob Erlbeck73685282014-05-23 20:48:07 +0200187{
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200188 const char *err_msg = NULL;
189 int apn_len;
Jacob Erlbeck73685282014-05-23 20:48:07 +0200190
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200191 if (!apn) {
192 talloc_free(g_cfg->core_apn);
193 g_cfg->core_apn = NULL;
194 g_cfg->core_apn_size = 0;
195 gbprox_set_patch_filter(NULL, NULL);
196 return CMD_SUCCESS;
197 }
Jacob Erlbeck73685282014-05-23 20:48:07 +0200198
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200199 apn_len = strlen(apn);
200
201 if (apn_len >= 100) {
Jacob Erlbeck73685282014-05-23 20:48:07 +0200202 vty_out(vty, "APN string too long (max 99 chars)%s",
203 VTY_NEWLINE);
204 return CMD_WARNING;
205 }
206
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200207 if (!filter) {
208 gbprox_set_patch_filter(NULL, NULL);
209 } else if (gbprox_set_patch_filter(filter, &err_msg) != 0) {
210 vty_out(vty, "Match expression invalid: %s%s",
211 err_msg, VTY_NEWLINE);
212 return CMD_WARNING;
213 }
214
215 talloc_free(g_cfg->match_re);
216 if (filter)
217 /* TODO: replace NULL */
218 g_cfg->match_re = talloc_strdup(NULL, filter);
219 else
220 g_cfg->match_re = NULL;
221
222 if (apn_len == 0) {
223 talloc_free(g_cfg->core_apn);
224 /* TODO: replace NULL */
225 g_cfg->core_apn = talloc_zero_size(NULL, 2);
226 g_cfg->core_apn_size = 0;
227 } else {
228 /* TODO: replace NULL */
229 g_cfg->core_apn =
230 talloc_realloc_size(NULL, g_cfg->core_apn, apn_len + 1);
231 g_cfg->core_apn_size =
232 gbprox_str_to_apn(g_cfg->core_apn, apn, apn_len + 1);
233 }
Jacob Erlbeck73685282014-05-23 20:48:07 +0200234
235 return CMD_SUCCESS;
236}
237
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200238DEFUN(cfg_gbproxy_core_apn,
239 cfg_gbproxy_core_apn_cmd,
240 "core-access-point-name (APN|none)",
241 GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR)
242{
243 if (strcmp(argv[0], "none") == 0)
244 return set_core_apn(vty, "", NULL);
245 else
246 return set_core_apn(vty, argv[0], NULL);
247}
248
249DEFUN(cfg_gbproxy_core_apn_match,
250 cfg_gbproxy_core_apn_match_cmd,
251 "core-access-point-name (APN|none) match-imsi .REGEXP",
252 GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR
253 "Only modify if the IMSI matches\n"
254 "Regular expression for the match\n")
255{
256 if (strcmp(argv[0], "none") == 0)
257 return set_core_apn(vty, "", argv[1]);
258 else
259 return set_core_apn(vty, argv[0], argv[1]);
260}
261
Jacob Erlbeck73685282014-05-23 20:48:07 +0200262DEFUN(cfg_gbproxy_no_core_apn,
263 cfg_gbproxy_no_core_apn_cmd,
264 "no core-access-point-name",
265 NO_STR GBPROXY_CORE_APN_STR)
266{
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200267 return set_core_apn(vty, NULL, NULL);
268}
269
270#define GBPROXY_TLLI_LIST_STR "Set TLLI list parameters\n"
271#define GBPROXY_MAX_AGE_STR "Limit maximum age\n"
272
273DEFUN(cfg_gbproxy_tlli_list_max_age,
274 cfg_gbproxy_tlli_list_max_age_cmd,
275 "tlli-list max-age <1-999999>",
276 GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR
277 "Maximum age in seconds\n")
278{
279 g_cfg->tlli_max_age = atoi(argv[0]);
280
Jacob Erlbeck73685282014-05-23 20:48:07 +0200281 return CMD_SUCCESS;
282}
283
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200284DEFUN(cfg_gbproxy_tlli_list_no_max_age,
285 cfg_gbproxy_tlli_list_no_max_age_cmd,
286 "no tlli-list max-age",
287 NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR)
288{
289 g_cfg->tlli_max_age = 0;
290
291 return CMD_SUCCESS;
292}
293
294#define GBPROXY_MAX_LEN_STR "Limit list length\n"
295
296DEFUN(cfg_gbproxy_tlli_list_max_len,
297 cfg_gbproxy_tlli_list_max_len_cmd,
298 "tlli-list max-length <1-99999>",
299 GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR
300 "Maximum number of TLLIs in the list\n")
301{
302 g_cfg->tlli_max_len = atoi(argv[0]);
303
304 return CMD_SUCCESS;
305}
306
307DEFUN(cfg_gbproxy_tlli_list_no_max_len,
308 cfg_gbproxy_tlli_list_no_max_len_cmd,
309 "no tlli-list max-length",
310 NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR)
311{
312 g_cfg->tlli_max_len = 0;
313
314 return CMD_SUCCESS;
315}
316
317
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200318DEFUN(cfg_gbproxy_patch_mode,
319 cfg_gbproxy_patch_mode_cmd,
Jacob Erlbeck73685282014-05-23 20:48:07 +0200320 "patch-mode (default|bssgp|llc-attach-req|llc-attach|llc-gmm|llc-gsm|llc)",
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200321 "Set patch mode\n"
Jacob Erlbeck73685282014-05-23 20:48:07 +0200322 "Use build-in default (best effort, try to patch everything)\n"
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200323 "Only patch BSSGP headers\n"
324 "Patch BSSGP headers and LLC Attach Request messages\n"
325 "Patch BSSGP headers and LLC Attach Request/Accept messages\n"
Jacob Erlbeck73685282014-05-23 20:48:07 +0200326 "Patch BSSGP headers and LLC GMM messages\n"
327 "Patch BSSGP headers, LLC GMM, and LLC GSM messages\n"
328 "Patch BSSGP headers and all supported LLC messages\n"
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200329 )
330{
331 int val = get_string_value(patch_modes, argv[0]);
332 OSMO_ASSERT(val >= 0);
333 g_cfg->patch_mode = val;
334 return CMD_SUCCESS;
335}
336
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200337DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]",
338 SHOW_STR "Display information about the Gb proxy\n" "Show statistics\n")
339{
340 struct gbprox_peer *peer;
341 int show_stats = argc >= 1;
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200342
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200343 if (show_stats)
Holger Hans Peter Freythera7027a02014-08-04 11:19:56 +0200344 vty_out_rate_ctr_group(vty, "", gbcfg.ctrg);
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200345
346 llist_for_each_entry(peer, &gbcfg.bts_peers, list) {
347 gbprox_vty_print_peer(vty, peer);
348
349 if (show_stats)
350 vty_out_rate_ctr_group(vty, " ", peer->ctrg);
351 }
352 return CMD_SUCCESS;
353}
354
355DEFUN(show_gbproxy_tllis, show_gbproxy_tllis_cmd, "show gbproxy tllis",
356 SHOW_STR "Display information about the Gb proxy\n" "Show TLLIs\n")
357{
358 struct gbprox_peer *peer;
359 char mi_buf[200];
360 time_t now = time(NULL);
361
362 llist_for_each_entry(peer, &gbcfg.bts_peers, list) {
363 struct gbprox_tlli_info *tlli_info;
364 struct gbprox_patch_state *state = &peer->patch_state;
365
366 gbprox_vty_print_peer(vty, peer);
367
368 llist_for_each_entry(tlli_info, &state->enabled_tllis, list) {
369 time_t age = now - tlli_info->timestamp;
370 snprintf(mi_buf, sizeof(mi_buf), "(invalid)");
371 gsm48_mi_to_string(mi_buf, sizeof(mi_buf),
372 tlli_info->mi_data,
373 tlli_info->mi_data_len);
374 vty_out(vty, " TLLI %08x, IMSI %s, AGE %d%s",
375 tlli_info->tlli, mi_buf, (int)age,
376 VTY_NEWLINE);
377 }
378 }
379 return CMD_SUCCESS;
380}
381
382DEFUN(delete_gb_bvci, delete_gb_bvci_cmd,
383 "delete-gbproxy-peer <0-65534> bvci <2-65534>",
384 "Delete a GBProxy peer by NSEI and optionally BVCI\n"
385 "NSEI number\n"
386 "Only delete peer with a matching BVCI\n"
387 "BVCI number\n")
388{
389 const uint16_t nsei = atoi(argv[0]);
390 const uint16_t bvci = atoi(argv[1]);
391 int counter;
392
393 counter = gbprox_cleanup_peers(nsei, bvci);
394
395 if (counter == 0) {
396 vty_out(vty, "BVC not found%s", VTY_NEWLINE);
397 return CMD_WARNING;
398 }
399
400 return CMD_SUCCESS;
401}
402
403DEFUN(delete_gb_nsei, delete_gb_nsei_cmd,
404 "delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]",
405 "Delete a GBProxy peer by NSEI and optionally BVCI\n"
406 "NSEI number\n"
407 "Only delete BSSGP connections (BVC)\n"
408 "Only delete dynamic NS connections (NS-VC)\n"
409 "Delete BVC and dynamic NS connections\n"
410 "Show what would be deleted instead of actually deleting\n"
411 )
412{
413 const uint16_t nsei = atoi(argv[0]);
414 const char *mode = argv[1];
415 int dry_run = argc > 2;
416 int delete_bvc = 0;
417 int delete_nsvc = 0;
418 int counter;
419
420 if (strcmp(mode, "only-bvc") == 0)
421 delete_bvc = 1;
422 else if (strcmp(mode, "only-nsvc") == 0)
423 delete_nsvc = 1;
424 else
425 delete_bvc = delete_nsvc = 1;
426
427 if (delete_bvc) {
428 if (!dry_run)
429 counter = gbprox_cleanup_peers(nsei, 0);
430 else {
431 struct gbprox_peer *peer;
432 counter = 0;
433 llist_for_each_entry(peer, &gbcfg.bts_peers, list) {
434 if (peer->nsei != nsei)
435 continue;
436
437 vty_out(vty, "BVC: ");
438 gbprox_vty_print_peer(vty, peer);
439 counter += 1;
440 }
441 }
442 vty_out(vty, "%sDeleted %d BVC%s",
443 dry_run ? "Not " : "", counter, VTY_NEWLINE);
444 }
445
446 if (delete_nsvc) {
447 struct gprs_ns_inst *nsi = gbcfg.nsi;
448 struct gprs_nsvc *nsvc, *nsvc2;
449
450 counter = 0;
451 llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) {
452 if (nsvc->nsei != nsei)
453 continue;
454 if (nsvc->persistent)
455 continue;
456
457 if (!dry_run)
458 gprs_nsvc_delete(nsvc);
459 else
460 vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, "
461 "remote %s%s",
462 nsvc->nsei, nsvc->nsvci,
463 gprs_ns_ll_str(nsvc), VTY_NEWLINE);
464 counter += 1;
465 }
466 vty_out(vty, "%sDeleted %d NS-VC%s",
467 dry_run ? "Not " : "", counter, VTY_NEWLINE);
468 }
469
470 return CMD_SUCCESS;
471}
472
473DEFUN(delete_gb_tlli, delete_gb_tlli_cmd,
474 "delete-gbproxy-tlli <0-65534> (tlli|imsi|stale) [IDENT]",
475 "Delete a GBProxy TLLI entry by NSEI and identification\n"
476 "NSEI number\n"
477 "Delete entries with a matching TLLI (hex)\n"
478 "Delete entries with a matching IMSI\n"
479 "Identification to match\n")
480{
481 const uint16_t nsei = atoi(argv[0]);
482 enum {MATCH_TLLI = 't', MATCH_IMSI = 'i', MATCH_STALE = 's'} match;
483 uint32_t tlli = 0;
484 const char *imsi = NULL;
485 struct gbprox_peer *peer = 0;
486 struct gbprox_tlli_info *tlli_info, *nxt;
487 struct gbprox_patch_state *state;
488 char mi_buf[200];
489 int found = 0;
490
491 match = argv[1][0];
492
493 switch (match) {
494 case MATCH_TLLI:
495 if (argc < 2 || !argv[2][0]) {
496 vty_out(vty, "%% Missing TLLI%s", VTY_NEWLINE);
497 return CMD_WARNING;
498 }
499 tlli = strtoll(argv[2], NULL, 16);
500 break;
501 case MATCH_IMSI:
502 if (argc < 2 || !argv[2][0]) {
503 vty_out(vty, "%% Missing IMSI%s", VTY_NEWLINE);
504 return CMD_WARNING;
505 }
506 imsi = argv[2];
507 break;
508 default:
509 break;
510 }
511
512 peer = peer_by_nsei(nsei);
513 if (!peer) {
514 vty_out(vty, "Didn't find peer with NSEI %d%s",
515 nsei, VTY_NEWLINE);
516 return CMD_WARNING;
517 }
518
519 state = &peer->patch_state;
520
521 if (match == MATCH_STALE) {
Holger Hans Peter Freytherd4d36f22014-08-04 11:14:54 +0200522 found = gbprox_remove_stale_tllis(peer, time(NULL));
Holger Hans Peter Freyther18739ea2014-08-04 11:10:09 +0200523 if (found)
524 vty_out(vty, "Deleted %d stale TLLI%s%s",
525 found, found == 1 ? "" : "s", VTY_NEWLINE);
526 return CMD_SUCCESS;
527 }
528
529 llist_for_each_entry_safe(tlli_info, nxt, &state->enabled_tllis, list) {
530 if (match == MATCH_TLLI && tlli_info->tlli != tlli)
531 continue;
532
533 if (match == MATCH_IMSI) {
534 mi_buf[0] = '\0';
535 gsm48_mi_to_string(mi_buf, sizeof(mi_buf),
536 tlli_info->mi_data,
537 tlli_info->mi_data_len);
538
539 if (strcmp(mi_buf, imsi) != 0)
540 continue;
541 }
542 vty_out(vty, "Deleting TLLI %08x%s", tlli_info->tlli, VTY_NEWLINE);
543 gbprox_delete_tlli(peer, tlli_info);
544 found += 1;
545 }
546
547 if (!found && argc >= 2) {
548 vty_out(vty, "Didn't find TLLI entry with %s %s%s",
549 argv[1], argv[2], VTY_NEWLINE);
550 }
551
552 return CMD_SUCCESS;
553}
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200554
Harald Welte799e0c92010-04-30 21:49:24 +0200555int gbproxy_vty_init(void)
556{
Harald Welte995a2d32010-05-12 16:50:52 +0000557 install_element_ve(&show_gbproxy_cmd);
Jacob Erlbeck7dd498d2014-06-19 10:15:27 +0200558 install_element_ve(&show_gbproxy_tllis_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200559
Jacob Erlbeck4211d792013-10-24 12:48:23 +0200560 install_element(ENABLE_NODE, &delete_gb_bvci_cmd);
561 install_element(ENABLE_NODE, &delete_gb_nsei_cmd);
Jacob Erlbeck7dd498d2014-06-19 10:15:27 +0200562 install_element(ENABLE_NODE, &delete_gb_tlli_cmd);
Holger Hans Peter Freyther90267a92013-10-23 11:24:17 +0200563
Harald Welte799e0c92010-04-30 21:49:24 +0200564 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
565 install_node(&gbproxy_node, config_write_gbproxy);
Jacob Erlbeck36722e12013-10-29 09:30:30 +0100566 vty_install_default(GBPROXY_NODE);
Harald Welte799e0c92010-04-30 21:49:24 +0200567 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200568 install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd);
569 install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd);
Jacob Erlbeck73685282014-05-23 20:48:07 +0200570 install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd);
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200571 install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_match_cmd);
572 install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_age_cmd);
573 install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_len_cmd);
Jacob Erlbeck67a44452014-05-19 10:14:58 +0200574 install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd);
575 install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd);
Jacob Erlbeck73685282014-05-23 20:48:07 +0200576 install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd);
Jacob Erlbeck7c101d92014-06-06 18:49:23 +0200577 install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_age_cmd);
578 install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_len_cmd);
Jacob Erlbeck91fb6802014-05-28 10:59:10 +0200579 install_element(GBPROXY_NODE, &cfg_gbproxy_patch_mode_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200580
581 return 0;
582}
583
584int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
585{
586 int rc;
587
588 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200589 rc = vty_read_config_file(config_file, NULL);
Harald Welte799e0c92010-04-30 21:49:24 +0200590 if (rc < 0) {
591 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
592 return rc;
593 }
594
595 return 0;
596}
597