From: "mrbff (Code Review)" Date: Wed, 15 Oct 2025 18:37:40 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., lstipakov@...277... Message-ID: <057e16068a61ddf2661dcb94e01b88622a637f0c-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="T9aB/c0/Iwk="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: redirect-gateway: add route toward new remote host when using persist... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel , stipa --T9aB/c0/Iwk= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, mrbff, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/901?usp=3Demail to look at the new patch set (#4). Change subject: redirect-gateway: add route toward new remote host when usi= ng persist-tun ...................................................................... redirect-gateway: add route toward new remote host when using persist-tun When both --redirect-gateway and --persist-tun are used together, a route must be added for each new remote host we attempt to connect to. Change-Id: Ic7b486ccb85df7fc1d6a573ac1315d235728822c Signed-off-by: Marco Baffo --- M src/openvpn/init.c M src/openvpn/route.c M src/openvpn/route.h 3 files changed, 189 insertions(+), 22 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/901/4 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index aaa0573..c5f10ee 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2106,6 +2106,10 @@ signal_description(c->sig->signal_received, c->sig= ->signal_text), "route-pre-down", c->c2.es); + if (c->mode =3D=3D CM_P2P && c->options.persist_tun) + { + del_route_towards_remote(c); + } delete_routes(c->c1.route_list, c->c1.route_ipv6_list, c->c1.t= untap, ROUTE_OPTION_FLAGS(&c->options), c->c2.es, &c->n= et_ctx); } @@ -2150,6 +2154,11 @@ c->c2.es); } + if (c->mode =3D=3D CM_P2P && c->options.persist_tun) + { + del_route_towards_remote(c); + } + del_wfp_block(c, adapter_index); } gc_free(&gc); @@ -4723,6 +4732,17 @@ } } + /** + * When using both --redirect-gateway and --persist-tun, + * if the connection to the server is lost, a /32 (or /128 if IPv6) ro= ute must be added + * to ensure connectivity to the next remote. + */ + if (c->mode =3D=3D CM_P2P + && c->options.persist_tun) + { + add_route_towards_remote(c); + } + /* * Actually do UID/GID downgrade, and chroot, if requested. * May be delayed by --client, --pull, or --up-delay. diff --git a/src/openvpn/route.c b/src/openvpn/route.c index 7d988da..94a1d53 100644 --- a/src/openvpn/route.c +++ b/src/openvpn/route.c @@ -42,6 +42,7 @@ #include "options.h" #include "networking.h" #include "integer.h" +#include "openvpn.h" #include "memdbg.h" @@ -840,30 +841,14 @@ } /* add VPN server host route if needed */ - if (need_remote_ipv6_route) + if (need_remote_ipv6_route + && !(rl6->iflags & RL_DID_LOCAL)) { if ((rl6->rgi6.flags & (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) =3D=3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) { - struct route_ipv6 *r6; - ALLOC_OBJ_CLEAR_GC(r6, struct route_ipv6, &rl6->gc); - - r6->network =3D *remote_host_ipv6; - r6->netbits =3D 128; - if (!(rl6->rgi6.flags & RGI_ON_LINK)) - { - r6->gateway =3D rl6->rgi6.gateway.addr_ipv6; - } - r6->metric =3D 1; -#ifdef _WIN32 - r6->adapter_index =3D rl6->rgi6.adapter_index; -#else - r6->iface =3D rl6->rgi6.iface; -#endif - r6->flags =3D RT_DEFINED | RT_METRIC_DEFINED; - - r6->next =3D rl6->routes_ipv6; - rl6->routes_ipv6 =3D r6; + rl6->routes_ipv6 =3D create_host_route_ipv6(*remote_host_ipv6,= rl6); + rl6->iflags |=3D RL_DID_LOCAL; } else { @@ -876,6 +861,30 @@ return ret; } +struct route_ipv6 * +create_host_route_ipv6(struct in6_addr remote_host_ipv6, struct route_ipv6= _list *rl6) +{ + struct route_ipv6 *r6; + ALLOC_OBJ_CLEAR_GC(r6, struct route_ipv6, &rl6->gc); + + r6->network =3D remote_host_ipv6; + r6->netbits =3D 128; + if (!(rl6->rgi6.flags & RGI_ON_LINK)) + { + r6->gateway =3D rl6->rgi6.gateway.addr_ipv6; + } + r6->metric =3D 1; +#ifdef _WIN32 + r6->adapter_index =3D rl6->rgi6.adapter_index; +#else + r6->iface =3D rl6->rgi6.iface; +#endif + r6->flags =3D RT_DEFINED | RT_METRIC_DEFINED; + r6->next =3D rl6->routes_ipv6; + + return r6; +} + static bool add_route3(in_addr_t network, in_addr_t netmask, in_addr_t gateway, const = struct tuntap *tt, unsigned int flags, const struct route_gateway_info *rgi, const= struct env_set *es, @@ -988,7 +997,8 @@ /* if remote_host is not ipv4 (ie: ipv6), just skip * adding this special /32 route */ if ((rl->spec.flags & RTSA_REMOTE_HOST) - && rl->spec.remote_host !=3D IPV4_INVALID_ADDR) + && rl->spec.remote_host !=3D IPV4_INVALID_ADDR + && !(rl->iflags & RL_DID_LOCAL)) { ret =3D add_route3(rl->spec.remote_host, IPV4_NETMASK_= HOST, rl->rgi.gateway.addr, tt, flags | ROUTE_REF_GW, &rl->rgi, e= s, ctx); @@ -1199,7 +1209,7 @@ { delete_route_ipv6(r6, tt, es, ctx); } - rl6->iflags &=3D ~RL_ROUTES_ADDED; + rl6->iflags &=3D ~(RL_ROUTES_ADDED | RL_DID_LOCAL); } if (rl6) @@ -1208,6 +1218,132 @@ } } +void +add_route_towards_remote(struct context *c) +{ + ASSERT(c->c1.link_socket_addrs); + + struct openvpn_sockaddr dest =3D c->c1.link_socket_addrs[0].actual.des= t; + + int current_remote_family =3D dest.addr.sa.sa_family; + + if (current_remote_family =3D=3D AF_INET && c->c1.route_list + && (c->c1.route_list->flags & RG_REROUTE_GW)) + { + if (c->c1.route_list->iflags & RL_DID_LOCAL) + { + del_route_towards_remote(c); + } + + in_addr_t current_remote =3D ntohl(dest.addr.in4.sin_addr.s_addr); + + if (add_route3(current_remote, + IPV4_NETMASK_HOST, + c->c1.route_list->rgi.gateway.addr, + c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options) | ROUTE_REF_GW, + &c->c1.route_list->rgi, + c->c2.es, + &c->net_ctx)) + { + c->c1.route_list->iflags |=3D RL_DID_LOCAL; + c->c1.route_list->spec.remote_host =3D current_remote; + } + } + else if (current_remote_family =3D=3D AF_INET6 && c->c1.route_ipv6_list + && (c->c1.route_ipv6_list->flags & RG_REROUTE_GW)) + { + if (c->c1.route_ipv6_list->iflags & RL_DID_LOCAL) + { + del_route_towards_remote(c); + } + + const struct in6_addr *remote_host_ipv6 =3D &(dest.addr.in6.sin6_a= ddr); + struct route_ipv6_list *rl6 =3D c->c1.route_ipv6_list; + + if ((rl6->rgi6.flags & (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) =3D= =3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) + { + struct route_ipv6 *r6 =3D create_host_route_ipv6(*remote_host_= ipv6, rl6); + + if (add_route_ipv6(r6, c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options), c->c2.es, = &c->net_ctx)) + { + rl6->routes_ipv6 =3D r6; + rl6->iflags |=3D RL_DID_LOCAL; + } + } + else + { + msg(M_WARN, "ROUTE6: IPv6 route overlaps with IPv6 remote addr= ess, but could not determine IPv6 gateway address + interface, expect failu= re\n"); + } + } +} + +void +del_route_towards_remote(struct context *c) +{ + /* If the function is called from do_close_tun() it means that the soc= ket + * has already been closed and c->c2.link_sockets[0]->info.lsa` used in + * `add_route_towards_remote()` cleaned up. So we should use + * `c->c1.link_socket_addrs[0]` instead. + */ + ASSERT(c->c1.link_socket_addrs); + + int current_remote_family =3D 0; + + if (c->c1.link_socket_addrs[0].actual.dest.addr.sa.sa_family) + { + current_remote_family =3D c->c1.link_socket_addrs[0].actual.dest.a= ddr.sa.sa_family; + } + else if (c->c1.link_socket_addrs[0].current_remote) + { + current_remote_family =3D c->c1.link_socket_addrs[0].current_remot= e->ai_family; + } + + if (current_remote_family =3D=3D AF_INET && c->c1.route_list + && (c->c1.route_list->flags & RG_REROUTE_GW) + && (c->c1.route_list->iflags & RL_DID_LOCAL)) + { + del_route3(c->c1.route_list->spec.remote_host, + IPV4_NETMASK_HOST, + c->c1.route_list->rgi.gateway.addr, + c->c1.tuntap, + ROUTE_OPTION_FLAGS(&c->options) | ROUTE_REF_GW, + &c->c1.route_list->rgi, + c->c2.es, + &c->net_ctx); + c->c1.route_list->iflags &=3D ~RL_DID_LOCAL; + } + else if (current_remote_family =3D=3D AF_INET6 && c->c1.route_ipv6_list + && (c->c1.route_ipv6_list->flags & RG_REROUTE_GW) + && (c->c1.route_ipv6_list->iflags & RL_DID_LOCAL)) + { + struct in6_addr *remote_host_ipv6 =3D &c->c1.route_ipv6_list->remo= te_host_ipv6; + struct route_ipv6 *host_route =3D create_host_route_ipv6(*remote_h= ost_ipv6, c->c1.route_ipv6_list); + + for (struct route_ipv6 *prev =3D NULL, *r6 =3D c->c1.route_ipv6_li= st->routes_ipv6; r6; r6 =3D r6->next) + { + if (memcmp(&r6->network, &host_route->network, sizeof(struct i= n6_addr)) + || r6->netbits !=3D host_route->netbits + || memcmp(&r6->gateway, &host_route->gateway, sizeof(struc= t in6_addr))) + { + continue; + } + + delete_route_ipv6(r6, c->c1.tuntap, c->c2.es, &c->net_ctx); + if (!prev) + { + c->c1.route_ipv6_list->routes_ipv6 =3D r6->next; + } + else + { + prev->next =3D r6->next; + } + c->c1.route_ipv6_list->iflags &=3D ~RL_DID_LOCAL; + } + } +} + #ifndef ENABLE_SMALL static const char * diff --git a/src/openvpn/route.h b/src/openvpn/route.h index 54fa137..56c9c7f 100644 --- a/src/openvpn/route.h +++ b/src/openvpn/route.h @@ -309,6 +309,14 @@ const struct route_gateway_info *rgi, const struct env_set = *es, openvpn_net_ctx_t *ctx); +/* Function to add a route towards the new remote when using + * `--redirect-gateway` and `--persist-tun` options together. */ +void add_route_towards_remote(struct context *c); + +/* Function to delete the route towards the remote when using + * `--redirect-gateway` and `--persist-tun` options together. */ +void del_route_towards_remote(struct context *c); + void add_route_to_option_list(struct route_option_list *l, const char *net= work, const char *netmask, const char *gateway, const char *metric, int= table_id); @@ -359,6 +367,9 @@ void print_default_gateway(const msglvl_t msglevel, const struct route_gat= eway_info *rgi, const struct route_ipv6_gateway_info *rgi6); +/* Return a `route_ipv6 *` /128 IPv6 route toward the remote host */ +struct route_ipv6 *create_host_route_ipv6(struct in6_addr remote_host_ipv6= , struct route_ipv6_list *rl6); + /* * Test if addr is reachable via a local interface (return ILA_LOCAL), * or if it needs to be routed via the default gateway (return -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/901?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ic7b486ccb85df7fc1d6a573ac1315d235728822c Gerrit-Change-Number: 901 Gerrit-PatchSet: 4 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-CC: stipa Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Attention: mrbff --T9aB/c0/Iwk= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: flichtenheld, mrbff, plaisthos.

mrbff uploaded patch set #4 to this change.

View Change

redirect-gateway: add route toward new remote host when =
using persist-tun

When both --redirect-gateway and --persist-tun are= used together,
a route must be added for each new remote host we attemp= t to connect to.

Change-Id: Ic7b486ccb85df7fc1d6a573ac1315d235728822= c
Signed-off-by: Marco Baffo <marco@...2726...>
---
M src/op= envpn/init.c
M src/openvpn/route.c
M src/openvpn/route.h
3 files c= hanged, 189 insertions(+), 22 deletions(-)

git p=
ull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/901/4
di=
ff --git a/src/openvpn/init.c b/src/openvpn/init.c
index aa= a0573..c5f10ee 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -2106,6 +2106,10 @@<= br> signal_description(c->sig->signal_r= eceived, c->sig->signal_text),
= "route-pre-down", c->c2.es);

+ if (c->mode =3D= =3D CM_P2P && c->options.persist_tun)
+ {
+ del_route_towards_remote(c);<= br>+ }
delete_routes(c->c1.route_list, c->c1.route_ipv6_list= , c->c1.tuntap,
ROUTE_OPTION_= FLAGS(&c->options), c->c2.es, &c->net_ctx);
}
@@ -2150,6 +2154,11 @@
= c->c2.es);
}
=
+ if (c->= mode =3D=3D CM_P2P && c->options.persist_tun)
+ {
+ del_route_towards_remote(c);<= br>+ }
+
del_wfp_blo= ck(c, adapter_index);
}
gc_free(&= amp;gc);
@@ -4723,6 +4732,17 @@
}<= /span>
}

+ /**
+ * When using both --redirect-gateway and --persist-tun,
+ * if the connection = to the server is lost, a /32 (or /128 if IPv6) route must be added+ * to ensure connectivit= y to the next remote.
+ */
+ if (c-= >mode =3D=3D CM_P2P
+ {
+ add_route_towards_remote(c);
+ }
+
/*
* Actual= ly do UID/GID downgrade, and chroot, if requested.
* = May be delayed by --client, --pull, or --up-delay.
diff --g= it a/src/openvpn/route.c b/src/openvpn/route.c
index 7d988d= a..94a1d53 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c

@@ -42,6 +42,7 @@
#include "options.h"

#include "networkin= g.h"
#include "integer.h"
+#include "openvpn.h"=

#include "memdbg.h"
=
@@ -840,30 +841,14 @@
}

/* add VPN server host route if needed */=
- if (need_remote_ipv6_rou= te)
+ if (need_rem= ote_ipv6_route
+ = && !(rl6->iflags & RL_DID_LOCAL))
{<= /span>
if ((rl6->rgi6.flags & (RGI_ADDR_DEFINED | = RGI_IFACE_DEFINED))
=3D=3D (RGI_ADDR_DEFINED |= RGI_IFACE_DEFINED))
{
- struct route_ipv6 *r6;
- ALLOC_OBJ_CLEAR_GC(r6, s= truct route_ipv6, &rl6->gc);

-
- = r6->network =3D *remote_host_ipv6;
- r6->netbits =3D 128;
- if (!(rl6->rgi6.flags &am= p; RGI_ON_LINK))
- = {
- = r6->gateway =3D rl6->rgi6.gateway.addr_ipv6;
- }
- r6->metric =3D 1;
-#ifdef _WIN32
- r6->adapter_index =3D rl6->rgi= 6.adapter_index;
-#else=
- r6->if= ace =3D rl6->rgi6.iface;
-#endif
- = r6->flags =3D RT_DEFINED | RT_METRIC_DEFINED;
-
- r6->next =3D rl6->routes_ipv6;
- rl6->routes_ipv6 =3D r= 6;
+ rl6-&= gt;routes_ipv6 =3D create_host_route_ipv6(*remote_host_ipv6, rl6);+ rl6->iflags |= =3D RL_DID_LOCAL;
}
else<= /span>
{
@@ -876,6 +861,30 @@
<= span> return ret;

}

+struct route_ipv6 *
+create_host_route_ipv6(struct in6_ad= dr remote_host_ipv6, struct route_ipv6_list *rl6)
+{
+ struct route_ipv6 *r6;
+ ALLOC_OBJ_CLEAR_GC(r6, struct route_ipv6, &rl6-&= gt;gc);
+
<= span style=3D"color: hsl(120, 100%, 40%);">+ r6->network =3D remote_h= ost_ipv6;
+ r6->= ;netbits =3D 128;
+ = if (!(rl6->rgi6.flags & RGI_ON_LINK))
+ {
+ r6->gateway =3D rl6->rgi6.gateway.addr_ipv6;

+ }
+ r6->metric =3D 1;
+#ifdef _WIN32
+ r6->adapter_index =3D rl6->r= gi6.adapter_index;
+#= else
+ r6->ifac= e =3D rl6->rgi6.iface;
+#endif
+ r6-= >flags =3D RT_DEFINED | RT_METRIC_DEFINED;
+ r6->next =3D rl6->routes_ipv6;+
+ return r6;
+}
+
static bool
add_route3(in_addr_t ne= twork, in_addr_t netmask, in_addr_t gateway, const struct tuntap *tt,
unsigned int flags, const struct route_gateway_info = *rgi, const struct env_set *es,
@@ -988,7 +997,8 @@<= br> /* if remote_host is not ipv4 (ie: ipv6), just sk= ip
* adding this special /32 route */
if ((rl->spec.flags & RTSA_REMOTE_HOST= )
- = && rl->spec.remote_host !=3D IPV4_INVALID_ADDR)
+ && rl-&g= t;spec.remote_host !=3D IPV4_INVALID_ADDR
+ && !(rl->iflags & = RL_DID_LOCAL))
{
= ret =3D add_route3(rl->spec.remote_host, IPV4_NETMASK_HOST, = rl->rgi.gateway.addr,
= tt, flags | ROUTE_REF_GW, &rl->rgi, es, ctx);
@@= -1199,7 +1209,7 @@
{
= delete_route_ipv6(r6, tt, es, ctx);
}
<= span style=3D"color: hsl(0, 100%, 40%);">- rl6->iflags &=3D ~= RL_ROUTES_ADDED;

+ = rl6->iflags &=3D ~(RL_ROUTES_ADDED | RL_DID_LOCAL);
<= span> }


if (rl6)
@@ -1208,6 +1218,132 @@
}
}
+void

+add_route_towards_remote(= struct context *c)
+{=
+ ASSERT(c->c1= .link_socket_addrs);
= +
+ struct openvpn= _sockaddr dest =3D c->c1.link_socket_addrs[0].actual.dest;
+
+ int current_remote_family =3D dest.addr.sa.sa_fa= mily;
+
+ if (current_remote_family =3D= =3D AF_INET && c->c1.route_list
+ && (c->c1.route_list->flags &a= mp; RG_REROUTE_GW))
+= {
+ if (c-= >c1.route_list->iflags & RL_DID_LOCAL)
+ {
+ del_route_towards_remote(c);
+ }
+
+ in_addr_t current_remote =3D ntohl(dest.addr.in4.sin_add= r.s_addr);
++ if (add_route3(curre= nt_remote,
+ = IPV4_NETMASK_HOST,
+ c->c1.route_list->rgi.gateway.add= r,
+ = c->c1.tuntap,
+ = &c->c1.route_list->rgi,
+ c->c2.es,
+ &c->ne= t_ctx))
+ {

+ c->c1.r= oute_list->iflags |=3D RL_DID_LOCAL;
+ c->c1.route_list->spec.remote_host = =3D current_remote;
+= }
+ }
+ else if (current_rem= ote_family =3D=3D AF_INET6 && c->c1.route_ipv6_list
+ && (c->c= 1.route_ipv6_list->flags & RG_REROUTE_GW))

+ {
+ if (c->c1.route_ipv6_list->iflags & RL_DI= D_LOCAL)
+ {
+ del_route= _towards_remote(c);
+= }
++ const struct in6_addr= *remote_host_ipv6 =3D &(dest.addr.in6.sin6_addr);
+ struct route_ipv6_list *rl6 =3D = c->c1.route_ipv6_list;
+
+ if ((= rl6->rgi6.flags & (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED)) =3D=3D (RG= I_ADDR_DEFINED | RGI_IFACE_DEFINED))
+ {
+ struct route_ipv6 *r6 =3D create_host_route_ipv6(*remote= _host_ipv6, rl6);
+
+ if (add_r= oute_ipv6(r6, c->c1.tuntap,
+ ROUTE_OPTION_FLAGS(&c->opt= ions), c->c2.es, &c->net_ctx))
+ {
+ rl6->routes_ipv6 =3D r6;
+ rl6->iflags |=3D = RL_DID_LOCAL;
+ = }
+ }

+ else+ {
+ msg(M_WARN, "ROUTE6: I= Pv6 route overlaps with IPv6 remote address, but could not determine IPv6 g= ateway address + interface, expect failure\n");
+ }
+ }
+}
+<= br>+void
+del_route_towards_remote(struct context *= c)
+{
+ /* If the function is called fr= om do_close_tun() it means that the socket
+ * has already been closed and c->c2.link_soc= kets[0]->info.lsa` used in
+ * `add_route_towards_remote()` cleaned up. So we should use<= /span>
+ * `c->c1.lin= k_socket_addrs[0]` instead.
+ */
+ = ASSERT(c->c1.link_socket_addrs);
+
+ = int current_remote_family =3D 0;
+
+ i= f (c->c1.link_socket_addrs[0].actual.dest.addr.sa.sa_family)
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

+ current_remote_family =3D c->c1.li= nk_socket_addrs[0].actual.dest.addr.sa.sa_family;
+ }
+ else if (c->c1.link_socket_addrs[0].current_remote)<= /span>
+ {
+ current_remote_family =3D = c->c1.link_socket_addrs[0].current_remote->ai_family;

+ }
+
+ if (current_remote_family =3D=3D AF_INET && c->c1.rou= te_list
+ &= ;& (c->c1.route_list->flags & RG_REROUTE_GW)
+ && (c->c1.route_l= ist->iflags & RL_DID_LOCAL))
+ {
+ del_route3(c->c1.route_list->spec.remote_host,
+ IPV4_NETMASK_= HOST,
+ = c->c1.route_list->rgi.gateway.addr,
+ c->c1.tuntap,
+ ROUTE_OPTION_= FLAGS(&c->options) | ROUTE_REF_GW,
+ &c->c1.route_list->rgi,<= /span>
+ c= ->c2.es,
+ = &c->net_ctx);
+ c->c1.route_list->iflags &=3D ~RL_DID_LOCAL;<= /span>
+ }
+ else if (current_remote_family= =3D=3D AF_INET6 && c->c1.route_ipv6_list

+ && (c->c1.route_i= pv6_list->flags & RG_REROUTE_GW)
+ && (c->c1.route_ipv6_list->i= flags & RL_DID_LOCAL))
+ {
+ = struct in6_addr *remote_host_ipv6 =3D &c->c1.route_ipv6_list->re= mote_host_ipv6;
+ = struct route_ipv6 *host_route =3D create_host_route_ipv6(*remote_host_i= pv6, c->c1.route_ipv6_list);
+
+ = for (struct route_ipv6 *prev =3D NULL, *r6 =3D c->c1.route_ipv6_list-&g= t;routes_ipv6; r6; r6 =3D r6->next)
+ {
+ if (memcmp(&r6->network, &host_route->ne= twork, sizeof(struct in6_addr))
+ || r6->netbits !=3D host_route->netbits
+ || me= mcmp(&r6->gateway, &host_route->gateway, sizeof(struct in6_ad= dr)))
+ {<= /span>
+ cont= inue;
+ }<= /span>
+
+ delete_route_ipv6(r6, c->= ;c1.tuntap, c->c2.es, &c->net_ctx);
+ if (!prev)
+ {
+ c->c1.route_ipv6_list->routes_= ipv6 =3D r6->next;
+ }
+ = else
+ = {
+ = prev->next =3D r6->next;
+ }
+ c->c1.route_ipv6_list->iflags &=3D ~RL_DID_LO= CAL;
+ }

+ }
+}
+
#ifndef ENABLE_SMALL
<= /span>
static const char *
diff --git a/src/openv= pn/route.h b/src/openvpn/route.h
index 54fa137..56c9c7f 100= 644
--- a/src/openvpn/route.h
+++ b/src/ope= nvpn/route.h
@@ -309,6 +309,14 @@
= const struct route_gateway_info *rgi, const struct env_set *es,
openvpn_net_ctx_t *ctx);

+/* Function to add a rou= te towards the new remote when using
+ * `--redirect-gateway` and `--persist-tun` options togeth= er. */
+void add_rout= e_towards_remote(struct context *c);
+
+/*= Function to delete the route towards the remote when using
+ * `--redirect-gateway` and `--pers= ist-tun` options together. */

+void del_route_towards_remote(struct context *c);
+

void add_route_to= _option_list(struct route_option_list *l, const char *network, const char *= netmask,
const char *gateway= , const char *metric, int table_id);

@@ -= 359,6 +367,9 @@
void print_default_gateway(const msglvl_t = msglevel, const struct route_gateway_info *rgi,
= const struct route_ipv6_gateway_info *rgi6);

+/* Return a `ro= ute_ipv6 *` /128 IPv6 route toward the remote host */
+struct route_ipv6 *create_host_route_ipv6= (struct in6_addr remote_host_ipv6, struct route_ipv6_list *rl6);
= +
/* * Test if addr is reachable via a local interface (return ILA_LOCA= L),
* or if it needs to be routed via the default gateway= (return

To view, visit change 901. To unsub= scribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic7b486ccb85df7fc1d6a573ac13= 15d235728822c
Gerrit-Change-Number: 901
Gerrit-PatchSet: 4
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-CC: stipa <lstipakov@...277...> <= /div>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Attention: mrbff <marco@...2726...&g= t;
= --T9aB/c0/Iwk=--