neels has submitted this change. (
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36912?usp=email )
Change subject: use osmo_jhash for the hnb_persistent hashtable
......................................................................
use osmo_jhash for the hnb_persistent hashtable
Use hashing like the linux kernel.
Related: SYS#6773
Depends: I0c9652bbc9e2a18b1200e7d63bb6f64ded7d75fa
Change-Id: I5441db4293dc6b57a1c606ef830656fa9fa01943
---
M TODO-RELEASE
M src/osmo-hnbgw/hnbgw.c
M src/osmo-hnbgw/hnbgw_hnbap.c
3 files changed, 27 insertions(+), 22 deletions(-)
Approvals:
laforge: Looks good to me, but someone else must approve
neels: Looks good to me, approved
osmith: Looks good to me, but someone else must approve
Jenkins Builder: Verified
diff --git a/TODO-RELEASE b/TODO-RELEASE
index b0ad6a0..a1206c1 100644
--- a/TODO-RELEASE
+++ b/TODO-RELEASE
@@ -12,3 +12,4 @@
MGW MGCP CRCX osmo-hnbgw used to CRCX in loopback mode, to trigger a legacy IuUP hack.
CRCX is no
longer in loopback mode now, so older osmo-mgw may fail to respond to IuUP
Initialization.
osmo-iuh >1.5.1 decoding of more RANAP procedures in ranap_common required for DTAP
rate_counters
+libosmocore >1.9.0 require osmo_jhash from osmocom/core/jhash.h added in
I0c9652bbc9e2a18b1200e7d63bb6f64ded7d75fa
diff --git a/src/osmo-hnbgw/hnbgw.c b/src/osmo-hnbgw/hnbgw.c
index 8dcf5f2..a36d107 100644
--- a/src/osmo-hnbgw/hnbgw.c
+++ b/src/osmo-hnbgw/hnbgw.c
@@ -25,6 +25,7 @@
#include <osmocom/core/stats.h>
#include <osmocom/core/rate_ctr.h>
#include <osmocom/core/stat_item.h>
+#include <osmocom/core/jhash.h>
#include <osmocom/vty/vty.h>
@@ -242,36 +243,22 @@
ucid->sac, ucid->cid);
}
-/* source:
http://www.cse.yorku.ca/~oz/hash.html */
-static inline void mkhash_init(uint32_t *hash)
-{
- *hash = 5381;
-}
-static inline void mkhash_add(uint32_t *hash, int32_t val)
-{
- uint32_t h = *hash;
- h = ((h << 5) + h) ^ val; /* (h * 33) ^ val */
- *hash = h;
-}
-
/* Useful to index a hash table by struct umts_cell_id. */
uint32_t umts_cell_id_hash(const struct umts_cell_id *ucid)
{
- uint32_t hash;
- mkhash_init(&hash);
- mkhash_add(&hash, ucid->mcc);
- mkhash_add(&hash, ucid->mnc);
- mkhash_add(&hash, ucid->lac);
- mkhash_add(&hash, ucid->rac);
- mkhash_add(&hash, ucid->sac);
- mkhash_add(&hash, ucid->cid);
- return hash;
+ return osmo_jhash(ucid, sizeof(*ucid), 0x423423);
}
/* parse a string representation of an umts_cell_id into its decoded representation */
int umts_cell_id_from_str(struct umts_cell_id *ucid, const char *instr)
{
- int rc = sscanf(instr, "%hu-%hu-L%hu-R%hu-S%hu-C%u", &ucid->mcc,
&ucid->mnc, &ucid->lac, &ucid->rac, &ucid->sac,
&ucid->cid);
+ int rc;
+
+ /* We want to use struct umts_cell_id as hashtable key. If it ever happens to contain
any padding bytes, make
+ * sure everything is deterministically zero. */
+ memset(ucid, 0, sizeof(*ucid));
+
+ rc = sscanf(instr, "%hu-%hu-L%hu-R%hu-S%hu-C%u", &ucid->mcc,
&ucid->mnc, &ucid->lac, &ucid->rac, &ucid->sac,
&ucid->cid);
if (rc < 0)
return -errno;
diff --git a/src/osmo-hnbgw/hnbgw_hnbap.c b/src/osmo-hnbgw/hnbgw_hnbap.c
index a011221..d7e4dc3 100644
--- a/src/osmo-hnbgw/hnbgw_hnbap.c
+++ b/src/osmo-hnbgw/hnbgw_hnbap.c
@@ -492,6 +492,10 @@
/* copy all identity parameters from the message to ctx */
OSMO_STRLCPY_ARRAY(ctx->identity_info, identity_str);
+
+ /* We want to use struct umts_cell_id as hashtable key. If it ever happens to contain
any padding bytes, make
+ * sure everything is deterministically zero. */
+ memset(&ctx->id, 0, sizeof(ctx->id));
ctx->id.lac = asn1str_to_u16(&ies.lac);
ctx->id.sac = asn1str_to_u16(&ies.sac);
ctx->id.rac = asn1str_to_u8(&ies.rac);
--
To view, visit
https://gerrit.osmocom.org/c/osmo-hnbgw/+/36912?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-hnbgw
Gerrit-Branch: master
Gerrit-Change-Id: I5441db4293dc6b57a1c606ef830656fa9fa01943
Gerrit-Change-Number: 36912
Gerrit-PatchSet: 3
Gerrit-Owner: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge(a)osmocom.org>
Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de>
Gerrit-Reviewer: osmith <osmith(a)sysmocom.de>
Gerrit-MessageType: merged