summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2017-12-24 19:27:55 +0100
committerNeels Hofmeyr <neels@hofmeyr.de>2017-12-24 20:32:03 +0100
commit8800b7cf9f8cce510cd78d4b7c100d2a5dc85a12 (patch)
tree28fb0b5cb96415e40f617899d71e8355a5269a64
parente4a77d46735046c09c3b58e9c404539bb5b8e2af (diff)
add osmo_ss7_route_name()
There is a naming dilemma: though the osmo_ prefix is now reserved for libosmocore, all surrounding API already has the osmo_ prefix. This will be used by osmo-hnbgw's VTY 'show cnlink' command. Change-Id: Ia0d15a2814b08bc3f052a1ed12dbb68bade55309
-rw-r--r--include/osmocom/sigtran/osmo_ss7.h1
-rw-r--r--src/osmo_ss7_hmrt.c59
2 files changed, 60 insertions, 0 deletions
diff --git a/include/osmocom/sigtran/osmo_ss7.h b/include/osmocom/sigtran/osmo_ss7.h
index 94d5e8a..fd3f103 100644
--- a/include/osmocom/sigtran/osmo_ss7.h
+++ b/include/osmocom/sigtran/osmo_ss7.h
@@ -234,6 +234,7 @@ struct osmo_ss7_route *
osmo_ss7_route_create(struct osmo_ss7_route_table *rtbl, uint32_t dpc,
uint32_t mask, const char *linkset_name);
void osmo_ss7_route_destroy(struct osmo_ss7_route *rt);
+const char *osmo_ss7_route_name(struct osmo_ss7_route *rt, bool list_asps);
/***********************************************************************
diff --git a/src/osmo_ss7_hmrt.c b/src/osmo_ss7_hmrt.c
index 51875b1..a1f9e92 100644
--- a/src/osmo_ss7_hmrt.c
+++ b/src/osmo_ss7_hmrt.c
@@ -139,6 +139,65 @@ static int hmdt_message_for_distribution(struct osmo_ss7_instance *inst, struct
}
}
+/*! Return human readable representation of the route, in a static buffer.
+ * This uses both osmo_ss7_pointcode_print() and osmo_ss7_pointcode_print2(), so pairing
+ * osmo_ss7_route_name() with osmo_ss7_pointcode_print() in the same printf statement is likely to
+ * conflict.
+ * \param[in] rt The route information to print, or NULL.
+ * \param[in] list_asps If true, append info for all ASPs for the route's AS.
+ * \returns A string constant or static buffer. */
+const char *osmo_ss7_route_name(struct osmo_ss7_route *rt, bool list_asps)
+{
+ static char buf[256];
+ char *pos = buf;
+ struct osmo_ss7_instance *inst;
+ size_t l;
+
+ if (!rt)
+ return "no route";
+
+ inst = rt->rtable->inst;
+
+#define APPEND(fmt, args ...) \
+ do { \
+ l = snprintf(pos, sizeof(buf) - (pos - buf), fmt, ## args); \
+ pos += l; \
+ if (pos - buf >= sizeof(buf) ) \
+ goto out; \
+ } while (0)
+
+ APPEND("pc=%u=%s mask=0x%x=%s",
+ rt->cfg.pc, osmo_ss7_pointcode_print(inst, rt->cfg.pc),
+ rt->cfg.mask, osmo_ss7_pointcode_print2(inst, rt->cfg.mask));
+
+ if (rt->dest.as) {
+ struct osmo_ss7_as *as = rt->dest.as;
+ int i;
+ APPEND(" via AS %s proto=%s", as->cfg.name, osmo_ss7_asp_protocol_name(as->cfg.proto));
+
+ if (list_asps) {
+ for (i = 0; i < ARRAY_SIZE(as->cfg.asps); i++) {
+ struct osmo_ss7_asp *asp = as->cfg.asps[i];
+ if (!asp)
+ continue;
+ APPEND(" ASP");
+ if (asp->cfg.name)
+ APPEND(" %s", asp->cfg.name);
+ if (asp->sock_name)
+ APPEND(" %s", asp->sock_name);
+ }
+ }
+ } else if (rt->dest.linkset)
+ APPEND(" via linkset %s", rt->dest.linkset->cfg.name);
+ else
+ APPEND(" has no route set");
+#undef APPEND
+
+out:
+ buf[sizeof(buf)-1] = '\0';
+ return buf;
+}
+
/* HMDC->HMRT Msg For Routing; Figure 26/Q.704 */
/* local message was receive d from L4, SRM, SLM, STM or SLTC, or
* remote message received from L2 and HMDC determined msg for routing */