Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Deduce nexthop ifindex for ipv6 when ifindex points to 'lo' (#42)
Browse files Browse the repository at this point in the history
* Deduce nexthop ifindex for ipv6 when bgpd decided to use loopback interface
  • Loading branch information
pavel-shirshov authored Jul 14, 2020
1 parent e3b3b63 commit 12a9c58
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,17 @@ bgp_nexthop_set (union sockunion *local, union sockunion *remote,
return ret;
}

static unsigned int
bgp_zebra_ifindex_by_ipv6(struct in6_addr *addr)
{
struct interface *ifp;
ifp = if_lookup_by_ipv6(addr);
if (ifp)
return ifp->ifindex;
else
return IFINDEX_INTERNAL;
}

void
bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, safi_t safi)
{
Expand Down Expand Up @@ -829,6 +840,22 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
else if (info->peer->nexthop.ifp)
ifindex = info->peer->nexthop.ifp->ifindex;
}

if (strcmp (ifindex2ifname (ifindex), "lo") == 0)
{
/* it doesn't make sense to send a traffic to lo interface */
ifindex = bgp_zebra_ifindex_by_ipv6 (nexthop);
if (ifindex == IFINDEX_INTERNAL)
{
char prefix_buf[INET6_ADDRSTRLEN];
char nexthop_buf[INET6_ADDRSTRLEN];
zlog_err ("Prefix '%s/%d' nexthop '%s'. Can't find nexthop ifindex.",
inet_ntop(AF_INET6, &p->u.prefix6, prefix_buf, sizeof(prefix_buf)),
p->prefixlen,
inet_ntop(AF_INET6, nexthop, nexthop_buf, sizeof(nexthop_buf)));
return;
}
}
stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in6_addr *));
stream_put (bgp_ifindices_buf, &ifindex, sizeof (unsigned int));
valid_nh_count++;
Expand Down Expand Up @@ -882,7 +909,21 @@ bgp_zebra_announce (struct prefix *p, struct bgp_info *info, struct bgp *bgp, sa
{
continue;
}

if (strcmp (ifindex2ifname (ifindex), "lo") == 0)
{
/* it doesn't make sense to send a traffic to lo interface */
ifindex = bgp_zebra_ifindex_by_ipv6 (nexthop);
if (ifindex == IFINDEX_INTERNAL)
{
char prefix_buf[INET6_ADDRSTRLEN];
char nexthop_buf[INET6_ADDRSTRLEN];
zlog_err ("Prefix '%s/%d' nexthop '%s'. Can't find nexthop ifindex.",
inet_ntop(AF_INET6, &p->u.prefix6, prefix_buf, sizeof(prefix_buf)),
p->prefixlen,
inet_ntop(AF_INET6, nexthop, nexthop_buf, sizeof(nexthop_buf)));
continue;
}
}
stream_put (bgp_nexthop_buf, &nexthop, sizeof (struct in6_addr *));
stream_put (bgp_ifindices_buf, &ifindex, sizeof (unsigned int));
valid_nh_count++;
Expand Down

0 comments on commit 12a9c58

Please sign in to comment.