From: "cron2 (Code Review)" Date: Fri, 31 Jan 2025 08:40:39 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181... Message-ID: <4b5fa336521feb2b29f6c55753209343547ae664-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="aUygOzAJWs8="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: get_default_gateway(): implement platform support for Linux/IPROUTE2 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos , flichtenheld Cc: openvpn-devel --aUygOzAJWs8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: cron2, flichtenheld, plaisthos. Hello flichtenheld, ordex, plaisthos, I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/884?usp=3Demail to look at the new patch set (#2). The change is no longer submittable: checks~ChecksSubmitRule is unsatisfied= now. Change subject: get_default_gateway(): implement platform support for Linux= /IPROUTE2 ...................................................................... get_default_gateway(): implement platform support for Linux/IPROUTE2 Remove the old "read /proc/net/route and try to parse it" implementation and always use the sitnl/netlink implementation of net_route_v4_best_gw(). This was kept "because we had it and it was working" but does not really provide any benefit - netlink for route queries is there for v6 anyway, and the main argument for keeping --enable-iproute2 is "some users want to run non-standard 'ip' binaries to do things" - which is not affected by this change. Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91 Signed-off-by: Gert Doering --- M src/openvpn/networking_iproute2.c M src/openvpn/networking_sitnl.c 2 files changed, 8 insertions(+), 55 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/84/884/2 diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networking_ipr= oute2.c index 975282c..6f13ef5 100644 --- a/src/openvpn/networking_iproute2.c +++ b/src/openvpn/networking_iproute2.c @@ -394,63 +394,15 @@ return ret; } -int -net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, - in_addr_t *best_gw, char *best_iface) -{ - best_iface[0] =3D '\0'; - - FILE *fp =3D fopen("/proc/net/route", "r"); - if (!fp) - { - return -1; - } - - char line[256]; - int count =3D 0; - unsigned int lowest_metric =3D UINT_MAX; - while (fgets(line, sizeof(line), fp) !=3D NULL) - { - if (count) - { - unsigned int net_x =3D 0; - unsigned int mask_x =3D 0; - unsigned int gw_x =3D 0; - unsigned int metric =3D 0; - unsigned int flags =3D 0; - char name[16]; - name[0] =3D '\0'; - - const int np =3D sscanf(line, "%15s\t%x\t%x\t%x\t%*s\t%*s\t%d\= t%x", - name, &net_x, &gw_x, &flags, &metric, - &mask_x); - - if (np =3D=3D 6 && (flags & IFF_UP)) - { - const in_addr_t net =3D ntohl(net_x); - const in_addr_t mask =3D ntohl(mask_x); - const in_addr_t gw =3D ntohl(gw_x); - - if (!net && !mask && metric < lowest_metric) - { - *best_gw =3D gw; - strcpy(best_iface, name); - lowest_metric =3D metric; - } - } - } - ++count; - } - fclose(fp); - - return 0; -} - /* - * The following function is not implemented in the iproute backend as it + * The following functions are not implemented in the iproute backend as it * uses the sitnl implementation from networking_sitnl.c. * * int + * net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, + * in_addr_t *best_gw, char *best_iface) + * + * int * net_route_v6_best_gw(const struct in6_addr *dst, * struct in6_addr *best_gw, char *best_iface) */ diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/networking_sitnl.c index 6b750e8..9de8912 100644 --- a/src/openvpn/networking_sitnl.c +++ b/src/openvpn/networking_sitnl.c @@ -619,8 +619,7 @@ } -#ifdef ENABLE_SITNL - +/* used by iproute2 implementation too */ int net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst, in_addr_t *best_gw, char *best_iface) @@ -652,6 +651,8 @@ return ret; } +#ifdef ENABLE_SITNL + int net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/884?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: I6f17140109106b37e6b0e690df1d87720ccf6f91 Gerrit-Change-Number: 884 Gerrit-PatchSet: 2 Gerrit-Owner: cron2 Gerrit-Reviewer: flichtenheld Gerrit-Reviewer: ordex Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: cron2 Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --aUygOzAJWs8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: cron2, flichtenheld, plaisthos. <= /p>

cron2 uploaded patch set #2 to this change.

View Change

The change is no longer submittable: checks~ChecksSubmitRule is uns= atisfied now.

get_default_gateway(): implement platform support for Linux/I=
PROUTE2

Remove the old "read /proc/net/route and try to parse i= t" implementation
and always use the sitnl/netlink implementation o= f net_route_v4_best_gw().

This was kept "because we had it and = it was working" but does not really
provide any benefit - netlink f= or route queries is there for v6 anyway,
and the main argument for keepi= ng --enable-iproute2 is "some users want
to run non-standard 'i= p' binaries to do things" - which is not affected
by this chang= e.

Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Signed-of= f-by: Gert Doering <gert@...1296...>
---
M src/openvpn/networki= ng_iproute2.c
M src/openvpn/networking_sitnl.c
2 files changed, 8 ins= ertions(+), 55 deletions(-)

git pull ssh://gerrit.openvpn.net:294=
18/openvpn refs/changes/84/884/2
diff --git a/src/openvpn/networkin=
g_iproute2.c b/src/openvpn/networking_iproute2.c
index 9752= 82c..6f13ef5 100644
--- a/src/openvpn/networking_iproute2.c=
+++ b/src/openvpn/networking_iproute2.c
@@= -394,63 +394,15 @@
return ret;
}

-int
-net_route_v4_best_gw(open= vpn_net_ctx_t *ctx, const in_addr_t *dst,
- in_addr_t *best_gw, char *best_ifa= ce)
-{
- best_iface[0] =3D '\0';
-
- FILE *fp =3D fopen("/proc/net/rout= e", "r");
- {<= /span>
- return -1;
- }
-
- char line[256];
- int count =3D 0;
- unsigned int lowest_metric =3D UINT_MAX;
- while (fgets(line, sizeof(line), fp) != =3D NULL)
- {=
- if (count)- {
- unsigned int net_x =3D 0;
- unsigned int ma= sk_x =3D 0;
- = unsigned int gw_x =3D 0;
- unsigned int metric =3D 0;
- unsigned int flags =3D 0;
- char name[16];

= - name[0] =3D '\0&= #39;;
-
- const int np =3D sscanf(l= ine, "%15s\t%x\t%x\t%x\t%*s\t%*s\t%d\t%x",

- name, &am= p;net_x, &gw_x, &flags, &metric,
- &mask_x);
-
- if (np =3D=3D 6 && (flags &= amp; IFF_UP))
- = {
- = const in_addr_t net =3D ntohl(net_x);
- const in_addr_t mask =3D ntohl(mask_x);
- const in_= addr_t gw =3D ntohl(gw_x);
-
- = if (!net && !mask && metric < lowest_metric)
<= span style=3D"color: hsl(0, 100%, 40%);">- {

- *best_gw =3D gw;<= /span>
- st= rcpy(best_iface, name);
- lowest_metric =3D metric;
- }
- }
- }
- ++count;
- = }
- fclose(fp);
-
- return 0;
-}
= -
/*
-= * The following function is not implemented in the iproute backend as it
+ * The following func= tions are not implemented in the iproute backend as it
* = uses the sitnl implementation from networking_sitnl.c.
*<= /span>
* int
+ * net_route_v4_best_gw(openvpn_net_ctx_t *ctx, const in_addr_t *dst,
+ * = in_addr_t *best_gw, char *best_iface)
+ *
-#ifdef ENABLE_SITNL=
-
+/* used by iproute2 implementation too */

int
net_route_v4_best_gw(openvpn_net_ctx_t *ct= x, const in_addr_t *dst,
in_addr_t *b= est_gw, char *best_iface)
@@ -652,6 +651,8 @@
return ret;

}

+#ifdef ENABLE_SITNL
+
int
= net_iface_up(openvpn_net_ctx_t *ctx, const char *iface, bool up) {

To view, visit change 884. To unsu= bscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1= d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 2
Gerrit-Owner: cron2 <gert@...1296...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-Reviewer: ordex <a@...2181...>
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: cron2 <gert@...1296...>= ;
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--aUygOzAJWs8=--