]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: generalize imported peer in bgp best selection function
authorPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 24 Feb 2023 13:19:06 +0000 (14:19 +0100)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Tue, 28 Feb 2023 21:00:25 +0000 (22:00 +0100)
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>
bgpd/bgp_route.c

index 92e7ee56687c70ea640f1557a832a1c638afb0b1..f9028422eb10b0f43196cd54ca5910132abda59f 100644 (file)
@@ -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);