summaryrefslogtreecommitdiff
path: root/lib/nexthop.c
diff options
context:
space:
mode:
authorpaulzlabn <paulz@labn.net>2018-03-14 13:31:58 -0700
committerGitHub <noreply@github.com>2018-03-14 13:31:58 -0700
commit3f1224cd1a9408bdad6aca8c0c205211cb548d5c (patch)
tree87e6a52a3e7ad7b09caa3207f081fd92bc8fd018 /lib/nexthop.c
parentfd9b55a2b77c187730600d429b3f290ab58fa035 (diff)
parent6ca96cc6ada990d052fcfc48cffeef454ae64a10 (diff)
Merge branch 'master' into working/master/bgp-vpn-vrf-leaking
Diffstat (limited to 'lib/nexthop.c')
-rw-r--r--lib/nexthop.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c
index cee34e85c7..fb7ccc169e 100644
--- a/lib/nexthop.c
+++ b/lib/nexthop.c
@@ -163,6 +163,57 @@ 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)