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

add OSMO_SS7_PC_INVALID, add osmo_ss7_pc_is_valid()

Introduce OSMO_SS7_PC_INVALID to mark an unset point code.

Add static osmo_ss7_pc_is_valid() (name matches schema of
osmo_ss7_pc_is_local()).

In osmo_ss7_pointcode_print(), return "(no PC)" if !osmo_ss7_pc_is_valid(), for
convenient printing of any PC state.

Subsequent patches will use this for
osmo_ss7_instance (I7f0f0c89b7335d9da24161bfac8234be214ca00c)
as well as osmo_sccp_user (I8684c9b559712072c772012890bbf7efa7c8eb35).

Rationale:

Currently, in osmo_ss7_vty.c we had "if (inst->cfg.primary_pc)" suggesting 0 is
invalid, but in struct osmo_sccp_user we have flag pc_valid suggesting 0 is
indeed valid. All known point code formats are <= 24bit, so we can easily use
0xffffffff as indicator for an unset PC, which removes the need to remember to
set a second field for validity and keeps the structs nice and lean.

Change-Id: Ib5715bf03a4de7713a7a809dfd821c700255ba8c
---
M include/osmocom/sigtran/osmo_ss7.h
M src/osmo_ss7.c
2 files changed, 17 insertions(+), 3 deletions(-)


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

diff --git a/include/osmocom/sigtran/osmo_ss7.h 
b/include/osmocom/sigtran/osmo_ss7.h
index bbe425c..967912a 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -26,6 +26,14 @@
 const char *osmo_ss7_pointcode_print(struct osmo_ss7_instance *inst, uint32_t 
pc);
 const char *osmo_ss7_pointcode_print2(struct osmo_ss7_instance *inst, uint32_t 
pc);
 
+/* All known point-code formats have a length of or below 24 bit.
+ * A point-code value exceeding that is used to indicate an unset PC. */
+#define OSMO_SS7_PC_INVALID 0xffffffff
+static inline bool osmo_ss7_pc_is_valid(uint32_t pc)
+{
+       return pc <= 0x00ffffff;
+}
+
 /***********************************************************************
  * SS7 Routing Tables
  ***********************************************************************/
diff --git a/src/osmo_ss7.c b/src/osmo_ss7.c
index eb5a4ef..6db3f14 100644
--- a/src/osmo_ss7.c
+++ b/src/osmo_ss7.c
@@ -247,10 +247,16 @@
 
 const char *_osmo_ss7_pointcode_print(char *buf, size_t len, struct 
osmo_ss7_instance *inst, uint32_t pc)
 {
-       const struct osmo_ss7_pc_fmt *pc_fmt = inst ? &inst->cfg.pc_fmt : 
&default_pc_fmt;
-       unsigned int num_comp_exp = num_pc_comp_exp(pc_fmt);
-       const char *fmtstr = gen_pc_fmtstr(pc_fmt, &num_comp_exp);
+       const struct osmo_ss7_pc_fmt *pc_fmt;
+       unsigned int num_comp_exp;
+       const char *fmtstr;
 
+       if (!osmo_ss7_pc_is_valid(pc))
+               return "(no PC)";
+
+       pc_fmt = inst ? &inst->cfg.pc_fmt : &default_pc_fmt;
+       num_comp_exp = num_pc_comp_exp(pc_fmt);
+       fmtstr = gen_pc_fmtstr(pc_fmt, &num_comp_exp);
        OSMO_ASSERT(fmtstr);
        snprintf(buf, len, fmtstr,
                 pc_comp_shift_and_mask(pc_fmt, 0, pc),

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib5715bf03a4de7713a7a809dfd821c700255ba8c
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-sccp
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofm...@sysmocom.de>

Reply via email to