diff options
-rw-r--r-- | bgpd/bgp_route.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 92e7ee566..1e9f9429c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -515,11 +515,19 @@ static uint32_t bgp_med_value(struct attr *attr, struct bgp *bgp) void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi, char *buf, size_t buf_len) { + struct peer *peer; + + if (pi->sub_type == BGP_ROUTE_IMPORTED && + bgp_get_imported_bpi_ultimate(pi)) + peer = bgp_get_imported_bpi_ultimate(pi)->peer; + else + peer = pi->peer; + if (pi->addpath_rx_id) - snprintf(buf, buf_len, "path %s (addpath rxid %d)", - pi->peer->host, pi->addpath_rx_id); + snprintf(buf, buf_len, "path %s (addpath rxid %d)", peer->host, + pi->addpath_rx_id); else - snprintf(buf, buf_len, "path %s", pi->peer->host); + snprintf(buf, buf_len, "path %s", peer->host); } @@ -1082,9 +1090,21 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, } } + if (exist->sub_type == BGP_ROUTE_IMPORTED) { + bpi_ultimate = bgp_get_imported_bpi_ultimate(exist); + peer_exist = bpi_ultimate->peer; + } else + peer_exist = exist->peer; + + if (new->sub_type == BGP_ROUTE_IMPORTED) { + bpi_ultimate = bgp_get_imported_bpi_ultimate(new); + peer_new = bpi_ultimate->peer; + } else + peer_new = new->peer; + /* 7. Peer type check. */ - new_sort = new->peer->sort; - exist_sort = exist->peer->sort; + new_sort = peer_new->sort; + exist_sort = peer_exist->sort; if (new_sort == BGP_PEER_EBGP && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED)) { @@ -1139,8 +1159,8 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, pair (newm, existm) with the cluster list length. Prefer the path with smaller cluster list length. */ if (newm == existm) { - if (peer_sort_lookup(new->peer) == BGP_PEER_IBGP && - peer_sort_lookup(exist->peer) == BGP_PEER_IBGP && + if (peer_sort_lookup(peer_new) == BGP_PEER_IBGP && + peer_sort_lookup(peer_exist) == BGP_PEER_IBGP && (mpath_cfg == NULL || mpath_cfg->same_clusterlen)) { newm = BGP_CLUSTER_LIST_LENGTH(new->attr); existm = BGP_CLUSTER_LIST_LENGTH(exist->attr); @@ -1237,7 +1257,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, zlog_debug( "%s: %s and %s are equal via multipath-relax", pfx_buf, new_buf, exist_buf); - } else if (new->peer->sort == BGP_PEER_IBGP) { + } else if (peer_new->sort == BGP_PEER_IBGP) { if (aspath_cmp(new->attr->aspath, exist->attr->aspath)) { *paths_eq = 1; @@ -1247,7 +1267,7 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, "%s: %s and %s are equal via matching aspaths", pfx_buf, new_buf, exist_buf); } - } else if (new->peer->as == exist->peer->as) { + } else if (peer_new->as == peer_exist->as) { *paths_eq = 1; if (debug) @@ -1327,11 +1347,11 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) new_id.s_addr = newattr->originator_id.s_addr; else - new_id.s_addr = new->peer->remote_id.s_addr; + new_id.s_addr = peer_new->remote_id.s_addr; if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) exist_id.s_addr = existattr->originator_id.s_addr; else - exist_id.s_addr = exist->peer->remote_id.s_addr; + exist_id.s_addr = peer_exist->remote_id.s_addr; if (ntohl(new_id.s_addr) < ntohl(exist_id.s_addr)) { *reason = bgp_path_selection_router_id; @@ -1398,23 +1418,15 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, } /* locally configured routes to advertise do not have su_remote */ - if (new->sub_type == BGP_ROUTE_IMPORTED) { - bpi_ultimate = bgp_get_imported_bpi_ultimate(new); - peer_new = bpi_ultimate->peer; - } else if (new->peer->su_remote == NULL) { + if (peer_new->su_remote == NULL) { *reason = bgp_path_selection_local_configured; return 0; - } else - peer_new = new->peer; + } - if (exist->sub_type == BGP_ROUTE_IMPORTED) { - bpi_ultimate = bgp_get_imported_bpi_ultimate(exist); - peer_exist = bpi_ultimate->peer; - } else if (exist->peer->su_remote == NULL) { + if (peer_exist->su_remote == NULL) { *reason = bgp_path_selection_local_configured; return 1; - } else - peer_exist = exist->peer; + } ret = sockunion_cmp(peer_new->su_remote, peer_exist->su_remote); |