From: "cron2 (Code Review)"
Date: Fri, 31 Jan 2025 09:40:58 +0000
In-Reply-To:
References:
Reply-To: gert@...1296..., arne-openvpn@...1227...,
openvpn-devel@lists.sourceforge.net, frank@...2641..., a@...2181...
Message-ID:
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Disposition: inline
Content-Type: multipart/alternative; boundary="ezyHXQrBqr0="; 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
--ezyHXQrBqr0=
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
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 (#3).
The following approvals got outdated and were removed:
Code-Review+2 by ordex
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
Acked-by: Antonio Quartulli
Message-Id: <20250131084707.24905-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30=
748.html
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/3
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: 3
Gerrit-Owner: cron2
Gerrit-Reviewer: flichtenheld
Gerrit-Reviewer: ordex
Gerrit-Reviewer: plaisthos
Gerrit-CC: openvpn-devel
Gerrit-MessageType: newpatchset
--ezyHXQrBqr0=
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
cron2 uploaded patch set #3 to this change.
View Change
The following approvals got outdated and were removed:
Code-Review+2 by ordex
get_default_gateway(): implement platform support fo=
r Linux/IPROUTE2
Remove the old "read /proc/net/route and try t=
o parse it" implementation
and always use the sitnl/netlink impleme=
ntation of net_route_v4_best_gw().
This was kept "because we ha=
d 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-standa=
rd 'ip' binaries to do things" - which is not affected
by t=
his change.
Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
=
Signed-off-by: Gert Doering <gert@...1296...>
Acked-by: Antonio Qu=
artulli <a@...2181...>
Message-Id: <20250131084707.24905-1-gert=
@...1296...>
URL: https://www.mail-archive.com/openvpn-devel@...1466...=
urceforge.net/msg30748.html
Signed-off-by: Gert Doering <gert@...1726...=
...>
---
M src/openvpn/networking_iproute2.c
M src/openvpn/netw=
orking_sitnl.c
2 files changed, 8 insertions(+), 55 deletions(-)
=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/84/884/3
=
diff --git a/src/openvpn/networking_iproute2.c b/src/openvpn/networki=
ng_iproute2.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';
-
- F=
ILE *fp =3D fopen("/proc/net/route", "r");
- if (!fp)
- {
- return -1;
- }
-
- char line[256];
- int count =3D 0;
- unsigned int lowest_met=
ric =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;
- uns=
igned 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, &m=
etric,
- =
&mask_x);
-
- =
if (np =3D=3D 6 && (flags & IFF_UP))
- {
- const in_addr_t net =3D ntohl(net_x);<=
/span>
- const =
in_addr_t mask =3D ntohl(mask_x);
- const in_addr_t gw =3D ntohl(gw_x);
<=
span style=3D"color: hsl(0, 100%, 40%);">-
- if (!net && !mask && m=
etric < lowest_metric)
- {
-=
*best_gw =3D gw;
- strcpy(best_iface, name);
- lowest_metric =
=3D metric;
- =
}
- }<=
/span>
- }
- ++count;
- }
- fclose(fp);
-
- ret=
urn 0;
-}
-
/*
- * The following function is not imp=
lemented in the iproute backend as it
+ * The following functions are not implemented in the ipr=
oute backend as it
* uses the sitnl implementation from n=
etworking_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_ifa=
ce)
+ *
+ * int
* net_ro=
ute_v6_best_gw(const struct in6_addr *dst,
* =
struct in6_addr *best_gw, char *best_iface)
*/=
span>
diff --git a/src/openvpn/networking_sitnl.c b/src/openvpn/ne=
tworking_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,
<=
span> 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 change 884. To unsubscribe, or for help writing mail fi=
lters, visit settings.=
p>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1=
d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 3
Gerrit-Owner: cron2 <gert@...1296...> =
div>
Gerrit-Reviewer: flichtenheld <frank@...2716...=
1...>
Gerrit-Reviewer: ordex <a@...2181...> =
div>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...=
.1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...=
ts.sourceforge.net>
Gerrit-MessageType: newpatchset
--ezyHXQrBqr0=--