From: "mrbff (Code Review)" Date: Mon, 6 Oct 2025 09:10:53 +0000 In-Reply-To: References: Reply-To: marco@...2726..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., gert@...1296... Message-ID: <30be7c355465afac670b79cb78aa8479dba51391-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="12zKmqO47T0="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: redirect-gateway: only redirect traffic through TUN if address famili... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --12zKmqO47T0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. Hello flichtenheld, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/1210?usp=3Demail to look at the new patch set (#3). Change subject: redirect-gateway: only redirect traffic through TUN if addr= ess families match ...................................................................... redirect-gateway: only redirect traffic through TUN if address families mat= ch Fixes an ifconfig push-reply bug where, if the remote is switched and the n= ew TUN has a different address family, the previous ifconfig options remain assigned to the new TUN. Adds a check in do_init_route_ipv6_list() to add default routes toward the = TUN only if the TUN has IPv6 addresses. It also resets the ifconfig and ifconfig-ipv6 options on every PUSH_REPLY a= nd whenever a valid ifconfig or ifconfig-ipv6 option is found in a PUSH_UPDATE message to avoid stale data conflicts. This may be necessary when the new address has a different address family than the old one. Change-Id: Ib3458a9ed2eb38e00184c4a92659b83b97fe476c --- M src/openvpn/init.c M src/openvpn/options.c 2 files changed, 62 insertions(+), 2 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/1210/3 diff --git a/src/openvpn/init.c b/src/openvpn/init.c index f8a0fee..aaa0573 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -1523,7 +1523,7 @@ /* redirect (IPv6) gateway to VPN? if yes, add a few more specifics */ - if (options->routes_ipv6->flags & RG_REROUTE_GW) + if (options->routes_ipv6->flags & RG_REROUTE_GW && options->ifconfig_i= pv6_local) { char *opt_list[] =3D { "::/3", "2000::/4", "3000::/4", "fc00::/7",= NULL }; int i; diff --git a/src/openvpn/options.c b/src/openvpn/options.c index f35738d..fc18931 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5459,6 +5459,17 @@ } } +/* Reset all ifconfig and ifconfig-ipv6 related options to their default/N= ULL state */ +#define RESET_IFCONFIG_OPTIONS(opt) \ + do \ + { \ + (opt)->ifconfig_local =3D NULL; \ + (opt)->ifconfig_remote_netmask =3D NULL; \ + (opt)->ifconfig_ipv6_local =3D NULL; \ + (opt)->ifconfig_ipv6_netbits =3D 0; \ + (opt)->ifconfig_ipv6_remote =3D NULL; \ + } while (0) + bool apply_push_options(struct context *c, struct options *options, struct buff= er *buf, unsigned int permission_mask, unsigned int *option_type= s_found, @@ -5470,6 +5481,14 @@ const msglvl_t msglevel =3D D_PUSH_ERRORS | M_OPTERR; unsigned int update_options_found =3D 0; + /* When receiving a PUSH_REPLY, reset the ifconfig options to prevent + * stale data conflicts. This could be necessary when the new address = has a + * different address family than the previous one. */ + if (!is_update) + { + RESET_IFCONFIG_OPTIONS(options); + } + while (buf_parse(buf, ',', line, sizeof(line))) { char *p[MAX_PARMS + 1]; @@ -6014,7 +6033,48 @@ const bool pull_mode =3D BOOL_CAST(permission_mask & OPT_P_PULL_MODE); ASSERT(MAX_PARMS >=3D 7); - if (streq(p[0], "route") && p[1] && !p[5]) + if (streq(p[0], "ifconfig") && p[1] && p[2] && !p[3]) + { + VERIFY_PERMISSION(OPT_P_UP); + if (ip_or_dns_addr_safe(p[1], options->allow_pull_fqdn) + && ip_or_dns_addr_safe(p[2], options->allow_pull_fqdn)) /* FQD= N -- may be DNS name */ + { + /* When receiving a PUSH_UPDATE containing a valid ifconfig op= tion, + * we should reset the ifconfig and ifconfig-ipv6 options to p= revent + * stale data conflicts. This could be necessary when the new = address has a + * different address family than the previous one. Same is tru= e when a valid + * ifconfig-ipv6 option is received. */ + RESET_IFCONFIG_OPTIONS(options); + } + else + { + msg(msglevel, "ifconfig parms '%s' and '%s' must be valid addr= esses", p[1], p[2]); + goto err; + } + } + else if (streq(p[0], "ifconfig-ipv6") && p[1] && p[2] && !p[3]) + { + unsigned int netbits; + + VERIFY_PERMISSION(OPT_P_UP); + if (get_ipv6_addr(p[1], NULL, &netbits, msglevel) && ipv6_addr_saf= e(p[2])) + { + if (netbits < 64 || netbits > 124) + { + msg(msglevel, "ifconfig-ipv6: /netbits must be between 64 = and 124, not '/%d'", + netbits); + goto err; + } + + RESET_IFCONFIG_OPTIONS(options); + } + else + { + msg(msglevel, "ifconfig-ipv6 parms '%s' and '%s' must be valid= addresses", p[1], p[2]); + goto err; + } + } + else if (streq(p[0], "route") && p[1] && !p[5]) { if (!(*update_options_found & OPT_P_U_ROUTE)) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1210?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: Ib3458a9ed2eb38e00184c4a92659b83b97fe476c Gerrit-Change-Number: 1210 Gerrit-PatchSet: 3 Gerrit-Owner: mrbff Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: cron2 Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld --12zKmqO47T0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

mrbff uploaded patch set #3 to this change.

View Change

redirect-gateway: only redirect traffic through TUN if =
address families match

Fixes an ifconfig push-reply bug where, if th= e remote is switched and the new
TUN has a different address family, the= previous ifconfig options remain
assigned to the new TUN.

Adds a= check in do_init_route_ipv6_list() to add default routes toward the TUNonly if the TUN has IPv6 addresses.

It also resets the ifconfig and= ifconfig-ipv6 options on every PUSH_REPLY and
whenever a valid ifconfig= or ifconfig-ipv6 option is found in a PUSH_UPDATE
message to avoid stal= e data conflicts. This may be necessary when the new
address has a diffe= rent address family than the old one.

Change-Id: Ib3458a9ed2eb38e001= 84c4a92659b83b97fe476c
---
M src/openvpn/init.c
M src/openvpn/opti= ons.c
2 files changed, 62 insertions(+), 2 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/10/= 1210/3
diff --git a/src/openvpn/init.c b/src/openvpn/init.c<=
br>index f8a0fee..aaa0573 100644
--- a/src/openvpn/in= it.c
+++ b/src/openvpn/init.c
@@ -1523,7 +1= 523,7 @@

/* redirect (IPv6) gateway = to VPN? if yes, add a few more specifics
*/- if (options->routes_ipv= 6->flags & RG_REROUTE_GW)
+ if (options->routes_ipv6->flags & RG_REROUTE_GW = && options->ifconfig_ipv6_local)
{ char *opt_list[] =3D { "::/3", "2000::/4&qu= ot;, "3000::/4", "fc00::/7", NULL };
= int i;
diff --git a/src/openvpn/options.c b/src/open= vpn/options.c
index f35738d..fc18931 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -5459,6 +5459,17 @@
}
}


+/* Reset all ifconfig and ifconfig-ipv6 related options to their default/= NULL state */
+#defin= e RESET_IFCONFIG_OPTIONS(opt) \
+ do \
+ { = \
+ (opt)->ifconfig_local =3D NULL; \
+ (opt)->ifconfig_remote_n= etmask =3D NULL; \

+ = (opt)->ifconfig_ipv6_local =3D NULL; \
+ (opt)->ifconfig_ipv6_netbits = =3D 0; \
+ = (opt)->ifconfig_ipv6_remote =3D NULL; \
+ } while (0)
+
bool
apply_push_= options(struct context *c, struct options *options, struct buffer *buf,
unsigned int permission_mask, unsigned int= *option_types_found,
@@ -5470,6 +5481,14 @@
const msglvl_t msglevel =3D D_PUSH_ERRORS | M_OPTERR;

unsigned int update_options_found =3D 0;
+ /* When receiving a PUSH_= REPLY, reset the ifconfig options to prevent
+ * stale data conflicts. This could be necessa= ry when the new address has a
+ * different address family than the previous one. */<= br>+ if (!is_update)<= br>+ {
+ RESET_IFCONFIG_OPTIONS(options);<= /span>
+ }
+

while (buf_p= arse(buf, ',', line, sizeof(line)))
{ char *p[MAX_PARMS + 1];
@@ -6014,7 +6033,4= 8 @@
const bool pull_mode =3D BOOL_CAST(permission_mas= k & OPT_P_PULL_MODE);
ASSERT(MAX_PARMS >=3D 7);=

- = if (streq(p[0], "route") && p[1] && !p[5])

+ if (streq(p[0], "= ;ifconfig") && p[1] && p[2] && !p[3])+ {
+ VERIFY_PERMISSION(OPT_P_UP);
+ if (ip_or_dns_ad= dr_safe(p[1], options->allow_pull_fqdn)
+ && ip_or_dns_addr_safe(p[2], opt= ions->allow_pull_fqdn)) /* FQDN -- may be DNS name */
+ {
+ /* When receiving a PUSH_UPDATE cont= aining a valid ifconfig option,
+ * we should reset the ifconfig and ifconfig-ipv6 o= ptions to prevent
+ = * stale data conflicts. This could be necessary when the new add= ress has a
+ = * different address family than the previous one. Same is true when a v= alid
+ * = ifconfig-ipv6 option is received. */
+ RESET_IFCONFIG_OPTIONS(options);
+ }

+ else
+ {
+ msg(msglevel, "ifconfig parms '%s'= ; and '%s' must be valid addresses", p[1], p[2]);
+ goto err;
= + }
+ }
+ else if (streq(p[0], "ifconfig-ipv6") &a= mp;& p[1] && p[2] && !p[3])
+ {
+ unsigned int netbits;
+
+ VERIFY_PERMISSION(OPT_P_UP);
+ if (get_ipv6_addr(p[1], NULL, &netbits, m= sglevel) && ipv6_addr_safe(p[2]))
+ {
+ if (netbits < 64 || netbits > 124)
= + {
+ msg(msglevel, "= ifconfig-ipv6: /netbits must be between 64 and 124, not '/%d'"= ,
+ = netbits);
+ = goto err;
+ = }
+<= br>+ RESET_IFCONFIG_= OPTIONS(options);
+ = }
+ else=
+ {+ msg(msglevel, &qu= ot;ifconfig-ipv6 parms '%s' and '%s' must be valid addresse= s", p[1], p[2]);
+ goto err;
+ }
+ }<= /span>
+ else if (streq(p= [0], "route") && p[1] && !p[5])
= {
if (!(*update_options_found & OPT_P_U_RO= UTE))
{

To vie= w, visit change 1210. To unsubscribe, or for help writing mail filters, visit <= a href=3D"http://gerrit.openvpn.net/settings?usp=3Demail">settings.

=
<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ib3458a9ed2eb38e00184c4a9265= 9b83b97fe476c
Gerrit-Change-Number: 1210
Gerrit-PatchSet: 3
Gerrit-Owner: mrbff <marco@...2726...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: cron2 <gert@...1296...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
= --12zKmqO47T0=--