From 2ba93fd65bb0d9942109a5fda925f0a90bff4442 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Thu, 16 Apr 2020 10:36:59 +0300 Subject: [PATCH] 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 --- bgpd/bgp_route.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d5f903f6e2..fc6b4ce7f9 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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();