From e8c8ec9683d909b32f1c5474e616fe24e6ef524c Mon Sep 17 00:00:00 2001 From: Daniel Willmann Date: Wed, 2 Dec 2020 19:33:50 +0100 Subject: gbproxy: Add BVC log filters Since gbproxy doesn't use bssgp_rcvmsg from libosmocore we need to implement our own filtering. Change-Id: I4d1b57b89990945d307f27a58a7f630be0253d5b Related: SYS#5232 --- include/osmocom/sgsn/gb_proxy.h | 3 +++ src/gbproxy/gb_proxy.c | 6 +++++- src/gbproxy/gb_proxy_peer.c | 1 + src/gbproxy/gb_proxy_vty.c | 37 +++++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/osmocom/sgsn/gb_proxy.h b/include/osmocom/sgsn/gb_proxy.h index fae95c160..b3a9a6cf7 100644 --- a/include/osmocom/sgsn/gb_proxy.h +++ b/include/osmocom/sgsn/gb_proxy.h @@ -15,6 +15,9 @@ #define GBPROXY_INIT_VU_GEN_TX 256 +/* BVCI uses 16 bits */ +#define BVC_LOG_CTX_FLAG (1<<17) + struct rate_ctr_group; struct gprs_gb_parse_context; struct tlv_parsed; diff --git a/src/gbproxy/gb_proxy.c b/src/gbproxy/gb_proxy.c index d8b828c68..329c1d1e5 100644 --- a/src/gbproxy/gb_proxy.c +++ b/src/gbproxy/gb_proxy.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -1568,12 +1569,12 @@ void gprs_ns_prim_status_cb(struct gbproxy_config *cfg, struct osmo_gprs_ns2_pri } } - /* called by the ns layer */ int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx) { struct osmo_gprs_ns2_prim *nsp; struct gbproxy_config *cfg = (struct gbproxy_config *) ctx; + uintptr_t bvci; int rc = 0; if (oph->sap != SAP_NS) @@ -1589,11 +1590,14 @@ int gprs_ns2_prim_cb(struct osmo_prim_hdr *oph, void *ctx) switch (oph->primitive) { case PRIM_NS_UNIT_DATA: + /* hand the message into the BSSGP implementation */ msgb_bssgph(oph->msg) = oph->msg->l3h; msgb_bvci(oph->msg) = nsp->bvci; msgb_nsei(oph->msg) = nsp->nsei; + bvci = nsp->bvci | BVC_LOG_CTX_FLAG; + log_set_context(LOG_CTX_GB_BVC, (void *)bvci); rc = gbprox_rcvmsg(cfg, oph->msg); msgb_free(oph->msg); break; diff --git a/src/gbproxy/gb_proxy_peer.c b/src/gbproxy/gb_proxy_peer.c index 62c4d94f1..2b28dd56d 100644 --- a/src/gbproxy/gb_proxy_peer.c +++ b/src/gbproxy/gb_proxy_peer.c @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/src/gbproxy/gb_proxy_vty.c b/src/gbproxy/gb_proxy_vty.c index caad52e65..379b8c234 100644 --- a/src/gbproxy/gb_proxy_vty.c +++ b/src/gbproxy/gb_proxy_vty.c @@ -39,6 +39,7 @@ #include #include +#include #include #include @@ -538,6 +539,41 @@ DEFUN(cfg_gbproxy_link_no_stored_msgs_max_len, return CMD_SUCCESS; } +static void log_set_bvc_filter(struct log_target *target, + const uint16_t *bvci) +{ + if (bvci) { + uintptr_t bvci_filter = *bvci | BVC_LOG_CTX_FLAG; + target->filter_map |= (1 << LOG_FLT_GB_BVC); + target->filter_data[LOG_FLT_GB_BVC] = (void *)bvci_filter; + } else if (target->filter_data[LOG_FLT_GB_BVC]) { + target->filter_map = ~(1 << LOG_FLT_GB_BVC); + target->filter_data[LOG_FLT_GB_BVC] = NULL; + } +} + +DEFUN(logging_fltr_bvc, + logging_fltr_bvc_cmd, + "logging filter bvc bvci <0-65535>", + LOGGING_STR FILTER_STR + "Filter based on BSSGP VC\n" + "Identify BVC by BVCI\n" + "Numeric identifier\n") +{ + struct log_target *tgt; + uint16_t id = atoi(argv[0]); + + log_tgt_mutex_lock(); + tgt = osmo_log_vty2tgt(vty); + if (!tgt) { + log_tgt_mutex_unlock(); + return CMD_WARNING; + } + + log_set_bvc_filter(tgt, &id); + log_tgt_mutex_unlock(); + return CMD_SUCCESS; +} DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy [stats]", SHOW_STR "Display information about the Gb proxy\n" "Show statistics\n") @@ -881,6 +917,7 @@ int gbproxy_vty_init(void) { install_element_ve(&show_gbproxy_cmd); install_element_ve(&show_gbproxy_links_cmd); + install_element_ve(&logging_fltr_bvc_cmd); install_element(ENABLE_NODE, &delete_gb_bvci_cmd); install_element(ENABLE_NODE, &delete_gb_nsei_cmd); -- cgit v1.2.3