Change in openvpn[master]: get_default_gateway(): implement platform support for Linux/IPROUTE2
A message that is not in the archive (sent off-list or not yet received): gerrit.1738260795000.I6f17140109106b37e6b0e690df1d87720ccf6f91@...2715...
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/+/884?usp=email
to review the following change.
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.
---
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/1
src/openvpn/networking_iproute2.c +5 -53
@@ -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 ] ='\0' ; - -FILE *fp =fopen ("/proc/net/route" ,"r" ); -if (!fp) - { -return -1 ; - } - -char line[256 ]; -int count =0 ; -unsigned int lowest_metric =UINT_MAX ; -while (fgets (line,sizeof (line), fp) !=NULL ) - { -if (count) - { -unsigned int net_x =0 ; -unsigned int mask_x =0 ; -unsigned int gw_x =0 ; -unsigned int metric =0 ; -unsigned int flags =0 ; -char name[16 ]; - name[0 ] ='\0' ; - -const int np =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 ==6 && (flags &IFF_UP )) - { -const in_addr_t net =ntohl (net_x); -const in_addr_t mask =ntohl (mask_x); -const in_addr_t gw =ntohl (gw_x); - -if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; -strcpy (best_iface, name); - lowest_metric = 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) */
src/openvpn/networking_sitnl.c +3 -2
@@ -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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newchange
Attention is currently required from: cron2, flichtenheld, plaisthos.
ordex has posted comments on this change. ( http://gerrit.openvpn.net/c/openvpn/+/884?usp=email )
Change subject: get_default_gateway(): implement platform support for Linux/IPROUTE2
......................................................................
Patch Set 1: Code-Review+2
(1 comment)
Patchset:
PS1:
Basically we're now sharing the implementation of net_route_v4_best_gw() from SITNL to iproute2, as we were already doing for net_route_v6_best_gw().
--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/884?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 1
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Fri, 31 Jan 2025 08:30:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
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=email
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.
---
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
src/openvpn/networking_iproute2.c +5 -53
@@ -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 ] ='\0' ; - -FILE *fp =fopen ("/proc/net/route" ,"r" ); -if (!fp) - { -return -1 ; - } - -char line[256 ]; -int count =0 ; -unsigned int lowest_metric =UINT_MAX ; -while (fgets (line,sizeof (line), fp) !=NULL ) - { -if (count) - { -unsigned int net_x =0 ; -unsigned int mask_x =0 ; -unsigned int gw_x =0 ; -unsigned int metric =0 ; -unsigned int flags =0 ; -char name[16 ]; - name[0 ] ='\0' ; - -const int np =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 ==6 && (flags &IFF_UP )) - { -const in_addr_t net =ntohl (net_x); -const in_addr_t mask =ntohl (mask_x); -const in_addr_t gw =ntohl (gw_x); - -if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; -strcpy (best_iface, name); - lowest_metric = 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) */
src/openvpn/networking_sitnl.c +3 -2
@@ -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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 2
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>
Gerrit-Attention: cron2 <[email protected]...>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-MessageType: newpatchset
PATCH v2 1/1 get_default_gateway(): implement platform support for Linux/IPROUTE2
In reply to a message not in the archiveRemove 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.
---
This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/884
This mail reflects revision 2 of this Change.
Acked-by according to Gerrit (reflected above):
Antonio Quartulli <[email protected]...>
src/openvpn/networking_iproute2.c +5 -53
@@ -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 ] ='\0' ; - -FILE *fp =fopen ("/proc/net/route" ,"r" ); -if (!fp) - { -return -1 ; - } - -char line[256 ]; -int count =0 ; -unsigned int lowest_metric =UINT_MAX ; -while (fgets (line,sizeof (line), fp) !=NULL ) - { -if (count) - { -unsigned int net_x =0 ; -unsigned int mask_x =0 ; -unsigned int gw_x =0 ; -unsigned int metric =0 ; -unsigned int flags =0 ; -char name[16 ]; - name[0 ] ='\0' ; - -const int np =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 ==6 && (flags &IFF_UP )) - { -const in_addr_t net =ntohl (net_x); -const in_addr_t mask =ntohl (mask_x); -const in_addr_t gw =ntohl (gw_x); - -if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; -strcpy (best_iface, name); - lowest_metric = 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) */
src/openvpn/networking_sitnl.c +3 -2
@@ -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) {
[Openvpn-devel] [PATCH applied] Re: get_default_gateway(): implement platform support for Linux/IPROUTE2
Tested on a gentoo system with "configure --enable-iproute2" and then asking the usual "--show-gateway ..." questions.
The actual code change is quite trivial - throw out old code, rely on the (by now) really well-tested and proven sitnl code.
Your patch has been applied to the master branch.
commit d83afe0e0c878164886d83f3ffddbc63680a6310
Author: Gert Doering Date: Fri Jan 31 09:47:07 2025 +0100
get_default_gateway(): implement platform support for Linux/IPROUTE2
Signed-off-by: Gert Doering <[email protected]...>
Acked-by: Antonio Quartulli <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30748.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering
Hello flichtenheld, ordex, plaisthos,
I'd like you to reexamine a change. Please visit
http://gerrit.openvpn.net/c/openvpn/+/884?usp=email
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30748.html
---
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
src/openvpn/networking_iproute2.c +5 -53
@@ -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 ] ='\0' ; - -FILE *fp =fopen ("/proc/net/route" ,"r" ); -if (!fp) - { -return -1 ; - } - -char line[256 ]; -int count =0 ; -unsigned int lowest_metric =UINT_MAX ; -while (fgets (line,sizeof (line), fp) !=NULL ) - { -if (count) - { -unsigned int net_x =0 ; -unsigned int mask_x =0 ; -unsigned int gw_x =0 ; -unsigned int metric =0 ; -unsigned int flags =0 ; -char name[16 ]; - name[0 ] ='\0' ; - -const int np =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 ==6 && (flags &IFF_UP )) - { -const in_addr_t net =ntohl (net_x); -const in_addr_t mask =ntohl (mask_x); -const in_addr_t gw =ntohl (gw_x); - -if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; -strcpy (best_iface, name); - lowest_metric = 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) */
src/openvpn/networking_sitnl.c +3 -2
@@ -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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 3
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: newpatchset
cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/884?usp=email )
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.
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg30748.html
---
M src/openvpn/networking_iproute2.c
M src/openvpn/networking_sitnl.c
2 files changed, 8 insertions(+), 55 deletions(-)
src/openvpn/networking_iproute2.c +5 -53
@@ -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 ] ='\0' ; - -FILE *fp =fopen ("/proc/net/route" ,"r" ); -if (!fp) - { -return -1 ; - } - -char line[256 ]; -int count =0 ; -unsigned int lowest_metric =UINT_MAX ; -while (fgets (line,sizeof (line), fp) !=NULL ) - { -if (count) - { -unsigned int net_x =0 ; -unsigned int mask_x =0 ; -unsigned int gw_x =0 ; -unsigned int metric =0 ; -unsigned int flags =0 ; -char name[16 ]; - name[0 ] ='\0' ; - -const int np =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 ==6 && (flags &IFF_UP )) - { -const in_addr_t net =ntohl (net_x); -const in_addr_t mask =ntohl (mask_x); -const in_addr_t gw =ntohl (gw_x); - -if (!net && !mask && metric < lowest_metric) - { - *best_gw = gw; -strcpy (best_iface, name); - lowest_metric = 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) */
src/openvpn/networking_sitnl.c +3 -2
@@ -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=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6f17140109106b37e6b0e690df1d87720ccf6f91
Gerrit-Change-Number: 884
Gerrit-PatchSet: 3
Gerrit-Owner: cron2 <[email protected]...>
Gerrit-Reviewer: flichtenheld <[email protected]...>
Gerrit-Reviewer: ordex <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-MessageType: merged