]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: compare aigp after local route check in bgp_path_info_cmp() 17234/head
authorEnke Chen <enchen@paloaltonetworks.com>
Thu, 24 Oct 2024 17:50:37 +0000 (10:50 -0700)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Fri, 25 Oct 2024 07:00:48 +0000 (07:00 +0000)
For consistency between RIB and BGP, the aigp comparison should
be made after the local route check in bgp bestpath selection.

Signed-off-by: Enke Chen <enchen@paloaltonetworks.com>
(cherry picked from commit 6a7049aaacc32e6a473a4d56ca61444d1e1eb45d)

bgpd/bgp_route.c
doc/user/bgp.rst

index 54d125a7dff48387f54c54033dc26e512acb5f7c..e7ea0cf6d4b54e5704d2b1b858d1729354c5dc6e 100644 (file)
@@ -1064,7 +1064,32 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
                }
        }
 
-       /* Tie-breaker - AIGP (Metric TLV) attribute */
+       /* 3. Local route check. We prefer:
+        *  - BGP_ROUTE_STATIC
+        *  - BGP_ROUTE_AGGREGATE
+        *  - BGP_ROUTE_REDISTRIBUTE
+        */
+       new_origin = !(new->sub_type == BGP_ROUTE_NORMAL || new->sub_type == BGP_ROUTE_IMPORTED);
+       exist_origin = !(exist->sub_type == BGP_ROUTE_NORMAL ||
+                        exist->sub_type == BGP_ROUTE_IMPORTED);
+
+       if (new_origin && !exist_origin) {
+               *reason = bgp_path_selection_local_route;
+               if (debug)
+                       zlog_debug("%s: %s wins over %s due to preferred BGP_ROUTE type", pfx_buf,
+                                  new_buf, exist_buf);
+               return 1;
+       }
+
+       if (!new_origin && exist_origin) {
+               *reason = bgp_path_selection_local_route;
+               if (debug)
+                       zlog_debug("%s: %s loses to %s due to preferred BGP_ROUTE type", pfx_buf,
+                                  new_buf, exist_buf);
+               return 0;
+       }
+
+       /* 3.5. Tie-breaker - AIGP (Metric TLV) attribute */
        if (CHECK_FLAG(newattr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)) &&
            CHECK_FLAG(existattr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)) &&
            CHECK_FLAG(bgp->flags, BGP_FLAG_COMPARE_AIGP)) {
@@ -1094,34 +1119,6 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,
                }
        }
 
-       /* 3. Local route check. We prefer:
-        *  - BGP_ROUTE_STATIC
-        *  - BGP_ROUTE_AGGREGATE
-        *  - BGP_ROUTE_REDISTRIBUTE
-        */
-       new_origin = !(new->sub_type == BGP_ROUTE_NORMAL ||
-                      new->sub_type == BGP_ROUTE_IMPORTED);
-       exist_origin = !(exist->sub_type == BGP_ROUTE_NORMAL ||
-                        exist->sub_type == BGP_ROUTE_IMPORTED);
-
-       if (new_origin && !exist_origin) {
-               *reason = bgp_path_selection_local_route;
-               if (debug)
-                       zlog_debug(
-                               "%s: %s wins over %s due to preferred BGP_ROUTE type",
-                               pfx_buf, new_buf, exist_buf);
-               return 1;
-       }
-
-       if (!new_origin && exist_origin) {
-               *reason = bgp_path_selection_local_route;
-               if (debug)
-                       zlog_debug(
-                               "%s: %s loses to %s due to preferred BGP_ROUTE type",
-                               pfx_buf, new_buf, exist_buf);
-               return 0;
-       }
-
        /* Here if these are imported routes then get ultimate pi for
         * path compare.
         */
index 4632c70d53c4ad16c4ef2027811bb6768969d955..0f64f4bc1c9626f204c64e7afc1d3e4daf69fa1f 100644 (file)
@@ -160,16 +160,16 @@ bottom until one of the factors can be used.
 
    Prefer higher local preference routes to lower.
 
+3. **Local route check**
+
+   Prefer local routes (statics, aggregates, redistributed) to received routes.
+
    If ``bgp bestpath aigp`` is enabled, and both paths that are compared have
    AIGP attribute, BGP uses AIGP tie-breaking unless both of the paths have the
    AIGP metric attribute. This means that the AIGP attribute is not evaluated
    during the best path selection process between two paths when one path does
    not have the AIGP attribute.
 
-3. **Local route check**
-
-   Prefer local routes (statics, aggregates, redistributed) to received routes.
-
 4. **AS path length check**
 
    Prefer shortest hop-count AS_PATHs.