]> git.proxmox.com Git - mirror_frr.git/blobdiff - babeld/kernel.c
Merge pull request #12795 from pguibert6WIND/vpnv6_nexthop_encoding
[mirror_frr.git] / babeld / kernel.c
index 8b1b80665c5afdb768138482f32ceccf6460f43c..f89fe268df370d362fbab054fda02eddc544666f 100644 (file)
@@ -1,26 +1,13 @@
+// SPDX-License-Identifier: MIT
 /*
 Copyright 2007, 2008 by GrĂ©goire Henry, Julien Cristau and Juliusz Chroboczek
 Copyright 2011, 2012 by Matthieu Boutier and Juliusz Chroboczek
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
 */
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #include <sys/time.h>
 #include <sys/param.h>
 #include <time.h>
@@ -73,9 +60,9 @@ kernel_interface_wireless(struct interface *interface)
 }
 
 int
-kernel_route(int operation, const unsigned char *pref, unsigned short plen,
-             const unsigned char *gate, int ifindex, unsigned int metric,
-             const unsigned char *newgate, int newifindex,
+kernel_route(enum babel_kernel_routes operation, const unsigned char *pref,
+            unsigned short plen, const unsigned char *gate, int ifindex,
+            unsigned int metric, const unsigned char *newgate, int newifindex,
              unsigned int newmetric)
 {
     int rc;
@@ -99,10 +86,8 @@ kernel_route(int operation, const unsigned char *pref, unsigned short plen,
     switch (operation) {
         case ROUTE_ADD:
             return zebra_route(1, family, pref, plen, gate, ifindex, metric);
-            break;
         case ROUTE_FLUSH:
             return zebra_route(0, family, pref, plen, gate, ifindex, metric);
-            break;
         case ROUTE_MODIFY:
             if(newmetric == metric && memcmp(newgate, gate, 16) == 0 &&
                newifindex == ifindex)
@@ -115,13 +100,9 @@ kernel_route(int operation, const unsigned char *pref, unsigned short plen,
             rc = zebra_route(1, family, pref, plen, newgate, newifindex,
                              newmetric);
             return rc;
-            break;
-        default:
-            zlog_err("this should never happen (false value - kernel_route)");
-            assert(0);
-            exit(1);
-            break;
     }
+
+    return 0;
 }
 
 static int
@@ -178,11 +159,11 @@ zebra_route(int add, int family, const unsigned char *pref, unsigned short plen,
        switch (family) {
         case AF_INET:
             uchar_to_inaddr(&api_nh->gate.ipv4, gate);
-            if (IPV4_ADDR_SAME (&api_nh->gate.ipv4, &quagga_prefix.u.prefix4) &&
-                    quagga_prefix.prefixlen == 32) {
-                api_nh->type = NEXTHOP_TYPE_IFINDEX;
-            } else {
-                api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
+           if (IPV4_ADDR_SAME(&api_nh->gate.ipv4, &quagga_prefix.u.prefix4)
+               && quagga_prefix.prefixlen == IPV4_MAX_BITLEN) {
+                   api_nh->type = NEXTHOP_TYPE_IFINDEX;
+           } else {
+                   api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX;
             }
             break;
         case AF_INET6:
@@ -210,7 +191,7 @@ if_eui64(int ifindex, unsigned char *eui)
         return -1;
     }
 
-    u_char len = (u_char) ifp->hw_addr_len;
+    uint8_t len = (uint8_t)ifp->hw_addr_len;
     char *tmp = (void*) ifp->hw_addr;
 
     if (len == 8) {
@@ -229,10 +210,10 @@ if_eui64(int ifindex, unsigned char *eui)
 
 /* Like gettimeofday, but returns monotonic time.  If POSIX clocks are not
    available, falls back to gettimeofday but enforces monotonicity. */
-int
+void
 gettime(struct timeval *tv)
 {
-    return monotime(tv);
+    monotime(tv);
 }
 
 /* If /dev/urandom doesn't exist, this will fail with ENOENT, which the