Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 54 additions & 62 deletions bgpd/bgp_attr.c

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ struct transit {
#define ATTR_FLAG_BIT(X) \
__builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0)

#define bgp_attr_exists(attr, id) CHECK_FLAG((attr)->flag, ATTR_FLAG_BIT(id))
#define bgp_attr_set(attr, id) SET_FLAG((attr)->flag, ATTR_FLAG_BIT(id))
#define bgp_attr_unset(attr, id) UNSET_FLAG((attr)->flag, ATTR_FLAG_BIT(id))

#define BGP_CLUSTER_LIST_LENGTH(attr) \
(CHECK_FLAG((attr)->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \
? bgp_attr_get_cluster((attr))->length \
Expand Down
34 changes: 17 additions & 17 deletions bgpd/bgp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,10 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)

buf[0] = '\0';

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)))
if (bgp_attr_exists(attr, BGP_ATTR_NEXT_HOP))
snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGIN)))
if (bgp_attr_exists(attr, BGP_ATTR_ORIGIN))
snprintf(buf + strlen(buf), size - strlen(buf), ", origin %s",
bgp_origin_str[attr->origin]);

Expand All @@ -426,54 +426,54 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
if (attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4)
snprintfrr(buf, size, "nexthop %pI4", &attr->nexthop);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF)))
if (bgp_attr_exists(attr, BGP_ATTR_LOCAL_PREF))
snprintf(buf + strlen(buf), size - strlen(buf),
", localpref %u", attr->local_pref);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AIGP)))
if (bgp_attr_exists(attr, BGP_ATTR_AIGP))
snprintf(buf + strlen(buf), size - strlen(buf),
", aigp-metric %" PRIu64,
(unsigned long long)bgp_attr_get_aigp_metric(attr));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC)))
if (bgp_attr_exists(attr, BGP_ATTR_MULTI_EXIT_DISC))
snprintf(buf + strlen(buf), size - strlen(buf), ", metric %u",
attr->med);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)))
if (bgp_attr_exists(attr, BGP_ATTR_COMMUNITIES))
snprintf(buf + strlen(buf), size - strlen(buf),
", community %s",
community_str(bgp_attr_get_community(attr), false,
true));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)))
if (bgp_attr_exists(attr, BGP_ATTR_LARGE_COMMUNITIES))
snprintf(buf + strlen(buf), size - strlen(buf),
", large-community %s",
lcommunity_str(bgp_attr_get_lcommunity(attr), false,
true));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
if (bgp_attr_exists(attr, BGP_ATTR_EXT_COMMUNITIES))
snprintf(buf + strlen(buf), size - strlen(buf),
", extcommunity %s",
ecommunity_str(bgp_attr_get_ecommunity(attr)));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES)))
if (bgp_attr_exists(attr, BGP_ATTR_IPV6_EXT_COMMUNITIES))
snprintf(buf + strlen(buf), size - strlen(buf), ", ipv6-extcommunity %s",
ecommunity_str(bgp_attr_get_ipv6_ecommunity(attr)));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
if (bgp_attr_exists(attr, BGP_ATTR_ATOMIC_AGGREGATE))
snprintf(buf + strlen(buf), size - strlen(buf),
", atomic-aggregate");

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AGGREGATOR)))
if (bgp_attr_exists(attr, BGP_ATTR_AGGREGATOR))
snprintfrr(buf + strlen(buf), size - strlen(buf),
", aggregated by %u %pI4", attr->aggregator_as,
&attr->aggregator_addr);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)))
if (bgp_attr_exists(attr, BGP_ATTR_ORIGINATOR_ID))
snprintfrr(buf + strlen(buf), size - strlen(buf),
", originator %pI4", &attr->originator_id);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) {
if (bgp_attr_exists(attr, BGP_ATTR_CLUSTER_LIST)) {
struct cluster_list *cluster;
int i;

Expand All @@ -486,21 +486,21 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
" %pI4", &cluster->list[i]);
}

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)))
if (bgp_attr_exists(attr, BGP_ATTR_PMSI_TUNNEL))
snprintf(buf + strlen(buf), size - strlen(buf),
", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)))
if (bgp_attr_exists(attr, BGP_ATTR_AS_PATH))
snprintf(buf + strlen(buf), size - strlen(buf), ", path %s",
aspath_print(attr->aspath));

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))) {
if (bgp_attr_exists(attr, BGP_ATTR_PREFIX_SID)) {
if (attr->label_index != BGP_INVALID_LABEL_INDEX)
snprintf(buf + strlen(buf), size - strlen(buf),
", label-index %u", attr->label_index);
}

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NHC))) {
if (bgp_attr_exists(attr, BGP_ATTR_NHC)) {
struct bgp_nhc_tlv *tlv;
struct bgp_nhc *nhc = bgp_attr_get_nhc(attr);

Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3779,7 +3779,7 @@ static int is_route_matching_for_vrf(struct bgp *bgp_vrf,

assert(attr);
/* Route should have valid RT to be even considered. */
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
if (!bgp_attr_exists(attr, BGP_ATTR_EXT_COMMUNITIES))
return 0;

ecom = bgp_attr_get_ecommunity(attr);
Expand Down Expand Up @@ -3846,7 +3846,7 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn,

assert(attr);
/* Route should have valid RT to be even considered. */
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
if (!bgp_attr_exists(attr, BGP_ATTR_EXT_COMMUNITIES))
return 0;

ecom = bgp_attr_get_ecommunity(attr);
Expand Down Expand Up @@ -4415,7 +4415,7 @@ static int bgp_evpn_install_uninstall_table(struct bgp *bgp, afi_t afi,
return 0;

/* If we don't have Route Target, nothing much to do. */
if (!CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
if (!bgp_attr_exists(attr, BGP_ATTR_EXT_COMMUNITIES))
return 0;

/* EAD prefix in the global table doesn't include the VTEP-IP so
Expand Down Expand Up @@ -5045,7 +5045,7 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi,
* Note: We just simply ignore the values as it is not clear if
* doing anything else is better.
*/
if (attr && CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) {
if (attr && bgp_attr_exists(attr, BGP_ATTR_PMSI_TUNNEL)) {
enum pta_type pmsi_tnl_type = bgp_attr_get_pmsi_tnl_type(attr);

if (pmsi_tnl_type != PMSI_TNLTYPE_INGR_REPL
Expand Down
5 changes: 2 additions & 3 deletions bgpd/bgp_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,8 @@ void bgp_reg_dereg_for_label(struct bgp_dest *dest, struct bgp_path_info *pi,
* Determine if we will let zebra should derive label from
* label index instead of bgpd requesting from label pool
*/
if (CHECK_FLAG(pi->attr->flag,
ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))
&& pi->attr->label_index != BGP_INVALID_LABEL_INDEX) {
if (bgp_attr_exists(pi->attr, BGP_ATTR_PREFIX_SID) &&
pi->attr->label_index != BGP_INVALID_LABEL_INDEX) {
with_label_index = true;
UNSET_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED);
} else {
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_mpath.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ enum bgp_wecmp_behavior bgp_path_info_mpath_chkwtd(struct bgp *bgp, struct bgp_p
* characteristic and do weighted ECMP based on that.
*/
if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW) {
if (CHECK_FLAG(path->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NHC)))
if (bgp_attr_exists(path->attr, BGP_ATTR_NHC))
return BGP_WECMP_BEHAVIOR_NNHN_COUNT;
}

Expand Down
14 changes: 5 additions & 9 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1297,10 +1297,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
* route-map test permit 10
* set extcommunity rt none
*/
if (CHECK_FLAG(bpi->attr->flag,
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) &&
CHECK_FLAG(new_attr->flag,
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
if (bgp_attr_exists(bpi->attr, BGP_ATTR_EXT_COMMUNITIES) &&
bgp_attr_exists(new_attr, BGP_ATTR_EXT_COMMUNITIES)) {
if (!ecommunity_cmp(
bgp_attr_get_ecommunity(bpi->attr),
bgp_attr_get_ecommunity(new_attr))) {
Expand Down Expand Up @@ -1618,9 +1616,8 @@ vpn_leak_from_vrf_get_per_nexthop_label(afi_t afi, struct bgp_path_info *pi,
bpi_ultimate->type == ZEBRA_ROUTE_BGP;

if (is_bgp_static_route == false && afi == AFI_IP &&
CHECK_FLAG(pi->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) &&
(pi->attr->nexthop.s_addr == INADDR_ANY ||
!ipv4_unicast_valid(&pi->attr->nexthop))) {
bgp_attr_exists(pi->attr, BGP_ATTR_NEXT_HOP) &&
(pi->attr->nexthop.s_addr == INADDR_ANY || !ipv4_unicast_valid(&pi->attr->nexthop))) {
/* IPv4 nexthop in standard BGP encoding format.
* Format of address is not valid (not any, not unicast).
* Fallback to the per VRF label.
Expand Down Expand Up @@ -4398,8 +4395,7 @@ bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi)
/* srv6 sid */
return false;

if (pi->attr &&
CHECK_FLAG(pi->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) &&
if (pi->attr && bgp_attr_exists(pi->attr, BGP_ATTR_PREFIX_SID) &&
pi->attr->label_index != BGP_INVALID_LABEL_INDEX)
/* prefix_sid attribute */
return false;
Expand Down
10 changes: 5 additions & 5 deletions bgpd/bgp_nexthop.c
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
tmp_addr.p.prefixlen = p->prefixlen;
} else {
/* Here we need to find out which nexthop to be used*/
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
if (bgp_attr_exists(attr, BGP_ATTR_NEXT_HOP)) {
tmp_addr.p.u.prefix4 = attr->nexthop;
tmp_addr.p.prefixlen = IPV4_MAX_BITLEN;
} else if ((attr->mp_nexthop_len) &&
Expand Down Expand Up @@ -574,16 +574,16 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
SET_IPADDR_V4(&tmp_tip.addr);
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->nexthop);

if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
if (bgp_attr_exists(attr, BGP_ATTR_NEXT_HOP)) {
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->nexthop);
} else if ((attr->mp_nexthop_len) &&
((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) {
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->mp_nexthop_global_in);
} else if ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)) {
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) ||
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)) {
SET_IPADDR_V6(&tmp_tip.addr);
IPV6_ADDR_COPY(&tmp_tip.addr.ipaddr_v6, &attr->mp_nexthop_global);
}
Expand Down
Loading
Loading