]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Multi-socket: local_list clean-up
authorGianmarco De Gregori <gianmarco@mandelbit.com>
Wed, 18 Jun 2025 14:00:09 +0000 (16:00 +0200)
committerGert Doering <gert@greenie.muc.de>
Wed, 18 Jun 2025 14:07:08 +0000 (16:07 +0200)
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: OpenVPN/openvpn#682

Change-Id: I32effed9e273fbe8986d1f4e8da4a4d0ac216463
Signed-off-by: Gianmarco De Gregori <gianmarco@mandelbit.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20250618140016.2766-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg31927.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpn/options.c
src/openvpn/options.h

index d758a674a19915272aa17438ead92a3e4414d745..3cf8c2a4e57f740894f509e258795d036534967f 100644 (file)
@@ -2067,12 +2067,20 @@ alloc_local_entry(struct connection_entry *ce, const int msglevel,
     struct local_list *l = alloc_local_list_if_undef(ce, gc);
     struct local_entry *e;
 
-    if (l->len >= CONNECTION_LIST_SIZE)
+    if (l->len >= l->capacity)
     {
-        msg(msglevel, "Maximum number of 'local' options (%d) exceeded",
-            CONNECTION_LIST_SIZE);
+        const int new_cap = l->capacity + 1;
+        const size_t elem_size = sizeof(*l->array);
 
-        return NULL;
+        struct local_entry **new_array = gc_realloc(l->array, new_cap * elem_size, gc);
+        if (!new_array)
+        {
+            msg(msglevel, "Unable to process more local options: out of memory. Number of entries = %d", l->len);
+            return NULL;
+        }
+
+        l->array = new_array;
+        l->capacity = new_cap;
     }
 
     ALLOC_OBJ_CLEAR_GC(e, struct local_entry, gc);
index b28ad582690f7399dbd1a67b1a7d7da2450957ba..46ec32b552875697dfb9b74f4904fe8ea5525328 100644 (file)
@@ -188,8 +188,9 @@ struct remote_entry
 
 struct local_list
 {
+    int capacity;
     int len;
-    struct local_entry *array[CONNECTION_LIST_SIZE];
+    struct local_entry **array;
 };
 
 struct connection_list