From: "plaisthos (Code Review)" Date: Mon, 15 Sep 2025 17:39:10 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <314262d5f3d87adc516359176d3632349b5b9e87-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="3zc/F/I3Pes="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Install host routes with onlink scope iroutes for ifconfig-push routes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --3zc/F/I3Pes= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1192?usp=3Demail to review the following change. Change subject: Install host routes with onlink scope iroutes for ifconfig-= push routes ...................................................................... Install host routes with onlink scope iroutes for ifconfig-push routes Additional IP addresses for hosts that lie outside the primary network of the configured device need to be added to the operating system to ensure that traffic for these IP addresses is also directed to the VPN. For Linux it is import that these extra routes are routes with scope link rather than static since otherwise routes via these IP addresses, like iroute, will not work. Change-Id: I83295e00d1a756dfa44050b0a4493095fb050fff Signed-off-by: Arne Schwabe --- M doc/man-sections/server-options.rst M src/openvpn/dco.c M src/openvpn/mroute.h M src/openvpn/multi.c M src/openvpn/multi.h 5 files changed, 153 insertions(+), 5 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/92/1192/1 diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-= options.rst index ccc1374..bb58330 100644 --- a/doc/man-sections/server-options.rst +++ b/doc/man-sections/server-options.rst @@ -314,6 +314,9 @@ 3. Use ``--ifconfig-pool`` allocation for dynamic IP (last choice). + When DCO is enabled, OpenVPN will install a /32 route for the local IP + address + --ifconfig-ipv6-push args for ``--client-config-dir`` per-client static IPv6 interface configuration, see ``--client-config-dir`` and ``--ifconfig-push`` for diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 70a8c0a..8280fbb 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -670,8 +670,14 @@ dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr, addr->n= etbits, c->c2.tls_multi->peer_id); #else + const struct in6_addr *gateway =3D &mi->context.c2.push_ifconfig_i= pv6_local; + if (addr->type & MR_ONLINK_ADDR) + { + gateway =3D NULL; + } + net_route_v6_add(&m->top.net_ctx, &addr->v6.addr, addr->netbits, - &mi->context.c2.push_ifconfig_ipv6_local, c->c1.t= untap->actual_name, 0, + gateway, c->c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC); #endif } @@ -682,7 +688,13 @@ c->c2.tls_multi->peer_id); #else in_addr_t dest =3D htonl(addr->v4.addr); - net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, &mi->conte= xt.c2.push_ifconfig_local, + const in_addr_t *gateway =3D &mi->context.c2.push_ifconfig_local; + if (addr->type & MR_ONLINK_ADDR) + { + gateway =3D NULL; + } + + net_route_v4_add(&m->top.net_ctx, &dest, addr->netbits, gateway, c->c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC); #endif } @@ -713,6 +725,18 @@ DCO_IROUTE_METRIC); #endif } + + /* Check if we added the local network as /32 route as it was not = in + * the normal on link scope */ + if (multi_check_push_ifconfig_extra_route(mi)) + { +#if defined(_WIN32) + dco_win_del_iroute_ipv4(&c->c1.tuntap->dco, push_ifconfig_loca= l, 32); +#else + net_route_v4_del(&m->top.net_ctx, &mi->context.c2.push_ifconfi= g_local, 32, + NULL, c->c1.tuntap->actual_name, 0, DCO_IROUT= E_METRIC); +#endif + } } if (mi->context.c2.push_ifconfig_ipv6_defined) @@ -727,6 +751,15 @@ DCO_IROUTE_METRIC); #endif } + if (multi_check_push_ifconfig_ipv6_extra_route(mi)) + { +#if defined(_WIN32) + dco_win_del_iroute_ipv6(&c->c1.tuntap->dco, &mi->context.c2.pu= sh_ifconfig_ipv6_local, 128); +#else + net_route_v6_del(&m->top.net_ctx, &mi->context.c2.push_ifconfi= g_ipv6_local, 128, + NULL, c->c1.tuntap->actual_name, 0, DCO_IROUT= E_METRIC); +#endif + } } #endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) || defined(_= WIN32) */ } diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h index 5b0c694..f4e54ca 100644 --- a/src/openvpn/mroute.h +++ b/src/openvpn/mroute.h @@ -20,6 +20,7 @@ * with this program; if not, see . */ + #ifndef MROUTE_H #define MROUTE_H @@ -74,6 +75,9 @@ /* Address type mask indicating that proto # is part of address */ #define MR_WITH_PROTO 32 +/* MRoute is an on link/scope address ather than a route */ +#define MR_ONLINK_ADDR 64 + struct mroute_addr { uint8_t len; /* length of address */ diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 6e4cc42..a9c753e 100644 --- a/src/openvpn/multi.c +++ b/src/openvpn/multi.c @@ -42,6 +42,7 @@ #include "ssl_ncp.h" #include "vlan.h" #include "auth_token.h" +#include "route.h" #include #include @@ -1240,11 +1241,26 @@ management_learn_addr(management, &mi->context.c2.mda_context, &ad= dr, primary); } #endif + if (primary && multi_check_push_ifconfig_extra_route(mi)) + { + /* "primary" is the VPN ifconfig address of the peer */ + /* if it does not fall into the network defined by ifconfig_local + * we install this as extra onscope address on the interface */ + struct gc_arena gc =3D gc_new(); + /* The IP address is not assigned to the interface of the DCO devi= ce */ + msg(D_MULTI_LOW, "MULTI: Adding /32 on-link route for route %s -> = %s", + print_in_addr_t(remote_si.addr.in4.sin_addr.s_addr, 0, &gc), + multi_instance_string(mi, false, &gc)); + + addr.netbits =3D 32; + addr.type |=3D MR_ONLINK_ADDR; + + dco_install_iroute(m, mi, &addr); + gc_free(&gc); + } + if (!primary) { - /* "primary" is the VPN ifconfig address of the peer and already - * known to DCO, so only install "extra" iroutes (primary =3D fals= e) - */ ASSERT(netbits >=3D 0); /* DCO requires populated netbits */ dco_install_iroute(m, mi, &addr); } @@ -1278,6 +1294,24 @@ management_learn_addr(management, &mi->context.c2.mda_context, &ad= dr, primary); } #endif + if (primary && multi_check_push_ifconfig_ipv6_extra_route(mi)) + { + /* "primary" is the VPN ifconfig address of the peer */ + /* if it does not fall into the network defined by ifconfig_local + * we install this as extra onscope address on the interface */ + struct gc_arena gc =3D gc_new(); + /* The IP address is not assigned to the interface of the DCO devi= ce */ + msg(D_MULTI_LOW, "MULTI: Adding /129 on-link route for " + "ifconfig-ipv6-push %s -> %s", + print_in6_addr(mi->context.options.push_ifconfig_ipv6_local, 0= , &gc), + multi_instance_string(mi, false, &gc)); + + addr.netbits =3D 128; + addr.type |=3D MR_ONLINK_ADDR; + + dco_install_iroute(m, mi, &addr); + gc_free(&gc); + } if (!primary) { /* "primary" is the VPN ifconfig address of the peer and already @@ -4309,3 +4343,57 @@ * } */ } + +/** + * Determines if the ifconfig_push_local address falls into the range of t= he local + * IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_= netmask) + * + * @return Returns true if ifconfig_push is outside that range and require= s an extra + * route to be installed. + */ +bool +multi_check_push_ifconfig_extra_route(struct multi_instance *mi) +{ + struct options *o =3D &mi->context.options; + in_addr_t local_addr, local_netmask; + + if (!o->ifconfig_local || !o->ifconfig_remote_netmask) + { + /* If we do not have a local address, we just return false as + * this check doesn't make sense. */ + return false; + } + + /* if it falls into the network defined by ifconfig_local we assume + * it is already known to DCO and only install "extra" iroutes */ + in_addr_t push_ifconfig_local =3D htonl(mi->context.c2.push_ifconfig_l= ocal); + inet_pton(AF_INET, o->ifconfig_local, &local_addr); + inet_pton(AF_INET, o->ifconfig_remote_netmask, &local_netmask); + + return (local_addr & local_netmask) !=3D (push_ifconfig_local & local_= netmask); +} + + +bool +multi_check_push_ifconfig_ipv6_extra_route(struct multi_instance *mi) +{ + struct options *o =3D &mi->context.options; + + if (!o->ifconfig_ipv6_local || !o->ifconfig_ipv6_netbits) + { + /* If we do not have a local address, we just return false as + * this check doesn't make sense. */ + return false; + } + + /* if it falls into the network defined by ifconfig_local we assume + * it is already known to DCO and only install "extra" iroutes */ + struct in6_addr ifconfig_local; + if (inet_pton(AF_INET6, o->ifconfig_ipv6_local, &ifconfig_local) !=3D = 1) + { + return false; + } + + return (!route_ipv6_match_host(&ifconfig_local, o->ifconfig_ipv6_netbi= ts, + &o->push_ifconfig_ipv6_local)); +} \ No newline at end of file diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 087c0e6..5ec3904 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -666,6 +666,26 @@ return ret; } +/** + * Determines if the ifconfig_push_local address falls into the range of t= he local + * IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_= netmask) + * + * @return Returns true if ifconfig_push is outside that range and require= s an extra + * route to be installed. + */ +bool +multi_check_push_ifconfig_extra_route(struct multi_instance *mi); + +/** + * Determines if the ifconfig_ipv6_local address falls into the range of t= he local + * IP addresses of the VPN interface (ifconfig_local with ifconfig_remote_= netmask) + * + * @return Returns true if ifconfig_push is outside that range and require= s an extra + * route to be installed. + */ +bool +multi_check_push_ifconfig_ipv6_extra_route(struct multi_instance *mi); + /* * Check for signals. */ -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1192?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: I83295e00d1a756dfa44050b0a4493095fb050fff Gerrit-Change-Number: 1192 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --3zc/F/I3Pes= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

V= iew Change

Install host routes with onlink scope iroutes for ifconfig-p=
ush routes

Additional IP addresses for hosts that lie outside the pr= imary network
of the configured device need to be added to the operating= system to
ensure that traffic for these IP addresses is also directed t= o the VPN.

For Linux it is import that these extra routes are routes= with scope link
rather than static since otherwise routes via these IP = addresses, like
iroute, will not work.

Change-Id: I83295e00d1a756= dfa44050b0a4493095fb050fff
Signed-off-by: Arne Schwabe <arne@...2639...= ..>
---
M doc/man-sections/server-options.rst
M src/openvpn/dco= .c
M src/openvpn/mroute.h
M src/openvpn/multi.c
M src/openvpn/mult= i.h
5 files changed, 153 insertions(+), 5 deletions(-)

git pul= l ssh://gerrit.openvpn.net:29418/openvpn refs/changes/92/1192/1
dif=
f --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-opt=
ions.rst
index ccc1374..bb58330 100644
--- = a/doc/man-sections/server-options.rst
+++ b/doc/man-section= s/server-options.rst
@@ -314,6 +314,9 @@
= 3. Use ``--ifconfig-pool`` allocation for dynamic IP (last
choice).

+ When DCO is enabled, OpenVPN will install a /32 route for= the local IP
+ addr= ess
+
--ifconfig-ipv6-push args
for ``--client-config-dir``= per-client static IPv6 interface
configuration, see ``-= -client-config-dir`` and ``--ifconfig-push`` for
diff --git= a/src/openvpn/dco.c b/src/openvpn/dco.c
index 70a8c0a..828= 0fbb 100644
--- a/src/openvpn/dco.c
+++ b/s= rc/openvpn/dco.c
@@ -670,8 +670,14 @@
= dco_win_add_iroute_ipv6(&c->c1.tuntap->dco, addr->v6.addr,= addr->netbits,
c->c= 2.tls_multi->peer_id);
#else
+ const struct in6_addr *gateway =3D &am= p;mi->context.c2.push_ifconfig_ipv6_local;
+ if (addr->type & MR_ONLINK_ADDR)
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ gateway =3D NULL;
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+

net_r= oute_v6_add(&m->top.net_ctx, &addr->v6.addr, addr->netbits= ,
- = &mi->context.c2.push_ifconfig_ipv6_local, c->c1.tuntap->a= ctual_name, 0,
+ = gateway, c->c1.tuntap->actual_name, 0,
= DCO_IROUTE_METRIC);
#endif=
}
@@ -682,7 +688,13 @@
c->c2.tls_multi->peer_id);<= br> #else
in_addr_t dest =3D htonl(addr->= v4.addr);
- net_= route_v4_add(&m->top.net_ctx, &dest, addr->netbits, &mi-&= gt;context.c2.push_ifconfig_local,
+ const in_addr_t *gateway =3D &mi->context.c2.= push_ifconfig_local;
= + if (addr->type & MR_ONLINK_ADDR)
+ {
+ gateway =3D NULL;
+ }
+
+= net_route_v4_add(&m->top.net_ctx, &dest, addr->netbit= s, gateway,
c->c1.tuntap->a= ctual_name, 0, DCO_IROUTE_METRIC);
#endif
= }
@@ -713,6 +725,18 @@
= DCO_IROUTE_METRIC);
#endif
= }
++ /* Check if we added= the local network as /32 route as it was not in
+ * the normal on link scope */<= br>+ if (multi_check_pus= h_ifconfig_extra_route(mi))
+ {
+#i= f defined(_WIN32)
+ = dco_win_del_iroute_ipv4(&c->c1.tuntap->dco, push_ifconf= ig_local, 32);
+#else=
+ net_rou= te_v4_del(&m->top.net_ctx, &mi->context.c2.push_ifconfig_loca= l, 32,
+ = NULL, c->c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC= );
+#endif
= + }
= }

if (mi->context.c2.push_ifconf= ig_ipv6_defined)
@@ -727,6 +751,15 @@
= DCO_IROUTE_METRIC);
#endif=
}
= + if (multi_check_push_ifconfig_ipv6_extra_route(mi))
+ {
+#if defined(_WIN32)
+ dco_win_del_iroute_ipv6(&c-&= gt;c1.tuntap->dco, &mi->context.c2.push_ifconfig_ipv6_local, 128)= ;
+#else
+ net_route_v6_del(&am= p;m->top.net_ctx, &mi->context.c2.push_ifconfig_ipv6_local, 128,<= /span>
+ = NULL, c->c1.tuntap->actual_name, 0, DCO_IROUTE_METRIC);

+#endif
+ }
}

#endif /* if defined(TARGET_LINUX) || defined(TARGET_FREEBSD) = || defined(_WIN32) */
}
diff --git a/src/o= penvpn/mroute.h b/src/openvpn/mroute.h
index 5b0c694..f4e54= ca 100644
--- a/src/openvpn/mroute.h
+++ b/= src/openvpn/mroute.h
@@ -20,6 +20,7 @@
* = with this program; if not, see <https://www.gnu.org/licenses/>.

*/

+
#ifndef MROUTE_H
#define = MROUTE_H

@@ -74,6 +75,9 @@
/* Address type mask indicating that proto # is part of address */
#define MR_WITH_PROTO 32

+/* MRoute is an on link/scope address a= ther than a route */
= +#define MR_ONLINK_ADDR 64
+
struct mroute_addr
{
uint8_t len; /* length of address */
diff --gi= t a/src/openvpn/multi.c b/src/openvpn/multi.c
index 6e4cc42= ..a9c753e 100644
--- a/src/openvpn/multi.c
= +++ b/src/openvpn/multi.c
@@ -42,6 +42,7 @@
#include "ssl_ncp.h"
#include "vlan.h&quo= t;
#include "auth_token.h"
+#include "route.h"
#include <inttypes.h>
#include <string.h>=

@@ -1240,11 +1241,26 @@
= management_learn_addr(management, &mi->context.c2.mda_conte= xt, &addr, primary);
}
#endif
+ if (primary &&a= mp; multi_check_push_ifconfig_extra_route(mi))
+ {
+ /* "primary" is the VPN ifconfig address of = the peer */
+ = /* if it does not fall into the network defined by ifconfig_local+ * we install this as= extra onscope address on the interface */
+ struct gc_arena gc =3D gc_new();
= + /* The IP address is n= ot assigned to the interface of the DCO device */
+ msg(D_MULTI_LOW, "MULTI: Adding = /32 on-link route for route %s -> %s",
+ print_in_addr_t(remote_si.addr.in4.s= in_addr.s_addr, 0, &gc),
+ multi_instance_string(mi, false, &gc));
= +
+ addr.netbits =3D 32;
+ addr.type |=3D MR_ONLINK_ADDR;
+
+ dco_install_iroute(m, mi, &a= ddr);
+ gc_fre= e(&gc);
+ }

+
= if (!primary)
{
- /* "primary" is the VPN ifconfig address o= f the peer and already
= - * known to DCO, so only install "extra" iroutes (primar= y =3D false)
- = */
ASSERT(netbits >=3D 0); /* DCO requires popu= lated netbits */
dco_install_iroute(m, mi, &ad= dr);
}
@@ -1278,6 +1294,24 @@ management_learn_addr(management, &mi->context.c2.m= da_context, &addr, primary);
}
#e= ndif
+ if (primary= && multi_check_push_ifconfig_ipv6_extra_route(mi))
+ {
+ /* "primary" is the VPN ifconfi= g address of the peer */
+ /* if it does not fall into the network defined by ifconfig_lo= cal
+ * we in= stall this as extra onscope address on the interface */
+ struct gc_arena gc =3D gc_new(= );
+ /* The IP= address is not assigned to the interface of the DCO device */
+ msg(D_MULTI_LOW, "M= ULTI: Adding /129 on-link route for "
+ "ifconfig-ipv6-push %s= -> %s",
+ = print_in6_addr(mi->context.options.push_ifconfig_ipv6_local, 0,= &gc),
+ = multi_instance_string(mi, false, &gc));
+
+ addr.netbits =3D 128;
+ addr.type |=3D MR_ONLINK_ADDR;
+
+ dco_install_iroute(m, mi, &addr);
<= span style=3D"color: hsl(120, 100%, 40%);">+ gc_free(&gc);

+ }
= if (!primary)
{
/* "pr= imary" is the VPN ifconfig address of the peer and already
<= span>@@ -4309,3 +4343,57 @@
* }
= */
}
+
+/**
<= span style=3D"color: hsl(120, 100%, 40%);">+ * Determines if the ifconfig_p= ush_local address falls into the range of the local
+ * IP addresses of the VPN interface (ifc= onfig_local with ifconfig_remote_netmask)
+ *
+ * @return Returns true if ifconfig_push is outside that range and req= uires an extra
+ * ro= ute to be installed.
= + */
+bool
= +multi_check_push_ifconfig_extr= a_route(struct multi_instance *mi)
+{
+ = struct options *o =3D &mi->context.options;
+ in_addr_t local_addr, local_netmask;<= /span>
+
+ if (!o->ifconfig_local || !o->= ;ifconfig_remote_netmask)
+ {
+ = /* If we do not have a local address, we just return false as
+ * this check doesn't= make sense. */

+ = return false;
+ = }
+
+ /* if it falls into the network= defined by ifconfig_local we assume
+ * it is already known to DCO and only install "e= xtra" iroutes */
+ inet= _pton(AF_INET, o->ifconfig_local, &local_addr);
+ inet_pton(AF_INET, o->ifconfig_re= mote_netmask, &local_netmask);
+
+ = return (local_addr & local_netmask) !=3D (push_ifconfig_local & loc= al_netmask);
+}

+
+
+bool
+mul= ti_check_push_ifconfig_ipv6_extra_route(struct multi_instance *mi)+{
+ struct options *o =3D &mi->context.= options;
+
= + if (!o->ifconfig_ipv6_l= ocal || !o->ifconfig_ipv6_netbits)
+ {
+ /* If we do not have a local address, we just return false as
+ * this check= doesn't make sense. */
+ return false;
+ }
+
+ /* if it falls into= the network defined by ifconfig_local we assume
+ * it is already known to DCO and only ins= tall "extra" iroutes */
+ struct in6_addr ifconfig_local;
+ if (inet_pton(AF_INET6, o->ifconfig_i= pv6_local, &ifconfig_local) !=3D 1)
+ {
+ return false;
+ }
+

+ return (!route_ipv6_m= atch_host(&ifconfig_local, o->ifconfig_ipv6_netbits,
+ = &o->push_ifconfig_ipv6_local));
+}
\ No newline at end of file
= diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h
index 087c0e6..5ec3904 100644
--- a/src/openvpn/multi.h
+++ b/src/openvpn/multi.h
@@ -666,6 +666,26 = @@
return ret;
}

+/**
+ * Determines if the ifconfig_push_loc= al address falls into the range of the local
+ * IP addresses of the VPN interface (ifconfig_loc= al with ifconfig_remote_netmask)
+ *
+ * @= return Returns true if ifconfig_push is outside that range and requires an = extra
+ * route to be= installed.
+ */

+bool
+multi_check_push_ifconfig_extra_route(s= truct multi_instance *mi);
+
+/**+ * Determines if the ifconfi= g_ipv6_local address falls into the range of the local
+ * IP addresses of the VPN interface (if= config_local with ifconfig_remote_netmask)
+ *
+ * @return Returns true if ifconfig_push is outside that range and re= quires an extra
+ * r= oute to be installed.
+ */
+bool+multi_check_push_ifconfig_ipv= 6_extra_route(struct multi_instance *mi);
+
/*
* Check for si= gnals.
*/

To view, vi= sit chan= ge 1192. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I83295e00d1a756dfa44050b0a44= 93095fb050fff
Gerrit-Change-Number: 1192
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--3zc/F/I3Pes=--