From: "reynir (Code Review)" Date: Mon, 22 Apr 2024 19:08:25 +0000 References: Reply-To: reynir@...2756..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <06e6119813c956c51c500ea004756c7fe47ebda4-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="l54QpwQccEA="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Address schedule_exit() review comments List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --l54QpwQccEA= 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/+/557?usp=3Demail to review the following change. Change subject: Address schedule_exit() review comments ...................................................................... Address schedule_exit() review comments schedule_exit() now only takes the context as argument. The signal is hard coded to SIGTERM, and the interval is read directly from the context options. Furthermore, schedule_exit() now returns a bool signifying whether an exit was scheduled; false if exit is already scheduled. The call sites are updated accordingly. A notable difference is that management is only notified *once* when an exit is scheduled - we no longer notify management on redundant exit. Change-Id: I1cf589ecad82eecf167fe5cf28cda0fe4d42d42f --- M src/openvpn/forward.c M src/openvpn/forward.h M src/openvpn/push.c 3 files changed, 14 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/557/1 diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c index 70f8e9d..937fae4 100644 --- a/src/openvpn/forward.c +++ b/src/openvpn/forward.c @@ -514,22 +514,23 @@ } /* - * Schedule a signal n_seconds from now. + * Schedule a SIGTERM signal c->options.scheduled_exit_interval seconds fr= om now. */ -void -schedule_exit(struct context *c, const int n_seconds, const int signal) +bool +schedule_exit(struct context *c) { - /* don't reschedule if already scheduled; we drop the new signal, but = it - * only ever seems to be SIGTERM anyway. */ + const int n_seconds =3D c->options.scheduled_exit_interval; + /* don't reschedule if already scheduled. */ if (event_timeout_defined(&c->c2.scheduled_exit)) { - return; + return false; } tls_set_single_session(c->c2.tls_multi); update_time(); reset_coarse_timers(c); event_timeout_init(&c->c2.scheduled_exit, n_seconds, now); - c->c2.scheduled_exit_signal =3D signal; + c->c2.scheduled_exit_signal =3D SIGTERM; msg(D_SCHED_EXIT, "Delayed exit in %d seconds", n_seconds); + return true; } /* diff --git a/src/openvpn/forward.h b/src/openvpn/forward.h index 6fb5a18..422c591 100644 --- a/src/openvpn/forward.h +++ b/src/openvpn/forward.h @@ -303,7 +303,7 @@ void process_ip_header(struct context *c, unsigned int flags, struct buffe= r *buf); -void schedule_exit(struct context *c, const int n_seconds, const int signa= l); +bool schedule_exit(struct context *c); static inline struct link_socket_info * get_link_socket_info(struct context *c) diff --git a/src/openvpn/push.c b/src/openvpn/push.c index 1b406b9..db1fd2e 100644 --- a/src/openvpn/push.c +++ b/src/openvpn/push.c @@ -191,6 +191,7 @@ receive_exit_message(struct context *c) { dmsg(D_STREAM_ERRORS, "CC-EEN exit message received by peer"); + bool notify_management =3D true; /* With control channel exit notification, we want to give the session * enough time to handle retransmits and acknowledgment, so that event= ual * retries from the client to resend the exit or ACKs will not trigger @@ -204,14 +205,14 @@ * */ if (c->options.mode =3D=3D MODE_SERVER) { - schedule_exit(c, c->options.scheduled_exit_interval, SIGTERM); + notify_management =3D schedule_exit(c); } else { register_signal(c->sig, SIGUSR1, "remote-exit"); } #ifdef ENABLE_MANAGEMENT - if (management) + if (management && notify_management) { management_notify(management, "info", "remote-exit", "EXIT"); } @@ -391,7 +392,7 @@ void send_auth_failed(struct context *c, const char *client_reason) { - if (event_timeout_defined(&c->c2.scheduled_exit)) + if (!schedule_exit(c)) { msg(D_TLS_DEBUG, "exit already scheduled for context"); return; @@ -401,8 +402,6 @@ static const char auth_failed[] =3D "AUTH_FAILED"; size_t len; - schedule_exit(c, c->options.scheduled_exit_interval, SIGTERM); - len =3D (client_reason ? strlen(client_reason)+1 : 0) + sizeof(auth_fa= iled); if (len > PUSH_BUNDLE_SIZE) { @@ -492,7 +491,7 @@ void send_restart(struct context *c, const char *kill_msg) { - schedule_exit(c, c->options.scheduled_exit_interval, SIGTERM); + schedule_exit(c); send_control_channel_string(c, kill_msg ? kill_msg : "RESTART", D_PUSH= ); } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/557?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: I1cf589ecad82eecf167fe5cf28cda0fe4d42d42f Gerrit-Change-Number: 557 Gerrit-PatchSet: 1 Gerrit-Owner: reynir Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --l54QpwQccEA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

reynir would like plaisthos and flichtenheld to review = this change.

Vi= ew Change

Address schedule_exit() review comments

schedule_exit(= ) now only takes the context as argument. The signal is
hard coded to SI= GTERM, and the interval is read directly from the
context options.
Furthermore, schedule_exit() now returns a bool signifying whether an
= exit was scheduled; false if exit is already scheduled. The call sites
a= re updated accordingly. A notable difference is that management is only
= notified *once* when an exit is scheduled - we no longer notify
manageme= nt on redundant exit.

Change-Id: I1cf589ecad82eecf167fe5cf28cda0fe4d= 42d42f
---
M src/openvpn/forward.c
M src/openvpn/forward.h
M sr= c/openvpn/push.c
3 files changed, 14 insertions(+), 14 deletions(-)
<= br>
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/57/557/1=
diff --git a/src/openvpn/forward.c b/src/openvpn/forward.c<=
br>index 70f8e9d..937fae4 100644
--- a/src/openvpn/fo= rward.c
+++ b/src/openvpn/forward.c
@@ -514= ,22 +514,23 @@
}

/*
- * Schedule a signal n_se= conds from now.
+ * S= chedule a SIGTERM signal c->options.scheduled_exit_interval seconds from= now.
*/
-void
-schedule_exi= t(struct context *c, const int n_seconds, const int signal)
+bool

+schedule_exit(struct context *c)
= {
- /* don't res= chedule if already scheduled; we drop the new signal, but it
- * only ever seems to be SIGTERM= anyway. */
+ cons= t int n_seconds =3D c->options.scheduled_exit_interval;
+ /* don't reschedule if alrea= dy scheduled. */
if (event_timeout_defined(&c->= c2.scheduled_exit)) {
-= return;
+ = return false;
}
tls_set_singl= e_session(c->c2.tls_multi);
update_time(); reset_coarse_timers(c);
event_timeout_ini= t(&c->c2.scheduled_exit, n_seconds, now);
- c->c2.scheduled_exit_signal =3D signal;
+ c->c2.schedule= d_exit_signal =3D SIGTERM;
msg(D_SCHED_EXIT, "Del= ayed exit in %d seconds", n_seconds);
+ return true;
}
=
/*
diff --git a/src/openvpn/forward.h b/= src/openvpn/forward.h
index 6fb5a18..422c591 100644<= br>--- a/src/openvpn/forward.h
+++ b/src/openvpn/forw= ard.h
@@ -303,7 +303,7 @@

void process_ip_header(struct context *c, unsigned int flags, struct buff= er *buf);


-void schedule_exit(struct context *c, const int n_seconds, const int = signal);
+bool schedu= le_exit(struct context *c);

static inlin= e struct link_socket_info *
get_link_socket_info(struct co= ntext *c)
diff --git a/src/openvpn/push.c b/src/openvpn/pus= h.c
index 1b406b9..db1fd2e 100644
--- a/src= /openvpn/push.c
+++ b/src/openvpn/push.c
@@= -191,6 +191,7 @@
receive_exit_message(struct context *c)<= /span>
{
dmsg(D_STREAM_ERRORS, "CC-EEN = exit message received by peer");
+ bool notify_management =3D true;
= /* With control channel exit notification, we want to give the session
* enough time to handle retransmits and acknowledgment, = so that eventual
* retries from the client to resend = the exit or ACKs will not trigger
@@ -204,14 +205,14 @@
* */
if (c->options.mode =3D=3D = MODE_SERVER)
{
- schedule_exit(c, c->options.scheduled_exit_interva= l, SIGTERM);
+ = notify_management =3D schedule_exit(c);
}
<= span> else

{
register_sig= nal(c->sig, SIGUSR1, "remote-exit");
}
#ifdef ENABLE_MANAGEMENT
- if (management)
+ if (management && notify_management) {
management_notify(management, "= ;info", "remote-exit", "EXIT");
= }
@@ -391,7 +392,7 @@
void
send_auth_failed(struct context *c, const char *client_reason)
<= br> {
- if (ev= ent_timeout_defined(&c->c2.scheduled_exit))
+ if (!schedule_exit(c))
= {
msg(D_TLS_DEBUG, "exit already schedule= d for context");
return;
@@ -= 401,8 +402,6 @@
static const char auth_failed[] =3D &q= uot;AUTH_FAILED";
size_t len;

- schedule_exit(c, c-= >options.scheduled_exit_interval, SIGTERM);
-
len =3D (client_reason ? str= len(client_reason)+1 : 0) + sizeof(auth_failed);
if (l= en > PUSH_BUNDLE_SIZE)
{
@@ -492,7 = +491,7 @@
void
send_restart(struct contex= t *c, const char *kill_msg)
{
- schedule_exit(c, c->options.scheduled_exit_= interval, SIGTERM);
+= schedule_exit(c);
send_control_channel_string(c, k= ill_msg ? kill_msg : "RESTART", D_PUSH);
}


To view, visit change 557. To u= nsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1cf589ecad82eecf167fe5cf28c= da0fe4d42d42f
Gerrit-Change-Number: 557
Gerrit-PatchSet: 1
Gerrit-Owner: reynir <reynir@...2756...>=
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
--l54QpwQccEA=--