]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/nexthop.c
zebra, lib: fix the ZEBRA_INTERFACE_VRF_UPDATE zapi message
[mirror_frr.git] / lib / nexthop.c
index cee34e85c72ff17b3caf1095bd2b88ad53ef625d..d25b470277b40167b6064a8a4719f145c555072c 100644 (file)
@@ -31,6 +31,7 @@
 #include "prefix.h"
 #include "nexthop.h"
 #include "mpls.h"
+#include "jhash.h"
 
 DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop")
 DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label")
@@ -163,9 +164,60 @@ void nexthops_free(struct nexthop *nexthop)
        }
 }
 
+bool nexthop_same(const struct nexthop *nh1, const struct nexthop *nh2)
+{
+       if (nh1 && !nh2)
+               return false;
+
+       if (!nh1 && nh2)
+               return false;
+
+       if (nh1 == nh2)
+               return true;
+
+       if (nh1->vrf_id != nh2->vrf_id)
+               return false;
+
+       if (nh1->type != nh2->type)
+               return false;
+
+       switch (nh1->type) {
+       case NEXTHOP_TYPE_IFINDEX:
+               if (nh1->ifindex != nh2->ifindex)
+                       return false;
+               break;
+       case NEXTHOP_TYPE_IPV4:
+               if (nh1->gate.ipv4.s_addr != nh2->gate.ipv4.s_addr)
+                       return false;
+               break;
+       case NEXTHOP_TYPE_IPV4_IFINDEX:
+               if (nh1->gate.ipv4.s_addr != nh2->gate.ipv4.s_addr)
+                       return false;
+               if (nh1->ifindex != nh2->ifindex)
+                       return false;
+               break;
+       case NEXTHOP_TYPE_IPV6:
+               if (memcmp(&nh1->gate.ipv6, &nh2->gate.ipv6, 16))
+                       return false;
+               break;
+       case NEXTHOP_TYPE_IPV6_IFINDEX:
+               if (memcmp(&nh1->gate.ipv6, &nh2->gate.ipv6, 16))
+                       return false;
+               if (nh1->ifindex != nh2->ifindex)
+                       return false;
+               break;
+       case NEXTHOP_TYPE_BLACKHOLE:
+               if (nh1->bh_type != nh2->bh_type)
+                       return false;
+               break;
+       }
+
+       return true;
+}
+
 /* Update nexthop with label information. */
 void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t type,
-                       u_int8_t num_labels, mpls_label_t *label)
+                       uint8_t num_labels, mpls_label_t *label)
 {
        struct mpls_label_stack *nh_label;
        int i;
@@ -189,22 +241,18 @@ void nexthop_del_labels(struct nexthop *nexthop)
        }
 }
 
-const char *nexthop2str(struct nexthop *nexthop, char *str, int size)
+const char *nexthop2str(const struct nexthop *nexthop, char *str, int size)
 {
        switch (nexthop->type) {
        case NEXTHOP_TYPE_IFINDEX:
                snprintf(str, size, "if %u", nexthop->ifindex);
                break;
        case NEXTHOP_TYPE_IPV4:
-               snprintf(str, size, "%s", inet_ntoa(nexthop->gate.ipv4));
-               break;
        case NEXTHOP_TYPE_IPV4_IFINDEX:
                snprintf(str, size, "%s if %u", inet_ntoa(nexthop->gate.ipv4),
                         nexthop->ifindex);
                break;
        case NEXTHOP_TYPE_IPV6:
-               snprintf(str, size, "%s", inet6_ntoa(nexthop->gate.ipv6));
-               break;
        case NEXTHOP_TYPE_IPV6_IFINDEX:
                snprintf(str, size, "%s if %u", inet6_ntoa(nexthop->gate.ipv6),
                         nexthop->ifindex);
@@ -259,3 +307,15 @@ unsigned int nexthop_level(struct nexthop *nexthop)
 
        return rv;
 }
+
+uint32_t nexthop_hash(struct nexthop *nexthop)
+{
+       uint32_t key;
+
+       key = jhash_1word(nexthop->vrf_id, 0x45afe398);
+       key = jhash_1word(nexthop->ifindex, key);
+       key = jhash_1word(nexthop->type, key);
+       key = jhash(&nexthop->gate, sizeof(union g_addr), key);
+
+       return key;
+}