bgpd: Show hostname in show [ip] bgp ... only if nexthop is connected

The problem is when using kinda such topologies:
(192.168.1.1/32) r1 <-- eBGP --> r2 <-- iBGP --> r3

Looking at r3's nexthop for 192.168.1.1/32 we have it as r2, but really
it MUST be r1.

Checking if the nexthop is connected solves the problem even for cases
when route-reflectors are used.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2020-04-16 10:36:59 +03:00
parent ee215461ac
commit 2ba93fd65b

View File

@ -7540,11 +7540,12 @@ static void route_vty_short_status_out(struct vty *vty,
vty_out(vty, " ");
}
static char *bgp_nexthop_hostname(struct peer *peer, struct attr *attr)
static char *bgp_nexthop_hostname(struct peer *peer,
struct bgp_nexthop_cache *bnc)
{
if (peer->hostname
&& CHECK_FLAG(peer->bgp->flags, BGP_FLAG_SHOW_HOSTNAME)
&& !(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
&& CHECK_FLAG(bnc->flags, BGP_NEXTHOP_CONNECTED))
return peer->hostname;
return NULL;
}
@ -7566,7 +7567,8 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
bool nexthop_othervrf = false;
vrf_id_t nexthop_vrfid = VRF_DEFAULT;
const char *nexthop_vrfname = VRF_DEFAULT_NAME;
char *nexthop_hostname = bgp_nexthop_hostname(path->peer, attr);
char *nexthop_hostname =
bgp_nexthop_hostname(path->peer, path->nexthop);
if (json_paths)
json_path = json_object_new_object();
@ -8637,7 +8639,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
bool nexthop_self =
CHECK_FLAG(path->flags, BGP_PATH_ANNC_NH_SELF) ? true : false;
int i;
char *nexthop_hostname = bgp_nexthop_hostname(path->peer, attr);
char *nexthop_hostname =
bgp_nexthop_hostname(path->peer, path->nexthop);
if (json_paths) {
json_path = json_object_new_object();