logging: Only compare the subscr address

Move the "logging filter imsi IMSI" into the BTS/NITB code to
allow to set the gsm_subscriber and only compare it. This way
we simply compare the subscriber address and don't have to care
if the subscriber data is still valid.
This commit is contained in:
Holger Hans Peter Freyther 2014-12-28 18:54:32 +01:00
parent b7ccac4d62
commit 6995f24831
7 changed files with 72 additions and 34 deletions

View File

@ -53,8 +53,9 @@ enum {
/* we don't need a header dependency for this... */ /* we don't need a header dependency for this... */
struct gprs_nsvc; struct gprs_nsvc;
struct bssgp_bvc_ctx; struct bssgp_bvc_ctx;
struct gsm_subscriber;
void log_set_imsi_filter(struct log_target *target, const char *imsi); void log_set_imsi_filter(struct log_target *target, struct gsm_subscriber *subscr);
void log_set_nsvc_filter(struct log_target *target, void log_set_nsvc_filter(struct log_target *target,
struct gprs_nsvc *nsvc); struct gprs_nsvc *nsvc);
void log_set_bvc_filter(struct log_target *target, void log_set_bvc_filter(struct log_target *target,

View File

@ -3183,22 +3183,6 @@ void openbsc_vty_print_statistics(struct vty *vty, struct gsm_network *net)
osmo_counter_get(net->stats.bts.rsl_fail), VTY_NEWLINE); osmo_counter_get(net->stats.bts.rsl_fail), VTY_NEWLINE);
} }
DEFUN(logging_fltr_imsi,
logging_fltr_imsi_cmd,
"logging filter imsi IMSI",
LOGGING_STR FILTER_STR
"Filter log messages by IMSI\n" "IMSI to be used as filter\n")
{
struct log_target *tgt = osmo_log_vty2tgt(vty);
if (!tgt)
return CMD_WARNING;
log_set_imsi_filter(tgt, argv[0]);
return CMD_SUCCESS;
}
DEFUN(drop_bts, DEFUN(drop_bts,
drop_bts_cmd, drop_bts_cmd,
"drop bts connection <0-65535> (oml|rsl)", "drop bts connection <0-65535> (oml|rsl)",
@ -3383,13 +3367,11 @@ int bsc_vty_init(const struct log_info *cat)
install_element_ve(&show_ts_cmd); install_element_ve(&show_ts_cmd);
install_element_ve(&show_lchan_cmd); install_element_ve(&show_lchan_cmd);
install_element_ve(&show_lchan_summary_cmd); install_element_ve(&show_lchan_summary_cmd);
install_element_ve(&logging_fltr_imsi_cmd);
install_element_ve(&show_paging_cmd); install_element_ve(&show_paging_cmd);
install_element_ve(&show_paging_group_cmd); install_element_ve(&show_paging_group_cmd);
logging_vty_add_cmds(cat); logging_vty_add_cmds(cat);
install_element(CFG_LOG_NODE, &logging_fltr_imsi_cmd);
install_element(CONFIG_NODE, &cfg_net_cmd); install_element(CONFIG_NODE, &cfg_net_cmd);
install_node(&net_node, config_write_net); install_node(&net_node, config_write_net);

View File

@ -250,12 +250,11 @@ static int paging_pending_request(struct gsm_bts_paging_state *bts,
static void paging_T3113_expired(void *data) static void paging_T3113_expired(void *data)
{ {
struct gsm_paging_request *req = (struct gsm_paging_request *)data; struct gsm_paging_request *req = (struct gsm_paging_request *)data;
struct gsm_subscriber *subscr = subscr_get(req->subscr);
void *cbfn_param; void *cbfn_param;
gsm_cbfn *cbfn; gsm_cbfn *cbfn;
int msg; int msg;
log_set_context(BSC_CTX_SUBSCR, subscr); log_set_context(BSC_CTX_SUBSCR, req->subscr);
LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n", LOGP(DPAG, LOGL_INFO, "T3113 expired for request %p (%s)\n",
req, req->subscr->imsi); req, req->subscr->imsi);
@ -275,8 +274,6 @@ static void paging_T3113_expired(void *data)
cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL, cbfn(GSM_HOOK_RR_PAGING, msg, NULL, NULL,
cbfn_param); cbfn_param);
log_set_context(BSC_CTX_SUBSCR, NULL);
subscr_put(subscr);
} }
static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr, static int _paging_request(struct gsm_bts *bts, struct gsm_subscriber *subscr,

View File

@ -177,7 +177,7 @@ static int filter_fn(const struct log_context *ctx,
const struct gprs_nsvc *bvc = ctx->ctx[GPRS_CTX_BVC]; const struct gprs_nsvc *bvc = ctx->ctx[GPRS_CTX_BVC];
if ((tar->filter_map & (1 << FLT_IMSI)) != 0 if ((tar->filter_map & (1 << FLT_IMSI)) != 0
&& subscr && strcmp(subscr->imsi, tar->filter_data[FLT_IMSI]) == 0) && subscr && subscr == tar->filter_data[FLT_IMSI])
return 1; return 1;
/* Filter on the NS Virtual Connection */ /* Filter on the NS Virtual Connection */
@ -199,14 +199,18 @@ const struct log_info log_info = {
.num_cat = ARRAY_SIZE(default_categories), .num_cat = ARRAY_SIZE(default_categories),
}; };
void log_set_imsi_filter(struct log_target *target, const char *imsi) void log_set_imsi_filter(struct log_target *target, struct gsm_subscriber *subscr)
{ {
if (imsi) { /* free the old data */
target->filter_map |= (1 << FLT_IMSI); if (target->filter_data[FLT_IMSI]) {
target->filter_data[FLT_IMSI] = talloc_strdup(target, imsi); subscr_put(target->filter_data[FLT_IMSI]);
} else if (target->filter_data[FLT_IMSI]) {
target->filter_map &= ~(1 << FLT_IMSI);
talloc_free(target->filter_data[FLT_IMSI]);
target->filter_data[FLT_IMSI] = NULL; target->filter_data[FLT_IMSI] = NULL;
} }
if (subscr) {
target->filter_map |= (1 << FLT_IMSI);
target->filter_data[FLT_IMSI] = subscr_get(subscr);
} else {
target->filter_map &= ~(1 << FLT_IMSI);
}
} }

View File

@ -49,6 +49,8 @@
#include <openbsc/mncc_int.h> #include <openbsc/mncc_int.h>
#include <openbsc/handover.h> #include <openbsc/handover.h>
#include <osmocom/vty/logging.h>
#include "meas_feed.h" #include "meas_feed.h"
extern struct gsm_network *gsmnet_from_vty(struct vty *v); extern struct gsm_network *gsmnet_from_vty(struct vty *v);
@ -1027,6 +1029,30 @@ DEFUN(meas_feed_scenario, meas_feed_scenario_cmd,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUN(logging_fltr_imsi,
logging_fltr_imsi_cmd,
"logging filter imsi IMSI",
LOGGING_STR FILTER_STR
"Filter log messages by IMSI\n" "IMSI to be used as filter\n")
{
struct gsm_subscriber *subscr;
struct gsm_network *gsmnet = gsmnet_from_vty(vty);
struct log_target *tgt = osmo_log_vty2tgt(vty);
if (!tgt)
return CMD_WARNING;
subscr = subscr_get_by_imsi(gsmnet->subscr_group, argv[0]);
if (!subscr) {
vty_out(vty, "%%no subscriber with IMSI(%s)%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
log_set_imsi_filter(tgt, subscr);
return CMD_SUCCESS;
}
int bsc_vty_init_extra(void) int bsc_vty_init_extra(void)
{ {
osmo_signal_register_handler(SS_SCALL, scall_cbfn, NULL); osmo_signal_register_handler(SS_SCALL, scall_cbfn, NULL);
@ -1045,6 +1071,7 @@ int bsc_vty_init_extra(void)
install_element_ve(&subscriber_update_cmd); install_element_ve(&subscriber_update_cmd);
install_element_ve(&show_stats_cmd); install_element_ve(&show_stats_cmd);
install_element_ve(&show_smsqueue_cmd); install_element_ve(&show_smsqueue_cmd);
install_element_ve(&logging_fltr_imsi_cmd);
install_element(ENABLE_NODE, &ena_subscr_delete_cmd); install_element(ENABLE_NODE, &ena_subscr_delete_cmd);
install_element(ENABLE_NODE, &ena_subscr_name_cmd); install_element(ENABLE_NODE, &ena_subscr_name_cmd);
@ -1071,6 +1098,7 @@ int bsc_vty_init_extra(void)
install_element(MNCC_INT_NODE, &mnccint_meas_feed_cmd); install_element(MNCC_INT_NODE, &mnccint_meas_feed_cmd);
install_element(CFG_LOG_NODE, &log_level_sms_cmd); install_element(CFG_LOG_NODE, &log_level_sms_cmd);
install_element(CFG_LOG_NODE, &logging_fltr_imsi_cmd);
return 0; return 0;
} }

View File

@ -22,8 +22,11 @@
#include <openbsc/osmo_bsc.h> #include <openbsc/osmo_bsc.h>
#include <openbsc/osmo_msc_data.h> #include <openbsc/osmo_msc_data.h>
#include <openbsc/vty.h> #include <openbsc/vty.h>
#include <openbsc/gsm_subscriber.h>
#include <openbsc/debug.h>
#include <osmocom/core/talloc.h> #include <osmocom/core/talloc.h>
#include <osmocom/vty/logging.h>
#include <time.h> #include <time.h>
@ -739,6 +742,29 @@ DEFUN(gen_position_trap,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFUN(logging_fltr_imsi,
logging_fltr_imsi_cmd,
"logging filter imsi IMSI",
LOGGING_STR FILTER_STR
"Filter log messages by IMSI\n" "IMSI to be used as filter\n")
{
struct gsm_subscriber *subscr;
struct log_target *tgt = osmo_log_vty2tgt(vty);
if (!tgt)
return CMD_WARNING;
subscr = subscr_get_or_create(bsc_gsmnet->subscr_group, argv[0]);
if (!subscr) {
vty_out(vty, "%%no subscriber with IMSI(%s)%s",
argv[0], VTY_NEWLINE);
return CMD_WARNING;
}
log_set_imsi_filter(tgt, subscr);
return CMD_SUCCESS;
}
int bsc_vty_init_extra(void) int bsc_vty_init_extra(void)
{ {
install_element(CONFIG_NODE, &cfg_net_msc_cmd); install_element(CONFIG_NODE, &cfg_net_msc_cmd);
@ -789,8 +815,11 @@ int bsc_vty_init_extra(void)
install_element_ve(&show_statistics_cmd); install_element_ve(&show_statistics_cmd);
install_element_ve(&show_mscs_cmd); install_element_ve(&show_mscs_cmd);
install_element_ve(&show_pos_cmd); install_element_ve(&show_pos_cmd);
install_element_ve(&logging_fltr_imsi_cmd);
install_element(ENABLE_NODE, &gen_position_trap_cmd); install_element(ENABLE_NODE, &gen_position_trap_cmd);
install_element(CFG_LOG_NODE, &logging_fltr_imsi_cmd);
return 0; return 0;
} }

View File

@ -53,9 +53,6 @@
#include "openbsc/mgcp_transcode.h" #include "openbsc/mgcp_transcode.h"
#endif #endif
/* this is here for the vty... it will never be called */
void subscr_put() { abort(); }
#define _GNU_SOURCE #define _GNU_SOURCE
#include <getopt.h> #include <getopt.h>