Skip to content

Commit 1cc3525

Browse files
committed
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: <not set> = no gateway redirection desired 1 = "redirect-gateway for that protocol in question" 2 = "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 <gert@greenie.muc.de> Acked-by: Arne Schwabe <arne-openvpn@rfc2549.org> Message-Id: <20250826184046.21434-1-gert@greenie.muc.de> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg32686.html Signed-off-by: Gert Doering <gert@greenie.muc.de>
1 parent 3671c42 commit 1cc3525

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

doc/man-sections/script-options.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,14 @@ instances.
874874
translations will be recorded rather than their names as denoted on the
875875
command line or configuration file.
876876

877+
:code:`route_redirect_gateway_ipv4`
878+
879+
:code:`route_redirect_gateway_ipv6`
880+
Set to `1` if the corresponding default gateway should be redirected
881+
into the tunnel, and to `2` if also the local LAN segment should be
882+
blocked (`block-local`). Not set otherwise. Set prior to **--up** script
883+
execution.
884+
877885
:code:`script_context`
878886
Set to "init" or "restart" prior to up/down script execution. For more
879887
information, see documentation for ``--up``.

src/openvpn/options.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5720,6 +5720,8 @@ remove_option(struct context *c, struct options *options, char *p[], bool is_inl
57205720
{
57215721
options->routes_ipv6->flags = 0;
57225722
}
5723+
env_set_del(es, "route_redirect_gateway_ipv4");
5724+
env_set_del(es, "route_redirect_gateway_ipv6");
57235725
}
57245726
else if (streq(p[0], "dns") && !p[1])
57255727
{
@@ -6039,6 +6041,8 @@ update_option(struct context *c, struct options *options, char *p[], bool is_inl
60396041
{
60406042
options->routes_ipv6->flags = 0;
60416043
}
6044+
env_set_del(es, "route_redirect_gateway_ipv4");
6045+
env_set_del(es, "route_redirect_gateway_ipv6");
60426046
*update_options_found |= OPT_P_U_REDIR_GATEWAY;
60436047
}
60446048
}
@@ -7661,6 +7665,16 @@ add_option(struct options *options, char *p[], bool is_inline, const char *file,
76617665
goto err;
76627666
}
76637667
}
7668+
if (options->routes->flags & RG_REROUTE_GW)
7669+
{
7670+
setenv_int(es, "route_redirect_gateway_ipv4",
7671+
options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7672+
}
7673+
if (options->routes_ipv6 && (options->routes_ipv6->flags & RG_REROUTE_GW))
7674+
{
7675+
setenv_int(es, "route_redirect_gateway_ipv6",
7676+
options->routes->flags & RG_BLOCK_LOCAL ? 2 : 1);
7677+
}
76647678
#ifdef _WIN32
76657679
/* we need this here to handle pushed --redirect-gateway */
76667680
remap_redirect_gateway_flags(options);

0 commit comments

Comments
 (0)