2010-04-30 19:49:24 +00:00
|
|
|
/*
|
|
|
|
* (C) 2010 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
* (C) 2010 by On-Waves
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
2011-01-01 14:25:50 +00:00
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2010-04-30 19:49:24 +00:00
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2011-01-01 14:25:50 +00:00
|
|
|
* GNU Affero General Public License for more details.
|
2010-04-30 19:49:24 +00:00
|
|
|
*
|
2011-01-01 14:25:50 +00:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2010-04-30 19:49:24 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <arpa/inet.h>
|
2014-05-23 18:48:07 +00:00
|
|
|
#include <string.h>
|
2014-08-04 09:10:09 +00:00
|
|
|
#include <time.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2011-03-22 15:47:59 +00:00
|
|
|
#include <osmocom/core/talloc.h>
|
2014-08-04 09:10:09 +00:00
|
|
|
#include <osmocom/core/rate_ctr.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
#include <openbsc/gsm_04_08.h>
|
2012-06-16 06:59:56 +00:00
|
|
|
#include <osmocom/gprs/gprs_ns.h>
|
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
#include <openbsc/debug.h>
|
2010-05-01 09:28:43 +00:00
|
|
|
#include <openbsc/gb_proxy.h>
|
2014-08-04 09:52:52 +00:00
|
|
|
#include <openbsc/gprs_utils.h>
|
2010-05-14 16:59:17 +00:00
|
|
|
#include <openbsc/vty.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2010-05-19 17:45:32 +00:00
|
|
|
#include <osmocom/vty/command.h>
|
|
|
|
#include <osmocom/vty/vty.h>
|
2014-08-04 09:10:09 +00:00
|
|
|
#include <osmocom/vty/misc.h>
|
2010-04-30 19:49:24 +00:00
|
|
|
|
|
|
|
static struct gbproxy_config *g_cfg = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* vty code for mgcp below
|
|
|
|
*/
|
2010-05-01 09:28:43 +00:00
|
|
|
static struct cmd_node gbproxy_node = {
|
2010-04-30 19:49:24 +00:00
|
|
|
GBPROXY_NODE,
|
2012-08-17 11:16:10 +00:00
|
|
|
"%s(config-gbproxy)# ",
|
2010-04-30 19:49:24 +00:00
|
|
|
1,
|
|
|
|
};
|
|
|
|
|
2014-09-12 13:09:56 +00:00
|
|
|
static const struct value_string keep_modes[] = {
|
|
|
|
{GBPROX_KEEP_NEVER, "never"},
|
|
|
|
{GBPROX_KEEP_REATTACH, "re-attach"},
|
|
|
|
{GBPROX_KEEP_IDENTIFIED, "identified"},
|
|
|
|
{GBPROX_KEEP_ALWAYS, "always"},
|
|
|
|
{0, NULL}
|
|
|
|
};
|
|
|
|
|
2014-08-04 09:35:32 +00:00
|
|
|
static void gbprox_vty_print_peer(struct vty *vty, struct gbproxy_peer *peer)
|
2014-08-04 09:10:09 +00:00
|
|
|
{
|
|
|
|
struct gprs_ra_id raid;
|
|
|
|
gsm48_parse_ra(&raid, peer->ra);
|
|
|
|
|
|
|
|
vty_out(vty, "NSEI %5u, PTP-BVCI %5u, "
|
|
|
|
"RAI %u-%u-%u-%u",
|
|
|
|
peer->nsei, peer->bvci,
|
|
|
|
raid.mcc, raid.mnc, raid.lac, raid.rac);
|
|
|
|
if (peer->blocked)
|
|
|
|
vty_out(vty, " [BVC-BLOCKED]");
|
|
|
|
|
|
|
|
vty_out(vty, "%s", VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
static int config_write_gbproxy(struct vty *vty)
|
|
|
|
{
|
|
|
|
vty_out(vty, "gbproxy%s", VTY_NEWLINE);
|
|
|
|
|
2010-05-19 13:09:09 +00:00
|
|
|
vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
|
2010-04-30 19:49:24 +00:00
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
if (g_cfg->core_mcc > 0)
|
|
|
|
vty_out(vty, " core-mobile-country-code %d%s",
|
|
|
|
g_cfg->core_mcc, VTY_NEWLINE);
|
|
|
|
if (g_cfg->core_mnc > 0)
|
|
|
|
vty_out(vty, " core-mobile-network-code %d%s",
|
|
|
|
g_cfg->core_mnc, VTY_NEWLINE);
|
2014-09-02 11:57:19 +00:00
|
|
|
|
|
|
|
if (g_cfg->match_re)
|
|
|
|
vty_out(vty, " match-imsi %s%s",
|
|
|
|
g_cfg->match_re, VTY_NEWLINE);
|
|
|
|
|
2014-05-23 18:48:07 +00:00
|
|
|
if (g_cfg->core_apn != NULL) {
|
|
|
|
if (g_cfg->core_apn_size > 0) {
|
|
|
|
char str[500] = {0};
|
2014-09-02 11:57:19 +00:00
|
|
|
vty_out(vty, " core-access-point-name %s%s",
|
2014-08-04 09:52:52 +00:00
|
|
|
gprs_apn_to_str(str, g_cfg->core_apn,
|
2014-09-02 11:57:19 +00:00
|
|
|
g_cfg->core_apn_size),
|
|
|
|
VTY_NEWLINE);
|
2014-05-23 18:48:07 +00:00
|
|
|
} else {
|
2014-09-02 11:57:19 +00:00
|
|
|
vty_out(vty, " core-access-point-name none%s",
|
|
|
|
VTY_NEWLINE);
|
2014-05-23 18:48:07 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-18 12:54:37 +00:00
|
|
|
|
2014-08-28 11:47:53 +00:00
|
|
|
if (g_cfg->route_to_sgsn2)
|
|
|
|
vty_out(vty, " secondary-sgsn nsei %u%s", g_cfg->nsip_sgsn2_nsei,
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
if (g_cfg->tlli_max_age > 0)
|
|
|
|
vty_out(vty, " tlli-list max-age %d%s",
|
|
|
|
g_cfg->tlli_max_age, VTY_NEWLINE);
|
|
|
|
if (g_cfg->tlli_max_len > 0)
|
|
|
|
vty_out(vty, " tlli-list max-length %d%s",
|
|
|
|
g_cfg->tlli_max_len, VTY_NEWLINE);
|
2014-09-12 13:09:56 +00:00
|
|
|
vty_out(vty, " tlli-list keep-mode %s%s",
|
|
|
|
get_value_string(keep_modes, g_cfg->keep_tlli_infos),
|
|
|
|
VTY_NEWLINE);
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy,
|
|
|
|
cfg_gbproxy_cmd,
|
|
|
|
"gbproxy",
|
|
|
|
"Configure the Gb proxy")
|
|
|
|
{
|
|
|
|
vty->node = GBPROXY_NODE;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_nsip_sgsn_nsei,
|
|
|
|
cfg_nsip_sgsn_nsei_cmd,
|
2010-05-19 13:09:09 +00:00
|
|
|
"sgsn nsei <0-65534>",
|
2011-11-05 14:14:59 +00:00
|
|
|
"SGSN information\n"
|
|
|
|
"NSEI to be used in the connection with the SGSN\n"
|
|
|
|
"The NSEI\n")
|
2010-04-30 19:49:24 +00:00
|
|
|
{
|
|
|
|
unsigned int port = atoi(argv[0]);
|
|
|
|
|
|
|
|
g_cfg->nsip_sgsn_nsei = port;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-19 08:14:58 +00:00
|
|
|
#define GBPROXY_CORE_MNC_STR "Use this network code for the core network\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_mnc,
|
|
|
|
cfg_gbproxy_core_mnc_cmd,
|
|
|
|
"core-mobile-network-code <1-999>",
|
|
|
|
GBPROXY_CORE_MNC_STR "NCC value\n")
|
|
|
|
{
|
|
|
|
g_cfg->core_mnc = atoi(argv[0]);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_core_mnc,
|
|
|
|
cfg_gbproxy_no_core_mnc_cmd,
|
|
|
|
"no core-mobile-network-code",
|
|
|
|
NO_STR GBPROXY_CORE_MNC_STR)
|
|
|
|
{
|
|
|
|
g_cfg->core_mnc = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GBPROXY_CORE_MCC_STR "Use this country code for the core network\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_core_mcc,
|
|
|
|
cfg_gbproxy_core_mcc_cmd,
|
|
|
|
"core-mobile-country-code <1-999>",
|
|
|
|
GBPROXY_CORE_MCC_STR "MCC value\n")
|
|
|
|
{
|
|
|
|
g_cfg->core_mcc = atoi(argv[0]);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_core_mcc,
|
|
|
|
cfg_gbproxy_no_core_mcc_cmd,
|
|
|
|
"no core-mobile-country-code",
|
|
|
|
NO_STR GBPROXY_CORE_MCC_STR)
|
|
|
|
{
|
|
|
|
g_cfg->core_mcc = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
#define GBPROXY_MATCH_IMSI_STR "Restrict DTAP patching to certain IMSIs\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_match_imsi,
|
|
|
|
cfg_gbproxy_match_imsi_cmd,
|
|
|
|
"match-imsi .REGEXP",
|
|
|
|
GBPROXY_MATCH_IMSI_STR
|
|
|
|
"Regular expression for the match\n")
|
|
|
|
{
|
|
|
|
const char *filter = argv[0];
|
|
|
|
const char *err_msg = NULL;
|
|
|
|
|
|
|
|
if (gbproxy_set_patch_filter(g_cfg, filter, &err_msg) != 0) {
|
|
|
|
vty_out(vty, "Match expression invalid: %s%s",
|
|
|
|
err_msg, VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
talloc_free(g_cfg->match_re);
|
|
|
|
/* TODO: replace NULL */
|
|
|
|
g_cfg->match_re = talloc_strdup(NULL, filter);
|
|
|
|
|
|
|
|
g_cfg->acquire_imsi = 1;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_match_imsi,
|
|
|
|
cfg_gbproxy_no_match_imsi_cmd,
|
|
|
|
"no match-imsi",
|
|
|
|
NO_STR GBPROXY_MATCH_IMSI_STR)
|
|
|
|
{
|
|
|
|
gbproxy_clear_patch_filter(g_cfg);
|
|
|
|
|
|
|
|
talloc_free(g_cfg->match_re);
|
|
|
|
g_cfg->match_re = NULL;
|
|
|
|
|
|
|
|
g_cfg->acquire_imsi = 0;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-05-23 18:48:07 +00:00
|
|
|
#define GBPROXY_CORE_APN_STR "Use this access point name (APN) for the backbone\n"
|
2014-06-06 16:49:23 +00:00
|
|
|
#define GBPROXY_CORE_APN_ARG_STR "Replace APN by this string\n" "Remove APN\n"
|
2014-05-23 18:48:07 +00:00
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
static int set_core_apn(struct vty *vty, const char *apn)
|
2014-05-23 18:48:07 +00:00
|
|
|
{
|
2014-06-06 16:49:23 +00:00
|
|
|
int apn_len;
|
|
|
|
|
|
|
|
if (!apn) {
|
|
|
|
talloc_free(g_cfg->core_apn);
|
|
|
|
g_cfg->core_apn = NULL;
|
|
|
|
g_cfg->core_apn_size = 0;
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2014-05-23 18:48:07 +00:00
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
apn_len = strlen(apn);
|
2014-05-23 18:48:07 +00:00
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
if (apn_len >= 100) {
|
2014-05-23 18:48:07 +00:00
|
|
|
vty_out(vty, "APN string too long (max 99 chars)%s",
|
|
|
|
VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
if (apn_len == 0) {
|
|
|
|
talloc_free(g_cfg->core_apn);
|
|
|
|
/* TODO: replace NULL */
|
|
|
|
g_cfg->core_apn = talloc_zero_size(NULL, 2);
|
|
|
|
g_cfg->core_apn_size = 0;
|
|
|
|
} else {
|
|
|
|
/* TODO: replace NULL */
|
|
|
|
g_cfg->core_apn =
|
|
|
|
talloc_realloc_size(NULL, g_cfg->core_apn, apn_len + 1);
|
|
|
|
g_cfg->core_apn_size =
|
2014-08-04 12:22:13 +00:00
|
|
|
gprs_str_to_apn(g_cfg->core_apn, apn_len + 1, apn);
|
2014-06-06 16:49:23 +00:00
|
|
|
}
|
2014-05-23 18:48:07 +00:00
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
DEFUN(cfg_gbproxy_core_apn,
|
|
|
|
cfg_gbproxy_core_apn_cmd,
|
|
|
|
"core-access-point-name (APN|none)",
|
|
|
|
GBPROXY_CORE_APN_STR GBPROXY_CORE_APN_ARG_STR)
|
|
|
|
{
|
|
|
|
if (strcmp(argv[0], "none") == 0)
|
2014-09-02 11:57:19 +00:00
|
|
|
return set_core_apn(vty, "");
|
2014-06-06 16:49:23 +00:00
|
|
|
else
|
2014-09-02 11:57:19 +00:00
|
|
|
return set_core_apn(vty, argv[0]);
|
2014-06-06 16:49:23 +00:00
|
|
|
}
|
|
|
|
|
2014-05-23 18:48:07 +00:00
|
|
|
DEFUN(cfg_gbproxy_no_core_apn,
|
|
|
|
cfg_gbproxy_no_core_apn_cmd,
|
|
|
|
"no core-access-point-name",
|
|
|
|
NO_STR GBPROXY_CORE_APN_STR)
|
|
|
|
{
|
2014-09-02 11:57:19 +00:00
|
|
|
return set_core_apn(vty, NULL);
|
2014-06-06 16:49:23 +00:00
|
|
|
}
|
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
/* TODO: Remove the patch-ptmsi command, since P-TMSI patching is enabled
|
|
|
|
* automatically when needed. This command is only left for manual testing
|
|
|
|
* (e.g. doing P-TMSI patching without using a secondary SGSN)
|
|
|
|
*/
|
2014-08-18 12:54:37 +00:00
|
|
|
#define GBPROXY_PATCH_PTMSI_STR "Patch P-TMSI/TLLI\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_patch_ptmsi,
|
|
|
|
cfg_gbproxy_patch_ptmsi_cmd,
|
|
|
|
"patch-ptmsi",
|
|
|
|
GBPROXY_PATCH_PTMSI_STR)
|
|
|
|
{
|
|
|
|
g_cfg->patch_ptmsi = 1;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_patch_ptmsi,
|
|
|
|
cfg_gbproxy_no_patch_ptmsi_cmd,
|
|
|
|
"no patch-ptmsi",
|
|
|
|
NO_STR GBPROXY_PATCH_PTMSI_STR)
|
|
|
|
{
|
|
|
|
g_cfg->patch_ptmsi = 0;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
/* TODO: Remove the acquire-imsi command, since that feature is enabled
|
|
|
|
* automatically when IMSI matching is enabled. This command is only left for
|
|
|
|
* manual testing (e.g. doing IMSI acquisition without IMSI based patching)
|
|
|
|
*/
|
2014-08-22 15:10:01 +00:00
|
|
|
#define GBPROXY_ACQUIRE_IMSI_STR "Acquire the IMSI before establishing a LLC connection (Experimental)\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_acquire_imsi,
|
|
|
|
cfg_gbproxy_acquire_imsi_cmd,
|
|
|
|
"acquire-imsi",
|
|
|
|
GBPROXY_ACQUIRE_IMSI_STR)
|
|
|
|
{
|
|
|
|
g_cfg->acquire_imsi = 1;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_acquire_imsi,
|
|
|
|
cfg_gbproxy_no_acquire_imsi_cmd,
|
|
|
|
"no acquire-imsi",
|
|
|
|
NO_STR GBPROXY_ACQUIRE_IMSI_STR)
|
|
|
|
{
|
|
|
|
g_cfg->acquire_imsi = 0;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
#define GBPROXY_SECOND_SGSN_STR "Route matching LLC connections to a second SGSN (Experimental)\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_secondary_sgsn,
|
|
|
|
cfg_gbproxy_secondary_sgsn_cmd,
|
|
|
|
"secondary-sgsn nsei <0-65534>",
|
|
|
|
GBPROXY_SECOND_SGSN_STR
|
|
|
|
"NSEI to be used in the connection with the SGSN\n"
|
|
|
|
"The NSEI\n")
|
|
|
|
{
|
|
|
|
g_cfg->route_to_sgsn2 = 1;
|
|
|
|
g_cfg->nsip_sgsn2_nsei = atoi(argv[0]);
|
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
g_cfg->patch_ptmsi = 1;
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_no_secondary_sgsn,
|
|
|
|
cfg_gbproxy_no_secondary_sgsn_cmd,
|
|
|
|
"no secondary-sgsn",
|
|
|
|
NO_STR GBPROXY_SECOND_SGSN_STR)
|
|
|
|
{
|
|
|
|
g_cfg->route_to_sgsn2 = 0;
|
|
|
|
g_cfg->nsip_sgsn2_nsei = 0xFFFF;
|
|
|
|
|
2014-09-02 11:57:19 +00:00
|
|
|
g_cfg->patch_ptmsi = 0;
|
|
|
|
|
2014-08-26 12:47:15 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
#define GBPROXY_TLLI_LIST_STR "Set TLLI list parameters\n"
|
|
|
|
#define GBPROXY_MAX_AGE_STR "Limit maximum age\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_tlli_list_max_age,
|
|
|
|
cfg_gbproxy_tlli_list_max_age_cmd,
|
|
|
|
"tlli-list max-age <1-999999>",
|
|
|
|
GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR
|
|
|
|
"Maximum age in seconds\n")
|
|
|
|
{
|
|
|
|
g_cfg->tlli_max_age = atoi(argv[0]);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_tlli_list_no_max_age,
|
|
|
|
cfg_gbproxy_tlli_list_no_max_age_cmd,
|
|
|
|
"no tlli-list max-age",
|
|
|
|
NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_AGE_STR)
|
|
|
|
{
|
|
|
|
g_cfg->tlli_max_age = 0;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GBPROXY_MAX_LEN_STR "Limit list length\n"
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_tlli_list_max_len,
|
|
|
|
cfg_gbproxy_tlli_list_max_len_cmd,
|
|
|
|
"tlli-list max-length <1-99999>",
|
|
|
|
GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR
|
|
|
|
"Maximum number of TLLIs in the list\n")
|
|
|
|
{
|
|
|
|
g_cfg->tlli_max_len = atoi(argv[0]);
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(cfg_gbproxy_tlli_list_no_max_len,
|
|
|
|
cfg_gbproxy_tlli_list_no_max_len_cmd,
|
|
|
|
"no tlli-list max-length",
|
|
|
|
NO_STR GBPROXY_TLLI_LIST_STR GBPROXY_MAX_LEN_STR)
|
|
|
|
{
|
|
|
|
g_cfg->tlli_max_len = 0;
|
|
|
|
|
2014-05-23 18:48:07 +00:00
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-09-12 13:09:56 +00:00
|
|
|
DEFUN(cfg_gbproxy_tlli_list_keep_mode,
|
|
|
|
cfg_gbproxy_tlli_list_keep_mode_cmd,
|
|
|
|
"tlli-list keep-mode (never|re-attach|identified|always)",
|
|
|
|
GBPROXY_TLLI_LIST_STR "How to keep entries for detached TLLIs\n"
|
|
|
|
"Discard entry immediately after detachment\n"
|
|
|
|
"Keep entry if a re-attachment has be requested\n"
|
|
|
|
"Keep entry if it associated with an IMSI\n"
|
|
|
|
"Don't discard entries after detachment\n")
|
|
|
|
{
|
|
|
|
int val = get_string_value(keep_modes, argv[0]);
|
|
|
|
OSMO_ASSERT(val >= GBPROX_KEEP_NEVER && val <= GBPROX_KEEP_ALWAYS);
|
|
|
|
g_cfg->keep_tlli_infos = val;
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2014-06-06 16:49:23 +00:00
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]",
|
|
|
|
SHOW_STR "Display information about the Gb proxy\n" "Show statistics\n")
|
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2014-08-04 09:10:09 +00:00
|
|
|
int show_stats = argc >= 1;
|
|
|
|
|
|
|
|
if (show_stats)
|
2014-08-04 13:42:36 +00:00
|
|
|
vty_out_rate_ctr_group(vty, "", g_cfg->ctrg);
|
2014-08-04 09:10:09 +00:00
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
llist_for_each_entry(peer, &g_cfg->bts_peers, list) {
|
2014-08-04 09:10:09 +00:00
|
|
|
gbprox_vty_print_peer(vty, peer);
|
|
|
|
|
|
|
|
if (show_stats)
|
|
|
|
vty_out_rate_ctr_group(vty, " ", peer->ctrg);
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(show_gbproxy_tllis, show_gbproxy_tllis_cmd, "show gbproxy tllis",
|
|
|
|
SHOW_STR "Display information about the Gb proxy\n" "Show TLLIs\n")
|
|
|
|
{
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2014-08-04 09:10:09 +00:00
|
|
|
char mi_buf[200];
|
|
|
|
time_t now = time(NULL);
|
|
|
|
|
2014-08-04 13:42:36 +00:00
|
|
|
llist_for_each_entry(peer, &g_cfg->bts_peers, list) {
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_tlli_info *tlli_info;
|
|
|
|
struct gbproxy_patch_state *state = &peer->patch_state;
|
2014-08-04 09:10:09 +00:00
|
|
|
|
|
|
|
gbprox_vty_print_peer(vty, peer);
|
|
|
|
|
|
|
|
llist_for_each_entry(tlli_info, &state->enabled_tllis, list) {
|
|
|
|
time_t age = now - tlli_info->timestamp;
|
2014-09-02 12:09:01 +00:00
|
|
|
int stored_msgs = 0;
|
|
|
|
struct llist_head *iter;
|
|
|
|
llist_for_each(iter, &tlli_info->stored_msgs)
|
|
|
|
stored_msgs++;
|
|
|
|
|
2014-09-11 12:57:03 +00:00
|
|
|
if (tlli_info->imsi > 0) {
|
2014-08-06 16:55:15 +00:00
|
|
|
snprintf(mi_buf, sizeof(mi_buf), "(invalid)");
|
|
|
|
gsm48_mi_to_string(mi_buf, sizeof(mi_buf),
|
2014-09-11 12:57:03 +00:00
|
|
|
tlli_info->imsi,
|
|
|
|
tlli_info->imsi_len);
|
2014-08-06 16:55:15 +00:00
|
|
|
} else {
|
|
|
|
snprintf(mi_buf, sizeof(mi_buf), "(none)");
|
|
|
|
}
|
2014-09-02 12:09:01 +00:00
|
|
|
vty_out(vty, " TLLI %08x, IMSI %s, AGE %d",
|
|
|
|
tlli_info->tlli.current, mi_buf, (int)age);
|
|
|
|
|
|
|
|
if (stored_msgs)
|
|
|
|
vty_out(vty, ", STORED %d", stored_msgs);
|
|
|
|
|
|
|
|
vty_out(vty, "%s", VTY_NEWLINE);
|
2014-08-04 09:10:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(delete_gb_bvci, delete_gb_bvci_cmd,
|
|
|
|
"delete-gbproxy-peer <0-65534> bvci <2-65534>",
|
|
|
|
"Delete a GBProxy peer by NSEI and optionally BVCI\n"
|
|
|
|
"NSEI number\n"
|
|
|
|
"Only delete peer with a matching BVCI\n"
|
|
|
|
"BVCI number\n")
|
|
|
|
{
|
|
|
|
const uint16_t nsei = atoi(argv[0]);
|
|
|
|
const uint16_t bvci = atoi(argv[1]);
|
|
|
|
int counter;
|
|
|
|
|
2014-08-21 08:01:30 +00:00
|
|
|
counter = gbproxy_cleanup_peers(g_cfg, nsei, bvci);
|
2014-08-04 09:10:09 +00:00
|
|
|
|
|
|
|
if (counter == 0) {
|
|
|
|
vty_out(vty, "BVC not found%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2014-05-28 08:59:10 +00:00
|
|
|
|
2014-08-04 09:10:09 +00:00
|
|
|
DEFUN(delete_gb_nsei, delete_gb_nsei_cmd,
|
|
|
|
"delete-gbproxy-peer <0-65534> (only-bvc|only-nsvc|all) [dry-run]",
|
|
|
|
"Delete a GBProxy peer by NSEI and optionally BVCI\n"
|
|
|
|
"NSEI number\n"
|
|
|
|
"Only delete BSSGP connections (BVC)\n"
|
|
|
|
"Only delete dynamic NS connections (NS-VC)\n"
|
|
|
|
"Delete BVC and dynamic NS connections\n"
|
|
|
|
"Show what would be deleted instead of actually deleting\n"
|
|
|
|
)
|
|
|
|
{
|
|
|
|
const uint16_t nsei = atoi(argv[0]);
|
|
|
|
const char *mode = argv[1];
|
|
|
|
int dry_run = argc > 2;
|
|
|
|
int delete_bvc = 0;
|
|
|
|
int delete_nsvc = 0;
|
|
|
|
int counter;
|
|
|
|
|
|
|
|
if (strcmp(mode, "only-bvc") == 0)
|
|
|
|
delete_bvc = 1;
|
|
|
|
else if (strcmp(mode, "only-nsvc") == 0)
|
|
|
|
delete_nsvc = 1;
|
|
|
|
else
|
|
|
|
delete_bvc = delete_nsvc = 1;
|
|
|
|
|
|
|
|
if (delete_bvc) {
|
|
|
|
if (!dry_run)
|
2014-08-21 08:01:30 +00:00
|
|
|
counter = gbproxy_cleanup_peers(g_cfg, nsei, 0);
|
2014-08-04 09:10:09 +00:00
|
|
|
else {
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer;
|
2014-08-04 09:10:09 +00:00
|
|
|
counter = 0;
|
2014-08-04 13:42:36 +00:00
|
|
|
llist_for_each_entry(peer, &g_cfg->bts_peers, list) {
|
2014-08-04 09:10:09 +00:00
|
|
|
if (peer->nsei != nsei)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
vty_out(vty, "BVC: ");
|
|
|
|
gbprox_vty_print_peer(vty, peer);
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
vty_out(vty, "%sDeleted %d BVC%s",
|
|
|
|
dry_run ? "Not " : "", counter, VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (delete_nsvc) {
|
2014-08-04 13:42:36 +00:00
|
|
|
struct gprs_ns_inst *nsi = g_cfg->nsi;
|
2014-08-04 09:10:09 +00:00
|
|
|
struct gprs_nsvc *nsvc, *nsvc2;
|
|
|
|
|
|
|
|
counter = 0;
|
|
|
|
llist_for_each_entry_safe(nsvc, nsvc2, &nsi->gprs_nsvcs, list) {
|
|
|
|
if (nsvc->nsei != nsei)
|
|
|
|
continue;
|
|
|
|
if (nsvc->persistent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (!dry_run)
|
|
|
|
gprs_nsvc_delete(nsvc);
|
|
|
|
else
|
|
|
|
vty_out(vty, "NS-VC: NSEI %5u, NS-VCI %5u, "
|
|
|
|
"remote %s%s",
|
|
|
|
nsvc->nsei, nsvc->nsvci,
|
|
|
|
gprs_ns_ll_str(nsvc), VTY_NEWLINE);
|
|
|
|
counter += 1;
|
|
|
|
}
|
|
|
|
vty_out(vty, "%sDeleted %d NS-VC%s",
|
|
|
|
dry_run ? "Not " : "", counter, VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
DEFUN(delete_gb_tlli, delete_gb_tlli_cmd,
|
|
|
|
"delete-gbproxy-tlli <0-65534> (tlli|imsi|stale) [IDENT]",
|
|
|
|
"Delete a GBProxy TLLI entry by NSEI and identification\n"
|
|
|
|
"NSEI number\n"
|
|
|
|
"Delete entries with a matching TLLI (hex)\n"
|
|
|
|
"Delete entries with a matching IMSI\n"
|
2014-08-29 08:50:50 +00:00
|
|
|
"Delete stale entries\n"
|
2014-08-04 09:10:09 +00:00
|
|
|
"Identification to match\n")
|
|
|
|
{
|
|
|
|
const uint16_t nsei = atoi(argv[0]);
|
|
|
|
enum {MATCH_TLLI = 't', MATCH_IMSI = 'i', MATCH_STALE = 's'} match;
|
|
|
|
uint32_t tlli = 0;
|
|
|
|
const char *imsi = NULL;
|
2014-08-04 09:35:32 +00:00
|
|
|
struct gbproxy_peer *peer = 0;
|
|
|
|
struct gbproxy_tlli_info *tlli_info, *nxt;
|
|
|
|
struct gbproxy_patch_state *state;
|
2014-08-04 09:10:09 +00:00
|
|
|
char mi_buf[200];
|
|
|
|
int found = 0;
|
|
|
|
|
|
|
|
match = argv[1][0];
|
|
|
|
|
|
|
|
switch (match) {
|
|
|
|
case MATCH_TLLI:
|
|
|
|
if (argc < 2 || !argv[2][0]) {
|
|
|
|
vty_out(vty, "%% Missing TLLI%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
tlli = strtoll(argv[2], NULL, 16);
|
|
|
|
break;
|
|
|
|
case MATCH_IMSI:
|
|
|
|
if (argc < 2 || !argv[2][0]) {
|
|
|
|
vty_out(vty, "%% Missing IMSI%s", VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
imsi = argv[2];
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2014-08-21 08:01:30 +00:00
|
|
|
peer = gbproxy_peer_by_nsei(g_cfg, nsei);
|
2014-08-04 09:10:09 +00:00
|
|
|
if (!peer) {
|
|
|
|
vty_out(vty, "Didn't find peer with NSEI %d%s",
|
|
|
|
nsei, VTY_NEWLINE);
|
|
|
|
return CMD_WARNING;
|
|
|
|
}
|
|
|
|
|
|
|
|
state = &peer->patch_state;
|
|
|
|
|
|
|
|
if (match == MATCH_STALE) {
|
2014-08-19 10:21:01 +00:00
|
|
|
found = gbproxy_remove_stale_tllis(peer, time(NULL));
|
2014-08-04 09:10:09 +00:00
|
|
|
if (found)
|
|
|
|
vty_out(vty, "Deleted %d stale TLLI%s%s",
|
|
|
|
found, found == 1 ? "" : "s", VTY_NEWLINE);
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
llist_for_each_entry_safe(tlli_info, nxt, &state->enabled_tllis, list) {
|
2014-08-12 14:30:30 +00:00
|
|
|
if (match == MATCH_TLLI && tlli_info->tlli.current != tlli)
|
2014-08-04 09:10:09 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (match == MATCH_IMSI) {
|
|
|
|
mi_buf[0] = '\0';
|
|
|
|
gsm48_mi_to_string(mi_buf, sizeof(mi_buf),
|
2014-09-11 12:57:03 +00:00
|
|
|
tlli_info->imsi,
|
|
|
|
tlli_info->imsi_len);
|
2014-08-04 09:10:09 +00:00
|
|
|
|
|
|
|
if (strcmp(mi_buf, imsi) != 0)
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-12 14:30:30 +00:00
|
|
|
vty_out(vty, "Deleting TLLI %08x%s", tlli_info->tlli.current,
|
|
|
|
VTY_NEWLINE);
|
2014-08-19 10:21:01 +00:00
|
|
|
gbproxy_delete_tlli(peer, tlli_info);
|
2014-08-04 09:10:09 +00:00
|
|
|
found += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found && argc >= 2) {
|
|
|
|
vty_out(vty, "Didn't find TLLI entry with %s %s%s",
|
|
|
|
argv[1], argv[2], VTY_NEWLINE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CMD_SUCCESS;
|
|
|
|
}
|
2014-05-19 08:14:58 +00:00
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
int gbproxy_vty_init(void)
|
|
|
|
{
|
2010-05-12 16:50:52 +00:00
|
|
|
install_element_ve(&show_gbproxy_cmd);
|
2014-06-19 08:15:27 +00:00
|
|
|
install_element_ve(&show_gbproxy_tllis_cmd);
|
2010-04-30 19:49:24 +00:00
|
|
|
|
2013-10-24 10:48:23 +00:00
|
|
|
install_element(ENABLE_NODE, &delete_gb_bvci_cmd);
|
|
|
|
install_element(ENABLE_NODE, &delete_gb_nsei_cmd);
|
2014-06-19 08:15:27 +00:00
|
|
|
install_element(ENABLE_NODE, &delete_gb_tlli_cmd);
|
2013-10-23 09:24:17 +00:00
|
|
|
|
2010-04-30 19:49:24 +00:00
|
|
|
install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
|
|
|
|
install_node(&gbproxy_node, config_write_gbproxy);
|
2013-10-29 08:30:30 +00:00
|
|
|
vty_install_default(GBPROXY_NODE);
|
2010-04-30 19:49:24 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
|
2014-05-19 08:14:58 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_mcc_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_mnc_cmd);
|
2014-09-02 11:57:19 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_match_imsi_cmd);
|
2014-05-23 18:48:07 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_core_apn_cmd);
|
2014-09-02 11:57:19 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_secondary_sgsn_cmd);
|
2014-08-18 12:54:37 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_patch_ptmsi_cmd);
|
2014-08-22 15:10:01 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_acquire_imsi_cmd);
|
2014-06-06 16:49:23 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_age_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_max_len_cmd);
|
2014-09-12 13:09:56 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_keep_mode_cmd);
|
2014-05-19 08:14:58 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mcc_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_mnc_cmd);
|
2014-09-02 11:57:19 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_match_imsi_cmd);
|
2014-05-23 18:48:07 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_core_apn_cmd);
|
2014-09-02 11:57:19 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_secondary_sgsn_cmd);
|
2014-08-18 12:54:37 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_patch_ptmsi_cmd);
|
2014-08-22 15:10:01 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_no_acquire_imsi_cmd);
|
2014-06-06 16:49:23 +00:00
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_age_cmd);
|
|
|
|
install_element(GBPROXY_NODE, &cfg_gbproxy_tlli_list_no_max_len_cmd);
|
2010-04-30 19:49:24 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
g_cfg = cfg;
|
2010-05-16 18:52:23 +00:00
|
|
|
rc = vty_read_config_file(config_file, NULL);
|
2010-04-30 19:49:24 +00:00
|
|
|
if (rc < 0) {
|
|
|
|
fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|