summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp Maier <pmaier@sysmocom.de>2017-08-01 15:07:20 +0200
committerHarald Welte <laforge@gnumonks.org>2017-08-09 09:53:35 +0000
commit81a029a4e46bb7c62b2401ec055fe44c5b7568cd (patch)
tree28b5ba4aa60872143c24b0a6fd9988ff1fc9a26e
parent41b6803fd5d69b3a0f126e75d7734425c57644ee (diff)
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
-rw-r--r--include/osmocom/sigtran/sccp_sap.h2
-rw-r--r--src/sccp_user.c42
2 files changed, 44 insertions, 0 deletions
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 @@ 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 495b6dc..71b3262 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
***********************************************************************/