From: "cron2 (Code Review)" Date: Sat, 25 Jan 2025 09:57:49 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., gianmarco@...2726..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: <73ed50f640fb4448ca0b80c29b6b6bc6c9110417-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="AkNJJpd7SbY="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: mroute: adapt to new protocol handling and hashing improvements List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: its_Giaan , plaisthos , flichtenheld Cc: openvpn-devel --AkNJJpd7SbY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#18) to the change originally created b= y its_Giaan. ( http://gerrit.openvpn.net/c/openvpn/+/765?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: mroute: adapt to new protocol handling and hashing improvem= ents ...................................................................... mroute: adapt to new protocol handling and hashing improvements Repurposing an unused field and renaming it to 'proto' instead of introducing a new field. The hashing now begins at the 'proto' field rather than the 'type' field. Additionally, the changes ensure that the correct protocol is consistently used with virtual addresses ensuring alignment. Change-Id: Ic66eccb5058fe9c0fae64d8e2ca88728068a92ab Signed-off-by: Gianmarco De Gregori Acked-by: Gert Doering Message-Id: <20250124205135.18765-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30= 579.html Signed-off-by: Gert Doering --- 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 5 files changed, 21 insertions(+), 4 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/765/18 diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c index 80e18b7..74923cf 100644 --- a/src/openvpn/mroute.c +++ b/src/openvpn/mroute.c @@ -454,6 +454,7 @@ buf_printf(&out, "UNKNOWN"); break; } + buf_printf(&out, "|%d", maddr.proto); return BSTR(&out); } else diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h index 8b457d4..2659695 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h @@ -74,7 +74,7 @@ struct mroute_addr { uint8_t len; /* length of address */ - uint8_t unused; + uint8_t proto; uint8_t type; /* MR_ADDR/MR_WITH flags */ uint8_t netbits; /* number of bits in network part of address, * valid if MR_WITH_NETBITS is set */ @@ -183,6 +183,15 @@ { unsigned int ret =3D 0; verify_align_4(buf); + + /* + * Since we don't really need the protocol on vaddresses for internal = VPN + * payload packets, make sure we have the same value to avoid hashing = insert + * and search issues. + */ + src->proto =3D 0; + dest->proto =3D src->proto; + if (tunnel_type =3D=3D DEV_TYPE_TUN) { ret =3D mroute_extract_addr_ip(src, dest, buf); @@ -201,6 +210,10 @@ { return false; } + if (a1->proto !=3D a2->proto) + { + return false; + } if (a1->netbits !=3D a2->netbits) { return false; @@ -216,13 +229,13 @@ mroute_addr_hash_ptr(const struct mroute_addr *a) { /* NOTE: depends on ordering of struct mroute_addr */ - return (uint8_t *) &a->type; + return (uint8_t *) &a->proto; } static inline uint32_t mroute_addr_hash_len(const struct mroute_addr *a) { - return (uint32_t) a->len + 2; + return (uint32_t) a->len + 3; } static inline void diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c index 6d1d5a0..62ed044 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -56,6 +56,7 @@ mi =3D multi_create_instance(m, NULL, ls); if (mi) { + mi->real.proto =3D ls->info.proto; struct hash_element *he; const uint32_t hv =3D hash_value(hash, &mi->real); struct hash_bucket *bucket =3D hash_bucket(hash, hv); diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index 6137578..4f2bbd7 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -192,6 +192,7 @@ struct mroute_addr real =3D {0}; struct multi_instance *mi =3D NULL; struct hash *hash =3D m->hash; + real.proto =3D ls->info.proto; if (mroute_extract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true) && m->top.c2.buf.len > 0) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 3f55dd7..9c8c014 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -794,6 +794,7 @@ { goto err; } + mi->real.proto =3D ls->info.proto; generate_prefix(mi); } @@ -1243,6 +1244,7 @@ CLEAR(remote_si); remote_si.addr.in4.sin_family =3D AF_INET; remote_si.addr.in4.sin_addr.s_addr =3D htonl(a); + addr.proto =3D 0; ASSERT(mroute_extract_openvpn_sockaddr(&addr, &remote_si, false)); if (netbits >=3D 0) @@ -3548,7 +3550,6 @@ const int dev_type =3D TUNNEL_TYPE(m->top.c1.tuntap); int16_t vid =3D 0; - #ifdef MULTI_DEBUG_EVENT_LOOP printf("TUN -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf)); #endif -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/765?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ic66eccb5058fe9c0fae64d8e2ca88728068a92ab Gerrit-Change-Number: 765 Gerrit-PatchSet: 18 Gerrit-Owner: its_Giaan Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-CC: ordex Gerrit-MessageType: newpatchset --AkNJJpd7SbY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #18 to the change originally c= reated by its_Giaan.

View Change

The following approvals got outdate= d and were removed: Code-Review+2 by cron2

mroute: adapt to new protocol handling and hashing i=
mprovements

Repurposing an unused field and renaming it to 'prot= o'
instead of introducing a new field. The hashing now
begins at = the 'proto' field rather than the 'type'
field. Addition= ally, the changes ensure that the
correct protocol is consistently used = with virtual
addresses ensuring alignment.

Change-Id: Ic66eccb505= 8fe9c0fae64d8e2ca88728068a92ab
Signed-off-by: Gianmarco De Gregori <g= ianmarco@...2726...>
Acked-by: Gert Doering <gert@...1296...>Message-Id: <20250124205135.18765-1-gert@...1296...>
URL: https:= //www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30579.htmlSigned-off-by: Gert Doering <gert@...1296...>
---
M src/openvp= n/mroute.c
M src/openvpn/mroute.h
M src/openvpn/mtcp.c
M src/openv= pn/mudp.c
M src/openvpn/multi.c
5 files changed, 21 insertions(+), 4 = deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs=
/changes/65/765/18
diff --git a/src/openvpn/mroute.c b/src/openvpn/=
mroute.c
index 80e18b7..74923cf 100644
--- = a/src/openvpn/mroute.c
+++ b/src/openvpn/mroute.c@@ -454,6 +454,7 @@
buf_printf(&= ;out, "UNKNOWN");
break;<= br> }
+= buf_printf(&out, "|%d", maddr.proto);
return BSTR(&out);
}
= else
diff --git a/src/openvpn/mroute.h b/src/openvpn/mrou= te.h
index 8b457d4..2659695 100644
--- a/sr= c/openvpn/mroute.h
+++ b/src/openvpn/mroute.h
@@ -74,7 +74,7 @@

struct mroute_addr = {
uint8_t len; /* length of address */
- uint8_t unused;
+ uint8_t proto;
uint8_t type; /* MR_ADDR/MR_WITH flags */
uint= 8_t netbits; /* number of bits in network part of address,
= * valid if MR_WITH_NETBITS is set */
@@ -183,6 +183,15 @@
{
unsigned int = ret =3D 0;
verify_align_4(buf);
+
+ /*
+ * Since we don't really need the protocol on vaddresses for inte= rnal VPN
+ * payl= oad packets, make sure we have the same value to avoid hashing insert

+ * and search issues.=
+ */
<= span style=3D"color: hsl(120, 100%, 40%);">+ src->proto =3D 0;=
+ dest->proto =3D src= ->proto;
+<= br> if (tunnel_type =3D=3D DEV_TYPE_TUN)
{
ret =3D mroute_extract_addr_ip(src, dest, buf);

@@ -201,6 +210,10 @@
{
= return false;
}
+ if (a1->proto !=3D a2->proto)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {
+ return false;
+ }
if (a1->net= bits !=3D a2->netbits)
{
r= eturn false;
@@ -216,13 +229,13 @@
mroute_= addr_hash_ptr(const struct mroute_addr *a)
{
/* NOTE: depends on ordering of struct mroute_addr */
- return (uint8_t *) &a->t= ype;
+ return (uin= t8_t *) &a->proto;
}

static inline uint32_t
mroute_addr_hash_len(const str= uct mroute_addr *a)
{
- return (uint32_t) a->len + 2;
+ return (uint32_t) a->len + 3;
}

static inline void=
diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index 6d1d5a0..62ed044 100644

--- a/src/openvpn/mtcp.c<= /span>
+++ b/src/openvpn/mtcp.c
@@ -56,6 +56,7 @@<= /span>
mi =3D multi_create_instance(m, NULL, ls);
<= span> if (mi)

{
+ mi->real.proto =3D ls->info.proto;

struct hash_element *he;
const= uint32_t hv =3D hash_value(hash, &mi->real);
= struct hash_bucket *bucket =3D hash_bucket(hash, hv);
di= ff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index 61= 37578..4f2bbd7 100644
--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@ -192,6 +192,7 @@
= struct mroute_addr real =3D {0};
struct mul= ti_instance *mi =3D NULL;
struct hash *hash =3D m->= hash;
+ real.proto= =3D ls->info.proto;

if (mroute_e= xtract_openvpn_sockaddr(&real, &m->top.c2.from.dest, true)
&& m->top.c2.buf.len > 0)
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c

ind= ex 3f55dd7..9c8c014 100644
--- a/src/openvpn/multi.c=
+++ b/src/openvpn/multi.c
@@ -794,6 +794,7 @@
{
goto err;
}

+ = mi->real.proto =3D ls->info.proto;
genera= te_prefix(mi);
}

@@ = -1243,6 +1244,7 @@
CLEAR(remote_si);
= remote_si.addr.in4.sin_family =3D AF_INET;
remote_= si.addr.in4.sin_addr.s_addr =3D htonl(a);
+ addr.proto =3D 0;
ASSERT(mro= ute_extract_openvpn_sockaddr(&addr, &remote_si, false));
=
if (netbits >=3D 0)
@@ -354= 8,7 +3550,6 @@
const int dev_type =3D TUNNEL_TYPE(= m->top.c1.tuntap);
int16_t vid =3D 0;
-
#ifdef MULTI_DEBUG_EVENT_LOOP
printf("TU= N -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf));
#endif

To view, visit change 765. To unsub= scribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic66eccb5058fe9c0fae64d8e2ca= 88728068a92ab
Gerrit-Change-Number: 765
Gerrit-PatchSet: 18
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: ordex <a@...2181...>
Gerrit-MessageType: newpatchset
--AkNJJpd7SbY=--