From: "flichtenheld (Code Review)" Date: Mon, 27 Oct 2025 13:08:21 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="HBrLgmg38Ho="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: multi: Fix type handling for hashes, mostly inotify_watchers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --HBrLgmg38Ho= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1312?usp=3Demail to review the following change. Change subject: multi: Fix type handling for hashes, mostly inotify_watchers ...................................................................... multi: Fix type handling for hashes, mostly inotify_watchers Change-Id: Idede28c850def5e3b4a17dcbd0a5771f15cfc668 Signed-off-by: Frank Lichtenheld --- M src/openvpn/multi.c 1 file changed, 15 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/12/1312/1 diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 74cc866..f9f6b16 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -268,7 +268,7 @@ */ int_hash_function(const void *key, uint32_t iv) { - return (unsigned long)key; + return (uint32_t)(uintptr_t)key; } static bool @@ -306,22 +306,23 @@ * to determine which client sent an incoming packet * which is seen on the TCP/UDP socket. */ - m->hash =3D hash_init(t->options.real_hash_size, get_random(), mroute_= addr_hash_function, - mroute_addr_compare_function); + m->hash =3D hash_init(t->options.real_hash_size, (uint32_t)get_random(= ), + mroute_addr_hash_function, mroute_addr_compare_fun= ction); /* * Virtual address hash table. Used to determine * which client to route a packet to. */ - m->vhash =3D hash_init(t->options.virtual_hash_size, get_random(), mro= ute_addr_hash_function, - mroute_addr_compare_function); + m->vhash =3D hash_init(t->options.virtual_hash_size, (uint32_t)get_ran= dom(), + mroute_addr_hash_function, mroute_addr_compare_fu= nction); /* * This hash table is a clone of m->hash but with a * bucket size of one so that it can be used * for fast iteration through the list. */ - m->iter =3D hash_init(1, get_random(), mroute_addr_hash_function, mrou= te_addr_compare_function); + m->iter =3D hash_init(1, (uint32_t)get_random(), mroute_addr_hash_func= tion, + mroute_addr_compare_function); #ifdef ENABLE_MANAGEMENT m->cid_hash =3D hash_init(t->options.real_hash_size, 0, cid_hash_funct= ion, cid_compare_function); @@ -332,8 +333,8 @@ * Mapping between inotify watch descriptors and * multi_instances. */ - m->inotify_watchers =3D - hash_init(t->options.real_hash_size, get_random(), int_hash_functi= on, int_compare_function); + m->inotify_watchers =3D hash_init(t->options.real_hash_size, (uint32_t= )get_random(), + int_hash_function, int_compare_functio= n); #endif /* @@ -623,7 +624,7 @@ #ifdef ENABLE_ASYNC_PUSH if (mi->inotify_watch !=3D -1) { - hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->in= otify_watch); + hash_remove(m->inotify_watchers, (void *)(uintptr_t)mi->inotif= y_watch); mi->inotify_watch =3D -1; } #endif @@ -2825,7 +2826,7 @@ msg(D_MULTI_DEBUG, "MULTI: modified fd %d, mask %d", pevent->wd, p= event->mask); struct multi_instance *mi =3D - hash_lookup(m->inotify_watchers, (void *)(unsigned long)pevent= ->wd); + hash_lookup(m->inotify_watchers, (void *)(uintptr_t)pevent->wd= ); if (pevent->mask & IN_CLOSE_WRITE) { @@ -2844,7 +2845,7 @@ /* this event is _always_ fired when watch is removed or file = is deleted */ if (mi) { - hash_remove(m->inotify_watchers, (void *)(unsigned long)pe= vent->wd); + hash_remove(m->inotify_watchers, (void *)(uintptr_t)pevent= ->wd); mi->inotify_watch =3D -1; } } @@ -2984,14 +2985,14 @@ const char *file) { /* watch acf file */ - long watch_descriptor =3D inotify_add_watch(inotify_fd, file, IN_CLOSE= _WRITE | IN_ONESHOT); + int watch_descriptor =3D inotify_add_watch(inotify_fd, file, IN_CLOSE_= WRITE | IN_ONESHOT); if (watch_descriptor >=3D 0) { if (mi->inotify_watch !=3D -1) { - hash_remove(m->inotify_watchers, (void *)(unsigned long)mi->in= otify_watch); + hash_remove(m->inotify_watchers, (void *)(uintptr_t)mi->inotif= y_watch); } - hash_add(m->inotify_watchers, (const uintptr_t *)watch_descriptor,= mi, true); + hash_add(m->inotify_watchers, (void *)(uintptr_t)watch_descriptor,= mi, true); mi->inotify_watch =3D watch_descriptor; } else -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1312?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Idede28c850def5e3b4a17dcbd0a5771f15cfc668 Gerrit-Change-Number: 1312 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --HBrLgmg38Ho= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

multi: Fix type handling for hashes, mostly=
 inotify_watchers

Change-Id: Idede28c850def5e3b4a17dcbd0a5771f15cfc6= 68
Signed-off-by: Frank Lichtenheld <frank@...2641...>
---
M= src/openvpn/multi.c
1 file changed, 15 insertions(+), 14 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn r=
efs/changes/12/1312/1
diff --git a/src/openvpn/multi.c b/src/openvp=
n/multi.c
index 74cc866..f9f6b16 100644
---= a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
= @@ -268,7 +268,7 @@
*/
int_hash_fu= nction(const void *key, uint32_t iv)
{
- return (unsigned long)key;
= + return (uint32_t)(uintptr_= t)key;
}

static bool
@@ -306,22 +306,23 @@
* to determine wh= ich client sent an incoming packet
* which is seen on= the TCP/UDP socket.
*/
- m->hash =3D hash_init(t->options.real_has= h_size, get_random(), mroute_addr_hash_function,
- mroute_addr_compare_func= tion);
+ m->has= h =3D hash_init(t->options.real_hash_size, (uint32_t)get_random(),
+ m= route_addr_hash_function, mroute_addr_compare_function);
<= /span>
/*
* Virtual address hash table.= Used to determine
* which client to route a packet = to.
*/
- m->vhash =3D hash_init(t->options.virtual_hash_size, get_r= andom(), mroute_addr_hash_function,
- mroute_addr_compare_function);
+ m->vhash =3D hash_= init(t->options.virtual_hash_size, (uint32_t)get_random(),
+ mroute_a= ddr_hash_function, mroute_addr_compare_function);

<= br> /*
* This hash table is a clone of m-&g= t;hash but with a
* bucket size of one so that it can= be used
* for fast iteration through the list.
*/
- = m->iter =3D hash_init(1, get_random(), mroute_addr_hash_function, mrou= te_addr_compare_function);
+ m->iter =3D hash_init(1, (uint32_t)get_random(), mroute_addr_= hash_function,
+ = mroute_addr_compare_function);
<= br> #ifdef ENABLE_MANAGEMENT
m->cid_hash =3D = hash_init(t->options.real_hash_size, 0, cid_hash_function, cid_compare_f= unction);
@@ -332,8 +333,8 @@
* Mappi= ng between inotify watch descriptors and
* multi_inst= ances.
*/
- m->inotify_watchers =3D
- hash_init(t->options.real_hash_size, get_rand= om(), int_hash_function, int_compare_function);
+ m->inotify_watchers =3D hash_init(t->= options.real_hash_size, (uint32_t)get_random(),
+ int_hash_fu= nction, int_compare_function);
#endif

/*
@@ -623,7 +624,7 @@
= #ifdef ENABLE_ASYNC_PUSH
if (mi->inotify_watch = !=3D -1)
{
- hash_remove(m->inotify_watchers, (void *)(unsi= gned long)mi->inotify_watch);
+ hash_remove(m->inotify_watchers, (void *)(uintp= tr_t)mi->inotify_watch);
mi->inotify_wat= ch =3D -1;
}
#endif
@@ -2825,7 +2826,7 @@

msg(D_MULTI_DEBUG, "= MULTI: modified fd %d, mask %d", pevent->wd, pevent->mask);

struct multi_instance *mi =3D=
- hash_lookup(m-&g= t;inotify_watchers, (void *)(unsigned long)pevent->wd);
+ hash_lookup(m->inotif= y_watchers, (void *)(uintptr_t)pevent->wd);

= if (pevent->mask & IN_CLOSE_WRITE)
= {
@@ -2844,7 +2845,7 @@
= /* this event is _always_ fired when watch is removed or file is deleted *= /
if (mi)
{
- hash_remove= (m->inotify_watchers, (void *)(unsigned long)pevent->wd);
<= span style=3D"color: hsl(120, 100%, 40%);">+ hash_remove(m-&= gt;inotify_watchers, (void *)(uintptr_t)pevent->wd);

= mi->inotify_watch =3D -1;
}
}
@@ -2984,14 +2985,14 @@ const char *file)
{<= br> /* watch acf file */
- long watch_descriptor =3D inotify_add_watch(inotify_fd, fi= le, IN_CLOSE_WRITE | IN_ONESHOT);
+ int watch_descriptor =3D inotify_add_watch(inotify_fd, fi= le, IN_CLOSE_WRITE | IN_ONESHOT);
if (watch_descriptor= >=3D 0)
{
if (mi->inot= ify_watch !=3D -1)
{
- hash_remove(m->inotify_watchers, (vo= id *)(unsigned long)mi->inotify_watch);
+ hash_remove(m->inotify_watchers, (voi= d *)(uintptr_t)mi->inotify_watch);
}
= - hash_add(m->inotify_w= atchers, (const uintptr_t *)watch_descriptor, mi, true);
+ hash_add(m->inotify_watcher= s, (void *)(uintptr_t)watch_descriptor, mi, true);
= mi->inotify_watch =3D watch_descriptor;
} else

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

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Idede28c850def5e3b4a17dcbd0a= 5771f15cfc668
Gerrit-Change-Number: 1312
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --HBrLgmg38Ho=--