[Openvpn-devel,v1] multi: don't let stale-routes-check delete permanent routes

Message ID 20260731202242.25159-1-gert@greenie.muc.de
State New
Headers
Series [Openvpn-devel,v1] multi: don't let stale-routes-check delete permanent routes |

Commit Message

Gert Doering July 31, 2026, 8:22 p.m. UTC
  From: Antonio Quartulli <antonio@mandelbit.com>

When --stale-routes-check is enabled the periodic check removed every
aged entry from the virtual address routing table, including the
permanent routes installed from --iroute (e.g. via --client-config-dir)
and the client's pushed ifconfig address. Once those entries were gone,
traffic towards the iroute networks was no longer forwarded and the
affected client suffered an outage until it reconnected.

Routes learned from configuration (iroutes and pushed ifconfig
addresses) and genuinely dynamic routes (TAP source addresses learned
from the data channel) were both added with flags == 0, so
check_stale_routes() could not tell them apart and aged out all of
them. Their last_reference is only refreshed when they are hit as a
packet destination, which never happens for an iroute network (CIDR
lookups create a separate cached child route instead) nor for an idle
client's pushed address, so both were eventually deleted.

Mark the config-derived routes with a new MULTI_ROUTE_PERMANENT flag in
the two learn helpers that install them, and skip permanent routes in
check_stale_routes(). Dynamically learned routes keep flags == 0
and are still aged out, preserving the documented purpose of the
option. Cleanup on disconnect is unaffected: a halted instance makes
multi_route_defined() return false, so the reaper still removes the
permanent routes when the client goes away.

Change-Id: I3f9834cc13c49b9249653d7d8637383f50c2fb87
Github: closes OpenVPN/openvpn#1063
Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1729
---

This change was reviewed on Gerrit and approved by at least one
developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1729
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <arne-openvpn@rfc2549.org>
  

Comments

Gert Doering Aug. 26, 2026, 9:50 a.m. UTC | #1
We had some discussions on "which routes to tag, which routes to default,
and which tags to use for what" but in the end that's a matter of taste,
not functionality, so Arne gave up and +2'ed this "because it works".

This is considered a bugfix because the current behaviour just makes
--stale-routes-check break non-dynamic routes, thus, the feature can not
be used.

Your patch has been applied to the master and release/2.7 branch (bugfix).

Arguably the bug is in all older releases as well (from the looks it's 
"from day one" with p2mp server and --iroute support), but it's not a
critical security bug, and affects an option not many people use - so
upgrade your server to 2.7+ instead if this hits you :-)

commit 01c8c4c624a7a1405c9afba8ad8d296dee595ee5 (master)
commit a2070e0b170ec8b953bf48236a5e8cb65a5d0921 (release/2.7)
Author: Antonio Quartulli
Date:   Fri Jul 31 22:22:36 2026 +0200

     multi: don't let stale-routes-check delete permanent routes

     Signed-off-by: Antonio Quartulli <antonio@mandelbit.com>
     Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1729
     Message-Id: <20260731202242.25159-1-gert@greenie.muc.de>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg38102.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering
  

Patch

diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-options.rst
index eb8e273..c9d29f6 100644
--- a/doc/man-sections/server-options.rst
+++ b/doc/man-sections/server-options.rst
@@ -671,6 +671,11 @@ 
 
   If ``t`` is not present it defaults to ``n``.
 
+  Only dynamically learned routes are subject to this check. Routes added from
+  configuration, such as ``--iroute`` entries and a client's pushed ifconfig
+  address, are never removed by it; they are dropped only when the client
+  disconnects.
+
   This option helps to keep the dynamic routing table small. See also
   ``--max-routes-per-client``
 
diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c
index a957fdf..b08ff08 100644
--- a/src/openvpn/multi.c
+++ b/src/openvpn/multi.c
@@ -1191,7 +1191,7 @@ 
         addr.netbits = (uint8_t)netbits;
     }
 
-    struct multi_instance *owner = multi_learn_addr(m, mi, &addr, 0);
+    struct multi_instance *owner = multi_learn_addr(m, mi, &addr, MULTI_ROUTE_PERMANENT);
 #ifdef ENABLE_MANAGEMENT
     if (management && owner)
     {
@@ -1236,7 +1236,7 @@ 
         mroute_addr_mask_host_bits(&addr);
     }
 
-    struct multi_instance *owner = multi_learn_addr(m, mi, &addr, 0);
+    struct multi_instance *owner = multi_learn_addr(m, mi, &addr, MULTI_ROUTE_PERMANENT);
 #ifdef ENABLE_MANAGEMENT
     if (management && owner)
     {
@@ -1360,7 +1360,7 @@ 
     while ((he = hash_iterator_next(&hi)) != NULL)
     {
         struct multi_route *r = (struct multi_route *)he->value;
-        if (multi_route_defined(m, r)
+        if (multi_route_defined(m, r) && !(r->flags & MULTI_ROUTE_PERMANENT)
             && difftime(now, r->last_reference) >= m->top.options.stale_routes_ageing_time)
         {
             dmsg(D_MULTI_DEBUG, "MULTI: Deleting stale route for address '%s'",
diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index 3ed08d4..22cfeee 100644
--- a/src/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -237,8 +237,9 @@ 
     struct mroute_addr addr;
     struct multi_instance *instance;
 
-#define MULTI_ROUTE_CACHE   (1 << 0)
-#define MULTI_ROUTE_AGEABLE (1 << 1)
+#define MULTI_ROUTE_CACHE     (1 << 0)
+#define MULTI_ROUTE_AGEABLE   (1 << 1)
+#define MULTI_ROUTE_PERMANENT (1 << 2) /* config-derived (iroute / pushed ifconfig); never stale-aged */
     unsigned int flags;
 
     unsigned int cache_generation;