From: "its_Giaan (Code Review)" Date: Fri, 6 Jun 2025 08:21:39 +0000 References: Reply-To: gianmarco@...2726..., 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="v+Ytc8PjCKI="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Multi-socket: local_list clean-up List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --v+Ytc8PjCKI= 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/+/1039?usp=3Demail to review the following change. Change subject: Multi-socket: local_list clean-up ...................................................................... Multi-socket: local_list clean-up Optimize the current local_list implementation by replacing the static array with a resizable one, as the static allocation serves no real purpose, particularly on the client side. Github: #682 Change-Id: I32effed9e273fbe8986d1f4e8da4a4d0ac216463 Signed-off-by: Gianmarco De Gregori --- M src/openvpn/options.c M src/openvpn/options.h 2 files changed, 14 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1039/1 diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 6ea01d4..70337b1 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -2212,12 +2212,20 @@ struct local_list *l =3D alloc_local_list_if_undef(ce, gc); struct local_entry *e; - if (l->len >=3D CONNECTION_LIST_SIZE) + if (l->len >=3D l->capacity) { - msg(msglevel, "Maximum number of 'local' options (%d) exceeded", - CONNECTION_LIST_SIZE); + const int new_cap =3D l->capacity + 1; + const size_t elem_size =3D sizeof(*l->array); - return NULL; + struct local_entry **new_array =3D gc_realloc(l->array, new_cap * = elem_size, gc); + if (!new_array) + { + msg(msglevel, "Unable to process more local options: out of me= mory. Number of entries =3D %d", l->len); + return NULL; + } + + l->array =3D new_array; + l->capacity =3D new_cap; } ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc); diff --git a/src/openvpn/options.h b/src/openvpn/options.h index b28ad58..46ec32b 100644 --- a/src/openvpn/options.h +++ b/src/openvpn/options.h @@ -188,8 +188,9 @@ struct local_list { + int capacity; int len; - struct local_entry *array[CONNECTION_LIST_SIZE]; + struct local_entry **array; }; struct connection_list -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1039?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: I32effed9e273fbe8986d1f4e8da4a4d0ac216463 Gerrit-Change-Number: 1039 Gerrit-PatchSet: 1 Gerrit-Owner: its_Giaan Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --v+Ytc8PjCKI= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

its_Giaan would like plaisthos and flichtenheld to review this change.

V= iew Change

Multi-socket: local_list clean-up

Optimize the curren= t local_list implementation
by replacing the static array with a resizab= le
one, as the static allocation serves no real
purpose, particularly= on the client side.

Github: #682

Change-Id: I32effed9e273fbe= 8986d1f4e8da4a4d0ac216463
Signed-off-by: Gianmarco De Gregori <gianma= rco@...2726...>
---
M src/openvpn/options.c
M src/openvpn/optio= ns.h
2 files changed, 14 insertions(+), 5 deletions(-)

git pul= l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/39/1039/1
dif=
f --git a/src/openvpn/options.c b/src/openvpn/options.c
ind= ex 6ea01d4..70337b1 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -2212,12 +2212,2= 0 @@
struct local_list *l =3D alloc_local_list_if_unde= f(ce, gc);
struct local_entry *e;

- if (l->len >= =3D CONNECTION_LIST_SIZE)
+ if (l->len >=3D l->capacity)
{
- msg(msglevel, &quo= t;Maximum number of 'local' options (%d) exceeded",
= - CONNECTION_LIST_SIZE= );
+ const int= new_cap =3D l->capacity + 1;
+ const size_t elem_size =3D sizeof(*l->array);

- r= eturn NULL;
+ = struct local_entry **new_array =3D gc_realloc(l->array, new_cap * elem_s= ize, gc);
+ if= (!new_array)
+ = {
+ msg(= msglevel, "Unable to process more local options: out of memory. Number= of entries =3D %d", l->len);
+ return NULL;
+ }
+
+ = l->array =3D new_array;
+ l->capacity =3D new_cap;
}<= br>
ALLOC_OBJ_CLEAR_GC(e, struct local_entry, g= c);
diff --git a/src/openvpn/options.h b/src/openvpn/option= s.h
index b28ad58..46ec32b 100644
--- a/src= /openvpn/options.h
+++ b/src/openvpn/options.h
@@ -188,8 +188,9 @@


struct local_lis= t
{
= + int capacity;
int len;
- struct local_entry *array[CONNECTION_LIST_SI= ZE];
+ struct loca= l_entry **array;
};

str= uct connection_list

To view, visit change 1039<= /a>. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I32effed9e273fbe8986d1f4e8da= 4a4d0ac216463
Gerrit-Change-Number: 1039
Gerrit-PatchSet: 1
Gerrit-Owner: its_Giaan <gianmarco@...2786...= ..>
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
--v+Ytc8PjCKI=--