From: "ralf_lici (Code Review)" Date: Tue, 10 Dec 2024 16:53:32 +0000 References: Reply-To: ralf@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <60542e3cbcd523a4391cc3a40577d474b02c4499-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="aosOOzHyI0k="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Handle missing DCO peer by restarting the session List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --aosOOzHyI0k= 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/+/831?usp=3Demail to review the following change. Change subject: Handle missing DCO peer by restarting the session ...................................................................... Handle missing DCO peer by restarting the session Occasionally, CMD_DEL_PEER is not delivered to userspace, preventing the openvpn process from registering the event. To handle this case, we check if calls to the DCO module return an error, and, if so, send a SIGUSR1 signal to reset the session. Change-Id: Ib118426c5a69256894040c69856a4003d9f4637c Signed-off-by: Ralf Lici --- M src/openvpn/dco_linux.c M src/openvpn/forward.c M src/openvpn/manage.c M src/openvpn/multi.c M src/openvpn/sig.c 5 files changed, 61 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/31/831/1 diff --git a/src/openvpn/dco_linux.c b/src/openvpn/dco_linux.c index b038382..3f8e206 100644 --- a/src/openvpn/dco_linux.c +++ b/src/openvpn/dco_linux.c @@ -979,7 +979,12 @@ int dco_get_peer_stats(struct context *c) { - uint32_t peer_id =3D c->c2.tls_multi->dco_peer_id; + int peer_id =3D c->c2.tls_multi->dco_peer_id; + if (peer_id =3D=3D -1) + { + return 0; + } + msg(D_DCO_DEBUG, "%s: peer-id %d", __func__, peer_id); if (!c->c1.tuntap) diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index d50b24c..4c4f3f7 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -483,16 +483,27 @@ static void check_inactivity_timeout(struct context *c) { - if (dco_enabled(&c->options) && dco_get_peer_stats(c) =3D=3D 0) + if (dco_enabled(&c->options)) { - int64_t tot_bytes =3D c->c2.tun_read_bytes + c->c2.tun_write_bytes; - int64_t new_bytes =3D tot_bytes - c->c2.inactivity_bytes; - - if (new_bytes > c->options.inactivity_minimum_bytes) + const int stats_request =3D dco_get_peer_stats(c); + if (stats_request =3D=3D 0) { - c->c2.inactivity_bytes =3D tot_bytes; - event_timeout_reset(&c->c2.inactivity_interval); + int64_t tot_bytes =3D c->c2.tun_read_bytes + c->c2.tun_write_b= ytes; + int64_t new_bytes =3D tot_bytes - c->c2.inactivity_bytes; + if (new_bytes > c->options.inactivity_minimum_bytes) + { + c->c2.inactivity_bytes =3D tot_bytes; + event_timeout_reset(&c->c2.inactivity_interval); + + return; + } + } + else if (stats_request < 0) + { + msg(M_WARN, "Error requesting peer %d DCO stats (%s). Restarti= ng the session", + c->c2.tls_multi->dco_peer_id, strerror(-stats_request)); + register_signal(c->sig, SIGUSR1, "dco peer stats error"); return; } } diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index e79a118..be2da4a 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -4138,10 +4138,21 @@ counter_type dco_read_bytes =3D 0; counter_type dco_write_bytes =3D 0; - if (dco_enabled(&c->options) && (dco_get_peer_stats(c) =3D=3D 0)) + if (dco_enabled(&c->options) && c->c2.tls_multi->peer_id !=3D -1) { - dco_read_bytes =3D c->c2.dco_read_bytes; - dco_write_bytes =3D c->c2.dco_write_bytes; + const int stats_request =3D dco_get_peer_stats(c); + if (stats_request =3D=3D 0) + { + dco_read_bytes =3D c->c2.dco_read_bytes; + dco_write_bytes =3D c->c2.dco_write_bytes; + } + else if (stats_request < 0) + { + msg(D_MANAGEMENT, "MANAGEMENT: Error requesting peer %d DC= O stats (%s). Restarting the session", + c->c2.tls_multi->dco_peer_id, strerror(-stats_request)= ); + register_signal(c->sig, SIGUSR1, "dco peer stats error"); + return; + } } if (!(man->persist.callback.flags & MCF_SERVER)) diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 45b3cfa..20724a0 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -549,7 +549,13 @@ { if (dco_enabled(&m->top.options)) { - dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m); + const int stats_request =3D dco_get_peer_stats_multi(&m->top.c1.tu= ntap->dco, m); + if (stats_request < 0) + { + msg(D_DCO, "Error requesting peer %d DCO stats (%s)", + c->c2.tls_multi->dco_peer_id, strerror(-stats_request)); + return; + } } setenv_counter(c->c2.es, "bytes_received", c->c2.link_read_bytes + c->= c2.dco_read_bytes); @@ -855,7 +861,14 @@ if (dco_enabled(&m->top.options)) { - dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m); + const int stats_request =3D dco_get_peer_stats_multi(&m->top.c= 1.tuntap->dco, m); + if (stats_request =3D=3D -ENOENT) + { + msg(M_WARN, "Error requesting peer DCO stats (%s)", + strerror(-stats_request)); + register_signal(m->top.sig, SIGUSR1, "dco peer stats error= "); + return; + } } if (version =3D=3D 1) diff --git a/src/openvpn/sig.c b/src/openvpn/sig.c index 8323f0d..3654033 100644 --- a/src/openvpn/sig.c +++ b/src/openvpn/sig.c @@ -489,7 +489,14 @@ if (dco_enabled(&c->options)) { - dco_get_peer_stats(c); + const int stats_request =3D dco_get_peer_stats(c); + if (stats_request < 0) + { + msg(M_WARN, "Error requesting peer %d DCO stats (%s). Restarti= ng the session", + c->c2.tls_multi->dco_peer_id, strerror(-stats_request)); + register_signal(c->sig, SIGUSR1, "dco peer stats error"); + return; + } } status_printf(so, "OpenVPN STATISTICS"); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/831?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: Ib118426c5a69256894040c69856a4003d9f4637c Gerrit-Change-Number: 831 Gerrit-PatchSet: 1 Gerrit-Owner: ralf_lici Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --aosOOzHyI0k= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

ralf_lici would like plaisthos and flichtenheld to review this change.

Vi= ew Change

Handle missing DCO peer by restarting the session

Occa= sionally, CMD_DEL_PEER is not delivered to userspace, preventing the
ope= nvpn process from registering the event. To handle this case, we
check i= f calls to the DCO module return an error, and, if so, send a
SIGUSR1 si= gnal to reset the session.

Change-Id: Ib118426c5a69256894040c69856a4= 003d9f4637c
Signed-off-by: Ralf Lici <ralf@...2726...>
---
M= src/openvpn/dco_linux.c
M src/openvpn/forward.c
M src/openvpn/manage= .c
M src/openvpn/multi.c
M src/openvpn/sig.c
5 files changed, 61 i= nsertions(+), 14 deletions(-)

git pull ssh://gerrit.openvpn.net:2=
9418/openvpn refs/changes/31/831/1
diff --git a/src/openvpn/dco_lin=
ux.c b/src/openvpn/dco_linux.c
index b038382..3f8e206 10064= 4
--- a/src/openvpn/dco_linux.c
+++ b/src/o= penvpn/dco_linux.c
@@ -979,7 +979,12 @@
in= t
dco_get_peer_stats(struct context *c)
{=
- uint32_t peer_id = =3D c->c2.tls_multi->dco_peer_id;
+ int peer_id =3D c->c2.tls_multi->dco_peer_id;=
+ if (peer_id =3D= =3D -1)
+ {=
+ return 0;+ }
+
msg(D_DCO_DEBUG, &q= uot;%s: peer-id %d", __func__, peer_id);

<= span> if (!c->c1.tuntap)
diff --git a/src/openvpn/fo= rward.c b/src/openvpn/forward.c
index d50b24c..4c4f3f7 1006= 44
--- a/src/openvpn/forward.c
+++ b/src/op= envpn/forward.c
@@ -483,16 +483,27 @@
stat= ic void
check_inactivity_timeout(struct context *c)=
{
- if (d= co_enabled(&c->options) && dco_get_peer_stats(c) =3D=3D 0)
+ if (dco_enabled(&= amp;c->options))
{
- int64_t tot_bytes =3D c->c2.tun_read_bytes = + c->c2.tun_write_bytes;
- int64_t new_bytes =3D tot_bytes - c->c2.inactivity_bytes;<= /span>
-
- if (new_bytes > c->options.in= activity_minimum_bytes)
+ const int stats_request =3D dco_get_peer_stats(c);
+ if (stats_request =3D=3D= 0)

{
- c->c2.inactivity_bytes =3D tot_bytes;
- event_timeout_reset(&am= p;c->c2.inactivity_interval);

+ int64_t tot_bytes =3D c->c2.tun_read_bytes + c-= >c2.tun_write_bytes;
+ int64_t new_bytes =3D tot_bytes - c->c2.inactivity_bytes= ;

+= if (new_bytes > c->options.inactivity_minimum_bytes)
+ {
= + c->c2.inact= ivity_bytes =3D tot_bytes;
+ event_timeout_reset(&c->c2.inactivity_interva= l);
+
+ return;

<= span style=3D"color: hsl(120, 100%, 40%);">+ }
+ }
+ else if (stats_request < 0)+ {
+ msg(M_WARN, "Error re= questing peer %d DCO stats (%s). Restarting the session",
+ c->c2.tls_mul= ti->dco_peer_id, strerror(-stats_request));
+ register_signal(c->sig, SIGUSR1, = "dco peer stats error");
return;
}
}
diff --git a= /src/openvpn/manage.c b/src/openvpn/manage.c
index e79a118.= .be2da4a 100644
--- a/src/openvpn/manage.c
= +++ b/src/openvpn/manage.c
@@ -4138,10 +4138,21 @@ counter_type dco_read_bytes =3D 0;
= counter_type dco_write_bytes =3D 0;

- if (dco_enabled(&c->option= s) && (dco_get_peer_stats(c) =3D=3D 0))
+ if (dco_enabled(&c->options) &am= p;& c->c2.tls_multi->peer_id !=3D -1)
{<= /span>
- dco_read_b= ytes =3D c->c2.dco_read_bytes;
- dco_write_bytes =3D c->c2.dco_write_bytes;
+ const int sta= ts_request =3D dco_get_peer_stats(c);
+ if (stats_request =3D=3D 0)
+ {
+ dco_read_bytes =3D c->= c2.dco_read_bytes;
+ = dco_write_bytes =3D c->c2.dco_write_bytes;
+ }

+ else if (stats_request < = 0)
+ {
+ msg(D_M= ANAGEMENT, "MANAGEMENT: Error requesting peer %d DCO stats (%s). Resta= rting the session",
+ c->c2.tls_multi->dco_peer_id, strerror(-stat= s_request));
+ = register_signal(c->sig, SIGUSR1, "dco peer stats error&quo= t;);
+ = return;
+ = }
}

if= (!(man->persist.callback.flags & MCF_SERVER))
diff = --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index 45b= 3cfa..20724a0 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c

@@ -549,7 +549,13 @@ {
if (dco_enabled(&m->top.options))

{
- = dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m);
+ const int stats_r= equest =3D dco_get_peer_stats_multi(&m->top.c1.tuntap->dco, m);
+ if (stats_req= uest < 0)
+ = {
+ msg(D= _DCO, "Error requesting peer %d DCO stats (%s)",
+ c->c2.tls_multi-&= gt;dco_peer_id, strerror(-stats_request));
+ return;
+ }
}

setenv_counter(c->c2.es, "bytes_received",= c->c2.link_read_bytes + c->c2.dco_read_bytes);
@@ -8= 55,7 +861,14 @@

if (dco_enabled(= &m->top.options))
{
- dco_get_peer_stats_multi(&m= ->top.c1.tuntap->dco, m);
+ const int stats_request =3D dco_get_peer_stats_mult= i(&m->top.c1.tuntap->dco, m);
+ if (stats_request =3D=3D -ENOENT)+ {
+ msg(M_WARN, "E= rror requesting peer DCO stats (%s)",

+ strerror(-stats_request));
+ register_= signal(m->top.sig, SIGUSR1, "dco peer stats error");+ return;
+ }
<= span> }


if (version =3D= =3D 1)
diff --git a/src/openvpn/sig.c b/src/openvpn/sig.c
index 8323f0d..3654033 100644
--- a/src/open= vpn/sig.c
+++ b/src/openvpn/sig.c
@@ -489,7= +489,14 @@

if (dco_enabled(&c-&= gt;options))
{
- dco_get_peer_stats(c);
+ const int stats_request =3D dco_get_peer_s= tats(c);
+ if = (stats_request < 0)
+ = msg(M_WARN, "Error requesting peer %d DCO stats (%s). Restarting = the session",
+ = c->c2.tls_multi->dco_peer_id, strerror(-stats_request)= );
+ regis= ter_signal(c->sig, SIGUSR1, "dco peer stats error");+ return;+ }
= }

status_printf(so, "OpenVPN = STATISTICS");

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib118426c5a69256894040c69856= a4003d9f4637c
Gerrit-Change-Number: 831
Gerrit-PatchSet: 1
Gerrit-Owner: ralf_lici <ralf@...2726...>= ;
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
--aosOOzHyI0k=--