[MERGED] openggsn[master]: Properly format IMSI before using it in trap

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Sat Aug 12 21:31:27 UTC 2017


Harald Welte has submitted this change and it was merged.

Change subject: Properly format IMSI before using it in trap
......................................................................


Properly format IMSI before using it in trap

For some reason Max' commits introducing the CTRL/trap interface
about one year ago didn't convert the IMSI to its actual textual
representation before usign it in the CTRL interface.

Let's clean that up by properly interpreting the IMSI.

Change-Id: I8b20d2e47a29de266d93a7ddd5e6877f7e346a63
---
M ggsn/ggsn.c
M gtp/gtp.c
M gtp/gtp.h
3 files changed, 30 insertions(+), 1 deletion(-)

Approvals:
  Harald Welte: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/ggsn/ggsn.c b/ggsn/ggsn.c
index 05a56ae..c6a6dac 100644
--- a/ggsn/ggsn.c
+++ b/ggsn/ggsn.c
@@ -146,7 +146,7 @@
 
 	const char *addrstr = in46a_ntop(&member->addr, addrbuf, sizeof(addrbuf));
 
-	snprintf(val, sizeof(val), "%" PRIu64 ",%s", pdp->imsi, addrstr);
+	snprintf(val, sizeof(val), "%s,%s", imsi_gtp2str(&pdp->imsi), addrstr);
 
 	if (ctrl_cmd_send_trap(gsn->ctrl, var, val) < 0) {
 		LOGP(DGGSN, LOGL_ERROR, "Failed to create and send TRAP for IMSI %" PRIu64 " [%s].\n", pdp->imsi, var);
diff --git a/gtp/gtp.c b/gtp/gtp.c
index 801664d..4aa6eb1 100644
--- a/gtp/gtp.c
+++ b/gtp/gtp.c
@@ -3244,3 +3244,31 @@
 	memcpy(gsna->v, src, gsna->l);
 	return 0;
 }
+
+/* TS 29.060 has yet again a different encoding for IMSIs than
+ * what we have in other places, so we cannot use the gsm48
+ * decoding functions.  Also, libgtp uses an uint64_t in
+ * _network byte order_ to contain BCD digits ?!? */
+const char *imsi_gtp2str(const uint64_t *imsi)
+{
+	static char buf[sizeof(*imsi)+1];
+	const uint8_t *imsi8 = (const uint8_t *) imsi;
+	unsigned int i, j = 0;
+
+	for (i = 0; i < sizeof(*imsi); i++) {
+		uint8_t nibble;
+
+		nibble = imsi8[i] & 0xf;
+		if (nibble == 0xf)
+			break;
+		buf[j++] = osmo_bcd2char(nibble);
+
+		nibble = imsi8[i] >> 4;
+		if (nibble == 0xf)
+			break;
+		buf[j++] = osmo_bcd2char(nibble);
+	}
+
+	buf[j++] = '\0';
+	return buf;
+}
diff --git a/gtp/gtp.h b/gtp/gtp.h
index fd138cc..8f13ed2 100644
--- a/gtp/gtp.h
+++ b/gtp/gtp.h
@@ -402,5 +402,6 @@
 extern int eua2ipv4(struct in_addr *dst, struct ul66_t *eua);
 extern int gsna2in_addr(struct in_addr *dst, struct ul16_t *gsna);
 extern int in_addr2gsna(struct ul16_t *gsna, struct in_addr *src);
+extern const char *imsi_gtp2str(const uint64_t *imsi);
 
 #endif /* !_GTP_H */

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I8b20d2e47a29de266d93a7ddd5e6877f7e346a63
Gerrit-PatchSet: 1
Gerrit-Project: openggsn
Gerrit-Branch: master
Gerrit-Owner: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Max <msuraev at sysmocom.de>



More information about the gerrit-log mailing list