Skip to content

Commit 94fa7a1

Browse files
authored
Merge pull request #19953 from opensourcerouting/fix/bgp_attr_helpers
bgpd: Use bgp_attr_[exists/set/unset] helpers when doing attr stuff
2 parents 67afeed + f8b81fe commit 94fa7a1

File tree

14 files changed

+163
-171
lines changed

14 files changed

+163
-171
lines changed

bgpd/bgp_attr.c

Lines changed: 54 additions & 62 deletions
Large diffs are not rendered by default.

bgpd/bgp_attr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ struct transit {
348348
#define ATTR_FLAG_BIT(X) \
349349
__builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0)
350350

351+
#define bgp_attr_exists(attr, id) CHECK_FLAG((attr)->flag, ATTR_FLAG_BIT(id))
352+
#define bgp_attr_set(attr, id) SET_FLAG((attr)->flag, ATTR_FLAG_BIT(id))
353+
#define bgp_attr_unset(attr, id) UNSET_FLAG((attr)->flag, ATTR_FLAG_BIT(id))
354+
351355
#define BGP_CLUSTER_LIST_LENGTH(attr) \
352356
(CHECK_FLAG((attr)->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \
353357
? bgp_attr_get_cluster((attr))->length \

bgpd/bgp_debug.c

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -406,10 +406,10 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
406406

407407
buf[0] = '\0';
408408

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

bgpd/bgp_evpn.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3779,7 +3779,7 @@ static int is_route_matching_for_vrf(struct bgp *bgp_vrf,
37793779

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

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

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

38523852
ecom = bgp_attr_get_ecommunity(attr);
@@ -4415,7 +4415,7 @@ static int bgp_evpn_install_uninstall_table(struct bgp *bgp, afi_t afi,
44154415
return 0;
44164416

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

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

50515051
if (pmsi_tnl_type != PMSI_TNLTYPE_INGR_REPL

bgpd/bgp_label.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,8 @@ void bgp_reg_dereg_for_label(struct bgp_dest *dest, struct bgp_path_info *pi,
374374
* Determine if we will let zebra should derive label from
375375
* label index instead of bgpd requesting from label pool
376376
*/
377-
if (CHECK_FLAG(pi->attr->flag,
378-
ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID))
379-
&& pi->attr->label_index != BGP_INVALID_LABEL_INDEX) {
377+
if (bgp_attr_exists(pi->attr, BGP_ATTR_PREFIX_SID) &&
378+
pi->attr->label_index != BGP_INVALID_LABEL_INDEX) {
380379
with_label_index = true;
381380
UNSET_FLAG(dest->flags, BGP_NODE_LABEL_REQUESTED);
382381
} else {

bgpd/bgp_mpath.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ enum bgp_wecmp_behavior bgp_path_info_mpath_chkwtd(struct bgp *bgp, struct bgp_p
373373
* characteristic and do weighted ECMP based on that.
374374
*/
375375
if (bgp->lb_handling == BGP_LINK_BW_IGNORE_BW) {
376-
if (CHECK_FLAG(path->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NHC)))
376+
if (bgp_attr_exists(path->attr, BGP_ATTR_NHC))
377377
return BGP_WECMP_BEHAVIOR_NNHN_COUNT;
378378
}
379379

bgpd/bgp_mplsvpn.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,10 +1297,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
12971297
* route-map test permit 10
12981298
* set extcommunity rt none
12991299
*/
1300-
if (CHECK_FLAG(bpi->attr->flag,
1301-
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) &&
1302-
CHECK_FLAG(new_attr->flag,
1303-
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
1300+
if (bgp_attr_exists(bpi->attr, BGP_ATTR_EXT_COMMUNITIES) &&
1301+
bgp_attr_exists(new_attr, BGP_ATTR_EXT_COMMUNITIES)) {
13041302
if (!ecommunity_cmp(
13051303
bgp_attr_get_ecommunity(bpi->attr),
13061304
bgp_attr_get_ecommunity(new_attr))) {
@@ -1618,9 +1616,8 @@ vpn_leak_from_vrf_get_per_nexthop_label(afi_t afi, struct bgp_path_info *pi,
16181616
bpi_ultimate->type == ZEBRA_ROUTE_BGP;
16191617

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

4401-
if (pi->attr &&
4402-
CHECK_FLAG(pi->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PREFIX_SID)) &&
4398+
if (pi->attr && bgp_attr_exists(pi->attr, BGP_ATTR_PREFIX_SID) &&
44034399
pi->attr->label_index != BGP_INVALID_LABEL_INDEX)
44044400
/* prefix_sid attribute */
44054401
return false;

bgpd/bgp_nexthop.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
539539
tmp_addr.p.prefixlen = p->prefixlen;
540540
} else {
541541
/* Here we need to find out which nexthop to be used*/
542-
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
542+
if (bgp_attr_exists(attr, BGP_ATTR_NEXT_HOP)) {
543543
tmp_addr.p.u.prefix4 = attr->nexthop;
544544
tmp_addr.p.prefixlen = IPV4_MAX_BITLEN;
545545
} else if ((attr->mp_nexthop_len) &&
@@ -574,16 +574,16 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
574574
SET_IPADDR_V4(&tmp_tip.addr);
575575
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->nexthop);
576576

577-
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
577+
if (bgp_attr_exists(attr, BGP_ATTR_NEXT_HOP)) {
578578
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->nexthop);
579579
} else if ((attr->mp_nexthop_len) &&
580580
((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ||
581581
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) {
582582
IPV4_ADDR_COPY(&tmp_tip.addr.ipaddr_v4, &attr->mp_nexthop_global_in);
583583
} else if ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) ||
584-
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) ||
585-
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) ||
586-
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)) {
584+
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) ||
585+
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) ||
586+
(attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL)) {
587587
SET_IPADDR_V6(&tmp_tip.addr);
588588
IPV6_ADDR_COPY(&tmp_tip.addr.ipaddr_v6, &attr->mp_nexthop_global);
589589
}

0 commit comments

Comments
 (0)