pespin has uploaded this change for review. ( 
https://gerrit.osmocom.org/c/libosmo-sigtran/+/41408?usp=email )


Change subject: m3ua: Drop rx packets with unexpected Network Indicator
......................................................................

m3ua: Drop rx packets with unexpected Network Indicator

Change-Id: I54de65b16949851062914ca5d3362d1e46158b8b
---
M src/m3ua.c
M src/ss7_asp.c
M src/ss7_asp.h
M src/ss7_instance.c
M src/ss7_instance.h
5 files changed, 28 insertions(+), 11 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/libosmo-sigtran 
refs/changes/08/41408/1

diff --git a/src/m3ua.c b/src/m3ua.c
index 8c30775..f5030d0 100644
--- a/src/m3ua.c
+++ b/src/m3ua.c
@@ -590,6 +590,7 @@
 /* This function takes ownership of xua msg passed to it. */
 static int m3ua_rx_xfer(struct osmo_ss7_asp *asp, struct xua_msg *xua)
 {
+       struct xua_msg_part *data_ie = xua_msg_find_tag(xua, 
M3UA_IEI_PROT_DATA);
        struct xua_msg_part *na_ie = xua_msg_find_tag(xua, M3UA_IEI_NET_APPEAR);
        struct xua_msg_part *rctx_ie = xua_msg_find_tag(xua, 
M3UA_IEI_ROUTE_CTX);
        struct m3ua_data_hdr *dh;
@@ -621,6 +622,29 @@
                goto ret_free;
        }

+       /* store the MTP-level information in the xua_msg for use by
+        * higher layer protocols */
+       OSMO_ASSERT(data_ie);
+       dh = (struct m3ua_data_hdr *) data_ie->dat;
+       OSMO_ASSERT(dh);
+       m3ua_dh_to_xfer_param(&xua->mtp, dh);
+       LOGPASP(asp, DLM3UA, LOGL_DEBUG,
+               "%s(): M3UA data header: opc=%u=%s dpc=%u=%s sls=%u\n",
+               __func__, xua->mtp.opc, osmo_ss7_pointcode_print(asp->inst, 
xua->mtp.opc),
+               xua->mtp.dpc, osmo_ss7_pointcode_print2(asp->inst, 
xua->mtp.dpc),
+               xua->mtp.sls);
+
+       /* Drop packets not matching our configured Network Indicator: */
+       if (dh->ni != asp->inst->cfg.network_indicator) {
+               LOGPASP(asp, DLM3UA, LOGL_NOTICE,
+                       "Discarding received XUA Message %s: NI=%u not matching 
ss7 instance configured NI=%u\n",
+                       xua_hdr_dump(xua, &xua_dialect_sua), dh->ni, 
asp->inst->cfg.network_indicator);
+               rate_ctr_inc2(asp->inst->ctrg, SS7_INST_CTR_PKT_RX_NI_MISMATCH);
+               rate_ctr_inc2(asp->ctrg, SS7_ASP_CTR_PKT_RX_NI_MISMATCH);
+               rc = M3UA_ERR_UNEXPECTED_MSG;
+               goto ret_free;
+       }
+
        rc = xua_find_as_for_asp(&as, asp, rctx_ie);
        if (rc)
                goto ret_free;
@@ -633,17 +657,6 @@
        }

        rate_ctr_inc2(as->ctrg, SS7_AS_CTR_RX_MSU_TOTAL);
-
-       /* store the MTP-level information in the xua_msg for use by
-        * higher layer protocols */
-       dh = data_hdr_from_m3ua(xua);
-       OSMO_ASSERT(dh);
-       m3ua_dh_to_xfer_param(&xua->mtp, dh);
-       LOGPASP(asp, DLM3UA, LOGL_DEBUG,
-               "%s(): M3UA data header: opc=%u=%s dpc=%u=%s sls=%u\n",
-               __func__, xua->mtp.opc, osmo_ss7_pointcode_print(asp->inst, 
xua->mtp.opc),
-               xua->mtp.dpc, osmo_ss7_pointcode_print2(asp->inst, 
xua->mtp.dpc),
-               xua->mtp.sls);
        OSMO_ASSERT(xua->mtp.sls <= 0xf);
        rate_ctr_inc2(as->ctrg, SS7_AS_CTR_RX_MSU_SLS_0 + xua->mtp.sls);

diff --git a/src/ss7_asp.c b/src/ss7_asp.c
index 976e54a..644c192 100644
--- a/src/ss7_asp.c
+++ b/src/ss7_asp.c
@@ -216,6 +216,7 @@
 static const struct rate_ctr_desc ss7_asp_rcd[] = {
        [SS7_ASP_CTR_PKT_RX_TOTAL] = { "rx:packets:total", "Total number of 
packets received" },
        [SS7_ASP_CTR_PKT_RX_UNKNOWN] = { "rx:packets:unknown", "Number of 
packets received for unknown PPID" },
+       [SS7_ASP_CTR_PKT_RX_NI_MISMATCH] = { "rx:packets:ni_mismatch", "Number 
of packets received and dropped due to Network Indicator mismatch" },
        [SS7_ASP_CTR_PKT_TX_TOTAL] = { "tx:packets:total", "Total number of 
packets transmitted" },
 };

diff --git a/src/ss7_asp.h b/src/ss7_asp.h
index e25c85c..62378a3 100644
--- a/src/ss7_asp.h
+++ b/src/ss7_asp.h
@@ -36,6 +36,7 @@
 enum ss7_asp_ctr {
        SS7_ASP_CTR_PKT_RX_TOTAL,
        SS7_ASP_CTR_PKT_RX_UNKNOWN,
+       SS7_ASP_CTR_PKT_RX_NI_MISMATCH,
        SS7_ASP_CTR_PKT_TX_TOTAL,
 };

diff --git a/src/ss7_instance.c b/src/ss7_instance.c
index b166e8a..7a9509e 100644
--- a/src/ss7_instance.c
+++ b/src/ss7_instance.c
@@ -52,6 +52,7 @@
 static const struct rate_ctr_desc ss7_inst_rcd[] = {
        [SS7_INST_CTR_PKT_RX_TOTAL] = { "rx:packets:total", "Total number of 
packets received" },
        [SS7_INST_CTR_PKT_RX_UNKNOWN] = { "rx:packets:unknown", "Number of 
packets received for unknown PPID" },
+       [SS7_INST_CTR_PKT_RX_NI_MISMATCH] = { "rx:packets:ni_mismatch", "Number 
of packets received and dropped due to Network Indicator mismatch" },
        [SS7_INST_CTR_PKT_TX_TOTAL] = { "tx:packets:total", "Total number of 
packets transmitted" },
 };
 
diff --git a/src/ss7_instance.h b/src/ss7_instance.h
index 5c76b46..eb444f1 100644
--- a/src/ss7_instance.h
+++ b/src/ss7_instance.h
@@ -17,6 +17,7 @@
 enum ss7_instance_ctr {
        SS7_INST_CTR_PKT_RX_TOTAL,
        SS7_INST_CTR_PKT_RX_UNKNOWN,
+       SS7_INST_CTR_PKT_RX_NI_MISMATCH,
        SS7_INST_CTR_PKT_TX_TOTAL,
 };


--
To view, visit https://gerrit.osmocom.org/c/libosmo-sigtran/+/41408?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: libosmo-sigtran
Gerrit-Branch: master
Gerrit-Change-Id: I54de65b16949851062914ca5d3362d1e46158b8b
Gerrit-Change-Number: 41408
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <[email protected]>

Reply via email to