summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_zebra.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_zebra.c')
-rw-r--r--bgpd/bgp_zebra.c58
1 files changed, 24 insertions, 34 deletions
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 49380cc3..d4f95745 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -432,6 +432,28 @@ if_lookup_by_ipv4_exact (struct in_addr *addr)
return NULL;
}
+static int
+if_get_ipv4 (struct interface *ifp, struct in_addr *addr)
+{
+ struct listnode *cnode;
+ struct connected *connected;
+ struct prefix *cp;
+ int hit = 0;
+
+ for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
+ {
+ cp = connected->address;
+
+ if (cp->family == AF_INET)
+ if (!hit || ntohl(cp->u.prefix4.s_addr) < ntohl(addr->s_addr))
+ {
+ memcpy (addr, &cp->u.prefix4, IPV4_MAX_BYTELEN);
+ hit = 1;
+ }
+ }
+ return hit;
+}
+
#ifdef HAVE_IPV6
struct interface *
if_lookup_by_ipv6 (struct in6_addr *addr)
@@ -586,7 +608,8 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
struct interface *direct = NULL;
/* IPv4 nexthop. I don't care about it. */
- if (peer->local_id.s_addr)
+ ret = if_get_ipv4 (ifp, &nexthop->v4);
+ if (!ret && peer->local_id.s_addr)
nexthop->v4 = peer->local_id;
/* Global address*/
@@ -639,39 +662,6 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
return ret;
}
-#ifdef HAVE_IPV6
-static unsigned int
-bgp_ifindex_by_nexthop (struct in6_addr *addr)
-{
- struct listnode *ifnode;
- struct listnode *cnode;
- struct interface *ifp;
- struct connected *connected;
- struct prefix_ipv6 p;
-
- p.family = AF_INET6;
- p.prefix = *addr;
- p.prefixlen = IPV6_MAX_BITLEN;
-
- for (ALL_LIST_ELEMENTS_RO (iflist, ifnode, ifp))
- {
- for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, connected))
- {
- struct prefix *cp;
-
- cp = connected->address;
-
- if (cp->family == AF_INET6)
- {
- if (prefix_match (cp, (struct prefix *)&p))
- return ifp->ifindex;
- }
- }
- }
- return 0;
-}
-#endif /* HAVE_IPV6 */
-
void
bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp)
{