From 7d9b9437f86e755f5b0f1c4ab40f9d4e2241c432 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 25 Sep 2020 00:48:24 +0000 Subject: bsc_subscr_name: print both IMSI and TMSI Always use a format containing only osmo_identifier_valid() characters. Change-Id: I6cdbaad2f0d0552f697440bf9a75bef36d59a597 --- src/osmo-bsc/bsc_subscriber.c | 40 +++++++++++++++++++++++----------------- tests/subscr/bsc_subscr_test.c | 1 + tests/subscr/bsc_subscr_test.err | 40 ++++++++++++++++++++-------------------- 3 files changed, 44 insertions(+), 37 deletions(-) diff --git a/src/osmo-bsc/bsc_subscriber.c b/src/osmo-bsc/bsc_subscriber.c index 79d0c8512..4a4829866 100644 --- a/src/osmo-bsc/bsc_subscriber.c +++ b/src/osmo-bsc/bsc_subscriber.c @@ -51,7 +51,7 @@ static int bsub_use_cb(struct osmo_use_count_entry *e, int32_t old_use_count, co 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 @@ struct bsc_subscr *bsc_subscr_find_or_create_by_mi(struct llist_head *list, cons } } -const char *bsc_subscr_name(struct bsc_subscr *bsub) +static int bsc_subscr_name_buf(char *buf, size_t buflen, struct bsc_subscr *bsub) { - static char buf[32]; - if (!bsub) - return "unknown"; + 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]) - snprintf(buf, sizeof(buf), "IMSI:%s", bsub->imsi); - else - snprintf(buf, sizeof(buf), "TMSI:0x%08x", bsub->tmsi); - return buf; + 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) +{ + 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 fcaea63eb..619d5e6bf 100644 --- a/tests/subscr/bsc_subscr_test.c +++ b/tests/subscr/bsc_subscr_test.c @@ -75,6 +75,7 @@ static void test_bsc_subscr(void) /* 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 a78e7576a..c41d3ca2a 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 (-) -- cgit v1.2.3