From: "cron2 (Code Review)" Date: Wed, 29 Jan 2025 11:30:58 +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="Yo1HMs8AFXw="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: options: add IPv4 support to '--show-gateway ' List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --Yo1HMs8AFXw= 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/+/881?usp=3Demail to review the following change. Change subject: options: add IPv4 support to '--show-gateway ' ...................................................................... options: add IPv4 support to '--show-gateway ' This is an old debug option, which used to print "the default routes found" for IPv4 and IPv6, and optionally "a route to a particular IPv6 target" if passed an argument. With the work started in commit 0fcfc8381f60d we want this to handle IPv4 as well, mostly to be able to easily test per-platform get_default_gateway() implementations. The implementation is simplistic - if can be parsed as an IPv4 or IPv6 address, that particular protocol lookup will do "the host route" and the other one will stick to "the default route". Change-Id: Ic438c583a782035ecb9b5ea65702a768ae2585f5 Signed-off-by: Gert Doering --- M doc/man-sections/advanced-options.rst M src/openvpn/options.c 2 files changed, 18 insertions(+), 8 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/81/881/1 diff --git a/doc/man-sections/advanced-options.rst b/doc/man-sections/advan= ced-options.rst index d5a6b4f..e1115e4 100644 --- a/doc/man-sections/advanced-options.rst +++ b/doc/man-sections/advanced-options.rst @@ -9,13 +9,17 @@ :: --show-gateway + --show-gateway IPv4-target --show-gateway IPv6-target + For IPv4 it looks for a 0.0.0.0/0 route, or the specified IPv4 address + if the target can be parsed as an IPv4 address. For IPv6 this queries the route towards ::/128, or the specified IPv6 - target address if passed as argument. - For IPv4 on Linux, Windows, MacOS and BSD it looks for a 0.0.0.0/0 route. - If there are more specific routes, the result will not always be matching - the route of the IPv4 packets to the VPN gateway. + target address if the argument is an IPv6 address. + + Adding a target is helpful for diagnostics to see if OpenVPN will do + the right thing if there are more specific IPv4/IPv6 routes to a + VPN server. Advanced Expert Options diff --git a/src/openvpn/options.c b/src/openvpn/options.c index 5a80e6b..2897961 100644 --- a/src/openvpn/options.c +++ b/src/openvpn/options.c @@ -5858,16 +5858,22 @@ { struct route_gateway_info rgi; struct route_ipv6_gateway_info rgi6; - struct in6_addr remote =3D IN6ADDR_ANY_INIT; + in_addr_t remote_ipv4 =3D 0; + struct in6_addr remote_ipv6 =3D IN6ADDR_ANY_INIT; openvpn_net_ctx_t net_ctx; VERIFY_PERMISSION(OPT_P_GENERAL); if (p[1]) { - get_ipv6_addr(p[1], &remote, NULL, M_WARN); + /* try parsing the argument as a v4 or v6 address - if + * possible, the output will show the exact route there, and + * "the default route" for the other protocol + */ + remote_ipv4 =3D get_ip_addr(p[1], M_WARN, NULL); + get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN); } net_ctx_init(NULL, &net_ctx); - get_default_gateway(&rgi, 0, &net_ctx); - get_default_gateway_ipv6(&rgi6, &remote, &net_ctx); + get_default_gateway(&rgi, remote_ipv4, &net_ctx); + get_default_gateway_ipv6(&rgi6, &remote_ipv6, &net_ctx); print_default_gateway(M_INFO, &rgi, &rgi6); openvpn_exit(OPENVPN_EXIT_STATUS_GOOD); /* exit point */ } -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/881?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: Ic438c583a782035ecb9b5ea65702a768ae2585f5 Gerrit-Change-Number: 881 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 --Yo1HMs8AFXw= 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.

Vi= ew Change

options: add IPv4 support to '--show-gateway <arg>&=
#39;

This is an old debug option, which used to print "the defa= ult routes found"
for IPv4 and IPv6, and optionally "a route t= o a particular IPv6 target"
if passed an argument.

With the = work started in commit 0fcfc8381f60d we want this to handle
IPv4 as well= , mostly to be able to easily test per-platform
get_default_gateway() im= plementations.

The implementation is simplistic - if <arg> can= be parsed as an IPv4 or
IPv6 address, that particular protocol lookup w= ill do "the host route"
and the other one will stick to "= the default route".

Change-Id: Ic438c583a782035ecb9b5ea65702a76= 8ae2585f5
Signed-off-by: Gert Doering <gert@...1296...>
---
= M doc/man-sections/advanced-options.rst
M src/openvpn/options.c
2 fil= es changed, 18 insertions(+), 8 deletions(-)

git pull ssh://gerri=
t.openvpn.net:29418/openvpn refs/changes/81/881/1
diff --git a/doc/=
man-sections/advanced-options.rst b/doc/man-sections/advanced-options.rst
index d5a6b4f..e1115e4 100644
--- a/doc/man-= sections/advanced-options.rst
+++ b/doc/man-sections/advanc= ed-options.rst
@@ -9,13 +9,17 @@
::

--show-gateway
+ --show-gateway IPv4-target
--show-gateway IPv6-target


+ For IPv4 it looks for a 0.0.0.0/0 rout= e, or the specified IPv4 address
+ if the target can be parsed as an IPv4 address.
For IPv6 this queries the route towards ::/128, or the specified IPv= 6

- target address if = passed as argument.
- = For IPv4 on Linux, Windows, MacOS and BSD it looks for a 0.0.0.0/0 route.
- If there are more spe= cific routes, the result will not always be matching
- the route of the IPv4 packets to the VPN = gateway.
+ target ad= dress if the argument is an IPv6 address.
+
+ the right thing if = there are more specific IPv4/IPv6 routes to a
+ VPN server.

=
Advanced Expert Options
diff --git a/src/= openvpn/options.c b/src/openvpn/options.c
index 5a80e6b..28= 97961 100644
--- a/src/openvpn/options.c
++= + b/src/openvpn/options.c
@@ -5858,16 +5858,22 @@ {
struct route_gateway_info rgi;
struct route_ipv6_gateway_info rgi6;
- struct in6_addr remote =3D IN6AD= DR_ANY_INIT;
+ = in_addr_t remote_ipv4 =3D 0;
+ struct in6_addr remote_ipv6 =3D IN6ADDR_ANY_INIT;<= br> openvpn_net_ctx_t net_ctx;
VERIF= Y_PERMISSION(OPT_P_GENERAL);
if (p[1])
<= span> {

- = get_ipv6_addr(p[1], &remote, NULL, M_WARN);
+ /* try parsing the argument a= s a v4 or v6 address - if
+ * possible, the output will show the exact route there, = and
+ * &= quot;the default route" for the other protocol
+ */
+ remote_ipv4 =3D get_ip_addr(p[1],= M_WARN, NULL);
+ = get_ipv6_addr(p[1], &remote_ipv6, NULL, M_WARN);
}

net_ctx_init(NULL, &net_ctx);
- get_default_gatew= ay(&rgi, 0, &net_ctx);
- get_default_gateway_ipv6(&rgi6, &remote, &net_= ctx);
+ get_de= fault_gateway(&rgi, remote_ipv4, &net_ctx);
+ get_default_gateway_ipv6(&rgi= 6, &remote_ipv6, &net_ctx);
print_default_= gateway(M_INFO, &rgi, &rgi6);
openvpn_exit= (OPENVPN_EXIT_STATUS_GOOD); /* exit point */
}<= br>

To view, visit change 881. To unsubscribe, or for h= elp writing mail filters, visit settings.

<= /div>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic438c583a782035ecb9b5ea6570= 2a768ae2585f5
Gerrit-Change-Number: 881
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
--Yo1HMs8AFXw=--