From: "cron2 (Code Review)" Date: Sat, 23 Aug 2025 20:16:13 +0000 References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="en2ySXKUMq0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Introduce env variables to communicate desired gateway redirection to... List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --en2ySXKUMq0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. Hello plaisthos, flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1156?usp=3Demail to review the following change. Change subject: Introduce env variables to communicate desired gateway redi= rection to NM. ...................................................................... Introduce env variables to communicate desired gateway redirection to NM. When run under Network Manager control, OpenVPN is not allowed to control routing. Instead, NM uses the OpenVPN-set environment variables ("route_network_1" etc) to set up routes as requested. This method never worked properly for "redirect-gateway", as the information was not made available in environment variables. Introduce new env vars: route_redirect_gateway_ipv4 route_redirect_gateway_ipv6 to communicate desired state: =3D no gateway redirection desired 1 =3D "redirect-gateway for that protocol in question" 2 =3D "include block-local to redirect the local LAN as well" We intentionally do not expose all the IPv4 flags ("local", "def1", ...) as this is really internal OpenVPN historical cruft. Change-Id: I1e623b4a836f7216750867243299c7e4d0bd32d0 Signed-off-by: Gert Doering --- M doc/man-sections/script-options.rst M src/openvpn/options.c 2 files changed, 22 insertions(+), 0 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/56/1156/1 diff --git a/doc/man-sections/script-options.rst b/doc/man-sections/script-= options.rst index bd5ecd4..670cd33 100644 --- a/doc/man-sections/script-options.rst +++ b/doc/man-sections/script-options.rst @@ -874,6 +874,14 @@ translations will be recorded rather than their names as denoted on the command line or configuration file. +:code:`route_redirect_gateway_ipv4` + +:code:`route_redirect_gateway_ipv6` + Set to `1` if the corresponding default gateway should be redirected + into the tunnel, and to `2` if also the local LAN segment should be + blocked (`block-local`). Not set otherwise. Set prior to **--up** sc= ript + execution. + :code:`script_context` Set to "init" or "restart" prior to up/down script execution. For more information, see documentation for ``--up``. diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 0b16c5a..648d526 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5720,6 +5720,8 @@ { options->routes_ipv6->flags =3D 0; } + env_set_del(es, "route_redirect_gateway_ipv4"); + env_set_del(es, "route_redirect_gateway_ipv6"); } else if (streq(p[0], "dns") && !p[1]) { @@ -6039,6 +6041,8 @@ { options->routes_ipv6->flags =3D 0; } + env_set_del(es, "route_redirect_gateway_ipv4"); + env_set_del(es, "route_redirect_gateway_ipv6"); *update_options_found |=3D OPT_P_U_REDIR_GATEWAY; } } @@ -7661,6 +7665,16 @@ goto err; } } + if (options->routes->flags & RG_REROUTE_GW) + { + setenv_int(es, "route_redirect_gateway_ipv4", + options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1); + } + if (options->routes_ipv6 && (options->routes_ipv6->flags & RG_RERO= UTE_GW)) + { + setenv_int(es, "route_redirect_gateway_ipv6", + options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1); + } #ifdef _WIN32 /* we need this here to handle pushed --redirect-gateway */ remap_redirect_gateway_flags(options); -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1156?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: I1e623b4a836f7216750867243299c7e4d0bd32d0 Gerrit-Change-Number: 1156 Gerrit-PatchSet: 1 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --en2ySXKUMq0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

cron2 would like plaisthos and flichtenheld to review t= his change.

V= iew Change

Introduce env variables to communicate desired gateway redir=
ection to NM.

When run under Network Manager control, OpenVPN is not= allowed to
control routing. Instead, NM uses the OpenVPN-set environme= nt variables
("route_network_1" etc) to set up routes as reque= sted. This method never
worked properly for "redirect-gateway"= ;, as the information was not made
available in environment variables.
Introduce new env vars:

route_redirect_gateway_ipv4
route= _redirect_gateway_ipv6

to communicate desired state:

<not= set> =3D no gateway redirection desired
1 =3D "redirect-gatewa= y for that protocol in question"
2 =3D "include block-local t= o redirect the local LAN as well"

We intentionally do not expos= e all the IPv4 flags ("local", "def1", ...)
as this = is really internal OpenVPN historical cruft.

Change-Id: I1e623b4a836= f7216750867243299c7e4d0bd32d0
Signed-off-by: Gert Doering <gert@...1711...= 96...>
---
M doc/man-sections/script-options.rst
M src/openvpn/= options.c
2 files changed, 22 insertions(+), 0 deletions(-)

gi=
t pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/56/1156/1
<= pre style=3D"font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/doc/man-sections/script-options.rst b/doc/man-sections/scrip= t-options.rst
index bd5ecd4..670cd33 100644
--- a/doc/man-sections/script-options.rst
+++ b/doc/man-se= ctions/script-options.rst
@@ -874,6 +874,14 @@
translations will be recorded rather than their names as denoted o= n the
command line or configuration file.

+:code:`route_r= edirect_gateway_ipv4`
+
+:code:`route_redi= rect_gateway_ipv6`
+ = Set to `1` if the corresponding default gateway should be redirected
+ into the tunnel, an= d to `2` if also the local LAN segment should be
+ blocked (`block-local`). Not set otherwis= e. Set prior to **--up** script
+ execution.
+
:code:`script_context`
Set t= o "init" or "restart" prior to up/down script execution= . For more
information, see documentation for ``--up``= .
diff --git a/src/openvpn/options.c b/src/openvpn/options.= c
index 0b16c5a..648d526 100644
--- a/src/o= penvpn/options.c
+++ b/src/openvpn/options.c
@@ -5720,6 +5720,8 @@

{
= options->routes_ipv6->flags =3D 0;
}

+ env_set_del(es= , "route_redirect_gateway_ipv4");
+ env_set_del(es, "route_redirect_gatewa= y_ipv6");
}
else if (streq(p= [0], "dns") && !p[1])
{
@@ -6039,6 +6041,8 @@
{
= options->routes_ipv6->flags =3D 0;
= }
+ = env_set_del(es, "route_redirect_gateway_ipv4");
+ env_set_del(es, "= ;route_redirect_gateway_ipv6");
*update_o= ptions_found |=3D OPT_P_U_REDIR_GATEWAY;
}<= br> }
@@ -7661,6 +7665,16 @@
= goto err;
}
= }
+ if (op= tions->routes->flags & RG_REROUTE_GW)
+ {
+ setenv_int(es, "route_redirect_gateway_i= pv4",
+ = options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
+ }
<= span style=3D"color: hsl(120, 100%, 40%);">+ if (options->routes_= ipv6 && (options->routes_ipv6->flags & RG_REROUTE_GW))

+ {
+ setenv_int(es, "= ;route_redirect_gateway_ipv6",
+ options->routes->flags & R= G_BLOCK_LOCAL ? 2 : 1);
+ }
#ifdef _WIN32
/* we= need this here to handle pushed --redirect-gateway */
= remap_redirect_gateway_flags(options);

To view, visit change 1156. To unsubscribe, or for help writing mail filte= rs, visit settings.

<= div itemscope itemtype=3D"http://schema.org/EmailMessage">
<= meta itemprop=3D"name" content=3D"View Change"/>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1e623b4a836f721675086724329= 9c7e4d0bd32d0
Gerrit-Change-Number: 1156
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <gert@...1296...>
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: newchange
--en2ySXKUMq0=--