diff options
author | David Lamparter <equinox@opensourcerouting.org> | 2017-05-30 16:14:42 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2017-09-12 16:05:07 +0200 |
commit | 25b9cb0cc834df7966338f76746e90bca8586161 (patch) | |
tree | 4ecaf2667b187f715aec7574bbd9e3f5dd0d310a /lib/nexthop.c | |
parent | Merge pull request #1154 from donaldsharp/bgp_aspath (diff) | |
download | frr-25b9cb0cc834df7966338f76746e90bca8586161.tar.xz frr-25b9cb0cc834df7966338f76746e90bca8586161.zip |
zebra: deduplicate nexthops
There exists situations where it is possible to have duplicate
nexthops passed from a higher level protocol into zebra.
This code notices this duplication of nexthops and marks
the duplicates as DUPLICATE so we don't attempt to install
it into the kernel.
This is important on *BSD as I understand it because passing
duplicate nexthops will cause the route to be rejected.
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'lib/nexthop.c')
-rw-r--r-- | lib/nexthop.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/nexthop.c b/lib/nexthop.c index 2dba412f4..ea6a310a4 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -71,6 +71,39 @@ int nexthop_same_no_recurse(const struct nexthop *next1, return 1; } +int +nexthop_same_firsthop (struct nexthop *next1, struct nexthop *next2) +{ + int type1 = NEXTHOP_FIRSTHOPTYPE(next1->type); + int type2 = NEXTHOP_FIRSTHOPTYPE(next2->type); + + if (type1 != type2) + return 0; + switch (type1) + { + case NEXTHOP_TYPE_IPV4_IFINDEX: + if (! IPV4_ADDR_SAME (&next1->gate.ipv4, &next2->gate.ipv4)) + return 0; + if (next1->ifindex != next2->ifindex) + return 0; + break; + case NEXTHOP_TYPE_IFINDEX: + if (next1->ifindex != next2->ifindex) + return 0; + break; + case NEXTHOP_TYPE_IPV6_IFINDEX: + if (! IPV6_ADDR_SAME (&next1->gate.ipv6, &next2->gate.ipv6)) + return 0; + if (next1->ifindex != next2->ifindex) + return 0; + break; + default: + /* do nothing */ + break; + } + return 1; +} + /* * nexthop_type_to_str */ |