]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: fix several issues in sourcing AIGP attribute
authorEnke Chen <enchen@paloaltonetworks.com>
Wed, 16 Oct 2024 18:15:28 +0000 (11:15 -0700)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Thu, 17 Oct 2024 05:57:12 +0000 (05:57 +0000)
Fix several issues in sourcing AIGP attribute:

1) AIGP should not be set as default for a redistributed route or a
   static network. It should be set by config instead.

2) AIGP sourced by "set aigp-metric igp-metric" in a route-map does
   not set the correct value for a redistributed route.

3) When redistribute a connected route like loopback, the AGIP (with
   value 0) is sourced by "set aigp-metric igp-metric", but the
   attribute is not propagated as the attribute flag is not set.

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

bgpd/bgp_attr.h
bgpd/bgp_route.c
bgpd/bgp_routemap.c

index 38e732a9fe61dd8a64774b28b5d2bb991145f369..0282818931655d9c7f5261aab5019b7d78a4244d 100644 (file)
@@ -592,9 +592,7 @@ static inline uint64_t bgp_attr_get_aigp_metric(const struct attr *attr)
 static inline void bgp_attr_set_aigp_metric(struct attr *attr, uint64_t aigp)
 {
        attr->aigp_metric = aigp;
-
-       if (aigp)
-               SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP));
+       SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP));
 }
 
 static inline uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi)
index 7ceba9a0d546f6bd3e34ba242caa881f2a98f5c2..6dc19a62565a182e825003a49d2147b9795917a3 100644 (file)
@@ -6334,9 +6334,6 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
        if (afi == AFI_IP)
                attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
 
-       if (bgp_static->igpmetric)
-               bgp_attr_set_aigp_metric(&attr, bgp_static->igpmetric);
-
        if (bgp_static->atomic)
                attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE);
 
@@ -8591,9 +8588,6 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
        attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
        attr.tag = tag;
 
-       if (metric)
-               bgp_attr_set_aigp_metric(&attr, metric);
-
        afi = family2afi(p->family);
 
        red = bgp_redist_lookup(bgp, afi, type, instance);
@@ -8603,10 +8597,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
                /* Copy attribute for modification. */
                attr_new = attr;
 
-               if (red->redist_metric_flag) {
+               if (red->redist_metric_flag)
                        attr_new.med = red->redist_metric;
-                       bgp_attr_set_aigp_metric(&attr_new, red->redist_metric);
-               }
 
                /* Apply route-map. */
                if (red->rmap.name) {
index 4a671db934dacf3523cbe05472d3bcb39d0613c7..34f8c7fdb5925482c1344aa2341fb3580f66f3d7 100644 (file)
@@ -3452,19 +3452,15 @@ route_set_aigp_metric(void *rule, const struct prefix *pfx, void *object)
 {
        const char *aigp_metric = rule;
        struct bgp_path_info *path = object;
-       uint32_t aigp = 0;
+       uint32_t aigp;
 
-       if (strmatch(aigp_metric, "igp-metric")) {
-               if (!path->nexthop)
-                       return RMAP_NOMATCH;
-
-               bgp_attr_set_aigp_metric(path->attr, path->nexthop->metric);
-       } else {
+       /* Note: the metric is stored as MED for a locally redistributed. */
+       if (strmatch(aigp_metric, "igp-metric"))
+               aigp = path->nexthop ? path->nexthop->metric : path->attr->med;
+       else
                aigp = atoi(aigp_metric);
-               bgp_attr_set_aigp_metric(path->attr, aigp);
-       }
 
-       path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AIGP);
+       bgp_attr_set_aigp_metric(path->attr, aigp);
 
        return RMAP_OKAY;
 }