summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_attr.c7
-rw-r--r--bgpd/bgp_attr.h6
-rw-r--r--bgpd/bgp_route.c7
-rw-r--r--bgpd/bgp_routemap.c3
-rw-r--r--bgpd/bgp_updgrp_adv.c4
-rw-r--r--bgpd/rfapi/rfapi.c12
-rw-r--r--bgpd/rfapi/vnc_export_bgp.c22
7 files changed, 30 insertions, 31 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 7aa9bbbb91..596d820f1b 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -1177,8 +1177,7 @@ struct attr *bgp_attr_aggregate_intern(
SET_FLAG(attr.flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN));
/* MED */
- attr.med = 0;
- SET_FLAG(attr.flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC));
+ bgp_attr_set_med(&attr, 0);
/* AS path attribute. */
if (aspath)
@@ -1933,9 +1932,7 @@ static enum bgp_attr_parse_ret bgp_attr_med(struct bgp_attr_parser_args *args)
args->total);
}
- attr->med = stream_getl(peer->curr);
-
- SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC));
+ bgp_attr_set_med(attr, stream_getl(peer->curr));
return BGP_ATTR_PARSE_PROCEED;
}
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 02ddf88b62..c10a9dc90a 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -608,6 +608,12 @@ static inline uint64_t bgp_aigp_metric_total(struct bgp_path_info *bpi)
return aigp;
}
+static inline void bgp_attr_set_med(struct attr *attr, uint32_t med)
+{
+ attr->med = med;
+ SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC));
+}
+
static inline struct cluster_list *bgp_attr_get_cluster(const struct attr *attr)
{
return attr->cluster1;
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index 0f196157c8..a8ca887cdc 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -6747,8 +6747,8 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
bgp_attr_default_set(&attr, bgp, BGP_ORIGIN_IGP);
attr.nexthop = bgp_static->igpnexthop;
- attr.med = bgp_static->igpmetric;
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
+
+ bgp_attr_set_med(&attr, bgp_static->igpmetric);
if (afi == AFI_IP)
attr.mp_nexthop_len = BGP_ATTR_NHLEN_IPV4;
@@ -9015,9 +9015,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
else
UNSET_FLAG(attr.nh_flags, BGP_ATTR_NH_IF_OPERSTATE);
- attr.med = metric;
+ bgp_attr_set_med(&attr, metric);
attr.distance = distance;
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
attr.tag = tag;
if (metric)
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 4900bb3ce3..0f8adea38d 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -2222,8 +2222,7 @@ route_set_metric(void *rule, const struct prefix *prefix, void *object)
if (path->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
med = path->attr->med;
- path->attr->med = route_value_adjust(rv, med, path->peer);
- path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
+ bgp_attr_set_med(path->attr, route_value_adjust(rv, med, path->peer));
return RMAP_OKAY;
}
diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c
index 250378af68..1a66df59fc 100644
--- a/bgpd/bgp_updgrp_adv.c
+++ b/bgpd/bgp_updgrp_adv.c
@@ -906,8 +906,8 @@ void subgroup_default_originate(struct update_subgroup *subgrp, bool withdraw)
assert(attr.aspath);
aspath = attr.aspath;
- attr.med = 0;
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
+
+ bgp_attr_set_med(&attr, 0);
if ((afi == AFI_IP6) || peer_cap_enhe(peer, afi, safi)) {
/* IPv6 global nexthop must be included. */
diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c
index 23e3eb4823..61d154f1b4 100644
--- a/bgpd/rfapi/rfapi.c
+++ b/bgpd/rfapi/rfapi.c
@@ -667,10 +667,8 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF);
}
- if (med) {
- attr.med = *med;
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
- }
+ if (med)
+ bgp_attr_set_med(&attr, *med);
/* override default weight assigned by bgp_attr_default_set() */
attr.weight = rfd->peer ? rfd->peer->weight[afi][safi] : 0;
@@ -863,10 +861,8 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
red = bgp_redist_lookup(bgp, afi, type, 0);
- if (red && red->redist_metric_flag) {
- attr.med = red->redist_metric;
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
- }
+ if (red && red->redist_metric_flag)
+ bgp_attr_set_med(&attr, red->redist_metric);
bn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd);
diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c
index 4de2306609..c9a058ea44 100644
--- a/bgpd/rfapi/vnc_export_bgp.c
+++ b/bgpd/rfapi/vnc_export_bgp.c
@@ -96,15 +96,16 @@ static void encap_attr_export_ce(struct attr *new, struct attr *orig,
* neighbor NEIGHBOR attribute-unchanged med
*/
if (!CHECK_FLAG(new->flag, BGP_ATTR_MULTI_EXIT_DISC)) {
+ uint32_t med = 255;
+
if (CHECK_FLAG(new->flag, BGP_ATTR_LOCAL_PREF)) {
if (new->local_pref > 255)
- new->med = 0;
+ med = 0;
else
- new->med = 255 - new->local_pref;
- } else {
- new->med = 255; /* shouldn't happen */
+ med = 255 - new->local_pref;
}
- new->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
+
+ bgp_attr_set_med(new, med);
}
/*
@@ -642,15 +643,16 @@ encap_attr_export(struct attr *new, struct attr *orig,
* neighbor NEIGHBOR attribute-unchanged med
*/
if (!CHECK_FLAG(new->flag, BGP_ATTR_MULTI_EXIT_DISC)) {
+ uint32_t med = 255;
+
if (CHECK_FLAG(new->flag, BGP_ATTR_LOCAL_PREF)) {
if (new->local_pref > 255)
- new->med = 0;
+ med = 0;
else
- new->med = 255 - new->local_pref;
- } else {
- new->med = 255; /* shouldn't happen */
+ med = 255 - new->local_pref;
}
- new->flag |= ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC);
+
+ bgp_attr_set_med(new, med);
}
/*