From: "its_Giaan (Code Review)"
Date: Thu, 12 Dec 2024 09:23:10 +0000
In-Reply-To:
References:
Reply-To: gianmarco@...2726..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641...,
gert@...1296..., a@...2181...
Message-ID: <1992fb81ab016c1ee5e9939cd9a023ff0bdbc5cc-EmailReplacePatchSet-HTML@...2715...>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="IcodN3rgU1M="; 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: plaisthos , cron2 , flichtenheld
Cc: openvpn-devel
--IcodN3rgU1M=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: cron2, flichtenheld, ordex, plaisthos.
Hello cron2, flichtenheld, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/765?usp=3Demail
to look at the new patch set (#7).
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
---
M src/openvpn/forward.c
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
6 files changed, 28 insertions(+), 10 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/765/7
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index f3f3503..854a549 100644
--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.c
@@ -1129,13 +1129,16 @@
decrypt_status =3D openvpn_decrypt(&c->c2.buf, c->c2.buffers->decr=
ypt_buf,
co, &c->c2.frame, ad_start);
- if (!decrypt_status
- /* on the instance context we have only one socket, so just ch=
eck the first one */
- && link_socket_connection_oriented(c->c2.link_sockets[0]))
+ for (int i =3D 0; i < c->c1.link_sockets_num; i++)
{
- /* decryption errors are fatal in TCP mode */
- register_signal(c->sig, SIGUSR1, "decryption-error"); /* SOFT-=
SIGUSR1 -- decryption error in TCP mode */
- msg(D_STREAM_ERRORS, "Fatal decryption error (process_incoming=
_link), restarting");
+ if (!decrypt_status
+ /* all sockets are of the same type, so just check the fir=
st one (not anymore!) */
+ && link_socket_connection_oriented(c->c2.link_sockets[i]))
+ {
+ /* decryption errors are fatal in TCP mode */
+ register_signal(c->sig, SIGUSR1, "decryption-error"); /* S=
OFT-SIGUSR1 -- decryption error in TCP mode */
+ msg(D_STREAM_ERRORS, "Fatal decryption error (process_inco=
ming_link), restarting");
+ }
}
}
else
diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c
index f4539dc..3a0224e 100644
--- a/src/openvpn/mroute.c
+++ b/src/openvpn/mroute.c
@@ -453,6 +453,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..570ccaa 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 */
@@ -216,7 +216,7 @@
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
diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp.c
index 1dae184..e173b80 100644
--- a/src/openvpn/mtcp.c
+++ b/src/openvpn/mtcp.c
@@ -56,6 +56,7 @@
mi =3D multi_create_instance(m, NULL, sock);
if (mi)
{
+ mi->real.proto =3D sock->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 0646662..c0db388 100644
--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@ -192,6 +192,8 @@
struct mroute_addr real =3D {0};
struct multi_instance *mi =3D NULL;
struct hash *hash =3D m->hash;
+ real.proto =3D sock->info.proto;
+ m->local.proto =3D real.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 4fddd62..559d77b 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -1153,11 +1153,12 @@
*/
static struct multi_instance *
multi_get_instance_by_virtual_addr(struct multi_context *m,
- const struct mroute_addr *addr,
+ struct mroute_addr *addr,
bool cidr_routing)
{
struct multi_route *route;
struct multi_instance *ret =3D NULL;
+ addr->proto =3D 0;
/* check for local address */
if (mroute_addr_equal(addr, &m->local))
@@ -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)
@@ -3343,6 +3345,14 @@
bool ret =3D true;
bool floated =3D false;
+ /*
+ * Since we don't really need the protocol on vaddresses for internal =
VPN
+ * payload packets, make sure we have the same value to void hashing i=
nsert
+ * and search issues.
+ */
+ src.proto =3D 0;
+ dest.proto =3D src.proto;
+
if (m->pending)
{
return true;
@@ -3409,7 +3419,6 @@
0,
&c->c2.to_t=
un,
DEV_TYPE_TU=
N);
-
/* drop packet if extract failed */
if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED))
{
@@ -3547,6 +3556,8 @@
const int dev_type =3D TUNNEL_TYPE(m->top.c1.tuntap);
int16_t vid =3D 0;
+ src.proto =3D 0;
+ dest.proto =3D src.proto;
#ifdef MULTI_DEBUG_EVENT_LOOP
printf("TUN -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf));
--
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: 7
Gerrit-Owner: its_Giaan
Gerrit-Reviewer: cron2
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-CC: ordex
Gerrit-Attention: plaisthos
Gerrit-Attention: cron2
Gerrit-Attention: flichtenheld
Gerrit-Attention: ordex
Gerrit-MessageType: newpatchset
--IcodN3rgU1M=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Attention is currently required from: cron2, flichtenheld, ordex, plais=
thos.
its_Giaan uploaded patch set #7 to this change.
<=
a href=3D"http://gerrit.openvpn.net/c/openvpn/+/765?usp=3Demail">View Chang=
e
mroute: adapt to new protocol handling and hashing improvementsRepurposing an unused field and renaming it to 'proto' instead=
of introducing a new field. The hashing now begins at the 'proto=
9; field rather than the 'type' field. Additionally, the changes=
ensure that the correct protocol is consistently used with virtual a=
ddresses ensuring alignment. Change-Id: Ic66eccb5058fe9c0fae64d8e2ca=
88728068a92ab Signed-off-by: Gianmarco De Gregori <gianmarco@...2786...=
..> --- M src/openvpn/forward.c 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 6 files changed, 28 insertions(+), 10 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/765/7<=
/pre>diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index f3f3503..854a549 100644 --- a/src/openvpn/for=
ward.c +++ b/src/openvpn/forward.c @@ -1129=
,13 +1129,16 @@ decrypt_status =3D openvpn_decrypt=
(&c->c2.buf, c->c2.buffers->decrypt_buf, =
co, &c->c2.frame, ad_start); - =
if (!decrypt_status -=
/* on the instance context we have only one socket, so just che=
ck the first one */ - =
&& link_socket_connection_oriented(c->c2.link_sockets[=
0])) + for (in=
t i =3D 0; i < c->c1.link_sockets_num; i++) =
{ - /* decry=
ption errors are fatal in TCP mode */ - register_signal(c->sig, SIGUSR1, "decry=
ption-error"); /* SOFT-SIGUSR1 -- decryption error in TCP mode */- msg(D_STREAM_E=
RRORS, "Fatal decryption error (process_incoming_link), restarting&quo=
t;); + if =
(!decrypt_status + =
/* all sockets are of the same type, so just check the first o=
ne (not anymore!) */ =
+ && link_socket_connection_oriented(c->c2.link_s=
ockets[i])) + =
{ + =
/* decryption errors are fatal in TCP mode */ + register_signal(c->sig, SIGU=
SR1, "decryption-error"); /* SOFT-SIGUSR1 -- decryption error in =
TCP mode */ + =
msg(D_STREAM_ERRORS, "Fatal decryption error (process_incoming=
_link), restarting"); + } } } else diff --git a/src/openvpn/mroute.c b/s=
rc/openvpn/mroute.c index f4539dc..3a0224e 100644 --- a/src/openvpn/mroute.c +++ b/src/openvpn/mroute.=
c @@ -453,6 +453,7 @@ buf_=
printf(&out, "UNKNOWN"); bre=
ak; } + buf_printf(&out, "|%d", maddr.proto); return BSTR(&out); } else diff --git a/src/openvpn/mroute.h b/src/o=
penvpn/mroute.h index 8b457d4..570ccaa 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h@@ -74,7 +74,7 @@ struct m=
route_addr { uint8_t len; /* length of address */=
span>- 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 */@@ -216,7 +216,7 @@ mroute_addr_hash_ptr(const=
struct mroute_addr *a) { /* NOTE: de=
pends on ordering of struct mroute_addr */ - return (uint8_t *) &a->type; + return (uint8_t *) &a->=
proto; } static inline =
uint32_t diff --git a/src/openvpn/mtcp.c b/src/openvpn/mtcp=
.c index 1dae184..e173b80 100644 --- a/src/=
openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ =
-56,6 +56,7 @@ mi =3D multi_create_instance(m, NULL, s=
ock); if (mi) { + mi->real.proto =3D sock-&g=
t;info.proto; struct hash_element *he; <=
span> 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 0646662..c0db388 100644 --- a/src/openvpn/=
mudp.c +++ b/src/openvpn/mudp.c @@ -192,6 +=
192,8 @@ struct mroute_addr real =3D {0}; struct multi_instance *mi =3D NULL; struct ha=
sh *hash =3D m->hash; + real.proto =3D sock->info.proto; + m->local.proto =3D real.proto; if (mroute_extract_openvpn_sockaddr(&real, &=
amp;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 4fddd62..559d77b 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c<=
/span>@@ -1153,11 +1153,12 @@ */ static struct multi_instance * multi_get_instance_by_vi=
rtual_addr(struct multi_context *m, - const struct mroute_addr *=
addr, + =
struct mroute_addr *addr, =
bool cidr_routing) { struct multi_route *route; struct multi_instan=
ce *ret =3D NULL; + =
addr->proto =3D 0; /* check for=
local address */ if (mroute_addr_equal(addr, &m-&=
gt;local)) @@ -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;=
span> ASSERT(mroute_extract_openvpn_sockaddr(&addr, &=
remote_si, false)); if (netbits >=
=3D 0) @@ -3343,6 +3345,14 @@ bool ret=
=3D true; bool floated =3D false; =
span>+ /* + * Since we don't really n=
eed the protocol on vaddresses for internal VPN + * payload packets, make sure we have the s=
ame value to void hashing insert + * and search issues. + */ + src.proto =3D 0; + dest.proto =3D src.proto; + if (m->pending) =
{ return true; @@ -3409,7 +34=
19,6 @@ =
0, =
&c->c2.to_tun, =
DEV_TYPE_TUN); - =
/* drop packet if extract failed */ if (!(=
mroute_flags & MROUTE_EXTRACT_SUCCEEDED)) =
{ @@ -3547,6 +3556,8 @@ const =
int dev_type =3D TUNNEL_TYPE(m->top.c1.tuntap); =
int16_t vid =3D 0; + src.proto =3D 0; + dest.proto =3D src.proto; <=
/span> #ifdef MULTI_DEBUG_EVENT_LOOP pri=
ntf("TUN -> TCP/UDP [%d]\n", BLEN(&m->top.c2.buf)); To view, visit change 765 . To unsubscribe, or f=
or help writing mail filters, visit settings .
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic66eccb5058fe9c0fae64d8e2ca=
88728068a92ab
Gerrit-Change-Number: 765
Gerrit-PatchSet: 7
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-Attention: plaisthos <arne-openvpn@...220...=
..1227...>
Gerrit-Attention: cron2 <gert@...1296...>=
;
Gerrit-Attention: flichtenheld <frank@...2375...=
41...>
Gerrit-Attention: ordex <a@...2181...> <=
/div>
Gerrit-MessageType: newpatchset
--IcodN3rgU1M=--