[MERGED] libosmo-sccp[master]: sccp: add function to check sccp addresses

2017-08-09 Thread Harald Welte
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 
Gerrit-Reviewer: Harald Welte 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 


libosmo-sccp[master]: sccp: add function to check sccp addresses

2017-08-08 Thread Neels Hofmeyr

Patch Set 2: Code-Review+2

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

Gerrit-MessageType: comment
Gerrit-Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
Gerrit-PatchSet: 2
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: No


libosmo-sccp[master]: sccp: add function to check sccp addresses

2017-08-08 Thread Neels Hofmeyr

Patch Set 1:

(1 comment)

https://gerrit.osmocom.org/#/c/3398/1/src/sccp_user.c
File src/sccp_user.c:

Line 256: /*! \brief check if a given SCCP-Address is consistant.
(at least in libosmocore, we have autobrief, so we'd drop the "\brief". In 
libosmo-sccp we don't even have a doxygen make target, not sure whether that 
will change.)

typo: "consistent"


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

Gerrit-MessageType: comment
Gerrit-Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter 
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Neels Hofmeyr 
Gerrit-HasComments: Yes


[PATCH] libosmo-sccp[master]: sccp: add function to check sccp addresses

2017-08-01 Thread dexter

Review at  https://gerrit.osmocom.org/3398

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(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-sccp refs/changes/98/3398/1

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..3724eb1 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 if a given SCCP-Address is consistant.
+ *  \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: newchange
Gerrit-Change-Id: Ic6245288b0171eae10aa708403c1ddb584c92f38
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: dexter