]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Fix display when using `missing-as-worst`
authorDonald Sharp <sharpd@nvidia.com>
Thu, 11 Apr 2024 14:46:46 +0000 (10:46 -0400)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Tue, 16 Apr 2024 14:15:20 +0000 (14:15 +0000)
The usage of the `bgp bestpath med missing-as-worst` command
was being accepted and applied during bestpath, but during output
of the routes affected by this it would not give any indication
that this was happening or what med value was being used.

Fixes: #15718
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
(cherry picked from commit bc9885b22e79ac14fd931517582d0d6d80f68c85)

bgpd/bgp_route.c
bgpd/bgp_route.h
bgpd/bgp_updgrp_adv.c
bgpd/bgp_vpn.c
doc/user/bgp.rst

index 3c3f3498d8ba72ae94ff07081ff26e8087d0f976..0a0289ac36b23ba14683fc9b1ec910be98c274ec 100644 (file)
@@ -542,6 +542,15 @@ void bgp_path_info_unset_flag(struct bgp_dest *dest, struct bgp_path_info *pi,
        bgp_pcount_adjust(dest, pi);
 }
 
+static bool use_bgp_med_value(struct attr *attr, struct bgp *bgp)
+{
+       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC) ||
+           CHECK_FLAG(bgp->flags, BGP_FLAG_MED_MISSING_AS_WORST))
+               return true;
+
+       return false;
+}
+
 /* Get MED value.  If MED value is missing and "bgp bestpath
    missing-as-worst" is specified, treat it as the worst value. */
 static uint32_t bgp_med_value(struct attr *attr, struct bgp *bgp)
@@ -9336,14 +9345,16 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
        }
 
        /* MED/Metric */
-       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
+       if (use_bgp_med_value(attr, path->peer->bgp)) {
+               uint32_t value = bgp_med_value(attr, path->peer->bgp);
+
                if (json_paths)
-                       json_object_int_add(json_path, "metric", attr->med);
+                       json_object_int_add(json_path, "metric", value);
                else if (wide)
-                       vty_out(vty, "%7u", attr->med);
+                       vty_out(vty, "%7u", value);
                else
-                       vty_out(vty, "%10u", attr->med);
-       else if (!json_paths) {
+                       vty_out(vty, "%10u", value);
+       else if (!json_paths) {
                if (wide)
                        vty_out(vty, "%*s", 7, " ");
                else
@@ -9464,7 +9475,7 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
 }
 
 /* called from terminal list command */
-void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
+void route_vty_out_tmp(struct vty *vty, struct bgp *bgp, struct bgp_dest *dest,
                       const struct prefix *p, struct attr *attr, safi_t safi,
                       bool use_json, json_object *json_ar, bool wide)
 {
@@ -9525,10 +9536,11 @@ void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
                                        &attr->mp_nexthop_global_in);
                        }
 
-                       if (attr->flag
-                           & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
-                               json_object_int_add(json_net, "metric",
-                                                   attr->med);
+                       if (use_bgp_med_value(attr, bgp)) {
+                               uint32_t value = bgp_med_value(attr, bgp);
+
+                               json_object_int_add(json_net, "metric", value);
+                       }
 
                        if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
                                json_object_int_add(json_net, "locPrf",
@@ -9573,13 +9585,15 @@ CPP_NOTICE("Drop `bgpOriginCodes` from JSON outputs")
                                else
                                        vty_out(vty, "%*s", len, " ");
                        }
-                       if (attr->flag
-                           & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
+
+                       if (use_bgp_med_value(attr, bgp)) {
+                               uint32_t value = bgp_med_value(attr, bgp);
+
                                if (wide)
-                                       vty_out(vty, "%7u", attr->med);
+                                       vty_out(vty, "%7u", value);
                                else
-                                       vty_out(vty, "%10u", attr->med);
-                       else if (wide)
+                                       vty_out(vty, "%10u", value);
+                       else if (wide)
                                vty_out(vty, "       ");
                        else
                                vty_out(vty, "          ");
@@ -10583,11 +10597,13 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
                vty_out(vty, "      Origin %s",
                        bgp_origin_long_str[attr->origin]);
 
-       if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)) {
+       if (use_bgp_med_value(attr, bgp)) {
+               uint32_t value = bgp_med_value(attr, bgp);
+
                if (json_paths)
-                       json_object_int_add(json_path, "metric", attr->med);
+                       json_object_int_add(json_path, "metric", value);
                else
-                       vty_out(vty, ", metric %u", attr->med);
+                       vty_out(vty, ", metric %u", value);
        }
 
        if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)) {
@@ -14235,7 +14251,7 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
                                                        json_ar, json_net,
                                                        "%pFX", rn_p);
                                } else
-                                       route_vty_out_tmp(vty, dest, rn_p,
+                                       route_vty_out_tmp(vty, bgp, dest, rn_p,
                                                          &attr, safi, use_json,
                                                          json_ar, wide);
                                bgp_attr_flush(&attr);
@@ -14298,11 +14314,15 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
                                                                        "%pFX",
                                                                        rn_p);
                                                } else
-                                                       route_vty_out_tmp(
-                                                               vty, dest, rn_p,
-                                                               &attr, safi,
-                                                               use_json,
-                                                               json_ar, wide);
+                                                       route_vty_out_tmp(vty,
+                                                                         bgp,
+                                                                         dest,
+                                                                         rn_p,
+                                                                         &attr,
+                                                                         safi,
+                                                                         use_json,
+                                                                         json_ar,
+                                                                         wide);
                                                (*output_count)++;
                                        } else {
                                                (*filtered_count)++;
@@ -14341,9 +14361,10 @@ show_adj_route(struct vty *vty, struct peer *peer, struct bgp_table *table,
                                                        json_ar, json_net,
                                                        "%pFX", rn_p);
                                } else
-                                       route_vty_out_tmp(
-                                               vty, dest, rn_p, pi->attr, safi,
-                                               use_json, json_ar, wide);
+                                       route_vty_out_tmp(vty, bgp, dest, rn_p,
+                                                         pi->attr, safi,
+                                                         use_json, json_ar,
+                                                         wide);
                                (*output_count)++;
                        }
                }
index 10b3ed5d0d4f9e0df7d9dbd850fb08aaab404e64..bfac44455eb81b3bc6f6e77c6fbbe92f6bbb6699 100644 (file)
@@ -828,10 +828,10 @@ extern void route_vty_out(struct vty *vty, const struct prefix *p,
 extern void route_vty_out_tag(struct vty *vty, const struct prefix *p,
                              struct bgp_path_info *path, int display,
                              safi_t safi, json_object *json);
-extern void route_vty_out_tmp(struct vty *vty, struct bgp_dest *dest,
-                             const struct prefix *p, struct attr *attr,
-                             safi_t safi, bool use_json, json_object *json_ar,
-                             bool wide);
+extern void route_vty_out_tmp(struct vty *vty, struct bgp *bgp,
+                             struct bgp_dest *dest, const struct prefix *p,
+                             struct attr *attr, safi_t safi, bool use_json,
+                             json_object *json_ar, bool wide);
 extern void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
                                  struct bgp_path_info *path, int display,
                                  json_object *json);
index 9d574a00ccb3805670a37fc7797aa052a11be89b..de05fa4fd3e341ff1bcc5cdcc0ee14b998b43b63 100644 (file)
@@ -305,15 +305,16 @@ static void subgrp_show_adjq_vty(struct update_subgroup *subgrp,
                        }
                        if ((flags & UPDWALK_FLAGS_ADVQUEUE) && adj->adv &&
                            adj->adv->baa) {
-                               route_vty_out_tmp(
-                                       vty, dest, dest_p, adj->adv->baa->attr,
-                                       SUBGRP_SAFI(subgrp), 0, NULL, false);
+                               route_vty_out_tmp(vty, bgp, dest, dest_p,
+                                                 adj->adv->baa->attr,
+                                                 SUBGRP_SAFI(subgrp), 0, NULL,
+                                                 false);
                                output_count++;
                        }
                        if ((flags & UPDWALK_FLAGS_ADVERTISED) && adj->attr) {
-                               route_vty_out_tmp(vty, dest, dest_p, adj->attr,
-                                                 SUBGRP_SAFI(subgrp), 0, NULL,
-                                                 false);
+                               route_vty_out_tmp(vty, bgp, dest, dest_p,
+                                                 adj->attr, SUBGRP_SAFI(subgrp),
+                                                 0, NULL, false);
                                output_count++;
                        }
                }
index 0ed1d04d83eab4f0f9ece783c838e11d1f8f3673..20a3b5b63950c618e9e01b1d8d1345b750ac0938 100644 (file)
@@ -212,7 +212,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer,
                                }
                                rd_header = 0;
                        }
-                       route_vty_out_tmp(vty, rm, bgp_dest_get_prefix(rm),
+                       route_vty_out_tmp(vty, bgp, rm, bgp_dest_get_prefix(rm),
                                          attr, safi, use_json, json_routes,
                                          false);
                        output_count++;
index 5b8ec11320f59a4702524a3af10d4c45b6e6f13a..03b150659dbdf187aec7ee14c221cba334a9e320 100644 (file)
@@ -428,6 +428,11 @@ Route Selection
 
    Disabled by default.
 
+.. clicmd:: bgp bestpath med missing-as-worst
+
+   If the paths MED value is missing and this command is configured
+   then treat it as the worse possible value that it can be.
+
 .. clicmd:: maximum-paths (1-128)
 
    Sets the maximum-paths value used for ecmp calculations for this