Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2129?usp=email

to review the following change.


Change subject: route: remove never-returned LR_ERROR
......................................................................

route: remove never-returned LR_ERROR

local_route() has never returned LR_ERROR since it was added in
7fb0e07e ("Added redirect-gateway block-local flag, ..."), so the
checks in add_route() and delete_route() were dead. They were also the
only readers of is_local_route on most platforms, so let is_on_link()
call local_route() itself and drop the variable and the unused done
labels.

Change-Id: I1a36c382af05c8db6d342b9bdfb2dc0aae2d10df
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpn/route.c
1 file changed, 7 insertions(+), 21 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/29/2129/1

diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index 53550c4..0ab9f6d 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1403,7 +1403,6 @@
 /* local_route() return values */
 #define LR_NOMATCH 0 /* route is not local */
 #define LR_MATCH   1 /* route is local */
-#define LR_ERROR   2 /* caller should abort adding route */

 static int
 local_route(in_addr_t network, in_addr_t netmask, in_addr_t gateway,
@@ -1438,10 +1437,11 @@
  * a route is specified as an interface rather than an address. */
 #if defined(TARGET_LINUX) || defined(_WIN32) || defined(TARGET_DARWIN)
 static inline bool
-is_on_link(const int is_local_route, const unsigned int flags, const struct 
route_gateway_info *rgi)
+is_on_link(const struct route_ipv4 *r, const unsigned int flags,
+           const struct route_gateway_info *rgi)
 {
     return rgi
-           && (is_local_route == LR_MATCH
+           && (local_route(r->network, r->netmask, r->gateway, rgi) == LR_MATCH
                || ((flags & ROUTE_REF_GW) && (rgi->flags & RGI_ON_LINK)));
 }
 #endif
@@ -1452,7 +1452,6 @@
           const struct env_set *es, openvpn_net_ctx_t *ctx)
 {
     int status = 0;
-    int is_local_route;

     if (!(r->flags & RT_DEFINED))
     {
@@ -1470,17 +1469,12 @@
     const char *gateway = print_in_addr_t(r->gateway, 0, &gc);
 #endif

-    is_local_route = local_route(r->network, r->netmask, r->gateway, rgi);
-    if (is_local_route == LR_ERROR)
-    {
-        goto done;
-    }

 #if defined(TARGET_LINUX)
     const char *iface = NULL;
     int metric = -1;

-    if (is_on_link(is_local_route, flags, rgi))
+    if (is_on_link(r, flags, rgi))
     {
         iface = rgi->iface;
     }
@@ -1528,7 +1522,7 @@
         {
             argv_printf_cat(&argv, "METRIC %d", r->metric);
         }
-        if (is_on_link(is_local_route, flags, rgi))
+        if (is_on_link(r, flags, rgi))
         {
             ai = rgi->adapter_index;
             argv_printf_cat(&argv, "IF %lu", ai);
@@ -1654,7 +1648,7 @@
     }
 #endif

-    if (is_on_link(is_local_route, flags, rgi))
+    if (is_on_link(r, flags, rgi))
     {
         /* Mac OS X route syntax for ON_LINK:
          * route add -cloning -net 10.10.0.1 -netmask 255.255.255.255 
-interface en0 */
@@ -1713,7 +1707,6 @@
         "Sorry, but I don't know how to do 'route' commands on this operating 
system.  Try putting your routes in a --route-up script");
 #endif /* if defined(TARGET_LINUX) */

-done:
     if (status == RTA_SUCCESS)
     {
         r->flags |= RT_ADDED;
@@ -2004,7 +1997,6 @@
 #else /* if !defined(TARGET_LINUX) */
     int metric;
 #endif
-    int is_local_route;

     if ((r->flags & (RT_DEFINED | RT_ADDED)) != (RT_DEFINED | RT_ADDED))
     {
@@ -2022,11 +2014,6 @@
     gateway = print_in_addr_t(r->gateway, 0, &gc);
 #endif

-    is_local_route = local_route(r->network, r->netmask, r->gateway, rgi);
-    if (is_local_route == LR_ERROR)
-    {
-        goto done;
-    }

 #if defined(TARGET_LINUX)
     metric = -1;
@@ -2105,7 +2092,7 @@

 #elif defined(TARGET_DARWIN)

-    if (is_on_link(is_local_route, flags, rgi))
+    if (is_on_link(r, flags, rgi))
     {
         argv_printf(&argv, "%s delete -cloning -net %s -netmask %s -interface 
%s", ROUTE_PATH,
                     network, netmask, rgi->iface);
@@ -2155,7 +2142,6 @@
         "Sorry, but I don't know how to do 'route' commands on this operating 
system.  Try putting your routes in a --route-up script");
 #endif /* if defined(TARGET_LINUX) */

-done:
     r->flags &= ~RT_ADDED;
     argv_free(&argv);
     gc_free(&gc);

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2129?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I1a36c382af05c8db6d342b9bdfb2dc0aae2d10df
Gerrit-Change-Number: 2129
Gerrit-PatchSet: 1
Gerrit-Owner: Răzvan Cojocaru <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel
  • [Openvpn-devel] [S] Chan... Code Review

Reply via email to