aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-12-27 21:19:51 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2017-12-27 21:19:51 +0100
commit7e3a0d59e9266856d1b81b2c9e13575bd2fb133e (patch)
tree71df8d87abd70b474715f947138967dd978583d3
parentf8455c4209abf1cf1574c836139fb175fe72da0f (diff)
add gprs subscriber log filter
-rw-r--r--include/osmocom/sgsn/debug.h15
-rw-r--r--src/gprs/gprs_gmm.c32
-rw-r--r--src/gprs/sgsn_libgtp.c14
-rw-r--r--src/gprs/sgsn_vty.c43
-rw-r--r--src/libcommon/debug.c12
5 files changed, 109 insertions, 7 deletions
diff --git a/include/osmocom/sgsn/debug.h b/include/osmocom/sgsn/debug.h
index 65e197d5..662567bc 100644
--- a/include/osmocom/sgsn/debug.h
+++ b/include/osmocom/sgsn/debug.h
@@ -6,6 +6,8 @@
#define DEBUG
#include <osmocom/core/logging.h>
+struct gprs_subscr;
+
/* Debug Areas of the code */
enum {
DRLL,
@@ -44,4 +46,17 @@ enum {
Debug_LastEntry,
};
+enum sgsn_log_flt {
+ LOG_FLT_GPRS_SUBSCR = _LOG_FLT_COUNT,
+ _LOG_FLT_COUNT_SGSN
+};
+
+enum sgsn_log_ctx_index {
+ LOG_CTX_GPRS_SUBSCR = _LOG_CTX_COUNT,
+ _LOG_CTX_COUNT_SGSN
+};
+
extern const struct log_info log_info;
+
+void log_set_filter_gprs_subscriber(struct log_target *target,
+ struct gprs_subscr *gsub);
diff --git a/src/gprs/gprs_gmm.c b/src/gprs/gprs_gmm.c
index ead958ee..f1b43486 100644
--- a/src/gprs/gprs_gmm.c
+++ b/src/gprs/gprs_gmm.c
@@ -182,6 +182,8 @@ int sgsn_ranap_iu_event(struct ranap_ue_conn_ctx *ctx, enum ranap_iu_event_type
return rc; \
}
+ log_set_context(LOG_CTX_GPRS_SUBSCR, mm->subscr);
+
switch (type) {
case RANAP_IU_EVENT_RAB_ASSIGN:
REQUIRE_MM
@@ -211,6 +213,8 @@ int sgsn_ranap_iu_event(struct ranap_ue_conn_ctx *ctx, enum ranap_iu_event_type
rc = -1;
break;
}
+
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
#endif
@@ -1386,6 +1390,9 @@ static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg,
reject_cause = GMM_CAUSE_MS_ID_NOT_DERIVED;
goto rejected;
}
+
+ log_set_context(LOG_CTX_GPRS_SUBSCR, ctx->subscr);
+
/* Update MM Context with currient RA and Cell ID */
ctx->ra = ra_id;
if (ctx->ran_type == MM_CTX_T_GERAN_Gb)
@@ -1425,7 +1432,8 @@ static int gsm48_rx_gmm_att_req(struct sgsn_mm_ctx *ctx, struct msgb *msg,
}
ctx->pending_req = GSM48_MT_GMM_ATTACH_REQ;
- return gsm48_gmm_authorize(ctx);
+ rc = gsm48_gmm_authorize(ctx);
+ goto out;
err_inval:
LOGPC(DMM, LOGL_INFO, "\n");
@@ -1441,7 +1449,8 @@ rejected:
mm_ctx_cleanup_free(ctx, "GPRS ATTACH REJ");
else if (llme)
gprs_llgmm_unassign(llme);
-
+out:
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
@@ -1707,6 +1716,8 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
goto rejected;
}
+ log_set_context(LOG_CTX_GPRS_SUBSCR, mmctx->subscr);
+
/* Store new BVCI/NSEI in MM context (FIXME: delay until we ack?) */
msgid2mmctx(mmctx, msg);
/* Bump the statistics of received signalling msgs for this MM context */
@@ -1758,7 +1769,8 @@ static int gsm48_rx_gmm_ra_upd_req(struct sgsn_mm_ctx *mmctx, struct msgb *msg,
* a new Iu connection, so we might need to re-authenticate the
* connection as well as turn on integrity protection. */
mmctx->pending_req = GSM48_MT_GMM_RA_UPD_REQ;
- return gsm48_gmm_authorize(mmctx);
+ rc = gsm48_gmm_authorize(mmctx);
+ goto out;
rejected:
/* Send RA UPDATE REJECT */
@@ -1773,6 +1785,8 @@ rejected:
gprs_llgmm_unassign(llme);
}
+out:
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
@@ -1854,6 +1868,8 @@ static int gsm48_rx_gmm_service_req(struct sgsn_mm_ctx *ctx, struct msgb *msg)
goto rejected;
}
+ log_set_context(LOG_CTX_GPRS_SUBSCR, ctx->subscr);
+
ctx->gmm_state = GMM_COMMON_PROC_INIT;
ctx->iu.service.type = service_type;
@@ -1868,7 +1884,8 @@ static int gsm48_rx_gmm_service_req(struct sgsn_mm_ctx *ctx, struct msgb *msg)
ctx->pending_req = GSM48_MT_GMM_SERVICE_REQ;
- return gsm48_gmm_authorize(ctx);
+ rc = gsm48_gmm_authorize(ctx);
+ goto out;
err_inval:
LOGPC(DMM, LOGL_INFO, "\n");
@@ -1881,6 +1898,8 @@ rejected:
get_value_string(gsm48_gmm_cause_names, reject_cause), reject_cause);
rc = gsm48_tx_gmm_service_rej_oldmsg(msg, reject_cause);
+out:
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
@@ -2801,6 +2820,8 @@ int gsm0408_gprs_rcvmsg_iu(struct msgb *msg, struct gprs_ra_id *ra_id,
rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]);
if (ra_id)
memcpy(&mmctx->ra, ra_id, sizeof(mmctx->ra));
+
+ log_set_context(LOG_CTX_GPRS_SUBSCR, mmctx->subscr);
}
/* MMCTX can be NULL */
@@ -2823,6 +2844,7 @@ int gsm0408_gprs_rcvmsg_iu(struct msgb *msg, struct gprs_ra_id *ra_id,
/* MMCTX can be invalid */
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
@@ -2842,6 +2864,7 @@ int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme,
msgid2mmctx(mmctx, msg);
rate_ctr_inc(&mmctx->ctrg->ctr[GMM_CTR_PKTS_SIG_IN]);
mmctx->gb.llme = llme;
+ log_set_context(LOG_CTX_GPRS_SUBSCR, mmctx->subscr);
}
/* MMCTX can be NULL */
@@ -2863,6 +2886,7 @@ int gsm0408_gprs_rcvmsg_gb(struct msgb *msg, struct gprs_llc_llme *llme,
/* MMCTX can be invalid */
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
return rc;
}
diff --git a/src/gprs/sgsn_libgtp.c b/src/gprs/sgsn_libgtp.c
index 1032230a..916164a0 100644
--- a/src/gprs/sgsn_libgtp.c
+++ b/src/gprs/sgsn_libgtp.c
@@ -746,6 +746,7 @@ int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
{
struct sgsn_mm_ctx *mmctx;
struct sgsn_pdp_ctx *pdp;
+ int rc = 0;
/* look-up the MM context for this message */
mmctx = sgsn_mm_ctx_by_tlli(tlli, ra_id);
@@ -754,16 +755,20 @@ int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
"Cannot find MM CTX for TLLI %08x\n", tlli);
return -EIO;
}
+
+ log_set_context(LOG_CTX_GPRS_SUBSCR, mmctx->subscr);
+
/* look-up the PDP context for this message */
pdp = sgsn_pdp_ctx_by_nsapi(mmctx, nsapi);
if (!pdp) {
LOGP(DGPRS, LOGL_ERROR, "Cannot find PDP CTX for "
"TLLI=%08x, NSAPI=%u\n", tlli, nsapi);
- return -EIO;
+ rc = -EIO;
}
if (!pdp->lib) {
LOGP(DGPRS, LOGL_ERROR, "PDP CTX without libgtp\n");
- return -EIO;
+ rc = -EIO;
+ goto out;
}
rate_ctr_inc(&pdp->ctrg->ctr[PDP_CTR_PKTS_UDATA_IN]);
@@ -774,7 +779,10 @@ int sgsn_rx_sndcp_ud_ind(struct gprs_ra_id *ra_id, int32_t tlli, uint8_t nsapi,
/* It is easier to have a global count */
pdp->cdr_bytes_in += npdu_len;
- return gtp_data_req(pdp->ggsn->gsn, pdp->lib, npdu, npdu_len);
+ rc = gtp_data_req(pdp->ggsn->gsn, pdp->lib, npdu, npdu_len);
+out:
+ log_set_context(LOG_CTX_GPRS_SUBSCR, NULL);
+ return rc;
}
/* libgtp select loop integration */
diff --git a/src/gprs/sgsn_vty.c b/src/gprs/sgsn_vty.c
index c2c03b5a..51d67547 100644
--- a/src/gprs/sgsn_vty.c
+++ b/src/gprs/sgsn_vty.c
@@ -40,6 +40,7 @@
#include <osmocom/vty/command.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/misc.h>
+#include <osmocom/vty/logging.h>
#include <osmocom/crypt/gprs_cipher.h>
#include <osmocom/abis/ipa.h>
@@ -1232,6 +1233,45 @@ DEFUN(cfg_comp_v42bisp, cfg_comp_v42bisp_cmd,
return CMD_SUCCESS;
}
+void log_set_filter_gprs_subscriber(struct log_target *target,
+ struct gprs_subscr *gsub)
+{
+ struct gprs_subscr **gsub_p = (void*)&target->filter_data[LOG_FLT_GPRS_SUBSCR];
+
+ /* free the old data */
+ if (*gsub_p) {
+ gprs_subscr_put(*gsub_p);
+ *gsub_p = NULL;
+ }
+
+ if (gsub) {
+ target->filter_map |= (1 << LOG_FLT_GPRS_SUBSCR);
+ *gsub_p = gprs_subscr_get(gsub);
+ } else
+ target->filter_map &= ~(1 << LOG_FLT_GPRS_SUBSCR);
+}
+
+DEFUN(logging_fltr_gprs_subscr,
+ logging_fltr_gprs_subscr_cmd,
+ "logging filter imsi IMSI",
+ LOGGING_STR FILTER_STR
+ "Filter by IMSI\n"
+ "IMSI to filter by\n")
+{
+ struct log_target *tgt = osmo_log_vty2tgt(vty);
+ struct gprs_subscr *gsub;
+ const char *imsi = argv[0];
+
+ if (!tgt)
+ return CMD_WARNING;
+
+ gsub = gprs_subscr_get_by_imsi(imsi);
+
+ log_set_filter_gprs_subscriber(tgt, gsub);
+ return CMD_SUCCESS;
+}
+
+
int sgsn_vty_init(struct sgsn_config *cfg)
{
g_cfg = cfg;
@@ -1243,6 +1283,9 @@ int sgsn_vty_init(struct sgsn_config *cfg)
install_element_ve(&show_pdpctx_all_cmd);
install_element_ve(&show_subscr_cache_cmd);
+ install_element_ve(&logging_fltr_gprs_subscr_cmd);
+ install_element(CFG_LOG_NODE, &logging_fltr_gprs_subscr_cmd);
+
install_element(ENABLE_NODE, &update_subscr_insert_auth_triplet_cmd);
install_element(ENABLE_NODE, &update_subscr_create_cmd);
install_element(ENABLE_NODE, &update_subscr_destroy_cmd);
diff --git a/src/libcommon/debug.c b/src/libcommon/debug.c
index 60764099..611b567a 100644
--- a/src/libcommon/debug.c
+++ b/src/libcommon/debug.c
@@ -34,6 +34,13 @@
#include <osmocom/sgsn/gsm_data.h>
#include <osmocom/sgsn/debug.h>
+osmo_static_assert(_LOG_CTX_COUNT_SGSN <= ARRAY_SIZE(((struct log_context*)NULL)->ctx),
+ enum_logging_ctx_items_fit_in_struct_log_context);
+osmo_static_assert(_LOG_FLT_COUNT_SGSN <= ARRAY_SIZE(((struct log_target*)NULL)->filter_data),
+ enum_sgsn_log_flt_fit_in_log_target_filter_data);
+osmo_static_assert(_LOG_FLT_COUNT_SGSN <= 8*sizeof(((struct log_target*)NULL)->filter_map),
+ enum_sgsn_log_flt_fit_in_log_target_filter_map);
+
/* default categories */
static const struct log_info_cat default_categories[] = {
[DRLL] = {
@@ -203,6 +210,7 @@ static int filter_fn(const struct log_context *ctx, struct log_target *tar)
const struct bsc_subscr *bsub = ctx->ctx[LOG_CTX_BSC_SUBSCR];
const struct gprs_nsvc *nsvc = ctx->ctx[LOG_CTX_GB_NSVC];
const struct gprs_nsvc *bvc = ctx->ctx[LOG_CTX_GB_BVC];
+ const struct gprs_subscr *gsub = ctx->ctx[LOG_CTX_GPRS_SUBSCR];
if ((tar->filter_map & (1 << LOG_FLT_VLR_SUBSCR)) != 0
&& vsub && vsub == tar->filter_data[LOG_FLT_VLR_SUBSCR])
@@ -222,6 +230,10 @@ static int filter_fn(const struct log_context *ctx, struct log_target *tar)
&& bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC]))
return 1;
+ if ((tar->filter_map & (1 << LOG_FLT_GPRS_SUBSCR))
+ && gsub && (gsub == tar->filter_data[LOG_CTX_GPRS_SUBSCR]))
+ return 1;
+
return 0;
}