From: "cron2 (Code Review)" Date: Mon, 11 Nov 2024 08:06:39 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <5e9363cdd2c73782962a006f6aa49f2422cd178c-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="+1UPJnaH9L0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Move should_trigger_renegotiation into its own function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --+1UPJnaH9L0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#2) to the change originally created by= plaisthos. ( http://gerrit.openvpn.net/c/openvpn/+/794?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: Move should_trigger_renegotiation into its own function ...................................................................... Move should_trigger_renegotiation into its own function The if statement has become quite large and unreadable. Reformat it and move it to a separate function. Change-Id: I210fa255921e7115bd66ba5f3e431562552e3335 Signed-off-by: Arne Schwabe Acked-by: Gert Doering Message-Id: <20241111074355.17918-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg29= 740.html Signed-off-by: Gert Doering --- M src/openvpn/ssl.c 1 file changed, 35 insertions(+), 7 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/94/794/2 diff --git a/src/openvpn/ssl.c b/src/openvpn/ssl.c index 93e31f1..d44185e 100644 --- a/src/openvpn/ssl.c +++ b/src/openvpn/ssl.c @@ -2962,8 +2962,42 @@ return true; } +/** + * Determines if a renegotiation should be triggerred based on the various + * factors that can trigger one + */ +static bool +should_trigger_renegotiation(const struct tls_session *session, const stru= ct key_state *ks) +{ + /* Time limit */ + if (session->opt->renegotiate_seconds + && now >=3D ks->established + session->opt->renegotiate_seconds) + { + return true; + } + /* Byte limit */ + if (session->opt->renegotiate_bytes > 0 + && ks->n_bytes >=3D session->opt->renegotiate_bytes) + { + return true; + } + /* Packet limit */ + if (session->opt->renegotiate_packets + && ks->n_packets >=3D session->opt->renegotiate_packets) + { + return true; + } + + /* Packet id approach the limit of the packet id */ + if (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send)) + { + return true; + } + + return false; +} /* * This is the primary routine for processing TLS stuff inside the * the main event loop. When this routine exits @@ -2991,13 +3025,7 @@ /* Should we trigger a soft reset? -- new key, keeps old key for a whi= le */ if (ks->state >=3D S_GENERATED_KEYS - && ((session->opt->renegotiate_seconds - && now >=3D ks->established + session->opt->renegotiate_secon= ds) - || (session->opt->renegotiate_bytes > 0 - && ks->n_bytes >=3D session->opt->renegotiate_bytes) - || (session->opt->renegotiate_packets - && ks->n_packets >=3D session->opt->renegotiate_packets) - || (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.= send)))) + && should_trigger_renegotiation(session, ks)) { msg(D_TLS_DEBUG_LOW, "TLS: soft reset sec=3D%d/%d bytes=3D" counte= r_format "/%d pkts=3D" counter_format "/%d", -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/794?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: I210fa255921e7115bd66ba5f3e431562552e3335 Gerrit-Change-Number: 794 Gerrit-PatchSet: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: newpatchset --+1UPJnaH9L0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 uploaded patch set #2 to the change originally cr= eated by plaisthos.

View Change

The following approvals got outdated= and were removed: Code-Review+2 by cron2

Move should_trigger_renegotiation into its own funct=
ion

The if statement has become quite large and unreadable. Reformat= it
and move it to a separate function.

Change-Id: I210fa255921e7= 115bd66ba5f3e431562552e3335
Signed-off-by: Arne Schwabe <arne@...1830...= ...>
Acked-by: Gert Doering <gert@...1296...>
Message-Id: &l= t;20241111074355.17918-1-gert@...1296...>
URL: https://www.mail-archi= ve.com/openvpn-devel@lists.sourceforge.net/msg29740.html
Signed-off-by: = Gert Doering <gert@...1296...>
---
M src/openvpn/ssl.c
1 fil= e changed, 35 insertions(+), 7 deletions(-)

git pull ssh://gerrit=
.openvpn.net:29418/openvpn refs/changes/94/794/2
diff --git a/src/o=
penvpn/ssl.c b/src/openvpn/ssl.c
index 93e31f1..d44185e 100= 644
--- a/src/openvpn/ssl.c
+++ b/src/openv= pn/ssl.c
@@ -2962,8 +2962,42 @@
return= true;
}

+/**
+ * Determines if a renegotiation should be triggerred based on the = various
+ * factors t= hat can trigger one
+= */
+static bool
+should_trigger_renegotia= tion(const struct tls_session *session, const struct key_state *ks)<= br>+{
+ /* Time limit */
+ if (session->opt->renegotiate_seco= nds
+ &&am= p; now >=3D ks->established + session->opt->renegotiate_seconds= )
+ {
+ return true;

<= span style=3D"color: hsl(120, 100%, 40%);">+ }
<= br>+ /* Byte limit */=
+ if (session->opt-&g= t;renegotiate_bytes > 0
+ && ks->n_bytes >=3D session->opt->renego= tiate_bytes)
+ {
+ return true;<= /span>
+ }

+ /* Packet li= mit */
+ if (sessi= on->opt->renegotiate_packets
+ && ks->n_packets >=3D session->opt-= >renegotiate_packets)
+ {
+ r= eturn true;
+ }
+
+ /* Packet id approach the limit of th= e packet id */
+ i= f (packet_id_close_to_wrapping(&ks->crypto_options.packet_id.send))<= /span>
+ {
+ return true;

+ }

+
+ return false;
+}
/*
* This is the primary routin= e for processing TLS stuff inside the
* the main event lo= op. When this routine exits
@@ -2991,13 +3025,7 @@<= br>
/* Should we trigger a soft reset? -- new k= ey, keeps old key for a while */
if (ks->state >= =3D S_GENERATED_KEYS
- = && ((session->opt->renegotiate_seconds
- && now >=3D k= s->established + session->opt->renegotiate_seconds)

- || (session->opt->= renegotiate_bytes > 0
- = || (session->opt->renegotiate_packets
- && ks->n_packets &g= t;=3D session->opt->renegotiate_packets)
- || (packet_id_close_to_wrapping(&k= s->crypto_options.packet_id.send))))
+ && should_trigger_renegotiation(session= , ks))
{
msg(D_TLS_DEBUG_LOW,= "TLS: soft reset sec=3D%d/%d bytes=3D" counter_format
= "/%d pkts=3D" counter_format "/%d",<= /span>

To view, visit change 794. To unsubscribe, o= r for help writing mail filters, visit settings.

=
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I210fa255921e7115bd66ba5f3e4= 31562552e3335
Gerrit-Change-Number: 794
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--+1UPJnaH9L0=--