ns2: Add log filtering by NSE/NSEI, fix NSVC filter on receive

NSVC filtering was only implemented on sending messages, this also adds
log_set_context() calls to  ns2_recv_vc()
Filtering by NSE is implemented similar to NSVC.

Change-Id: I63c0e85f82f5d08c5a6f535da94b8648498439d2
Related: SYS#5232
This commit is contained in:
Daniel Willmann 2020-12-02 18:59:44 +01:00
parent d87a2f14e6
commit 751977be6f
5 changed files with 74 additions and 2 deletions

View File

@ -165,6 +165,7 @@ enum log_ctx_index {
LOG_CTX_BSC_SUBSCR,
LOG_CTX_VLR_SUBSCR,
LOG_CTX_L1_SAPI,
LOG_CTX_GB_NSE,
_LOG_CTX_COUNT
};
@ -178,6 +179,7 @@ enum log_filter_index {
LOG_FLT_BSC_SUBSCR,
LOG_FLT_VLR_SUBSCR,
LOG_FLT_L1_SAPI,
LOG_FLT_GB_NSE,
_LOG_FLT_COUNT
};

View File

@ -40,15 +40,21 @@
int gprs_log_filter_fn(const struct log_context *ctx,
struct log_target *tar)
{
const void *nse = ctx->ctx[LOG_CTX_GB_NSE];
const void *nsvc = ctx->ctx[LOG_CTX_GB_NSVC];
const void *bvc = ctx->ctx[LOG_CTX_GB_BVC];
/* Filter on the NS Entity */
if ((tar->filter_map & (1 << LOG_FLT_GB_NSE)) != 0
&& nse && (nse == tar->filter_data[LOG_FLT_GB_NSE]))
return 1;
/* Filter on the NS Virtual Connection */
if ((tar->filter_map & (1 << LOG_FLT_GB_NSVC)) != 0
&& nsvc && (nsvc == tar->filter_data[LOG_FLT_GB_NSVC]))
return 1;
/* Filter on the NS Virtual Connection */
/* Filter on the BSSGP Virtual Connection */
if ((tar->filter_map & (1 << LOG_FLT_GB_BVC)) != 0
&& bvc && (bvc == tar->filter_data[LOG_FLT_GB_BVC]))
return 1;

View File

@ -72,6 +72,7 @@
#include <arpa/inet.h>
#include <osmocom/core/fsm.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/msgb.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/socket.h>
@ -1010,6 +1011,9 @@ int ns2_recv_vc(struct gprs_ns2_vc *nsvc,
struct tlv_parsed tp;
int rc = 0;
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (msg->len < sizeof(struct gprs_ns_hdr))
return -EINVAL;

View File

@ -189,6 +189,7 @@ static int ns2_tx_simple(struct gprs_ns2_vc *nsvc, uint8_t pdu_type)
struct msgb *msg = gprs_ns2_msgb_alloc();
struct gprs_ns_hdr *nsh;
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
@ -212,6 +213,7 @@ int ns2_tx_block(struct gprs_ns2_vc *nsvc, uint8_t cause)
struct gprs_ns_hdr *nsh;
uint16_t nsvci = osmo_htons(nsvc->nsvci);
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS BLOCK");
@ -244,6 +246,7 @@ int ns2_tx_block_ack(struct gprs_ns2_vc *nsvc)
struct gprs_ns_hdr *nsh;
uint16_t nsvci = osmo_htons(nsvc->nsvci);
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS BLOCK ACK");
@ -275,6 +278,7 @@ int ns2_tx_reset(struct gprs_ns2_vc *nsvc, uint8_t cause)
uint16_t nsvci = osmo_htons(nsvc->nsvci);
uint16_t nsei = osmo_htons(nsvc->nse->nsei);
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS RESET");
@ -307,6 +311,7 @@ int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc)
uint16_t nsvci, nsei;
/* Section 9.2.6 */
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS RESET ACK");
@ -337,6 +342,7 @@ int ns2_tx_reset_ack(struct gprs_ns2_vc *nsvc)
* \returns 0 in case of success */
int ns2_tx_unblock(struct gprs_ns2_vc *nsvc)
{
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS UNBLOCK");
@ -353,6 +359,7 @@ int ns2_tx_unblock(struct gprs_ns2_vc *nsvc)
* \returns 0 in case of success */
int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc)
{
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
ERR_IF_NSVC_USES_SNS(nsvc, "transmit NS UNBLOCK ACK");
@ -368,6 +375,7 @@ int ns2_tx_unblock_ack(struct gprs_ns2_vc *nsvc)
* \returns 0 in case of success */
int ns2_tx_alive(struct gprs_ns2_vc *nsvc)
{
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
LOGP(DLNS, LOGL_DEBUG, "NSEI=%u Tx NS ALIVE (NSVCI=%u)\n",
nsvc->nse->nsei, nsvc->nsvci);
@ -380,6 +388,7 @@ int ns2_tx_alive(struct gprs_ns2_vc *nsvc)
* \returns 0 in case of success */
int ns2_tx_alive_ack(struct gprs_ns2_vc *nsvc)
{
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
LOGP(DLNS, LOGL_DEBUG, "NSEI=%u Tx NS ALIVE_ACK (NSVCI=%u)\n",
nsvc->nse->nsei, nsvc->nsvci);
@ -399,6 +408,7 @@ int ns2_tx_unit_data(struct gprs_ns2_vc *nsvc,
{
struct gprs_ns_hdr *nsh;
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
msg->l2h = msgb_push(msg, sizeof(*nsh) + 3);
@ -430,6 +440,7 @@ int ns2_tx_status(struct gprs_ns2_vc *nsvc, uint8_t cause,
struct gprs_ns_hdr *nsh;
uint16_t nsvci = osmo_htons(nsvc->nsvci);
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
bvci = osmo_htons(bvci);
@ -495,6 +506,7 @@ int ns2_tx_sns_ack(struct gprs_ns2_vc *nsvc, uint8_t trans_id, uint8_t *cause,
msg = gprs_ns2_msgb_alloc();
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
return -ENOMEM;
@ -553,6 +565,7 @@ int ns2_tx_sns_config(struct gprs_ns2_vc *nsvc, bool end_flag,
msg = gprs_ns2_msgb_alloc();
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
return -ENOMEM;
@ -601,6 +614,7 @@ int ns2_tx_sns_config_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause)
return -1;
msg = gprs_ns2_msgb_alloc();
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
return -ENOMEM;
@ -646,6 +660,7 @@ int ns2_tx_sns_size(struct gprs_ns2_vc *nsvc, bool reset_flag, uint16_t max_nr_n
msg = gprs_ns2_msgb_alloc();
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
return -ENOMEM;
@ -685,6 +700,7 @@ int ns2_tx_sns_size_ack(struct gprs_ns2_vc *nsvc, uint8_t *cause)
struct gprs_ns_hdr *nsh;
uint16_t nsei;
log_set_context(LOG_CTX_GB_NSE, nsvc->nse);
log_set_context(LOG_CTX_GB_NSVC, nsvc);
if (!msg)
return -ENOMEM;

View File

@ -110,6 +110,18 @@ static const struct value_string gprs_ns_timer_strs[] = {
{ 0, NULL }
};
static void log_set_nse_filter(struct log_target *target,
struct gprs_ns2_nse *nse)
{
if (nse) {
target->filter_map |= (1 << LOG_FLT_GB_NSE);
target->filter_data[LOG_FLT_GB_NSE] = nse;
} else if (target->filter_data[LOG_FLT_GB_NSE]) {
target->filter_map = ~(1 << LOG_FLT_GB_NSE);
target->filter_data[LOG_FLT_GB_NSE] = NULL;
}
}
static void log_set_nsvc_filter(struct log_target *target,
struct gprs_ns2_vc *nsvc)
{
@ -756,7 +768,37 @@ DEFUN(cfg_frgre_enable, cfg_frgre_enable_cmd,
/* TODO: allow vty to reset/block/unblock nsvc/nsei */
/* TODO: add filter for NSEI as ns1 code does */
DEFUN(logging_fltr_nse,
logging_fltr_nse_cmd,
"logging filter nse nsei <0-65535>",
LOGGING_STR FILTER_STR
"Filter based on NS Entity\n"
"Identify NSE by NSEI\n"
"Numeric identifier\n")
{
struct log_target *tgt;
struct gprs_ns2_nse *nse;
uint16_t id = atoi(argv[1]);
log_tgt_mutex_lock();
tgt = osmo_log_vty2tgt(vty);
if (!tgt) {
log_tgt_mutex_unlock();
return CMD_WARNING;
}
nse = gprs_ns2_nse_by_nsei(vty_nsi, id);
if (!nse) {
vty_out(vty, "No NSE by that identifier%s", VTY_NEWLINE);
log_tgt_mutex_unlock();
return CMD_WARNING;
}
log_set_nse_filter(tgt, nse);
log_tgt_mutex_unlock();
return CMD_SUCCESS;
}
/* TODO: add filter for single connection by description */
DEFUN(logging_fltr_nsvc,
logging_fltr_nsvc_cmd,
@ -818,10 +860,12 @@ int gprs_ns2_vty_init(struct gprs_ns2_inst *nsi,
install_lib_element_ve(&show_ns_entities_cmd);
install_lib_element_ve(&show_ns_pers_cmd);
install_lib_element_ve(&show_nse_cmd);
install_lib_element_ve(&logging_fltr_nse_cmd);
install_lib_element_ve(&logging_fltr_nsvc_cmd);
install_lib_element(ENABLE_NODE, &nsvc_force_unconf_cmd);
install_lib_element(CFG_LOG_NODE, &logging_fltr_nse_cmd);
install_lib_element(CFG_LOG_NODE, &logging_fltr_nsvc_cmd);
install_lib_element(CONFIG_NODE, &cfg_ns_cmd);