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)
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);
attr.distance = distance;
attr.tag = tag;
- if (metric)
- bgp_attr_set_aigp_metric(&attr, metric);
-
afi = family2afi(p->family);
red = bgp_redist_lookup(bgp, afi, type, instance);
/* 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) {
{
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;
}