From: "plaisthos (Code Review)" Date: Thu, 19 Mar 2026 14:17:13 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <057e429f99c42fa31e8a3099eb6db790cf24dc16-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="V6z4+YmaitU="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Change hash values in our hash map from uint32_t to uint64_t List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --V6z4+YmaitU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1570?usp=3Demail to look at the new patch set (#4). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld Change subject: Change hash values in our hash map from uint32_t to uint64_t ...................................................................... Change hash values in our hash map from uint32_t to uint64_t 32 bit architectures are playing a very small role today, so the difference between 64 bit and 32 bit hash values is not expected to be large anymore. This is also in preparation to replace our hash function with a more modern replacement. Change-Id: Ib8140107f98164d2a2e1768a6d8ac65016cd7f7c Signed-off-by: Arne Schwabe --- M src/openvpn/list.c M src/openvpn/list.h M src/openvpn/mroute.c M src/openvpn/mroute.h M src/openvpn/mtcp.c M src/openvpn/mudp.c M src/openvpn/multi.c M tests/unit_tests/openvpn/test_misc.c 8 files changed, 30 insertions(+), 30 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/70/1570/4 diff --git a/src/openvpn/list.c b/src/openvpn/list.c index f0e9908..50defb85 100644 --- a/src/openvpn/list.c +++ b/src/openvpn/list.c @@ -34,8 +34,8 @@ #include "memdbg.h" struct hash * -hash_init(const uint32_t n_buckets, const uint32_t iv, - uint32_t (*hash_function)(const void *key, uint32_t iv), +hash_init(const uint32_t n_buckets, uint32_t iv, + uint64_t (*hash_function)(const void *key, uint32_t iv), bool (*compare_function)(const void *key1, const void *key2)) { struct hash *h; @@ -76,7 +76,7 @@ } struct hash_element * -hash_lookup_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint32_t hv) +hash_lookup_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint64_t hv) { struct hash_element *he; struct hash_element *prev =3D NULL; @@ -104,7 +104,7 @@ } bool -hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint32_t hv) +hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const void= *key, uint64_t hv) { struct hash_element *he; struct hash_element *prev =3D NULL; @@ -136,7 +136,7 @@ bool hash_add(struct hash *hash, const void *key, void *value, bool replace) { - uint32_t hv; + uint64_t hv; struct hash_bucket *bucket; struct hash_element *he; bool ret =3D false; @@ -412,7 +412,7 @@ c ^=3D (b >> 15); \ } -uint32_t +uint64_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval) { uint32_t a, b, c, len; diff --git a/src/openvpn/list.h b/src/openvpn/list.h index 04cc3ab..06377c6 100644 --- a/src/openvpn/list.h +++ b/src/openvpn/list.h @@ -40,7 +40,7 @@ { void *value; const void *key; - uint32_t hash_value; + uint64_t hash_value; struct hash_element *next; }; @@ -55,13 +55,13 @@ uint32_t n_elements; uint32_t mask; uint32_t iv; - uint32_t (*hash_function)(const void *key, uint32_t iv); + uint64_t (*hash_function)(const void *key, uint32_t iv); bool (*compare_function)(const void *key1, const void *key2); /* retur= n true if equal */ struct hash_bucket *buckets; }; struct hash *hash_init(const uint32_t n_buckets, const uint32_t iv, - uint32_t (*hash_function)(const void *key, uint32_t= iv), + uint64_t (*hash_function)(const void *key, uint32_t= iv), bool (*compare_function)(const void *key1, const vo= id *key2)); void hash_free(struct hash *hash); @@ -69,9 +69,9 @@ bool hash_add(struct hash *hash, const void *key, void *value, bool replac= e); struct hash_element *hash_lookup_fast(struct hash *hash, struct hash_bucke= t *bucket, - const void *key, uint32_t hv); + const void *key, uint64_t hv); -bool hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const= void *key, uint32_t hv); +bool hash_remove_fast(struct hash *hash, struct hash_bucket *bucket, const= void *key, uint64_t hv); void hash_remove_by_value(struct hash *hash, void *value); @@ -98,9 +98,9 @@ void hash_iterator_free(struct hash_iterator *hi); -uint32_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval); +uint64_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval); -static inline uint32_t +static inline uint64_t hash_value(const struct hash *hash, const void *key) { return (*hash->hash_function)(key, hash->iv); @@ -119,7 +119,7 @@ } static inline struct hash_bucket * -hash_bucket(struct hash *hash, uint32_t hv) +hash_bucket(struct hash *hash, uint64_t hv) { return &hash->buckets[hv & hash->mask]; } @@ -129,7 +129,7 @@ { void *ret =3D NULL; struct hash_element *he; - uint32_t hv =3D hash_value(hash, key); + uint64_t hv =3D hash_value(hash, key); struct hash_bucket *bucket =3D &hash->buckets[hv & hash->mask]; he =3D hash_lookup_fast(hash, bucket, key, hv); @@ -143,7 +143,7 @@ /* NOTE: assumes that key is not a duplicate */ static inline void -hash_add_fast(struct hash *hash, struct hash_bucket *bucket, const void *k= ey, uint32_t hv, +hash_add_fast(struct hash *hash, struct hash_bucket *bucket, const void *k= ey, uint64_t hv, void *value) { struct hash_element *he; @@ -160,7 +160,7 @@ static inline bool hash_remove(struct hash *hash, const void *key) { - uint32_t hv; + uint64_t hv; struct hash_bucket *bucket; bool ret; diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c index 6fa70a3..78c689e 100644 --- a/src/openvpn/mroute.c +++ b/src/openvpn/mroute.c @@ -354,7 +354,7 @@ * address type, number of bits in the network address, * and the actual address. */ -uint32_t +uint64_t mroute_addr_hash_function(const void *key, uint32_t iv) { return hash_func(mroute_addr_hash_ptr((const struct mroute_addr *)key), diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h index c8daa15..2f5d019 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h @@ -144,7 +144,7 @@ bool mroute_learnable_address(const struct mroute_addr *addr, struct gc_ar= ena *gc); -uint32_t mroute_addr_hash_function(const void *key, uint32_t iv); +uint64_t mroute_addr_hash_function(const void *key, uint32_t iv); bool mroute_addr_compare_function(const void *key1, const void *key2); diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index b7bef46..5583d1c 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -57,7 +57,7 @@ { mi->real.proto =3D sock->info.proto; struct hash_element *he; - const uint32_t hv =3D hash_value(hash, &mi->real); + const uint64_t hv =3D hash_value(hash, &mi->real); struct hash_bucket *bucket =3D hash_bucket(hash, hv); multi_assign_peer_id(m, mi); diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index b359750..c272f79 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -204,7 +204,7 @@ if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true)= && m->top.c2.buf.len > 0) { struct hash_element *he; - const uint32_t hv =3D hash_value(hash, &real); + const uint64_t hv =3D hash_value(hash, &real); struct hash_bucket *bucket =3D hash_bucket(hash, hv); uint8_t *ptr =3D BPTR(&m->top.c2.buf); uint8_t op =3D ptr[0] >> P_OPCODE_SHIFT; diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index c03e821..01d7e9d 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -228,11 +228,11 @@ #ifdef ENABLE_MANAGEMENT -static uint32_t +static uint64_t cid_hash_function(const void *key, uint32_t iv) { const unsigned long *k =3D (const unsigned long *)key; - return (uint32_t)*k; + return (uint64_t)*k; } static bool @@ -246,19 +246,19 @@ #endif #ifdef ENABLE_ASYNC_PUSH -static uint32_t +static uint64_t /* * inotify watcher descriptors are used as hash value */ int_hash_function(const void *key, uint32_t iv) { - return (uint32_t)(uintptr_t)key; + return (uintptr_t)key; } static bool int_compare_function(const void *key1, const void *key2) { - return (unsigned long)key1 =3D=3D (unsigned long)key2; + return (uintptr_t)key1 =3D=3D (uintptr_t)key2; } #endif @@ -1021,7 +1021,7 @@ const unsigned int flags) { struct hash_element *he; - const uint32_t hv =3D hash_value(m->vhash, addr); + const uint64_t hv =3D hash_value(m->vhash, addr); struct hash_bucket *bucket =3D hash_bucket(m->vhash, hv); struct multi_route *oldroute =3D NULL; struct multi_instance *owner =3D NULL; @@ -3103,7 +3103,7 @@ goto done; } - const uint32_t hv =3D hash_value(hash, &real); + const uint64_t hv =3D hash_value(hash, &real); struct hash_bucket *bucket =3D hash_bucket(hash, hv); /* make sure that we don't float to an address taken by another client= */ @@ -4247,7 +4247,7 @@ multi_unlearn_addr(struct multi_context *m, struct multi_instance *mi, con= st struct mroute_addr *addr) { struct hash_element *he; - const uint32_t hv =3D hash_value(m->vhash, addr); + const uint64_t hv =3D hash_value(m->vhash, addr); struct hash_bucket *bucket =3D hash_bucket(m->vhash, hv); struct multi_route *r =3D NULL; diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvp= n/test_misc.c index a9ae33f..ccdfdee 100644 --- a/tests/unit_tests/openvpn/test_misc.c +++ b/tests/unit_tests/openvpn/test_misc.c @@ -124,7 +124,7 @@ }; -static uint32_t +static uint64_t word_hash_function(const void *key, uint32_t iv) { const char *str =3D (const char *)key; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1570?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ib8140107f98164d2a2e1768a6d8ac65016cd7f7c Gerrit-Change-Number: 1570 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld --V6z4+YmaitU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld.

plaisthos uploaded patch set #4 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/1570?usp=3Demail">View Chan= ge

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

Change hash values in our ha=
sh map from uint32_t to uint64_t

32 bit architectures are playing a = very small role today, so the difference
between 64 bit and 32 bit hash = values is not expected to be large anymore.

This is also in preparat= ion to replace our hash function with a more modern
replacement.

= Change-Id: Ib8140107f98164d2a2e1768a6d8ac65016cd7f7c
Signed-off-by: Arne= Schwabe <arne@...1227...>
---
M src/openvpn/list.c
M src/op= envpn/list.h
M src/openvpn/mroute.c
M src/openvpn/mroute.h
M src/o= penvpn/mtcp.c
M src/openvpn/mudp.c
M src/openvpn/multi.c
M tests/u= nit_tests/openvpn/test_misc.c
8 files changed, 30 insertions(+), 30 dele= tions(-)

git pull ssh://gerrit.openvpn.net:29418=
/openvpn refs/changes/70/1570/4
diff --git a/src/openvpn/list.c b/s=
rc/openvpn/list.c
index f0e9908..50defb85 100644
= --- a/src/openvpn/list.c
+++ b/src/openvpn/list.c
@@ -34,8 +34,8 @@
#include "memdbg.h&quo= t;

struct hash *
-hash_init(const uint32_t n_buckets, const u= int32_t iv,
- = uint32_t (*hash_function)(const void *key, uint32_t iv),
+hash_init(const uint32_t n_buckets, ui= nt32_t iv,
+ = uint64_t (*hash_function)(const void *key, uint32_t iv),
= bool (*compare_function)(const void *key1, const void *key2))
{
struct hash *h;
@@ -76= ,7 +76,7 @@
}

struct ha= sh_element *
-hash_look= up_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uin= t32_t hv)
+hash_looku= p_fast(struct hash *hash, struct hash_bucket *bucket, const void *key, uint= 64_t hv)
{
struct hash_element *he;
struct hash_element *prev =3D NULL;
@@ = -104,7 +104,7 @@
}

bool=
-hash_remove_fast(stru= ct hash *hash, struct hash_bucket *bucket, const void *key, uint32_t hv)
+hash_remove_fast(struc= t hash *hash, struct hash_bucket *bucket, const void *key, uint64_t hv)
{
struct hash_element *he;
struct hash_element *prev =3D NULL;

@@ -136,7 +136,= 7 @@
bool
hash_add(struct hash *hash, con= st void *key, void *value, bool replace)
{
- uint32_t hv;

+ uint64_t hv;
st= ruct hash_bucket *bucket;
struct hash_element *he;
bool ret =3D false;
@@ -412,7 +412,7 @@
c ^=3D (b >> 15); \
}

-uint32= _t
+uint64_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval)
{
uint32_t a, b, c, len;
diff --git a/src/openvpn/list.h b/src/openvpn/list.h

index= 04cc3ab..06377c6 100644
--- a/src/openvpn/list.h+++ b/src/openvpn/list.h
@@ -40,7 +40,7 @@ {
void *value;
const void= *key;
- uint32_t ha= sh_value;
+ uint64= _t hash_value;
struct hash_element *next;
};


@@ -55,13 +55,13 @@
uint32_t n_elements;

uint32_t mask;
= uint32_t iv;
- uint32_t (*hash_function)(const void *key, uint32_t iv);
+ uint64_t (*hash_function)(co= nst void *key, uint32_t iv);

bool (*compare_function)(= const void *key1, const void *key2); /* return true if equal */
<= span> struct hash_bucket *buckets;

};
=
struct hash *hash_init(const uint32_t n_buckets, const u= int32_t iv,
- = uint32_t (*hash_function)(const void *key, uint32_t iv),
+ ui= nt64_t (*hash_function)(const void *key, uint32_t iv),
= bool (*compare_function)(const void *key1, const void *= key2));

void hash_free(struct hash *hash= );
@@ -69,9 +69,9 @@
bool hash_add(struct = hash *hash, const void *key, void *value, bool replace);
<= /span>
struct hash_element *hash_lookup_fast(struct hash *hash, s= truct hash_bucket *bucket,
- const void *key, uint32_t hv);
+ = const void *key, uint64_t hv);
-bool hash_remove_fast(struct ha= sh *hash, struct hash_bucket *bucket, const void *key, uint32_t hv);=
+bool hash_remove_fast(stru= ct hash *hash, struct hash_bucket *bucket, const void *key, uint64_t hv);

void hash_remove_by_value(struct hash *ha= sh, void *value);

@@ -98,9 +98,9 @@

void hash_iterator_free(struct hash_iterator = *hi);

-uint32_t hash_func(const uint8_t *k, uint32_t length, uint32_t initval);<= /span>
+uint64_t hash_func(c= onst uint8_t *k, uint32_t length, uint32_t initval);

-static inline uint32_t
+static inline uint64_t<= /span>
hash_value(const struct hash *hash, const void *key)
{
return (*hash->hash_function)(key, ha= sh->iv);
@@ -119,7 +119,7 @@
}
static inline struct hash_bucket *
-hash_bucket(struct hash *hash, uint= 32_t hv)

+hash_bucket= (struct hash *hash, uint64_t hv)
{
re= turn &hash->buckets[hv & hash->mask];
}
@@ -129,7 +129,7 @@
{
voi= d *ret =3D NULL;
struct hash_element *he;
- uint32_t hv =3D hash_value(has= h, key);

+ uint64_= t hv =3D hash_value(hash, key);
struct hash_bucket *bu= cket =3D &hash->buckets[hv & hash->mask];

he =3D hash_lookup_fast(hash, bucket, key, hv);<= br>@@ -143,7 +143,7 @@

/* NOTE: as= sumes that key is not a duplicate */
static inline void
-hash_add_fast(struct has= h *hash, struct hash_bucket *bucket, const void *key, uint32_t hv,+hash_add_fast(struct hash *h= ash, struct hash_bucket *bucket, const void *key, uint64_t hv,
void *value)

{
str= uct hash_element *he;
@@ -160,7 +160,7 @@
= static inline bool
hash_remove(struct hash *hash, const vo= id *key)
{
- uint32_t hv;
-uint32_t
+uint64_t
mroute_addr_hash_function(const voi= d *key, uint32_t iv)
{
return hash_fu= nc(mroute_addr_hash_ptr((const struct mroute_addr *)key),
d= iff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h
ind= ex c8daa15..2f5d019 100644
--- a/src/openvpn/mroute.h
+++ b/src/openvpn/mroute.h
@@ -144,7 +144,7 @@

bool mroute_learnable_address(const struc= t mroute_addr *addr, struct gc_arena *gc);

-uint32_t mroute_addr_hash_function(c= onst void *key, uint32_t iv);

+uint64_t mroute_addr_hash_function(const void *key, uint32_t iv);=

bool mroute_addr_compare_function(const= void *key1, const void *key2);

diff --gi= t a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index b7bef46..= 5583d1c 100644
--- a/src/openvpn/mtcp.c
+++= b/src/openvpn/mtcp.c
@@ -57,7 +57,7 @@
= {
mi->real.proto =3D sock->info.proto;
struct hash_element *he;
- const uint32_t hv =3D hash_value(hash, &am= p;mi->real);
+ = const uint64_t hv =3D hash_value(hash, &mi->real);
struct hash_bucket *bucket =3D hash_bucket(hash, hv);

multi_assign_peer_id(m, mi);
diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c

in= dex b359750..c272f79 100644
--- a/src/openvpn/mudp.c=
+++ b/src/openvpn/mudp.c
@@ -204,7 +204,7 @@
if (mroute_extract_openvpn_sockaddr(&real, &m->= top.c2.from.dest, true) && m->top.c2.buf.len > 0)
<= span> {

struct hash_element *he;
- const uint32_t hv =3D hash_= value(hash, &real);

+ const uint64_t hv =3D hash_value(hash, &real);
struct hash_bucket *bucket =3D hash_bucket(hash, hv);
uint8_t *ptr =3D BPTR(&m->top.c2.buf);
uint8_t op =3D ptr[0] >> P_OPCODE_SHIFT;

diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c

ind= ex c03e821..01d7e9d 100644
--- a/src/openvpn/multi.c=
+++ b/src/openvpn/multi.c
@@ -228,11 +228,11 @@

#ifdef ENABLE_MANAGEMENT
=
-static uint32_t
+static uint64_t cid_hash_function(const void *key, uint32_t iv)
{=
const unsigned long *k =3D (const unsigned long *)key= ;
- return (uint32_t= )*k;
+ return (uin= t64_t)*k;
}

static bool=
@@ -246,19 +246,19 @@
#endif

#ifdef ENABLE_ASYNC_PUSH
-static uint32_t
+static uint64_t
/*
= * inotify watcher descriptors are used as hash value
*/<= /span>
int_hash_function(const void *key, uint32_t iv)
= {
- return (u= int32_t)(uintptr_t)key;
+ return (uintptr_t)key;
}
<= br> static bool
int_compare_function(const void *key= 1, const void *key2)
{
- return (unsigned long)key1 =3D=3D (unsigned long)key2= ;
+ return (uintpt= r_t)key1 =3D=3D (uintptr_t)key2;
}
#endif=

@@ -1021,7 +1021,7 @@
= const unsigned int flags)
{
struct hash_element *he;

- const uint32_t hv =3D hash_value(m->vhash, addr);+ const uint64_t hv =3D ha= sh_value(m->vhash, addr);
struct hash_bucket *bucke= t =3D hash_bucket(m->vhash, hv);
struct multi_route= *oldroute =3D NULL;
struct multi_instance *owner =3D = NULL;
@@ -3103,7 +3103,7 @@
goto d= one;
}

- const uint32_t hv =3D hash_value(hash, &rea= l);
+ const uint64= _t hv =3D hash_value(hash, &real);
struct hash_buc= ket *bucket =3D hash_bucket(hash, hv);

= /* make sure that we don't float to an address taken by another clie= nt */
@@ -4247,7 +4247,7 @@
multi_unlearn_= addr(struct multi_context *m, struct multi_instance *mi, const struct mrout= e_addr *addr)
{
struct hash_element *= he;
- const uint32_t= hv =3D hash_value(m->vhash, addr);
+ const uint64_t hv =3D hash_value(m->vhash, addr);=
struct hash_bucket *bucket =3D hash_bucket(m->vhas= h, hv);
struct multi_route *r =3D NULL;

diff --git a/tests/unit_tests/openvpn/test_misc.c b/tes= ts/unit_tests/openvpn/test_misc.c
index a9ae33f..ccdfdee 10= 0644
--- a/tests/unit_tests/openvpn/test_misc.c
<= span>+++ b/tests/unit_tests/openvpn/test_misc.c

@@ -124,7 += 124,7 @@
};


= -static uint32_t
+static uint64_t
wor= d_hash_function(const void *key, uint32_t iv)
{
= const char *str =3D (const char *)key;

To view, visit change 1570. To unsubscribe, or for help writing mail= filters, visit = settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib8140107f98164d2a2e1768a6d8= ac65016cd7f7c
Gerrit-Change-Number: 1570
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --V6z4+YmaitU=--