From: "mrbff (Code Review)" Date: Tue, 5 Aug 2025 23:49:52 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <82d4e8f6b32031af22cba181ab1eb9f50610c6c7-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Fp/aBwvIT7s="; 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 --Fp/aBwvIT7s= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, 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 (#2). 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, 187 insertions(+), 22 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/01/901/2 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 40ae2c8..e79b777 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -2101,6 +2101,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); } @@ -2145,6 +2149,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); @@ -4714,6 +4723,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 e504485..1f43d5a 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" @@ -844,30 +845,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 { @@ -880,6 +865,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, @@ -992,7 +1001,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); @@ -1203,7 +1213,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) @@ -1212,6 +1222,130 @@ } } +void +add_route_towards_remote(struct context *c) +{ + ASSERT(c->c1.link_socket_addrs); + + int current_remote_family =3D c->c1.link_socket_addrs[0].actual.dest.a= ddr.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(c->c1.link_socket_addrs[0].actu= al.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 &(c->c1.link_socket_ad= drs[0].actual.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 (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 ea8b767..642ec35 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 int msglevel, const struct route_gateway_= 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 Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Ic7b486ccb85df7fc1d6a573ac1315d235728822c Gerrit-Change-Number: 901 Gerrit-PatchSet: 2 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --Fp/aBwvIT7s= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

mrbff uploaded patch set #2 to this change.

View Change

git pull ssh://gerrit.openvpn.net:29418=
/openvpn refs/changes/01/901/2
diff --git a/src/openvpn/init.c b/sr=
c/openvpn/init.c
index 40ae2c8..e79b777 100644
--- a/src/openvpn/init.c
+++ b/src/openvpn/init.c
@@ -2101,6 +2101,10 @@
= signal_description(c->sig->signal_received, c->sig->signal_text= ),
"route-pre-down", c-&= gt;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.tuntap,
= ROUTE_OPTION_FLAGS(&c->options), c->c2.= es, &c->net_ctx);
}
@@ -214= 5,6 +2149,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);
@@ -4714,6 = +4723,17 @@
}
}

+ /**<= br>+ * When using both --re= direct-gateway and --persist-tun,
+ * if the connection to the server is lost, a /32 (or /12= 8 if IPv6) route must be added
+ * to ensure connectivity to the next remote.
+ */
+ if (c->mode =3D=3D CM_P2P
+ && c->options.= persist_tun)
+ {
+ add_route_tow= ards_remote(c);
+ = }
+
= /*
* Actually do UID/GID downgrade, and chroot, i= f requested.
* May be delayed by --client, --pull, or= --up-delay.
diff --git a/src/openvpn/route.c b/src/openvpn= /route.c
index e504485..1f43d5a 100644
--- = a/src/openvpn/route.c
+++ b/src/openvpn/route.c
<= span>@@ -42,6 +42,7 @@

#include "options.h"

#include "networking.h"
#include &q= uot;integer.h"
+= #include "openvpn.h"

#include = "memdbg.h"

@@ -844,30 +845,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-&g= t;rgi6.flags & (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED))
= =3D=3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED))
{
- = struct route_ipv6 *r6;
-
- r6->network =3D *remote_host= _ipv6;
- r6-= >netbits =3D 128;
- = if (!(rl6->rgi6.flags & RGI_ON_LINK))
- {
- r6->gateway =3D rl6->rgi6.g= ateway.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 | R= T_METRIC_DEFINED;
-
- r6->next = =3D rl6->routes_ipv6;
+ rl6->routes_ipv6 =3D create_host_rout= e_ipv6(*remote_host_ipv6, rl6);
+ rl6->iflags |=3D RL_DID_LOCAL;
= }
else
{@@ -880,6 +865,30 @@
return ret;
}


+struct route_ipv6 *
+create_host_route_ipv6(struct in6_addr remote_host_ipv6, struct route_i= pv6_list *rl6)
+{
+ struct route_ipv6 *= r6;
+ ALLOC_OBJ_CL= EAR_GC(r6, struct route_ipv6, &rl6->gc);
+
+ r6->network =3D remote_host_ipv6;
+ r6->netbits =3D 128;
+ if (!(rl6->rgi6.flags & RG= I_ON_LINK))
+ {

+ r6->gateway= =3D rl6->rgi6.gateway.addr_ipv6;
+ }
+#ifdef _WIN32
+ r6->adapter_index =3D rl6->rgi6.adapter_index;
+#else
+ r6->iface =3D rl6->rgi6.iface;+#endif
+ r6->flags =3D RT_DEFINED | RT_METR= IC_DEFINED;
+ r6-&= gt;next =3D rl6->routes_ipv6;
+
+ re= turn r6;
+}+
static bool=
add_route3(in_addr_t network, in_addr_t netmask, in_addr_= t gateway, const struct tuntap *tt,
unsigned in= t flags, const struct route_gateway_info *rgi, const struct env_set *es,
@@ -992,7 +1001,8 @@
/* if r= emote_host is not ipv4 (ie: ipv6), just skip
= * adding this special /32 route */
if = ((rl->spec.flags & RTSA_REMOTE_HOST)
- && rl->spec.remote_hos= t !=3D IPV4_INVALID_ADDR)
+ && rl->spec.remote_host !=3D IPV4_INVA= LID_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, &am= p;rl->rgi, es, ctx);
@@ -1203,7 +1213,7 @@
{

delete_route_ipv6(r6, tt, es, ct= x);
}
- rl6->iflags &=3D ~RL_ROUTES_ADDED;
+ rl6->iflags &=3D ~(RL= _ROUTES_ADDED | RL_DID_LOCAL);
}

if (rl6)
@@ -1212,6 +1222,130 @@ }
}

+void
+add_route_towards_remote(struct context *c)
+{

+ ASSERT(c->c1.link_socket_addrs);
= +
+ int current_remote_family =3D c->c1.link_s= ocket_addrs[0].actual.dest.addr.sa.sa_family;
+
+ if (current_remote_family =3D=3D AF_INET && c->c1.rou= te_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 curren= t_remote =3D ntohl(c->c1.link_socket_addrs[0].actual.dest.addr.in4.sin_a= ddr.s_addr);
+=
+ if (add_route3(cur= rent_remote,
+ = IPV4_NETMASK_HOST,
+ c->c1.route_list->rgi.gateway.a= ddr,
+ = c->c1.tuntap,
+ ROUTE_OPTION_FLAGS(&c->options) | ROUTE_= REF_GW,
+ = &c->c1.route_list->rgi,
+ c->c2.es,
+ &c->= net_ctx))

+ {<= /span>
+ c->c1= .route_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 &(c->c1.link_socket_addrs[0].actual.dest.addr= .in6.sin6_addr);
+ = struct route_ipv6_list *rl6 =3D c->c1.route_ipv6_list;
+

+ if ((rl6->rgi6.flags & (RGI_ADDR_DEF= INED | RGI_IFACE_DEFINED)) =3D=3D (RGI_ADDR_DEFINED | RGI_IFACE_DEFINED))
+ {
<= span style=3D"color: hsl(120, 100%, 40%);">+ struct route_ipv6 *= r6 =3D create_host_route_ipv6(*remote_host_ipv6, rl6);

+
+ if (add_route_ipv6(r6, c->c1.tuntap,<= br>+ = 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 ad= dress, but could not determine IPv6 gateway address + interface, expect fai= lure\n");
+ = }
+ }+}
+
+void
+del_ro= ute_towards_remote(struct context *c)
+{
+= /* If the function is called from do_close_tun() it means that the sock= et
+ * has alread= y been closed and c->c2.link_sockets[0]->info.lsa` used in
= + * `add_route_towards_remo= te()` 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].act= ual.dest.addr.sa.sa_family)
+ {
+ = current_remote_family =3D c->c1.link_socket_addrs[0].actual.dest.addr.= sa.sa_family;
+ }<= /span>
+ else if (c->c= 1.link_socket_addrs[0].current_remote)
+ {
+ current_remote_family =3D c->c1.link_socket_addrs[0].curren= t_remote->ai_family;
+ }
++ if (current_remote_family= =3D=3D AF_INET && c->c1.route_list
+ && (c->c1.route_list->flag= s & RG_REROUTE_GW)
+ {
+ del_route3(c->c1.route_= list->spec.remote_host,

+ IPV4_NETMASK_HOST,
+ c->c1.route_list->rgi.gat= eway.addr,
+ = c->c1.tuntap,
+ ROUTE_OPTION_FLAGS(&c->options) | ROUTE_RE= F_GW,
+ = &c->c1.route_list->rgi,
+ c->c2.es,
+ &c->net_ctx);
+ c->c1.route_l= ist->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_G= W)
+ &= ;& (c->c1.route_ipv6_list->iflags & RL_DID_LOCAL))
= + {
+ struct in6_addr *remote_host_ipv6 = =3D &c->c1.route_ipv6_list->remote_host_ipv6;
+ struct route_ipv6 *host_route = =3D create_host_route_ipv6(*remote_host_ipv6, c->c1.route_ipv6_list);
+
+ for (struct route_ipv6 *prev =3D = NULL, *r6 =3D c->c1.route_ipv6_list->routes_ipv6; r6; r6 =3D r6->n= ext)
+ {

+ if (memcmp(&a= mp;r6->network, &host_route->network, sizeof(struct in6_addr))
+ || r6-= >netbits !=3D host_route->netbits
+ || memcmp(&r6->gateway, &hos= t_route->gateway, sizeof(struct in6_addr)))
+ {
+ continue;
+ }
+
+ delete_route_ipv6(r6, c->c1.tuntap, c->c2.es, &c-&g= t;net_ctx);
+ = if (!prev)
+ = {
+ = c->c1.route_ipv6_list->routes_ipv6 =3D r6->next;
+ }

+ else
+ {
+ prev->next =3D r6->next;<= /span>
+ }=
+ 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 ea8b767..642ec35 100644
--- a/src/open= vpn/route.h
+++ b/src/openvpn/route.h
@@ -3= 09,6 +309,14 @@
const struct route_gateway_= info *rgi, const struct env_set *es,
openvp= n_net_ctx_t *ctx);

+/* Function to add a route towards the new remote when usi= ng
+ * `--redirect-ga= teway` and `--persist-tun` options together. */
+void add_route_towards_remote(struct context *c= );
+
+/* Function to delete the route towa= rds the remote when using
+ * `--redirect-gateway` and `--persist-tun` options together. */
+void del_route_towards_r= emote(struct context *c);
+
void add_route_to_option_list(struct route_option_l= ist *l, const char *network, const char *netmask,
= const char *gateway, const char *metric, int table_id= );

@@ -359,6 +367,9 @@
v= oid print_default_gateway(const int msglevel, const struct route_gateway_in= fo *rgi,
const struct route_ipv= 6_gateway_info *rgi6);

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

To view, visit change 901. To unsubscribe, or for help writing mail filter= s, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic7b486ccb85df7fc1d6a573ac13= 15d235728822c
Gerrit-Change-Number: 901
Gerrit-PatchSet: 2
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-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--Fp/aBwvIT7s=--