From: "cron2 (Code Review)" Date: Wed, 29 Oct 2025 07:53:19 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., heiko@...515..., openvpn-devel@lists.sourceforge.net, frank@...2641..., antonio@...2726... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="I0qll9vX85Y="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Install host routes for out-of-subnet ifconfig-push addresses when DC... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: d12fk , flichtenheld , openvpn-devel --I0qll9vX85Y= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/11= 92?usp=3Demail ) Change subject: Install host routes for out-of-subnet ifconfig-push address= es when DCO is enabled ...................................................................... Install host routes for out-of-subnet ifconfig-push addresses when DCO is e= nabled ifconfig-push and ifconfig-ipv6-push can configure the IP address of a client. If this IP address lies inside the network that is configured on the ovpn/tun device this works as expected as the routing table point to the ovpn/tun interface. However, if the IP address is outside that range, the IP packets are not forwarded to the ovpn/tun interface and Linux and FreeBSD DCO implementations need a "connected" route so kernel routing knows that the IP in question is a peer VPN IP. This patch adds logic to add host routes for these ifconfig-push + ifconfig-ipv6-push addresses to ensure that traffic for these IP addresses is also directed to the VPN. For Linux it is important that these extra routes are routes using scope link rather than static since otherwise indirect routes via these IP addresses, like iroute, will not work. On FreeBSD we also use interface routes as that works and routes that target interfaces instead of next-hop IP addresses are less brittle. Tested using a server with ccd: openvpn --server 10.33.0.0 255.255.192.0 --server-ipv6 fd00:f00f::1/64 = --client-config-dir ~/ccd [...] and a client with lwipvonpn and the following ccd file: iroute-ipv6 FD00:F00F:CAFE::1001/64 ifconfig-ipv6-push FD00:F00F:D00D::77/64 push "setenv-safe ifconfig_ipv6_local_2 FD00:F00F:CAFE::1001" push "setenv-safe ifconfig_ipv6_netbits_2 64" iroute 10.234.234.0 255.255.255.0 ifconfig-push 10.11.12.13 255.255.255.0 push "setenv-safe ifconfig_local_2 10.234.234.12" push "setenv-safe ifconfig_netmask_2 255.255.255.0" This setups an ifconfig-push addresses outside the --server/--server-ipv6 network and additionally configures a iroute behind that client. The setenv-safe configure lwipovpn to use that additional IP addresses to allow testing via ping. Windows behaves like the user space implementation. It does not require the= se special routes but instead (like user space) needs static routes to redirect IP traffic for these IP addresses to the tunnel interface. E.g. in the exam= ple above the server config needs to have: route 10.234.234.0 255.255.255.0 route 10.11.12.0 255.255.255.0 route-ipv6 FD00:F00F:CAFE::1001/64 route-ipv6 FD00:F00F:D00D::77/64 Change-Id: I83295e00d1a756dfa44050b0a4493095fb050fff Signed-off-by: Arne Schwabe Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1192 Message-Id: <20251029070701.11457-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg33= 991.html Signed-off-by: Gert Doering --- 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, 156 insertions(+), 7 deletions(-) diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/server-= options.rst index 347a251..ade4d41 100644 --- a/doc/man-sections/server-options.rst +++ b/doc/man-sections/server-options.rst @@ -314,6 +314,10 @@ 3. Use ``--ifconfig-pool`` allocation for dynamic IP (last choice). + When DCO is enabled and the IP is not in contained in the network specif= ied + by ``--ifconfig``, OpenVPN will install a /32 host 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 @@ -324,6 +328,10 @@ ifconfig-ipv6-push ipv6addr/bits ipv6remote + When DCO is enabled and the IP is not in contained in the network specif= ied + by ``--ifconfig-ipv6``, OpenVPN will install a /128 host route for the + ``ipv6addr`` IP address. + --multihome Configure a multi-homed UDP server. This option needs to be used when a server has more than one IP address (e.g. multiple interfaces, or diff --git a/src/openvpn/dco.c b/src/openvpn/dco.c index 8fb4662..7abdad3 100644 --- a/src/openvpn/dco.c +++ b/src/openvpn/dco.c @@ -664,6 +664,14 @@ return; } +#if defined(_WIN32) + if (addr->type & MR_ONLINK_DCO_ADDR) + { + /* Windows does not need these extra routes, so we ignore/skip the= m */ + return; + } +#endif + struct context *c =3D &mi->context; if (addrtype =3D=3D MR_ADDR_IPV6) { @@ -671,8 +679,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_DCO_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 } @@ -683,7 +697,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_DCO_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 } @@ -714,6 +734,20 @@ DCO_IROUTE_METRIC); #endif } + +#if !defined(_WIN32) + /* Check if we added a host route as the assigned client IP addres= s was + * not in the on link scope defined by --ifconfig */ + in_addr_t ifconfig_local =3D mi->context.c2.push_ifconfig_local; + + if (multi_check_push_ifconfig_extra_route(mi, htonl(ifconfig_local= ))) + { + /* On windows we do not install these routes, so we also do no= t need to delete them */ + net_route_v4_del(&m->top.net_ctx, &ifconfig_local, + 32, NULL, c->c1.tuntap->actual_name, 0, + DCO_IROUTE_METRIC); + } +#endif } if (mi->context.c2.push_ifconfig_ipv6_defined) @@ -728,6 +762,18 @@ DCO_IROUTE_METRIC); #endif } + + /* Checked if we added a host route as the assigned client IP addr= ess was + * outside the --ifconfig-ipv6 tun interface config */ +#if !defined(_WIN32) + struct in6_addr *dest =3D &mi->context.c2.push_ifconfig_ipv6_local; + if (multi_check_push_ifconfig_ipv6_extra_route(mi, dest)) + { + /* On windows we do not install these routes, so we also do no= t need to delete them */ + net_route_v6_del(&m->top.net_ctx, dest, 128, NULL, + c->c1.tuntap->actual_name, 0, DCO_IROUTE_METR= IC); + } +#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..afd2e6c 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 needed for DCO on Unix platforms */ +#define MR_ONLINK_DCO_ADDR 64 + struct mroute_addr { uint8_t len; /* length of address */ diff --git a/src/openvpn/multi.c b/src/openvpn/multi.c index 11e4d8c..285671d 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 @@ -1231,11 +1232,18 @@ management_learn_addr(management, &mi->context.c2.mda_context, &ad= dr, primary); } #endif - if (!primary) + if (primary && multi_check_push_ifconfig_extra_route(mi, addr.v4.addr)) { - /* "primary" is the VPN ifconfig address of the peer and already - * known to DCO, so only install "extra" iroutes (primary =3D fals= e) - */ + /* "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 */ + addr.netbits =3D 32; + addr.type |=3D MR_ONLINK_DCO_ADDR; + + dco_install_iroute(m, mi, &addr); + } + else if (!primary) + { ASSERT(netbits >=3D 0); /* DCO requires populated netbits */ dco_install_iroute(m, mi, &addr); } @@ -1269,7 +1277,17 @@ management_learn_addr(management, &mi->context.c2.mda_context, &ad= dr, primary); } #endif - if (!primary) + if (primary && multi_check_push_ifconfig_ipv6_extra_route(mi, &addr.v6= .addr)) + { + /* "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 */ + addr.netbits =3D 128; + addr.type |=3D MR_ONLINK_DCO_ADDR; + + dco_install_iroute(m, mi, &addr); + } + else 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) @@ -4407,3 +4425,49 @@ } } } + +bool +multi_check_push_ifconfig_extra_route(struct multi_instance *mi, in_addr_t= dest) +{ + 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 */ + 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 (dest & local_netmask); +} + +bool +multi_check_push_ifconfig_ipv6_extra_route(struct multi_instance *mi, + struct in6_addr *dest) +{ + 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 (!ipv6_net_contains_host(&ifconfig_local, o->ifconfig_ipv6_netb= its, + dest)); +} \ No newline at end of file diff --git a/src/openvpn/multi.h b/src/openvpn/multi.h index 50f8d10..a62b07a 100644 --- a/src/openvpn/multi.h +++ b/src/openvpn/multi.h @@ -666,6 +666,33 @@ 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) + * + * @param mi The multi-instance to check this condition for + * @param dest The destination IP address to check + * + * @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, in_addr_t= dest); + +/** + * 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) + * + * @param mi The multi-instance to check this condition for + * @param dest The destination IPv6 address to check + * + * @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, + struct in6_addr *dest); + /* * 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?usp=3Demail Gerrit-MessageType: merged Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I83295e00d1a756dfa44050b0a4493095fb050fff Gerrit-Change-Number: 1192 Gerrit-PatchSet: 15 Gerrit-Owner: plaisthos Gerrit-Reviewer: cron2 Gerrit-Reviewer: d12fk Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-CC: openvpn-devel --I0qll9vX85Y= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 sub= mitted this change.

View Change

Install host routes for out-of-subnet ifconfig-p=
ush addresses when DCO is enabled

ifconfig-push and ifconfig-ipv6-pu= sh can configure the IP address of a
client. If this IP address lies ins= ide the network that is configured
on the ovpn/tun device this works as = expected as the routing table point to
the ovpn/tun interface. However,= if the IP address is outside that range,
the IP packets are not forward= ed to the ovpn/tun interface and Linux
and FreeBSD DCO implementations n= eed a "connected" route so kernel
routing knows that the IP in= question is a peer VPN IP.

This patch adds logic to add host routes= for these ifconfig-push +
ifconfig-ipv6-push addresses to ensure that t= raffic for these IP
addresses is also directed to the VPN.

For Li= nux it is important that these extra routes are routes using scope
link = rather than static since otherwise indirect routes via these IP
addresse= s, like iroute, will not work. On FreeBSD we also use interface
routes a= s that works and routes that target interfaces instead of
next-hop IP ad= dresses are less brittle.

Tested using a server with ccd:

= openvpn --server 10.33.0.0 255.255.192.0 --server-ipv6 fd00:f00f::1/64 --c= lient-config-dir ~/ccd [...]

and a client with lwipvonpn and the fol= lowing ccd file:

iroute-ipv6 FD00:F00F:CAFE::1001/64
ifconf= ig-ipv6-push FD00:F00F:D00D::77/64
push "setenv-safe ifconfig_ip= v6_local_2 FD00:F00F:CAFE::1001"
push "setenv-safe ifconfig= _ipv6_netbits_2 64"

iroute 10.234.234.0 255.255.255.0
= ifconfig-push 10.11.12.13 255.255.255.0
push "setenv-safe ifconf= ig_local_2 10.234.234.12"
push "setenv-safe ifconfig_netmas= k_2 255.255.255.0"

This setups an ifconfig-push addresses outsi= de the --server/--server-ipv6
network and additionally configures a irou= te behind that client. The
setenv-safe configure lwipovpn to use that ad= ditional IP addresses to allow
testing via ping.

Windows behaves = like the user space implementation. It does not require these
special ro= utes but instead (like user space) needs static routes to redirect
IP tr= affic for these IP addresses to the tunnel interface. E.g. in the exampleabove the server config needs to have:

route 10.234.234.0 255.2= 55.255.0
route 10.11.12.0 255.255.255.0

route-ipv6 FD00:F00= F:CAFE::1001/64
route-ipv6 FD00:F00F:D00D::77/64

Change-Id: I8= 3295e00d1a756dfa44050b0a4493095fb050fff
Signed-off-by: Arne Schwabe <= arne@...1227...>
Acked-by: Gert Doering <gert@...1296...>
Ge= rrit URL: https://gerrit.openvpn.net/c/openvpn/+/1192
Message-Id: <20= 251029070701.11457-1-gert@...1296...>
URL: https://www.mail-archive.c= om/openvpn-devel@lists.sourceforge.net/msg33991.html
Signed-off-by: Gert= Doering <gert@...1296...>
---
M doc/man-sections/server-option= s.rst
M src/openvpn/dco.c
M src/openvpn/mroute.h
M src/openvpn/mul= ti.c
M src/openvpn/multi.h
5 files changed, 156 insertions(+), 7 dele= tions(-)

diff --git a/doc/man-sections/server-options.rst b/doc/man-sections/serv=
er-options.rst
index 347a251..ade4d41 100644
--- a/doc/man-sections/server-options.rst
+++ b/doc/man-s= ections/server-options.rst
@@ -314,6 +314,10 @@
<= span> 3. Use ``--ifconfig-pool`` allocation for dynamic IP (last<= br> choice).

+ When DCO is enabled and the IP is not in contained= in the network specified
+ by ``--ifconfig``, OpenVPN will install a /32 host route for the ``= local``
+ IP address= .
+
= --ifconfig-ipv6-push args
for ``--client-config-dir`` pe= r-client static IPv6 interface
configuration, see ``--cl= ient-config-dir`` and ``--ifconfig-push`` for
@@ -324,6 +32= 8,10 @@

ifconfig-ipv6-push ipv6addr= /bits ipv6remote

+ When DCO is enabled and the IP is not in contained in the = network specified
+ = by ``--ifconfig-ipv6``, OpenVPN will install a /128 host route for the

+ ``ipv6addr`` IP addres= s.
+
= --multihome
Configure a multi-homed UDP server. This op= tion needs to be used when a
server has more than one IP= address (e.g. multiple interfaces, or
diff --git a/src/ope= nvpn/dco.c b/src/openvpn/dco.c
index 8fb4662..7abdad3 10064= 4
--- a/src/openvpn/dco.c
+++ b/src/openvpn= /dco.c
@@ -664,6 +664,14 @@
return= ;
}

+#if defined(_WIN32)
+ if (addr->type & MR_ONLINK_DCO_ADDR)
+ {
+ /* Windows does not need these= extra routes, so we ignore/skip them */
+ return;
+ }
+ struct context *c =3D &mi->context;
= if (addrtype =3D=3D MR_ADDR_IPV6)
{
@= @ -671,8 +679,14 @@
dco_win_add_iroute_ipv6(&c= ->c1.tuntap->dco, addr->v6.addr, addr->netbits,
c->c2.tls_multi->peer_id);
#else
+ = const struct in6_addr *gateway =3D &mi->context.c2.push_ifconfig_= ipv6_local;
+ = if (addr->type & MR_ONLINK_DCO_ADDR)
+ {
+ gateway =3D NULL;
+ }
+
net_route_v6_add(&m->top.net= _ctx, &addr->v6.addr, addr->netbits,
- &mi->context.c2.pu= sh_ifconfig_ipv6_local, c->c1.tuntap->actual_name, 0,
+ gateway, c= ->c1.tuntap->actual_name, 0,
= DCO_IROUTE_METRIC);
#endif
}=
@@ -683,7 +697,13 @@
= c->c2.tls_multi->peer_id);
#else
in_addr_t dest =3D htonl(addr->v4.addr);
- net_route_v4_add(&m->top.ne= t_ctx, &dest, addr->netbits, &mi->context.c2.push_ifconfig_lo= cal,
+ const i= n_addr_t *gateway =3D &mi->context.c2.push_ifconfig_local;+ if (addr->type &am= p; MR_ONLINK_DCO_ADDR)
+ = gateway =3D NULL;
+=
+ net_route_v4_add(&= amp;m->top.net_ctx, &dest, addr->netbits, gateway,
c->c1.tuntap->actual_name, 0, DCO_IROUTE_= METRIC);
#endif
}
@@ = -714,6 +734,20 @@
DCO_IROUTE_= METRIC);
#endif
}
+
+#if !defined(_WIN32)
+ /* Check if we added a host route as the assi= gned client IP address was
+ * not in the on link scope defined by --ifconfig */<= br>+ in_addr_t ifconfig_= local =3D mi->context.c2.push_ifconfig_local;
+
+ if (multi_check_push_ifconfig_extra_route(mi, htonl(ifcon= fig_local)))
+ = {
+ /* On= windows we do not install these routes, so we also do not need to delete t= hem */
+ n= et_route_v4_del(&m->top.net_ctx, &ifconfig_local,
+ 32, N= ULL, c->c1.tuntap->actual_name, 0,
+ DCO_IROUTE_METRIC);

+ }
+#endif
}


if (mi->context.c2.push_ifconfig_ipv6_= defined)
@@ -728,6 +762,18 @@
= DCO_IROUTE_METRIC);
#endif
}
+=
+ /* Checked if we a= dded a host route as the assigned client IP address was
+ * outside the --ifconfig-ipv6 = tun interface config */
+#if !defined(_WIN32)
+ struct in6_addr *dest =3D &mi->context.c2.push_ifconfig= _ipv6_local;
+ = if (multi_check_push_ifconfig_ipv6_extra_route(mi, dest))
+ {
+ /* On windows we do not install th= ese routes, so we also do not need to delete them */
+ net_route_v6_del(&m->t= op.net_ctx, dest, 128, NULL,
+ c->c1.tuntap->actual_name, 0, D= CO_IROUTE_METRIC);
+ = }
+#endif

}
#endif /* if defined(TARGET_LINUX) || d= efined(TARGET_FREEBSD) || defined(_WIN32) */
}
<= span>diff --git a/src/openvpn/mroute.h b/src/openvpn/mroute.h
index 5b0c694..afd2e6c 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 p= art of address */
#define MR_WITH_PROTO 32

+/* MRoute is an o= n link/scope address needed for DCO on Unix platforms */
+#define MR_ONLINK_DCO_ADDR 64+
struct mro= ute_addr
{
uint8_t len; /* length= of address */
diff --git a/src/openvpn/multi.c b/src/openv= pn/multi.c
index 11e4d8c..285671d 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 <inttypes.h>
#include <string.h>

= @@ -1231,11 +1232,18 @@
management_learn_addr(mana= gement, &mi->context.c2.mda_context, &addr, primary);
= }
#endif
- if (!primary)
+ if (primary && multi_check_push_ifconfig_extra_rou= te(mi, addr.v4.addr))
{
- /* "primary" is the VPN ifconfig a= ddress of the peer and already
- * known to DCO, so only install "extra" iroutes= (primary =3D false)
- = */
+ /= * "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 */
+ addr.netbits =3D 32;
+ addr.type |=3D MR_ONLINK_DCO_ADDR;
+
+ dco_install_iroute(m, mi, &addr);
+ }

+ else if (!primary)
+ {
ASSERT(netbits= >=3D 0); /* DCO requires populated netbits */
= dco_install_iroute(m, mi, &addr);
}
@@ -1269,7 +1277,17 @@

management_learn_addr(man= agement, &mi->context.c2.mda_context, &addr, primary); }
#endif
- if (!primary)
+ if (primary && multi_check_push_ifconfig_ipv6_ext= ra_route(mi, &addr.v6.addr))
+ {
+ = /* "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 onsco= pe address on the interface */
+ addr.netbits =3D 128;
+ addr.type |=3D MR_ONLINK_DCO_ADDR;
= +
+ dco_install_iroute(m, mi, &addr);

+ }
+ else if (!primary)
{
/* "primary" is the VPN ifconfi= g address of the peer and already
* known to DCO,= so only install "extra" iroutes (primary =3D false)
@@ -4407,3 +4425,49 @@
}
= }
}
= +
+bool
+multi_check_push_ifconfig_extra_r= oute(struct multi_instance *mi, in_addr_t dest)
+{
+ struct options *o =3D &mi->context.options;
= + in_addr_t local_addr, loca= l_netmask;
++ if (!o->ifconfig_loca= l || !o->ifconfig_remote_netmask)
+ {
+ * 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 inst= all "extra" iroutes */
+ inet_pton(AF_INET, o->ifconfig_local, &local_addr)= ;
+ inet_pton(AF_I= NET, o->ifconfig_remote_netmask, &local_netmask);
+
+ return (local_addr & local_netmask) !=3D (dest &a= mp; local_netmask);
+= }
+
+bool
+multi_check_push_ifconfig_ipv6_extra_route(struct mu= lti_instance *mi,
+ = struct in6_addr *dest)
<= span style=3D"color: hsl(120, 100%, 40%);">+{
+ struct options *o =3D &mi->context.opt= ions;
+
+ if (!o->ifconfig_ipv6_loca= l || !o->ifconfig_ipv6_netbits)
+ {
= + /* If we do not have a local address, we just return false as

+ * this check do= esn't make sense. */
+ return false;
+ }
+=
+ /* if it falls into th= e network defined by ifconfig_local we assume
+ * it is already known to DCO and only instal= l "extra" iroutes */
+ struct in6_addr ifconfig_local;
+ if (inet_pton(AF_INET6, o->ifconfig_ipv6= _local, &ifconfig_local) !=3D 1)
+ {
+ }
++ return (!ipv6_net_contai= ns_host(&ifconfig_local, o->ifconfig_ipv6_netbits,
+ d= est));
+}
<= span>\ No newline at end of file
diff --git a/src/openvpn/m= ulti.h b/src/openvpn/multi.h
index 50f8d10..a62b07a 100644<= /span>
--- a/src/openvpn/multi.h
+++ b/src/openvpn= /multi.h
@@ -666,6 +666,33 @@
return r= et;
}

+/**
+ * Determines if the ifconfig_push_local address falls into the range = of the local
+ * IP a= ddresses of the VPN interface (ifconfig_local with ifconfig_remote_netmask)=
+ *
+ * @param mi The multi-ins= tance to check this condition for
+ * @param dest The destination IP address to check
+ *
+ * @return Returns true if ifconfig_pus= h is outside that range and requires an extra
+ * route to be installed.
+ */
+bool
++/**
+ * Determines if the ifconfig_ipv6_local addr= ess falls into the range of the local
+ * IP addresses of the VPN interface (ifconfig_local with= ifconfig_remote_netmask)
+ *
+ * @param m= i The multi-instance to check this condition for
+ * @param dest The destinati= on IPv6 address to check
+ *
+ * @return R= eturns true if ifconfig_push is outside that range and requires an extra
+ * route to be install= ed.
+ */
+bool

+multi_check_push_ifconfig_ipv6_extra_route(stru= ct multi_instance *mi,
+
/*

* Check for signals.
*/

To view, visit change 1192. To unsubscribe, or for help writin= g mail filters, visit settings.

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I83295e00d1a756dfa44050b0a44= 93095fb050fff
Gerrit-Change-Number: 1192
Gerrit-PatchSet: 15
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: d12fk <heiko@...515...>=
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: ordex <antonio@...2726...&= gt;
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --I0qll9vX85Y=--