Skip to content

Commit 02c3c84

Browse files
authored
Merge pull request #22093 from opensourcerouting/fix/move_link_bw_from_attr_extra_to_bgp_path_info_extra
bgpd: Move link_bw from attr_extra to bgp_path_info_extra
2 parents bbf019e + b4880ab commit 02c3c84

5 files changed

Lines changed: 22 additions & 60 deletions

File tree

bgpd/bgp_attr.c

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,8 +1705,6 @@ void bgp_attr_unintern_sub(struct attr *attr)
17051705

17061706
bgp_attr_unset_aigp_metric(attr);
17071707

1708-
bgp_attr_set_link_bw(attr, 0);
1709-
17101708
bgp_attr_set_pmsi_tnl_type(attr, PMSI_TNLTYPE_NO_INFO);
17111709

17121710
XFREE(MTYPE_ATTR_EXTRA, attr->extra);
@@ -1842,8 +1840,6 @@ void bgp_attr_flush(struct attr *attr)
18421840

18431841
bgp_attr_unset_aigp_metric(attr);
18441842

1845-
bgp_attr_set_link_bw(attr, 0);
1846-
18471843
bgp_attr_set_pmsi_tnl_type(attr, PMSI_TNLTYPE_NO_INFO);
18481844

18491845
XFREE(MTYPE_ATTR_EXTRA, attr->extra);
@@ -3198,14 +3194,6 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
31983194
bgp_attr_extcom_tunnel_type(attr, &tun_type);
31993195
attr->encap_tunneltype = tun_type;
32003196

3201-
/* Extract link bandwidth, if any. */
3202-
{
3203-
uint64_t link_bw = 0;
3204-
3205-
(void)ecommunity_linkbw_present(bgp_attr_get_ecommunity(attr), &link_bw);
3206-
bgp_attr_set_link_bw(attr, link_bw);
3207-
}
3208-
32093197
return BGP_ATTR_PARSE_PROCEED;
32103198
}
32113199

@@ -3238,14 +3226,6 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args)
32383226
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
32393227
args->total);
32403228

3241-
/* Extract link bandwidth, if any. */
3242-
{
3243-
uint64_t link_bw = 0;
3244-
3245-
(void)ecommunity_linkbw_present(bgp_attr_get_ipv6_ecommunity(attr), &link_bw);
3246-
bgp_attr_set_link_bw(attr, link_bw);
3247-
}
3248-
32493229
return BGP_ATTR_PARSE_PROCEED;
32503230

32513231
ipv6_ext_community_ignore:

bgpd/bgp_attr.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -148,9 +148,6 @@ struct attr_extra {
148148
/* For BGP-LS Attribute (RFC 9552) */
149149
struct bgp_ls_attr *ls_attr;
150150

151-
/* Link bandwidth value extracted from ecommunity, if any. */
152-
uint64_t link_bw;
153-
154151
/* SRv6 VPN SID */
155152
struct bgp_attr_srv6_vpn *srv6_vpn;
156153

@@ -809,25 +806,6 @@ static inline void bgp_attr_set_ls_attr(struct attr *attr, struct bgp_ls_attr *l
809806
bgp_attr_unset(attr, BGP_ATTR_LINK_STATE);
810807
}
811808

812-
static inline uint64_t bgp_attr_get_link_bw(const struct attr *attr)
813-
{
814-
return attr->extra ? attr->extra->link_bw : 0;
815-
}
816-
817-
static inline void bgp_attr_set_link_bw(struct attr *attr, uint64_t link_bw)
818-
{
819-
uint64_t old = bgp_attr_get_link_bw(attr);
820-
821-
if (link_bw && !old) {
822-
bgp_attr_extra_get(attr)->link_bw = link_bw;
823-
} else if (link_bw && old) {
824-
attr->extra->link_bw = link_bw; /* replace; refcnt unchanged */
825-
} else if (!link_bw && old) {
826-
attr->extra->link_bw = 0;
827-
bgp_attr_extra_put(attr);
828-
}
829-
}
830-
831809
static inline uint32_t bgp_attr_get_otc(const struct attr *attr)
832810
{
833811
return attr->extra ? attr->extra->otc : 0;

bgpd/bgp_route.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,24 @@ uint32_t bgp_path_info_get_srte_color(struct bgp_path_info *bpi)
433433
return 0;
434434
}
435435

436+
/* Extract link bandwidth from the BGP path's extended communities.
437+
* Falls back to the IPv6 address-specific extended community when no
438+
* link-bandwidth value is encoded in the standard extended community.
439+
*/
440+
uint64_t bgp_path_info_get_link_bw(struct bgp_path_info *bpi)
441+
{
442+
uint64_t link_bw = 0;
443+
444+
if (!bpi || !bpi->attr)
445+
return 0;
446+
447+
(void)ecommunity_linkbw_present(bgp_attr_get_ecommunity(bpi->attr), &link_bw);
448+
if (!link_bw)
449+
(void)ecommunity_linkbw_present(bgp_attr_get_ipv6_ecommunity(bpi->attr), &link_bw);
450+
451+
return link_bw;
452+
}
453+
436454
bool bgp_path_info_has_valid_label(const struct bgp_path_info *path)
437455
{
438456
if (!BGP_PATH_INFO_NUM_LABELS(path))

bgpd/bgp_route.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,4 +1072,5 @@ extern uint32_t bgp_med_value(struct attr *attr, struct bgp *bgp);
10721072
extern int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete);
10731073
extern void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest, afi_t afi, safi_t safi);
10741074
extern uint32_t bgp_path_info_get_srte_color(struct bgp_path_info *bpi);
1075+
extern uint64_t bgp_path_info_get_link_bw(struct bgp_path_info *bpi);
10751076
#endif /* _QUAGGA_BGP_ROUTE_H */

bgpd/bgp_zebra.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1268,13 +1268,13 @@ static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp,
12681268
return true;
12691269
}
12701270

1271-
static bool bgp_zebra_use_nhop_weighted(struct bgp *bgp, struct attr *attr,
1271+
static bool bgp_zebra_use_nhop_weighted(struct bgp *bgp, struct bgp_path_info *bpi,
12721272
uint64_t *nh_weight)
12731273
{
12741274
/* zero link-bandwidth and link-bandwidth not present are treated
12751275
* as the same situation.
12761276
*/
1277-
uint64_t link_bw = bgp_attr_get_link_bw(attr);
1277+
uint64_t link_bw = bgp_path_info_get_link_bw(bpi);
12781278

12791279
if (!link_bw) {
12801280
/* the only situations should be if we're either told
@@ -1355,22 +1355,7 @@ static void bgp_zebra_announce_parse_nexthop(struct bgp_path_info *info, const s
13551355
* in some situations.
13561356
*/
13571357
if (do_wt_ecmp == BGP_WECMP_BEHAVIOR_LINK_BW) {
1358-
/* Extended communities are exported/imported correctly
1359-
* between VRFs, but we need to extract the actual link-bandwidth
1360-
* value from the extended communities.
1361-
*/
1362-
uint64_t link_bw = 0;
1363-
1364-
(void)ecommunity_linkbw_present(bgp_attr_get_ecommunity(mpinfo->attr),
1365-
&link_bw);
1366-
/* Fallback to IPv6 address-specific extended community */
1367-
if (!link_bw)
1368-
(void)ecommunity_linkbw_present(bgp_attr_get_ipv6_ecommunity(
1369-
mpinfo->attr),
1370-
&link_bw);
1371-
bgp_attr_set_link_bw(mpinfo->attr, link_bw);
1372-
if (!bgp_zebra_use_nhop_weighted(bgp, mpinfo->attr,
1373-
&nh_weight))
1358+
if (!bgp_zebra_use_nhop_weighted(bgp, mpinfo, &nh_weight))
13741359
continue;
13751360
} else if (do_wt_ecmp == BGP_WECMP_BEHAVIOR_NNHN_COUNT) {
13761361
if (bgp_attr_exists(mpinfo->attr, BGP_ATTR_NHC))

0 commit comments

Comments
 (0)