bgpd: Make source interface selection in BGP for nexthop determination more robust
Ensure that if 'update-source <interface>' is specified, that interface is
chosen as the source for the local nexthops. Otherwise, do a complete
match on the local IP address of the connection to determine the source
interface for the local nexthops; this will handle scenarios where there
is an overlap of subnets between interfaces (e.g., loopback and another
interface).
Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index be17d23..b9e8a5c 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -576,7 +576,10 @@
if (local->sa.sa_family == AF_INET)
{
nexthop->v4 = local->sin.sin_addr;
- ifp = if_lookup_by_ipv4 (&local->sin.sin_addr);
+ if (peer->update_if)
+ ifp = if_lookup_by_name (peer->update_if);
+ else
+ ifp = if_lookup_by_ipv4_exact (&local->sin.sin_addr);
}
if (local->sa.sa_family == AF_INET6)
{
@@ -585,8 +588,10 @@
if (peer->ifname)
ifp = if_lookup_by_name (peer->ifname);
}
+ else if (peer->update_if)
+ ifp = if_lookup_by_name (peer->update_if);
else
- ifp = if_lookup_by_ipv6 (&local->sin6.sin6_addr);
+ ifp = if_lookup_by_ipv6_exact (&local->sin6.sin6_addr);
}
if (!ifp)