From: "ordex (Code Review)" Date: Wed, 15 Nov 2023 13:45:17 +0000 References: Reply-To: a@...2181..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="iH9PD1ex4p0="; charset=UTF-8 Subject: [Openvpn-devel] [M] 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 --iH9PD1ex4p0= 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/+/439?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 vaddressed Change-Id: I6688362d8461c112bf425ddfe488d511a64cc37e 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 M src/openvpn/ssl.c 7 files changed, 45 insertions(+), 29 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/439/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 27415ee..63a684b 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -1114,13 +1114,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 @@ -2239,6 +2242,7 @@ if (status > 0) { + /*printf("\nstatus: %d\n", status); */ int i; mtcp->event_set_status =3D 0; for (i =3D 0; i < status; ++i) @@ -2275,10 +2279,6 @@ mtcp->event_set_status =3D ES_TIMEOUT; } } - else - { - mtcp->event_set_status =3D SOCKET_READ; - } } /* 'now' should always be a reasonably up-to-date timestamp */ diff --git a/src/openvpn/mroute.c b/src/openvpn/mroute.c index 0017a48..c72fe10 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 7c8972f..4e6d32c 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 { @@ -231,7 +230,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 d4ce642..ba0905e 100644 --- a/src/openvpn/mtcp.c +++ b/src/openvpn/mtcp.c @@ -109,7 +109,7 @@ mi =3D multi_create_instance(m, NULL, ls); if (mi && !proto_is_dgram(ls->info.proto)) { - printf("\nTCP add\n"); + 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); @@ -746,22 +746,26 @@ ev_arg->u.ls); } } - multi_get_timeout(m, &m->top.c2.timeval); - io_wait_udp(&m->top, m->mtcp, p2mp_iow_flags(m)); - MULTI_CHECK_SIG(m); - multi_process_per_second_timers(m); - - if (m->mtcp->event_set_status =3D=3D ES_TIMEOUT) + while (true) { - multi_process_timeout(m, MPP_PRE_SELECT | MPP_= CLOSE_ON_SIGNAL); - } - else - { - multi_process_io_udp(m); + multi_get_timeout(m, &m->top.c2.timeval); + io_wait_udp(&m->top, m->mtcp, p2mp_iow_flags(m= )); MULTI_CHECK_SIG(m); - } + multi_process_per_second_timers(m); + + if (m->mtcp->event_set_status =3D=3D ES_TIMEOU= T) + { + multi_process_timeout(m, MPP_PRE_SELECT | = MPP_CLOSE_ON_SIGNAL); + } + else + { + multi_process_io_udp(m); + MULTI_CHECK_SIG(m); + break; + } + } break; } } diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c index e9182c8..4979751 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 3522206..5098581 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -1157,11 +1157,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)) @@ -1247,6 +1248,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) @@ -3351,6 +3353,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; @@ -3417,7 +3427,6 @@ 0, &c->c2.to_t= un, DEV_TYPE_TU= N); - /* drop packet if extract failed */ if (!(mroute_flags & MROUTE_EXTRACT_SUCCEEDED)) { @@ -3555,6 +3564,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)); diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index cee4afe..73d6db0 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -3926,6 +3926,7 @@ { msg(D_MULTI_DROPPED, "Incoming control channel packet too big, drop= ping."); + printf("\nif (!buf_copy(in, buf))\n"); goto error; } reliable_mark_active_incoming(ks->rec_reliable, in, id= , op); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/439?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: I6688362d8461c112bf425ddfe488d511a64cc37e Gerrit-Change-Number: 439 Gerrit-PatchSet: 1 Gerrit-Owner: ordex Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --iH9PD1ex4p0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

ordex would like plaisthos and flichtenheld to review t= his 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 vaddressed

Change-Id: I6688362d8461c112bf425ddf= e488d511a64cc37e
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
M src/openvpn/ssl.c
7 files changed, 45 insertions= (+), 29 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/open=
vpn refs/changes/39/439/1
diff --git a/src/openvpn/forward.c b/src/=
openvpn/forward.c
index 27415ee..63a684b 100644
<= span>--- a/src/openvpn/forward.c
+++ b/src/openvpn/forward.= c
@@ -1114,13 +1114,16 @@
decrypt_= status =3D openvpn_decrypt(&c->c2.buf, c->c2.buffers->decrypt_= buf,
co, &c-&= gt;c2.frame, ad_start);

- if (!decrypt_status
- /* all sockets are of the same type, = so just check the first one */
- && link_socket_connection_oriented(c->c2.li= nk_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 m= ode */
- msg= (D_STREAM_ERRORS, "Fatal decryption error (process_incoming_link), res= tarting");
+ = if (!decrypt_status
+ /* all sockets are of the same type, so just check = the first one (not anymore!) */
+ && link_socket_connection_oriented(c-&g= t;c2.link_sockets[i]))
+ = /* decryption errors are fatal in TCP mode */
+ register_signal(c-&g= t;sig, SIGUSR1, "decryption-error"); /* SOFT-SIGUSR1 -- decryptio= n error in TCP mode */
+ }
}
= }
else
@@ -2239,6 +2242,7 @@


if (status > 0)
{
+ = /*printf("\nstatus: %d\n", status); */
int i;
mtcp->event= _set_status =3D 0;
for (i =3D 0; i < st= atus; ++i)
@@ -2275,10 +2279,6 @@
= mtcp->event_set_status =3D ES_TIMEOUT;
= }
}
- else
- {
- = mtcp->event_set_status =3D SOCKET_READ;
- }
}

/* 'now' should always be a reasonably up-to-da= te timestamp */
diff --git a/src/openvpn/mroute.c b/src/ope= nvpn/mroute.c
index 0017a48..c72fe10 100644
--- a/src/openvpn/mroute.c

+++ b/src/openvpn/mroute.c
@@ -421,7 +421,6 @@
{ buf_printf(&out, ":%d", ntohs(ma= ddr.v4.port));
}
- buf_printf(&out, ":%d&= quot;, maddr.proto);
}
= break;

@@ -454,6 +453,7 @@ buf_printf(&out, "UNKNOWN");<= br> break;
}
+ buf_printf(&out, "= |%d", maddr.proto);

return BSTR(&out);

}
else
diff --git a= /src/openvpn/mroute.h b/src/openvpn/mroute.h
index 7c8972f.= .4e6d32c 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 */
ui= nt8_t proto;
+ uin= t8_t type; /* MR_ADDR/MR_WITH flags */
uint8_t netbi= ts; /* number of bits in network part of address,
= * valid if MR_WITH_NETBITS is set */
uni= on {
@@ -231,7 +230,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;
}

sta= tic inline uint32_t
diff --git a/src/openvpn/mtcp.c b/src/o= penvpn/mtcp.c
index d4ce642..ba0905e 100644
--- a/src/openvpn/mtcp.c
+++ b/src/openvpn/mtcp.c@@ -109,7 +109,7 @@
mi =3D multi_create_instan= ce(m, NULL, ls);
if (mi && !proto_is_dgram(ls-= >info.proto))
{
- printf("\nTCP add\n");
+ 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);<= /span>
@@ -746,22 +746,26 @@
= ev_arg->u.ls);
= }
}

- = multi_get_timeout(m, &m->top.c2.timeval);
- io_wait_udp(&m->t= op, m->mtcp, p2mp_iow_flags(m));
- MULTI_CHECK_SIG(m);
=
- = multi_process_per_second_timers(m);
-
- = if (m->mtcp->event_set_status =3D=3D ES_TIMEOUT)<= /span>
+ = while (true)
{
- multi_pro= cess_timeout(m, MPP_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);

- }
- else- {

- = multi_process_io_udp(m);
+ multi_get_timeout(m, &m->top.c2.ti= meval);
+ = io_wait_udp(&m->top, m->mtcp, p2mp_iow_flags(m));=
MULTI_CHECK_SIG(m);- }

+ = multi_process_per_second_timers(m);
+
+ if (m->mtcp->event_set_= status =3D=3D ES_TIMEOUT)
+ {
+ multi_process_timeout(m, MP= P_PRE_SELECT | MPP_CLOSE_ON_SIGNAL);
+ }
+ else
+ {
+ = multi_process_io_udp(m);
+ MULTI_CHECK_SIG(m);
<= span style=3D"color: hsl(120, 100%, 40%);">+ = break;

+ = }
+ = }
break;
}
}diff --git a/src/openvpn/mudp.c b/src/openvpn/mudp.c
index e9182c8..4979751 100644

--- a/src/openvpn/mudp.c
+++ b/src/openvpn/mudp.c
@@ -193,6 +193,7 @@<= /span>
struct multi_instance *mi =3D NULL;
= struct hash *hash =3D m->hash;
real.proto =3D ls= ->info.proto;
+ = m->local.proto =3D real.proto;

i= f (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.cindex 3522206..5098581 100644
--- a/src/openvpn/mul= ti.c
+++ b/src/openvpn/multi.c
@@ -1157,11 = +1157,12 @@
*/
static struct multi_insta= nce *
multi_get_instance_by_virtual_addr(struct multi_cont= ext *m,
- = const struct mroute_addr *addr,
+ struct= mroute_addr *addr,
boo= l 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))
= @@ -1247,6 +1248,7 @@
CLEAR(remote_si);
remote_si.addr.in4.sin_family =3D AF_INET;

remo= te_si.addr.in4.sin_addr.s_addr =3D htonl(a);
+ addr.proto =3D 0;
ASSERT(= mroute_extract_openvpn_sockaddr(&addr, &remote_si, false));<= br>
if (netbits >=3D 0)
@@ -= 3351,6 +3353,14 @@
bool ret =3D true;
= bool floated =3D false;

+ /*
+ * Since we don't really need the protocol on vaddres= ses for internal VPN
= + * payload packets, make sure we have the same value to void hashing i= nsert
+ * and sea= rch issues.
+ */<= /span>
+ src.proto =3D 0;=
+ dest.proto =3D = src.proto;
+ if (m->pending)
{
= return true;
@@ -3417,7 +3427,6 @@
= 0,
<= span> &c= ->c2.to_tun,

= DEV_TYPE_TUN);
-
/* drop packet if extract f= ailed */
if (!(mroute_flags & MROUTE_E= XTRACT_SUCCEEDED))
{
@@ -3= 555,6 +3564,8 @@
const int dev_type =3D TUNNEL_TYP= E(m->top.c1.tuntap);
int16_t vid =3D 0;<= br>
+ s= rc.proto =3D 0;
+ = dest.proto =3D src.proto;

#ifdef MUL= TI_DEBUG_EVENT_LOOP
printf("TUN -> TCP/UDP= [%d]\n", BLEN(&m->top.c2.buf));
diff --git a/s= rc/openvpn/ssl.c b/src/openvpn/ssl.c
index cee4afe..73d6db0= 100644
--- a/src/openvpn/ssl.c
+++ b/src/o= penvpn/ssl.c
@@ -3926,6 +3926,7 @@
= {
msg(D_MULTI_DROPPED= ,
"Incoming control chann= el packet too big, dropping.");
+ printf("\nif (!buf_copy(in, b= uf))\n");
goto error;<= br> }
reliab= le_mark_active_incoming(ks->rec_reliable, in, id, op);
<= /span>

To view, visit change 439. To unsubscribe, or for help writin= g mail filters, visit settin= gs.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6688362d8461c112bf425ddfe48= 8d511a64cc37e
Gerrit-Change-Number: 439
Gerrit-PatchSet: 1
Gerrit-Owner: ordex <a@...2181...>
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
--iH9PD1ex4p0=--