diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2023-02-24 14:19:06 +0100 |
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2023-02-28 22:00:25 +0100 |
| commit | 8cd3d07097a50c3e9282d293928c82c11a15ce60 (patch) | |
| tree | 269f5431cbf4be056f6d3699da903f824c785610 | |
| parent | 516444e6b17c0043e7abe88ce6587d7dd37ed5e5 (diff) | |
bgpd: generalize imported peer in bgp best selection function
The bgp_path_info_cmp() function needs to get the peer of
imported prefixes in many parts of the algorithm. Use two
local variables to get the original peer either for vpn
imported prefixes or from standard prefixes.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
| -rw-r--r-- | bgpd/bgp_route.c | 44 |
1 files changed, 24 insertions, 20 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 92e7ee5668..f9028422eb 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1082,9 +1082,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 +1151,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 +1249,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 +1259,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 +1339,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 +1410,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); |
