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/+/2153?usp=email

to review the following change.


Change subject: networking_freebsd: fix route command and return value details
......................................................................

networking_freebsd: fix route command and return value details

- Return -1 on failure, as networking.h documents, instead of 1.
- Pass -fib only for a non-zero table. Without it, route(8) uses the
  FIB of the process, like the route commands in route.c.
- Add the interface as scope to link-local IPv6 gateways.
- Use "delete" and "-inet6", as route.c does.

All current callers (DCO iroutes) ignore the return value.

Change-Id: I3e6043178935fdd05e6ea78c411dac5decb7ac64
Signed-off-by: Razvan Cojocaru <[email protected]>
---
M src/openvpn/networking_freebsd.c
1 file changed, 27 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/53/2153/1

diff --git a/src/openvpn/networking_freebsd.c b/src/openvpn/networking_freebsd.c
index 88fd5c0..e3697d4 100644
--- a/src/openvpn/networking_freebsd.c
+++ b/src/openvpn/networking_freebsd.c
@@ -24,18 +24,21 @@
      * if not, install "connected" route to interface
      * (needed to make 'ifconfig-push IPs outside server subnet' work)
      */
+    argv_printf(&argv, "%s %s -net %s/%d", ROUTE_PATH, op,
+                inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen);
     if (gw)
     {
         _gw = ntohl(*gw);
-        argv_printf(&argv, "%s %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                    inet_ntop(AF_INET, &_gw, buf2, sizeof(buf2)), table);
+        argv_printf_cat(&argv, "%s", inet_ntop(AF_INET, &_gw, buf2, 
sizeof(buf2)));
     }
     else
     {
-        argv_printf(&argv, "%s %s -net %s/%d -iface %s -fib %d", ROUTE_PATH, 
op,
-                    inet_ntop(AF_INET, &_dst, buf1, sizeof(buf1)), prefixlen,
-                    iface, table);
+        argv_printf_cat(&argv, "-iface %s", iface);
+    }
+    /* without -fib, route(8) uses the FIB of the process */
+    if (table)
+    {
+        argv_printf_cat(&argv, "-fib %u", table);
     }

     argv_msg(M_INFO, &argv);
@@ -43,7 +46,7 @@

     argv_free(&argv);

-    return (!status);
+    return status ? 0 : -1;
 }

 static int
@@ -59,26 +62,32 @@
      * if not, install "connected" route to interface
      * (needed to make 'ifconfig-push IPs outside server subnet' work)
      */
-    if (gw)
+    argv_printf(&argv, "%s %s -inet6 %s/%d", ROUTE_PATH, op,
+                inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen);
+    if (gw && iface && IN6_IS_ADDR_LINKLOCAL(gw))
     {
-        argv_printf(&argv, "%s -6 %s -net %s/%d %s -fib %d", ROUTE_PATH, op,
-                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                    inet_ntop(AF_INET6, gw, buf2, sizeof(buf2)), table);
+        /* a link-local gateway needs the interface as scope */
+        argv_printf_cat(&argv, "%s%%%s", inet_ntop(AF_INET6, gw, buf2, 
sizeof(buf2)), iface);
+    }
+    else if (gw)
+    {
+        argv_printf_cat(&argv, "%s", inet_ntop(AF_INET6, gw, buf2, 
sizeof(buf2)));
     }
     else
     {
-        argv_printf(&argv, "%s -6 %s -net %s/%d -iface %s -fib %d", 
ROUTE_PATH, op,
-                    inet_ntop(AF_INET6, dst, buf1, sizeof(buf1)), prefixlen,
-                    iface, table);
+        argv_printf_cat(&argv, "-iface %s", iface);
     }
-
+    if (table)
+    {
+        argv_printf_cat(&argv, "-fib %u", table);
+    }
 
     argv_msg(M_INFO, &argv);
     bool status = openvpn_execve_check(&argv, NULL, 0, "ERROR: FreeBSD route 
command failed");

     argv_free(&argv);

-    return (!status);
+    return status ? 0 : -1;
 }

 int
@@ -99,14 +108,14 @@
 net_route_v4_del(const openvpn_net_ctx_t *ctx, const in_addr_t *dst, int 
prefixlen, const in_addr_t *gw,
                  const char *iface, uint32_t table, int metric)
 {
-    return net_route_v4("del", dst, prefixlen, gw, iface, table, metric);
+    return net_route_v4("delete", dst, prefixlen, gw, iface, table, metric);
 }

 int
 net_route_v6_del(const openvpn_net_ctx_t *ctx, const struct in6_addr *dst, int 
prefixlen,
                  const struct in6_addr *gw, const char *iface, uint32_t table, 
int metric)
 {
-    return net_route_v6("del", dst, prefixlen, gw, iface, table, metric);
+    return net_route_v6("delete", dst, prefixlen, gw, iface, table, metric);
 }

 #endif /* if defined(TARGET_FREEBSD) */

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2153?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: I3e6043178935fdd05e6ea78c411dac5decb7ac64
Gerrit-Change-Number: 2153
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

Reply via email to