From: "flichtenheld (Code Review)" Date: Thu, 10 Jul 2025 09:39:47 +0000 References: Reply-To: frank@...2641..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <4286a2d91285649c60e5a89156caff3c371d68c8-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="AugD/lVwLqE="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: reliable: Move gc_arena inside reliable_print_ids List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --AugD/lVwLqE= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1083?usp=3Demail to review the following change. Change subject: reliable: Move gc_arena inside reliable_print_ids ...................................................................... reliable: Move gc_arena inside reliable_print_ids There was no user that actually used it for anything else. But there were some previous users that generated a now useless gc_arena. While looking through the code, modernize the loop variable usage. Change-Id: I8cefa9a406fe90bb3cbe481304782c639691a3a0 Signed-off-by: Frank Lichtenheld --- M src/openvpn/reliable.c 1 file changed, 25 insertions(+), 56 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/83/1083/1 diff --git a/src/openvpn/reliable.c b/src/openvpn/reliable.c index 424d194..6477c45 100644 --- a/src/openvpn/reliable.c +++ b/src/openvpn/reliable.c @@ -446,13 +446,13 @@ #ifdef ENABLE_DEBUG /* print the current sequence of active packet IDs */ static const char * -reliable_print_ids(const struct reliable *rel, struct gc_arena *gc) +reliable_print_ids(const struct reliable *rel) { - struct buffer out =3D alloc_buf_gc(256, gc); - int i; + struct gc_arena gc =3D gc_new(); + struct buffer out =3D alloc_buf_gc(256, &gc); buf_printf(&out, "[" packet_id_format "]", (packet_id_print_type)rel->= packet_id); - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active) @@ -460,6 +460,7 @@ buf_printf(&out, " " packet_id_format, (packet_id_print_type)e= ->packet_id); } } + gc_free(&gc); return BSTR(&out); } #endif /* ENABLE_DEBUG */ @@ -468,9 +469,7 @@ bool reliable_can_get(const struct reliable *rel) { - struct gc_arena gc =3D gc_new(); - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (!e->active) @@ -478,8 +477,7 @@ return true; } } - dmsg(D_REL_LOW, "ACK no free receive buffer available: %s", reliable_p= rint_ids(rel, &gc)); - gc_free(&gc); + dmsg(D_REL_LOW, "ACK no free receive buffer available: %s", reliable_p= rint_ids(rel)); return false; } @@ -487,13 +485,11 @@ bool reliable_not_replay(const struct reliable *rel, packet_id_type id) { - struct gc_arena gc =3D gc_new(); - int i; if (reliable_pid_min(id, rel->packet_id)) { goto bad; } - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active && e->packet_id =3D=3D id) @@ -501,12 +497,10 @@ goto bad; } } - gc_free(&gc); return true; bad: - dmsg(D_REL_DEBUG, "ACK " packet_id_format " is a replay: %s", (packet_= id_print_type)id, reliable_print_ids(rel, &gc)); - gc_free(&gc); + dmsg(D_REL_DEBUG, "ACK " packet_id_format " is a replay: %s", (packet_= id_print_type)id, reliable_print_ids(rel)); return false; } @@ -514,19 +508,15 @@ bool reliable_wont_break_sequentiality(const struct reliable *rel, packet_id_ty= pe id) { - struct gc_arena gc =3D gc_new(); - const int ret =3D reliable_pid_in_range2(id, rel->packet_id, rel->size= ); if (!ret) { dmsg(D_REL_LOW, "ACK " packet_id_format " breaks sequentiality: %s= ", - (packet_id_print_type)id, reliable_print_ids(rel, &gc)); + (packet_id_print_type)id, reliable_print_ids(rel)); } dmsg(D_REL_DEBUG, "ACK RWBS rel->size=3D%d rel->packet_id=3D%08x id=3D= %08x ret=3D%d", rel->size, rel->packet_id, id, ret); - - gc_free(&gc); return ret; } @@ -534,8 +524,7 @@ struct buffer * reliable_get_buf(struct reliable *rel) { - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (!e->active) @@ -550,7 +539,6 @@ int reliable_get_num_output_sequenced_available(struct reliable *rel) { - struct gc_arena gc =3D gc_new(); packet_id_type min_id =3D 0; bool min_id_defined =3D false; @@ -573,7 +561,6 @@ { ret -=3D subtract_pid(rel->packet_id, min_id); } - gc_free(&gc); return ret; } @@ -581,14 +568,12 @@ struct buffer * reliable_get_buf_output_sequenced(struct reliable *rel) { - struct gc_arena gc =3D gc_new(); - int i; packet_id_type min_id =3D 0; bool min_id_defined =3D false; struct buffer *ret =3D NULL; /* find minimum active packet_id */ - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active) @@ -607,9 +592,8 @@ } else { - dmsg(D_REL_LOW, "ACK output sequence broken: %s", reliable_print_i= ds(rel, &gc)); + dmsg(D_REL_LOW, "ACK output sequence broken: %s", reliable_print_i= ds(rel)); } - gc_free(&gc); return ret; } @@ -617,8 +601,7 @@ struct reliable_entry * reliable_get_entry_sequenced(struct reliable *rel) { - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (e->active && e->packet_id =3D=3D rel->packet_id) @@ -633,10 +616,8 @@ bool reliable_can_send(const struct reliable *rel) { - struct gc_arena gc =3D gc_new(); - int i; int n_active =3D 0, n_current =3D 0; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active) @@ -652,9 +633,8 @@ dmsg(D_REL_DEBUG, "ACK reliable_can_send active=3D%d current=3D%d : %s= ", n_active, n_current, - reliable_print_ids(rel, &gc)); + reliable_print_ids(rel)); - gc_free(&gc); return n_current > 0 && !rel->hold; } @@ -662,11 +642,10 @@ struct buffer * reliable_send(struct reliable *rel, int *opcode) { - int i; struct reliable_entry *best =3D NULL; const time_t local_now =3D now; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; @@ -701,10 +680,9 @@ void reliable_schedule_now(struct reliable *rel) { - int i; dmsg(D_REL_DEBUG, "ACK reliable_schedule_now"); rel->hold =3D false; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (e->active) @@ -720,12 +698,10 @@ interval_t reliable_send_timeout(const struct reliable *rel) { - struct gc_arena gc =3D gc_new(); interval_t ret =3D BIG_TIMEOUT; - int i; const time_t local_now =3D now; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active) @@ -744,9 +720,8 @@ dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s", (int) ret, - reliable_print_ids(rel, &gc)); + reliable_print_ids(rel)); - gc_free(&gc); return ret; } @@ -758,8 +733,7 @@ reliable_mark_active_incoming(struct reliable *rel, struct buffer *buf, packet_id_type pid, int opcode) { - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (buf =3D=3D &e->buf) @@ -790,8 +764,7 @@ void reliable_mark_active_outgoing(struct reliable *rel, struct buffer *buf, in= t opcode) { - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (buf =3D=3D &e->buf) @@ -817,8 +790,7 @@ void reliable_mark_deleted(struct reliable *rel, struct buffer *buf) { - int i; - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { struct reliable_entry *e =3D &rel->array[i]; if (buf =3D=3D &e->buf) @@ -836,10 +808,8 @@ void reliable_ack_debug_print(const struct reliable_ack *ack, char *desc) { - int i; - printf("********* struct reliable_ack %s\n", desc); - for (i =3D 0; i < ack->len; ++i) + for (int i =3D 0; i < ack->len; ++i) { printf(" %d: " packet_id_format "\n", i, (packet_id_print_type) a= ck->packet_id[i]); } @@ -848,14 +818,13 @@ void reliable_debug_print(const struct reliable *rel, char *desc) { - int i; update_time(); printf("********* struct reliable %s\n", desc); printf(" initial_timeout=3D%d\n", (int)rel->initial_timeout); printf(" packet_id=3D" packet_id_format "\n", rel->packet_id); printf(" now=3D%" PRIi64 "\n", (int64_t)now); - for (i =3D 0; i < rel->size; ++i) + for (int i =3D 0; i < rel->size; ++i) { const struct reliable_entry *e =3D &rel->array[i]; if (e->active) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1083?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: I8cefa9a406fe90bb3cbe481304782c639691a3a0 Gerrit-Change-Number: 1083 Gerrit-PatchSet: 1 Gerrit-Owner: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-MessageType: newchange --AugD/lVwLqE= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: plaisthos.

flichtenheld would like plaisthos to review this change.

V= iew Change

reliable: Move gc_arena inside reliable_print_ids

The= re was no user that actually used it for
anything else. But there were s= ome previous
users that generated a now useless gc_arena.

While l= ooking through the code, modernize
the loop variable usage.

Chang= e-Id: I8cefa9a406fe90bb3cbe481304782c639691a3a0
Signed-off-by: Frank Lic= htenheld <frank@...2641...>
---
M src/openvpn/reliable.c
1 f= ile changed, 25 insertions(+), 56 deletions(-)

git pull ssh://ger=
rit.openvpn.net:29418/openvpn refs/changes/83/1083/1
diff --git a/s=
rc/openvpn/reliable.c b/src/openvpn/reliable.c
index 424d19= 4..6477c45 100644
--- a/src/openvpn/reliable.c
+++ b/src/openvpn/reliable.c
@@ -446,13 +446,13 @@
#ifdef ENABLE_DEBUG
/* print the current sequ= ence of active packet IDs */
static const char *-reliable_print_ids(const struct= reliable *rel, struct gc_arena *gc)
+reliable_print_ids(const struct reliable *rel)
<= span> {

- struct buf= fer out =3D alloc_buf_gc(256, gc);
- int i;
+ struct gc_arena gc =3D gc_new();
+ struct buffer out =3D alloc_buf_gc(256, &gc);<= /span>

buf_printf(&out, "[" p= acket_id_format "]", (packet_id_print_type)rel->packet_id);

- for (i =3D 0; i <= rel->size; ++i)
+= for (int i =3D 0; i < rel->size; ++i)
{
const struct reliable_entry *e =3D &rel->array[= i];
if (e->active)
@@ -460,6 +4= 60,7 @@
buf_printf(&out, " " pac= ket_id_format, (packet_id_print_type)e->packet_id);
= }
}
+ gc_free(&gc);
return BSTR(&out);=
}
#endif /* ENABLE_DEBUG */
@@ -468,9 +469,7 @@

bool
reliable_can= _get(const struct reliable *rel)
{
- struct gc_arena gc =3D gc_new();=
- int i;
- for (i =3D 0; i < rel->size; = ++i)
+ for (int i = =3D 0; i < rel->size; ++i)
{
= const struct reliable_entry *e =3D &rel->array[i];
<= span> if (!e->active)
@@ -478,8 +477,7 @@=
return true;
}
}
- dmsg(D_= REL_LOW, "ACK no free receive buffer available: %s", reliable_pri= nt_ids(rel, &gc));
= - gc_free(&gc);
- struct gc_arena gc =3D gc_new();
- int i;
if (reliabl= e_pid_min(id, rel->packet_id))
{
= goto bad;
}
- for (i =3D 0; i < rel->size; ++i)
+ for (int i =3D 0; i < rel-= >size; ++i)
{
const struct= reliable_entry *e =3D &rel->array[i];
if (= e->active && e->packet_id =3D=3D id)
@@ -501,= 12 +497,10 @@
goto bad;
= }
}
- gc_free(&gc);
return true;

bad:
- dmsg(D_REL_DEBUG, "ACK " packet_id_format " is a re= play: %s", (packet_id_print_type)id, reliable_print_ids(rel, &gc))= ;
- gc_free(&gc)= ;
+ dmsg(D_REL_DEB= UG, "ACK " packet_id_format " is a replay: %s", (packet= _id_print_type)id, reliable_print_ids(rel));
return fa= lse;
}

@@ -514,19 +508,1= 5 @@
bool
reliable_wont_break_sequentiali= ty(const struct reliable *rel, packet_id_type id)
{=
- struct gc_arena gc =3D g= c_new();
-
const int ret =3D reliable_pid_in_range2(id, rel->packet_id, re= l->size);

if (!ret)
{
dmsg(D_REL_LOW, "ACK " packet_= id_format " breaks sequentiality: %s",
- (packet_id_print_type)id, reliable_= print_ids(rel, &gc));
+ (packet_id_print_type)id, reliable_print_ids(rel));
}

dmsg(D_REL_DEBUG,= "ACK RWBS rel->size=3D%d rel->packet_id=3D%08x id=3D%08x ret=3D= %d", rel->size, rel->packet_id, id, ret);
-
- gc_free(&gc);
return ret; }

@@ -534,8 +524,7 @@
<= span> struct buffer *

reliable_get_buf(struct reliable *re= l)
{
-= int i;
- for (i = =3D 0; i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)
{
struct reliable_entry *e =3D &rel->= ;array[i];
if (!e->active)
@@ -= 550,7 +539,6 @@
int
reliable_get_num_outp= ut_sequenced_available(struct reliable *rel)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct gc_arena gc =3D gc_new= ();
packet_id_type min_id =3D 0;
= bool min_id_defined =3D false;

@@ -573,7 = +561,6 @@
{
ret -=3D subtract= _pid(rel->packet_id, min_id);
}
- gc_free(&gc);
= return ret;
}

@@ -581,= 14 +568,12 @@
struct buffer *
reliable_ge= t_buf_output_sequenced(struct reliable *rel)
{
<= span style=3D"color: hsl(0, 100%, 40%);">- struct gc_arena gc =3D gc_new= ();
- int i;<= br> packet_id_type min_id =3D 0;
bool min_id= _defined =3D false;
struct buffer *ret =3D NULL;

/* find minimum active packet_id */
- for (i =3D 0; i < re= l->size; ++i)
+ = for (int i =3D 0; i < rel->size; ++i)
{<= br> const struct reliable_entry *e =3D &rel->array[i];=
if (e->active)
@@ -607,9 +592,= 8 @@
}
else
= {
- dmsg(D_REL_L= OW, "ACK output sequence broken: %s", reliable_print_ids(rel, &am= p;gc));
+ dmsg= (D_REL_LOW, "ACK output sequence broken: %s", reliable_print_ids(= rel));
}
- gc_free(&gc);
return ret;
}


@@ -617,8 +601,7 @@
struct reliable_entry *

reliable_get_entry_sequenced(st= ruct reliable *rel)
{
- int i;
- for (i =3D 0; i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++= i)
{
struct reliable_entry *e= =3D &rel->array[i];
if (e->active &= & e->packet_id =3D=3D rel->packet_id)
@@ -633,10 = +616,8 @@
bool
reliable_can_send(const st= ruct reliable *rel)
{
- struct gc_arena gc =3D gc_new();
- int i;
int n_activ= e =3D 0, n_current =3D 0;
- for (i =3D 0; i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)=
{
const struct reliable_entr= y *e =3D &rel->array[i];
if (e->active)<= /span>
@@ -652,9 +633,8 @@
dmsg(D_REL_DEBUG, = "ACK reliable_can_send active=3D%d current=3D%d : %s",
= n_active,
n_current,
- reliable_print_ids(rel, &= amp;gc));

+ r= eliable_print_ids(rel));

- gc_free(&gc);
return n_cu= rrent > 0 && !rel->hold;
}
=
@@ -662,11 +642,10 @@
struct buffer *

reliable_send(struct reliable *rel, int *opcode)
{
- int i;
struct reliable_entry *best =3D NULL;
= const time_t local_now =3D now;

- for (i =3D 0; i < rel->size; ++i)

+ for (int i =3D 0; = i < rel->size; ++i)
{
s= truct reliable_entry *e =3D &rel->array[i];
=
@@ -701,10 +680,9 @@
void
relia= ble_schedule_now(struct reliable *rel)
{
- int i;
dmsg(D_= REL_DEBUG, "ACK reliable_schedule_now");
rel= ->hold =3D false;
- = for (i =3D 0; i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)
{
struct reliable_entry *e =3D &a= mp;rel->array[i];
if (e->active)
<= span>@@ -720,12 +698,10 @@

interval_t
rel= iable_send_timeout(const struct reliable *rel)
{- struct gc_arena gc =3D gc_n= ew();
interval_t ret =3D BIG_TIMEOUT;
- int i;
const = time_t local_now =3D now;

- for (i =3D 0; i < rel->size; ++i)+ for (int i =3D 0; i < = rel->size; ++i)
{
const st= ruct reliable_entry *e =3D &rel->array[i];
= if (e->active)
@@ -744,9 +720,8 @@

dmsg(D_REL_DEBUG, "ACK reliable_send_timeout %d %s&q= uot;,
(int) ret,
- reliable_print_ids(rel, &gc));
= + reliable_print_ids(re= l));

= - gc_free(&gc);
return ret;
}<= /span>

@@ -758,8 +733,7 @@
reli= able_mark_active_incoming(struct reliable *rel, struct buffer *buf,<= br> packet_id_type pid, int opcode)

{
- in= t i;
- for (i =3D 0;= i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)
= {
struct reliable_entry *e =3D &rel->array= [i];
if (buf =3D=3D &e->buf)
@@ -790,8 +764,7 @@
void
reliable_mark_= active_outgoing(struct reliable *rel, struct buffer *buf, int opcode)
{
- int = i;
- for (i =3D 0; i= < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)
{=
struct reliable_entry *e =3D &rel->array[i= ];
if (buf =3D=3D &e->buf)
= @@ -817,8 +790,7 @@
void
reliable_mark_de= leted(struct reliable *rel, struct buffer *buf)
{- int i;
- for (i =3D 0; i < rel->size; ++= i)
+ for (int i = =3D 0; i < rel->size; ++i)
{
= struct reliable_entry *e =3D &rel->array[i];
= if (buf =3D=3D &e->buf)
@@ -836,10 +808,8 @@=
void
reliable_ack_debug_print(const stru= ct reliable_ack *ack, char *desc)
{
- int i;
-
printf("********* struct re= liable_ack %s\n", desc);
- for (i =3D 0; i < ack->len; ++i)
+ for (int i =3D 0; i < ack->len; ++= i)
{
printf(" %d: "= ; packet_id_format "\n", i, (packet_id_print_type) ack->packet= _id[i]);
}
@@ -848,14 +818,13 @@
void
reliable_debug_print(const struct reliabl= e *rel, char *desc)
{
- int i;
update_time();
<= span>

printf("********* struct reliable %s\n&quo= t;, desc);
printf(" initial_timeout=3D%d\n"= , (int)rel->initial_timeout);
printf(" packet= _id=3D" packet_id_format "\n", rel->packet_id); printf(" now=3D%" PRIi64 "\n", (int64_t)no= w);
- for (i =3D 0; = i < rel->size; ++i)
+ for (int i =3D 0; i < rel->size; ++i)
= {
const struct reliable_entry *e =3D &rel->= array[i];
if (e->active)

To view, visit change 1083. To unsubscribe, or for help writing m= ail filters, visit settings<= /a>.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I8cefa9a406fe90bb3cbe4813047= 82c639691a3a0
Gerrit-Change-Number: 1083
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <frank@...2723...= .>
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-MessageType: newchange
--AugD/lVwLqE=--