Change in osmo-bsc[master]: bsc_subscr_name: print both IMSI and TMSI

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/.

neels gerrit-no-reply at lists.osmocom.org
Wed Oct 7 12:38:13 UTC 2020


neels has submitted this change. ( https://gerrit.osmocom.org/c/osmo-bsc/+/20352 )

Change subject: bsc_subscr_name: print both IMSI and TMSI
......................................................................

bsc_subscr_name: print both IMSI and TMSI

Always use a format containing only osmo_identifier_valid() characters.

Change-Id: I6cdbaad2f0d0552f697440bf9a75bef36d59a597
---
M src/osmo-bsc/bsc_subscriber.c
M tests/subscr/bsc_subscr_test.c
M tests/subscr/bsc_subscr_test.err
3 files changed, 44 insertions(+), 37 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Vadim Yanitskiy: Looks good to me, approved
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, but someone else must approve



diff --git a/src/osmo-bsc/bsc_subscriber.c b/src/osmo-bsc/bsc_subscriber.c
index 79d0c85..4a48298 100644
--- a/src/osmo-bsc/bsc_subscriber.c
+++ b/src/osmo-bsc/bsc_subscriber.c
@@ -51,7 +51,7 @@
 	else
 		level = LOGL_DEBUG;
 
-	LOGPSRC(DREF, level, file, line, "BSC subscr %s: %s %s: now used by %s\n",
+	LOGPSRC(DREF, level, file, line, "%s: %s %s: now used by %s\n",
 		bsc_subscr_name(bsub),
 		(e->count - old_use_count) > 0? "+" : "-", e->use,
 		osmo_use_count_to_str_c(OTC_SELECT, &bsub->use_count));
@@ -188,30 +188,36 @@
 	}
 }
 
+static int bsc_subscr_name_buf(char *buf, size_t buflen, struct bsc_subscr *bsub)
+{
+	struct osmo_strbuf sb = { .buf = buf, .len = buflen };
+	OSMO_STRBUF_PRINTF(sb, "subscr");
+	if (!bsub) {
+		OSMO_STRBUF_PRINTF(sb, "-null");
+		return sb.chars_needed;
+	}
+	if (bsub->imsi[0])
+		OSMO_STRBUF_PRINTF(sb, "-IMSI-%s", bsub->imsi);
+	if (bsub->tmsi != GSM_RESERVED_TMSI)
+		OSMO_STRBUF_PRINTF(sb, "-TMSI-0x%08x", bsub->tmsi);
+	return sb.chars_needed;
+}
+
+static char *bsc_subscr_name_c(void *ctx, struct bsc_subscr *bsub)
+{
+	OSMO_NAME_C_IMPL(ctx, 64, "ERROR", bsc_subscr_name_buf, bsub)
+}
+
 const char *bsc_subscr_name(struct bsc_subscr *bsub)
 {
-	static char buf[32];
-	if (!bsub)
-		return "unknown";
-	if (bsub->imsi[0])
-		snprintf(buf, sizeof(buf), "IMSI:%s", bsub->imsi);
-	else
-		snprintf(buf, sizeof(buf), "TMSI:0x%08x", bsub->tmsi);
-	return buf;
+	return bsc_subscr_name_c(OTC_SELECT, bsub);
 }
 
 /* Like bsc_subscr_name() but returns only characters approved by osmo_identifier_valid(), useful for
  * osmo_fsm_inst IDs. */
 const char *bsc_subscr_id(struct bsc_subscr *bsub)
 {
-	static char buf[32];
-	if (!bsub)
-		return "unknown";
-	if (bsub->imsi[0])
-		snprintf(buf, sizeof(buf), "IMSI%s", bsub->imsi);
-	else
-		snprintf(buf, sizeof(buf), "TMSI%08x", bsub->tmsi);
-	return buf;
+	return bsc_subscr_name(bsub);
 }
 
 static void bsc_subscr_free(struct bsc_subscr *bsub)
diff --git a/tests/subscr/bsc_subscr_test.c b/tests/subscr/bsc_subscr_test.c
index fcaea63..619d5e6 100644
--- a/tests/subscr/bsc_subscr_test.c
+++ b/tests/subscr/bsc_subscr_test.c
@@ -75,6 +75,7 @@
 
 	/* Allocate entry 2 */
 	s2 = bsc_subscr_find_or_create_by_imsi(bsc_subscribers, imsi2, BSUB_USE);
+	s2->tmsi = 0x73517351;
 	VERBOSE_ASSERT(llist_count(bsc_subscribers), == 2, "%d");
 
 	/* Allocate entry 3 */
diff --git a/tests/subscr/bsc_subscr_test.err b/tests/subscr/bsc_subscr_test.err
index a78e757..c41d3ca 100644
--- a/tests/subscr/bsc_subscr_test.err
+++ b/tests/subscr/bsc_subscr_test.err
@@ -1,20 +1,20 @@
-DREF BSC subscr IMSI:1234567890: + test: now used by 1 (test)
-DREF BSC subscr IMSI:1234567890: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:1234567890: - test: now used by 1 (test)
-DREF BSC subscr IMSI:9876543210: + test: now used by 1 (test)
-DREF BSC subscr IMSI:5656565656: + test: now used by 1 (test)
-DREF BSC subscr IMSI:1234567890: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:1234567890: - test: now used by 1 (test)
-DREF BSC subscr IMSI:9876543210: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:9876543210: - test: now used by 1 (test)
-DREF BSC subscr IMSI:5656565656: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:5656565656: - test: now used by 1 (test)
-DREF BSC subscr IMSI:1234567890: - test: now used by 0 (-)
-DREF BSC subscr IMSI:9876543210: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:9876543210: - test: now used by 1 (test)
-DREF BSC subscr IMSI:5656565656: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:5656565656: - test: now used by 1 (test)
-DREF BSC subscr IMSI:9876543210: - test: now used by 0 (-)
-DREF BSC subscr IMSI:5656565656: + test: now used by 2 (2*test)
-DREF BSC subscr IMSI:5656565656: - test: now used by 1 (test)
-DREF BSC subscr IMSI:5656565656: - test: now used by 0 (-)
+DREF subscr-IMSI-1234567890: + test: now used by 1 (test)
+DREF subscr-IMSI-1234567890: + test: now used by 2 (2*test)
+DREF subscr-IMSI-1234567890: - test: now used by 1 (test)
+DREF subscr-IMSI-9876543210: + test: now used by 1 (test)
+DREF subscr-IMSI-5656565656: + test: now used by 1 (test)
+DREF subscr-IMSI-1234567890: + test: now used by 2 (2*test)
+DREF subscr-IMSI-1234567890: - test: now used by 1 (test)
+DREF subscr-IMSI-9876543210-TMSI-0x73517351: + test: now used by 2 (2*test)
+DREF subscr-IMSI-9876543210-TMSI-0x73517351: - test: now used by 1 (test)
+DREF subscr-IMSI-5656565656: + test: now used by 2 (2*test)
+DREF subscr-IMSI-5656565656: - test: now used by 1 (test)
+DREF subscr-IMSI-1234567890: - test: now used by 0 (-)
+DREF subscr-IMSI-9876543210-TMSI-0x73517351: + test: now used by 2 (2*test)
+DREF subscr-IMSI-9876543210-TMSI-0x73517351: - test: now used by 1 (test)
+DREF subscr-IMSI-5656565656: + test: now used by 2 (2*test)
+DREF subscr-IMSI-5656565656: - test: now used by 1 (test)
+DREF subscr-IMSI-9876543210-TMSI-0x73517351: - test: now used by 0 (-)
+DREF subscr-IMSI-5656565656: + test: now used by 2 (2*test)
+DREF subscr-IMSI-5656565656: - test: now used by 1 (test)
+DREF subscr-IMSI-5656565656: - test: now used by 0 (-)

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/20352
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I6cdbaad2f0d0552f697440bf9a75bef36d59a597
Gerrit-Change-Number: 20352
Gerrit-PatchSet: 4
Gerrit-Owner: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Vadim Yanitskiy <vyanitskiy at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: pespin <pespin at sysmocom.de>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20201007/689073c1/attachment.htm>


More information about the gerrit-log mailing list