Change in osmo-gbproxy[master]: gbproxy: Add usage flag to the imsi_cache

daniel gerrit-no-reply at lists.osmocom.org
Fri Jul 9 18:12:33 UTC 2021


daniel has submitted this change. ( https://gerrit.osmocom.org/c/osmo-gbproxy/+/24904 )

Change subject: gbproxy: Add usage flag to the imsi_cache
......................................................................

gbproxy: Add usage flag to the imsi_cache

This is only used for the imsi cache entries for now. Further uses will
be added in subsequent commits.

Related: OS#4472
Change-Id: I4a4b8c99eb97f6bb5387d0f26aecd861e07d9914
---
M include/osmocom/gbproxy/gb_proxy.h
M src/gb_proxy.c
M src/gb_proxy_peer.c
3 files changed, 24 insertions(+), 15 deletions(-)

Approvals:
  pespin: Looks good to me, but someone else must approve
  lynxis lazus: Looks good to me, approved
  Jenkins Builder: Verified



diff --git a/include/osmocom/gbproxy/gb_proxy.h b/include/osmocom/gbproxy/gb_proxy.h
index afd4b5f..c1cc35f 100644
--- a/include/osmocom/gbproxy/gb_proxy.h
+++ b/include/osmocom/gbproxy/gb_proxy.h
@@ -192,6 +192,10 @@
 	} pool;
 };
 
+enum cache_usage_type {
+	CACHE_USAGE_PAGING,
+};
+
 /* TLLI cache */
 struct gbproxy_tlli_cache_entry {
 	/* linked to gbproxy_config.tlli_cache.entries */
@@ -199,6 +203,8 @@
 
 	/* TLLI of the entry */
 	uint32_t tlli;
+	enum cache_usage_type usage;
+
 	/* When was this entry last seen */
 	time_t tstamp;
 	/* The Cell this TLLI was last seen */
@@ -212,6 +218,8 @@
 
 	/* IMSI of the entry */
 	char imsi[OSMO_IMSI_BUF_SIZE];
+	enum cache_usage_type usage;
+
 	/* When was this entry last seen */
 	time_t tstamp;
 	/* The SGSN where the request came from */
@@ -286,7 +294,7 @@
 struct gbproxy_nse *gbproxy_nse_by_nsei(struct gbproxy_config *cfg, uint16_t nsei, uint32_t flags);
 struct gbproxy_nse *gbproxy_nse_by_nsei_or_new(struct gbproxy_config *cfg, uint16_t nsei, bool sgsn_facing);
 struct gbproxy_nse *gbproxy_nse_by_tlli(struct gbproxy_config *cfg, uint32_t tlli);
-struct gbproxy_nse *gbproxy_nse_by_imsi(struct gbproxy_config *cfg, const char *imsi);
+struct gbproxy_nse *gbproxy_nse_by_imsi(struct gbproxy_config *cfg, const char *imsi, enum cache_usage_type usage);
 
 /* TLLI cache */
 void gbproxy_tlli_cache_update(struct gbproxy_nse *nse, uint32_t tlli);
@@ -294,8 +302,8 @@
 int gbproxy_tlli_cache_cleanup(struct gbproxy_config *cfg);
 
 /* IMSI cache */
-void gbproxy_imsi_cache_update(struct gbproxy_nse *nse, const char *imsi);
-void gbproxy_imsi_cache_remove(struct gbproxy_config *cfg, const char *imsi);
+void gbproxy_imsi_cache_update(struct gbproxy_nse *nse, const char *imsi, enum cache_usage_type usage);
+void gbproxy_imsi_cache_remove(struct gbproxy_config *cfg, const char *imsi, enum cache_usage_type usage);
 int gbproxy_imsi_cache_cleanup(struct gbproxy_config *cfg);
 
 /* SGSN handling */
diff --git a/src/gb_proxy.c b/src/gb_proxy.c
index 8c8faf7..e017abe 100644
--- a/src/gb_proxy.c
+++ b/src/gb_proxy.c
@@ -484,7 +484,7 @@
 		const uint8_t *mi_data = TLVP_VAL(&tp, BSSGP_IE_IMSI);
 		uint8_t mi_len = TLVP_LEN(&tp, BSSGP_IE_IMSI);
 		osmo_mobile_identity_decode(&mi, mi_data, mi_len, false);
-		nse = gbproxy_nse_by_imsi(nse->cfg, mi.imsi);
+		nse = gbproxy_nse_by_imsi(nse->cfg, mi.imsi, CACHE_USAGE_PAGING);
 		if (nse) {
 			OSMO_ASSERT(nse->sgsn_facing);
 			rc = gbprox_relay2nse(msg, nse, ns_bvci);
@@ -586,7 +586,7 @@
 		const uint8_t *mi_data = TLVP_VAL(&tp, BSSGP_IE_IMSI);
 		uint8_t mi_len = TLVP_LEN(&tp, BSSGP_IE_IMSI);
 		osmo_mobile_identity_decode(&mi, mi_data, mi_len, false);
-		gbproxy_imsi_cache_update(nse, mi.imsi);
+		gbproxy_imsi_cache_update(nse, mi.imsi, CACHE_USAGE_PAGING);
 		break;
 	}
 	default:
@@ -1106,7 +1106,7 @@
 		const uint8_t *mi_data = TLVP_VAL(&tp[0], BSSGP_IE_IMSI);
 		uint8_t mi_len = TLVP_LEN(&tp[0], BSSGP_IE_IMSI);
 		osmo_mobile_identity_decode(&mi, mi_data, mi_len, false);
-		nse = gbproxy_nse_by_imsi(nse->cfg, mi.imsi);
+		nse = gbproxy_nse_by_imsi(nse->cfg, mi.imsi, CACHE_USAGE_PAGING);
 		if (!nse) {
 			return tx_status(nse, ns_bvci, BSSGP_CAUSE_INV_MAND_INF, NULL, msg);
 		}
@@ -1386,7 +1386,7 @@
 		const uint8_t *mi_data = TLVP_VAL(&tp[0], BSSGP_IE_IMSI);
 		uint8_t mi_len = TLVP_LEN(&tp[0], BSSGP_IE_IMSI);
 		osmo_mobile_identity_decode(&mi, mi_data, mi_len, false);
-		gbproxy_imsi_cache_update(nse, mi.imsi);
+		gbproxy_imsi_cache_update(nse, mi.imsi, CACHE_USAGE_PAGING);
 		/* fall through */
 	}
 	case BSSGP_PDUT_PAGING_CS:
diff --git a/src/gb_proxy_peer.c b/src/gb_proxy_peer.c
index 0f15e9d..f5ad445 100644
--- a/src/gb_proxy_peer.c
+++ b/src/gb_proxy_peer.c
@@ -347,23 +347,23 @@
 	return osmo_crc16(0, (const uint8_t *)imsi, len);
 }
 
-static inline struct gbproxy_imsi_cache_entry *_get_imsi_entry(struct gbproxy_config *cfg, const char *imsi)
+static inline struct gbproxy_imsi_cache_entry *_get_imsi_entry(struct gbproxy_config *cfg, const char *imsi, enum cache_usage_type usage)
 {
 	struct gbproxy_imsi_cache_entry *cache_entry;
 	uint16_t imsi_hash = _checksum_imsi(imsi);
 
 	hash_for_each_possible(cfg->imsi_cache.entries, cache_entry, list, imsi_hash) {
-		if (!strncmp(cache_entry->imsi, imsi, sizeof(cache_entry->imsi)))
+		if (!strncmp(cache_entry->imsi, imsi, sizeof(cache_entry->imsi)) && cache_entry->usage == usage)
 			return cache_entry;
 	}
 	return NULL;
 }
 
-void gbproxy_imsi_cache_update(struct gbproxy_nse *nse, const char *imsi)
+void gbproxy_imsi_cache_update(struct gbproxy_nse *nse, const char *imsi, enum cache_usage_type usage)
 {
 	struct gbproxy_config *cfg = nse->cfg;
 	struct timespec now;
-	struct gbproxy_imsi_cache_entry *cache_entry = _get_imsi_entry(cfg, imsi);
+	struct gbproxy_imsi_cache_entry *cache_entry = _get_imsi_entry(cfg, imsi, usage);
 	uint16_t imsi_hash = _checksum_imsi(imsi);
 
 	osmo_clock_gettime(CLOCK_MONOTONIC, &now);
@@ -378,6 +378,7 @@
 	cache_entry = talloc_zero(cfg, struct gbproxy_imsi_cache_entry);
 	OSMO_STRLCPY_ARRAY(cache_entry->imsi, imsi);
 	cache_entry->nse = nse;
+	cache_entry->usage = usage;
 	cache_entry->tstamp = now.tv_sec;
 	hash_add(cfg->imsi_cache.entries, &cache_entry->list, imsi_hash);
 }
@@ -396,14 +397,14 @@
 	}
 }
 
-void gbproxy_imsi_cache_remove(struct gbproxy_config *cfg, const char *imsi)
+void gbproxy_imsi_cache_remove(struct gbproxy_config *cfg, const char *imsi, enum cache_usage_type usage)
 {
 	struct gbproxy_imsi_cache_entry *imsi_cache;
 	struct hlist_node *tmp;
 	uint16_t imsi_hash = _checksum_imsi(imsi);
 
 	hash_for_each_possible_safe(cfg->imsi_cache.entries, imsi_cache, tmp, list, imsi_hash) {
-		if (!(strncmp(imsi_cache->imsi, imsi, sizeof(imsi_cache->imsi)))) {
+		if (!(strncmp(imsi_cache->imsi, imsi, sizeof(imsi_cache->imsi))) && imsi_cache->usage == usage) {
 			hash_del(&imsi_cache->list);
 			talloc_free(imsi_cache);
 			return;
@@ -546,13 +547,13 @@
 	return NULL;
 }
 
-struct gbproxy_nse *gbproxy_nse_by_imsi(struct gbproxy_config *cfg, const char *imsi)
+struct gbproxy_nse *gbproxy_nse_by_imsi(struct gbproxy_config *cfg, const char *imsi, enum cache_usage_type usage)
 {
 	struct gbproxy_imsi_cache_entry *imsi_cache;
 	uint16_t imsi_hash = _checksum_imsi(imsi);
 
 	hash_for_each_possible(cfg->imsi_cache.entries, imsi_cache, list, imsi_hash) {
-		if (!strncmp(imsi_cache->imsi, imsi, sizeof(imsi_cache->imsi)))
+		if (!strncmp(imsi_cache->imsi, imsi, sizeof(imsi_cache->imsi)) && imsi_cache->usage == usage)
 			return imsi_cache->nse;
 	}
 	return NULL;

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

Gerrit-Project: osmo-gbproxy
Gerrit-Branch: master
Gerrit-Change-Id: I4a4b8c99eb97f6bb5387d0f26aecd861e07d9914
Gerrit-Change-Number: 24904
Gerrit-PatchSet: 2
Gerrit-Owner: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: daniel <dwillmann at sysmocom.de>
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-Reviewer: lynxis lazus <lynxis at fe80.eu>
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/20210709/a1d4a629/attachment.htm>


More information about the gerrit-log mailing list