From 801bb996a4837690e303a8c93aa7bc085079cc62 Mon Sep 17 00:00:00 2001 From: Chirag Shah Date: Tue, 1 Dec 2020 16:02:36 -0800 Subject: [PATCH] bgpd: fix distance for aggregate route bgp aggregate address installs route with self peer which can have peer->su of unspecifed type. bgp_distance_apply bailed out as it fails to parse sockunion2hostprefix for af type unspec. config: address-family ipv4 unicast aggregate-address 50.1.0.0/16 summary-only Testing Done: Before: B>* 50.1.0.0/16 [20/0] unreachable (blackhole), weight 1, 00:00:02 After: B>* 50.1.0.0/16 [200/0] unreachable (blackhole), weight 1, 00:01:28 Signed-off-by: Chirag Shah --- bgpd/bgp_route.c | 9 ++++++--- bgpd/bgp_zebra.c | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index a13d52b4c9..a1cf6ac3e8 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -13702,7 +13702,7 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, afi_t afi, safi_t safi, struct bgp *bgp) { struct bgp_dest *dest; - struct prefix q; + struct prefix q = {0}; struct peer *peer; struct bgp_distance *bdistance; struct access_list *alist; @@ -13716,8 +13716,11 @@ uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, if (pinfo->attr->distance) return pinfo->attr->distance; - /* Check source address. */ - if (!sockunion2hostprefix(&peer->su, &q)) + /* Check source address. + * Note: for aggregate route, peer can have unspec af type. + */ + if (pinfo->sub_type != BGP_ROUTE_AGGREGATE + && !sockunion2hostprefix(&peer->su, &q)) return 0; dest = bgp_node_match(bgp_distance_table[afi][safi], &q); diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 8d07e050f8..8c85725bdc 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -526,10 +526,10 @@ static int zebra_read_route(ZAPI_CALLBACK_ARGS) inet_ntop(api.prefix.family, &nexthop, buf, sizeof(buf)); zlog_debug( - "Rx route ADD VRF %u %s[%d] %pFX nexthop %s (type %d if %u) metric %u tag %" ROUTE_TAG_PRI, + "Rx route ADD VRF %u %s[%d] %pFX nexthop %s (type %d if %u) metric %u distance %u tag %" ROUTE_TAG_PRI, vrf_id, zebra_route_string(api.type), api.instance, &api.prefix, buf, nhtype, ifindex, - api.metric, api.tag); + api.metric, api.distance, api.tag); } else { zlog_debug("Rx route DEL VRF %u %s[%d] %pFX", vrf_id, zebra_route_string(api.type), api.instance,