From: "its_Giaan (Code Review)" Date: Mon, 23 Sep 2024 13:41:31 +0000 References: Reply-To: gianmarco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <9b77ecdf4ba9bc5d24a2113a16cd5ea24c065b62-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="R8YGToc2hRo="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: mroute: properly print protocol at the end of the string List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --R8YGToc2hRo= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/765?usp=3Demail to review the following change. Change subject: mroute: properly print protocol at the end of the string ...................................................................... mroute: properly print protocol at the end of the string mroute: substitute unused field with proto Rather than adding a new field 'proto', take advantage of the 'unused' field and rename it. Hashing will now start at the 'proto' field rather than 'type'. MULTI: ensure we've got the correct protocol with virtual addresses MULTI: ensure we've got the same value as protocol for vaddresses 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, 27 insertions(+), 12 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/765/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 7559a71..1357cad 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 - /* all sockets are of the same type, so just check the first o= ne */ - && 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 6c8e8dd..3a0224e 100644 --- a/src/openvpn/mroute.c +++ b/src/openvpn/mroute.c @@ -421,7 +421,6 @@ { buf_printf(&out, ":%d", ntohs(maddr.v4.port)); } - buf_printf(&out, ":%d", maddr.proto); } break; @@ -454,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 fd1dbfe..e844c21 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h @@ -74,9 +74,8 @@ struct mroute_addr { uint8_t len; /* length of address */ - uint8_t unused; - uint8_t type; /* MR_ADDR/MR_WITH flags */ 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 */ union { @@ -221,7 +220,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 73f6bcc..1eb28ec 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 && !proto_is_dgram(ls->info.proto)) { + 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 a7e6e1d..f9efcd5 100644 --- a/src/openvpn/mudp.c +++ b/src/openvpn/mudp.c @@ -193,6 +193,7 @@ struct multi_instance *mi =3D NULL; struct hash *hash =3D m->hash; real.proto =3D ls->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 2d4fbe7..4a6dd52 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -1156,11 +1156,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)) @@ -1246,6 +1247,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) @@ -3346,6 +3348,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; @@ -3412,7 +3422,6 @@ 0, &c->c2.to_t= un, DEV_TYPE_TU= N); - /* drop packet if extract failed */ if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED)) { @@ -3550,6 +3559,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: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --R8YGToc2hRo= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

Vi= ew Change

mroute: properly print protocol at the end of the string
<= br>mroute: substitute unused field with proto

Rather than adding a n= ew field 'proto', take advantage of the 'unused'
field a= nd rename it.

Hashing will now start at the 'proto' field ra= ther than 'type'.

MULTI: ensure we've got the correct pr= otocol with virtual addresses

MULTI: ensure we've got the same v= alue as protocol for vaddresses

Change-Id: Ic66eccb5058fe9c0fae64d8e= 2ca88728068a92ab
Signed-off-by: Gianmarco De Gregori <gianmarco@...1664...= 26...>
---
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 s= rc/openvpn/multi.c
6 files changed, 27 insertions(+), 12 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/65/765=
/1
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c
index 7559a71..1357cad 100644
--- a/src/openvpn/= forward.c
+++ b/src/openvpn/forward.c
@@ -1= 129,13 +1129,16 @@
decrypt_status =3D openvpn_decr= ypt(&c->c2.buf, c->c2.buffers->decrypt_buf,
= co, &c->c2.frame, ad_start);=

- = if (!decrypt_status
- &a= mp;& link_socket_connection_oriented(c->c2.link_sockets[0]))<= br>+ 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&= quot;); /* SOFT-SIGUSR1 -- decryption error in TCP mode */
- msg(D_STREAM_ERRORS, "= ;Fatal decryption error (process_incoming_link), restarting");<= br>+ if (!decrypt_st= atus
+ = /* all sockets are of the same type, so just check the first one (not anym= ore!) */
+ = && link_socket_connection_oriented(c->c2.link_sockets[i]))<= /span>
+ {=
+ /* decrypt= ion errors are fatal in TCP mode */
+ register_signal(c->sig, SIGUSR1, "d= ecryption-error"); /* SOFT-SIGUSR1 -- decryption error in TCP mode */<= /span>
+ msg(= D_STREAM_ERRORS, "Fatal decryption error (process_incoming_link), rest= arting");
+ = }
}
}
= else
diff --git a/src/openvpn/mroute.c b/src/openvpn/m= route.c
index 6c8e8dd..3a0224e 100644
--- a= /src/openvpn/mroute.c
+++ b/src/openvpn/mroute.c
= @@ -421,7 +421,6 @@
{
buf_printf(&out, ":%d", ntohs(maddr.v4= .port));

}
- buf_printf(&out, ":%d",= maddr.proto);
}
= break;

@@ -454,6 +453,7 @@
buf_printf(&out, "UNKNOWN");

break;

}
+ buf_printf(&out, "|%d&qu= ot;, maddr.proto);
return BSTR(&out); }
else
diff --git a/src/o= penvpn/mroute.h b/src/openvpn/mroute.h
index fd1dbfe..e844c= 21 100644
--- a/src/openvpn/mroute.h
+++ b/= src/openvpn/mroute.h
@@ -74,9 +74,8 @@

struct mroute_addr {
uint8_t len; /*= length of address */
-= uint8_t unused;
- = uint8_t type; /* MR_ADDR/MR_WITH flags */
uint8_t = proto;
+ uint8_t t= ype; /* MR_ADDR/MR_WITH flags */
uint8_t netbits; /*= number of bits in network part of address,
= * valid if MR_WITH_NETBITS is set */
union {
@@ -221,7 +220,7 @@
mroute_addr_hash_ptr(co= nst struct mroute_addr *a)
{
/* NOTE:= depends on ordering of struct mroute_addr */
- return (uint8_t *) &a->type;
<= span style=3D"color: hsl(120, 100%, 40%);">+ return (uint8_t *) &a-&= gt;proto;

}

static inli= ne uint32_t
diff --git a/src/openvpn/mtcp.c b/src/openvpn/m= tcp.c
index 73f6bcc..1eb28ec 100644
--- a/s= rc/openvpn/mtcp.c
+++ b/src/openvpn/mtcp.c
= @@ -56,6 +56,7 @@
mi =3D multi_create_instance(m, NULL= , ls);
if (mi && !proto_is_dgram(ls->info.p= roto))
{
+ mi->real.proto =3D ls->info.proto;
= struct hash_element *he;
const uint32_t h= v =3D hash_value(hash, &mi->real);
struct h= ash_bucket *bucket =3D hash_bucket(hash, hv);
diff --git a/= src/openvpn/mudp.c b/src/openvpn/mudp.c
index a7e6e1d..f9ef= cd5 100644
--- a/src/openvpn/mudp.c
+++ b/s= rc/openvpn/mudp.c
@@ -193,6 +193,7 @@
= struct multi_instance *mi =3D NULL;
struct hash *hash = =3D m->hash;
real.proto =3D ls->info.proto;
+ m->local.proto = =3D real.proto;

if (mroute_extract_o= penvpn_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 2d4fb= e7..4a6dd52 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c

@@ -1156,11 +1156,12 @@<= br> */
static struct multi_instance *
multi_get_instance_by_virtual_addr(struct multi_context *m,
<= span style=3D"color: hsl(0, 100%, 40%);">- = const struct mroute_addr *addr,
+ struct mroute_addr *addr,<= /span>
bool cidr_routing)
{
struct multi_route *route;
struct multi_instance *ret =3D NULL;

+ addr->proto =3D 0;

/* check for local address */
if (mrou= te_addr_equal(addr, &m->local))
@@ -1246,6 +1247,7 @= @
CLEAR(remote_si);
remote_si.add= r.in4.sin_family =3D AF_INET;
remote_si.addr.in4.sin_a= ddr.s_addr =3D htonl(a);
+ addr.proto =3D 0;
ASSERT(mroute_extract_openv= pn_sockaddr(&addr, &remote_si, false));
if (netbits >=3D 0)
@@ -3346,6 +3348,14 @@
bool ret =3D true;
bool floated = =3D false;

+ /*
+ = * Since we don't really need the protocol on vaddresses for internal V= PN
+ * payload pa= ckets, make sure we have the same value to void hashing insert
+ * and search issues.
=
+ */
+ src.proto =3D 0;
+ dest.proto =3D src.proto;<= br>+
if (m= ->pending)
{
return true;<= /span>
@@ -3412,7 +3422,6 @@
= 0,
= &c->c2.to_tun,
= DEV_TYPE_TUN);
-

/* drop packet if extract failed */ if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED))=
{
@@ -3550,6 +3559,8 @@
const int dev_type =3D TUNNEL_TYPE(m->top.c1.tun= tap);
int16_t vid =3D 0;
<= br>+ src.proto =3D 0;
+ dest.proto =3D= src.proto;

#ifdef MULTI_DEBUG_EVENT_LOO= P
printf("TUN -> TCP/UDP [%d]\n", BLE= N(&m->top.c2.buf));

To view, vis= it change= 765. To unsubscribe, 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: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--R8YGToc2hRo=--