From 81a029a4e46bb7c62b2401ec055fe44c5b7568cd Mon Sep 17 00:00:00 2001 From: Philipp Maier Date: Tue, 1 Aug 2017 15:07:20 +0200 Subject: [PATCH] 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 --- include/osmocom/sigtran/sccp_sap.h | 2 ++ src/sccp_user.c | 42 ++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/osmocom/sigtran/sccp_sap.h b/include/osmocom/sigtran/sccp_sap.h index 732df2a4..90da686d 100644 --- a/include/osmocom/sigtran/sccp_sap.h +++ b/include/osmocom/sigtran/sccp_sap.h @@ -257,3 +257,5 @@ const char *osmo_sccp_name_by_addr(const struct osmo_sccp_addr *addr); 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 495b6dca..71b32627 100644 --- a/src/sccp_user.c +++ b/src/sccp_user.c @@ -253,6 +253,48 @@ void osmo_sccp_local_addr_by_instance(struct osmo_sccp_addr *dest_addr, 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 ***********************************************************************/