Harald Welte has submitted this change and it was merged.

Change subject: sccp: add function to check sccp addresses
......................................................................


sccp: add function to check sccp addresses

In order to catch invalid CS7 configurations, It is necessary
to check if sccp addresses contain plausible address data.

Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
---
M include/osmocom/sigtran/sccp_sap.h
M src/sccp_user.c
2 files changed, 44 insertions(+), 0 deletions(-)

Approvals:
  Neels Hofmeyr: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/sigtran/sccp_sap.h 
b/include/osmocom/sigtran/sccp_sap.h
index 732df2a..90da686 100644
--- a/include/osmocom/sigtran/sccp_sap.h
+++ b/include/osmocom/sigtran/sccp_sap.h
@@ -257,3 +257,5 @@
 void osmo_sccp_local_addr_by_instance(struct osmo_sccp_addr *dest_addr,
                                      const struct osmo_sccp_instance *inst,
                                      uint32_t ssn);
+
+bool osmo_sccp_check_addr(struct osmo_sccp_addr *addr, uint32_t presence);
diff --git a/src/sccp_user.c b/src/sccp_user.c
index 495b6dc..71b3262 100644
--- a/src/sccp_user.c
+++ b/src/sccp_user.c
@@ -253,6 +253,48 @@
        osmo_sccp_make_addr_pc_ssn(dest_addr, ss7->cfg.primary_pc, ssn);
 }
 
+/*! \brief check whether a given SCCP-Address is consistent.
+ *  \param[in] addr SCCP address to check
+ *  \param[in] presence mask with minimum required address components
+ *  \returns true when address data seems plausible */
+bool osmo_sccp_check_addr(struct osmo_sccp_addr *addr, uint32_t presence)
+{
+       /* Minimum requirements do not match */
+       if ((addr->presence & presence) != presence)
+               return false;
+
+       /* GT ranges */
+       if (addr->presence & OSMO_SCCP_ADDR_T_GT) {
+               if (addr->gt.gti > 15)
+                       return false;
+               if (addr->gt.npi > 15)
+                       return false;
+               if (addr->gt.nai > 127)
+                       return false;
+       }
+
+       /* Routing by GT, but no GT present */
+       if (addr->ri == OSMO_SCCP_RI_GT
+           && !(addr->presence & OSMO_SCCP_ADDR_T_GT))
+               return false;
+
+       /* Routing by PC/SSN, but no PC/SSN present */
+       if (addr->ri == OSMO_SCCP_RI_SSN_PC) {
+               if ((addr->presence & OSMO_SCCP_ADDR_T_PC) == 0)
+                       return false;
+               if ((addr->presence & OSMO_SCCP_ADDR_T_SSN) == 0)
+                       return false;
+       }
+
+       if (addr->ri == OSMO_SCCP_RI_SSN_IP) {
+               if ((addr->presence & OSMO_SCCP_ADDR_T_IPv4) == 0 &&
+                   (addr->presence & OSMO_SCCP_ADDR_T_IPv6) == 0)
+                       return false;
+       }
+
+       return true;
+}
+
 /***********************************************************************
  * Convenience function for CLIENT
  ***********************************************************************/

-- 
To view, visit https://gerrit.osmocom.org/3398
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
Gerrit-PatchSet: 3
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter <pma...@sysmocom.de>
Gerrit-Reviewer: Harald Welte <lafo...@gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr <nhofm...@sysmocom.de>

Reply via email to