Skip to content

Commit d10b08e

Browse files
authored
Merge pull request #18097 from louis-6wind/attrhash_cmp
bgpd: optimize attrhash_cmp calls
2 parents 90b004c + cbf27be commit d10b08e

File tree

5 files changed

+15
-19
lines changed

5 files changed

+15
-19
lines changed

bgpd/bgp_evpn.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,8 +2062,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
20622062
bgp_path_info_add(dest, tmp_pi);
20632063
} else {
20642064
tmp_pi = local_pi;
2065-
if (attrhash_cmp(tmp_pi->attr, attr)
2066-
&& !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
2065+
if (!CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(tmp_pi->attr, attr))
20672066
route_change = 0;
20682067
else {
20692068
/*
@@ -3154,8 +3153,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
31543153
pi = bgp_create_evpn_bgp_path_info(parent_pi, dest, &attr);
31553154
new_pi = true;
31563155
} else {
3157-
if (attrhash_cmp(pi->attr, &attr)
3158-
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
3156+
if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(pi->attr, &attr)) {
31593157
bgp_dest_unlock_node(dest);
31603158
return 0;
31613159
}
@@ -3278,8 +3276,8 @@ static int install_evpn_route_entry_in_vni_common(
32783276
* install_evpn_route_entry_in_vni_mac() or
32793277
* install_evpn_route_entry_in_vni_ip()
32803278
*/
3281-
if (attrhash_cmp(pi->attr, parent_pi->attr) &&
3282-
!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
3279+
if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
3280+
attrhash_cmp(pi->attr, parent_pi->attr))
32833281
return 0;
32843282
/* The attribute has changed. */
32853283
/* Add (or update) attribute to hash. */

bgpd/bgp_evpn_mh.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ static int bgp_evpn_es_route_install(struct bgp *bgp,
212212
bgp_dest_lock_node((struct bgp_dest *)parent_pi->net);
213213
bgp_path_info_add(dest, pi);
214214
} else {
215-
if (attrhash_cmp(pi->attr, parent_pi->attr)
216-
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
215+
if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
216+
attrhash_cmp(pi->attr, parent_pi->attr)) {
217217
bgp_dest_unlock_node(dest);
218218
return 0;
219219
}
@@ -421,8 +421,7 @@ int bgp_evpn_mh_route_update(struct bgp *bgp, struct bgp_evpn_es *es,
421421
bgp_path_info_add(dest, tmp_pi);
422422
} else {
423423
tmp_pi = local_pi;
424-
if (attrhash_cmp(tmp_pi->attr, attr)
425-
&& !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
424+
if (!CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(tmp_pi->attr, attr))
426425
*route_changed = 0;
427426
else {
428427
/* The attribute has changed.

bgpd/bgp_mplsvpn.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,8 +1207,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
12071207
return NULL;
12081208
}
12091209

1210-
if (attrhash_cmp(bpi->attr, new_attr) && labelssame &&
1211-
!CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
1210+
if (labelssame && !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
1211+
attrhash_cmp(bpi->attr, new_attr) &&
12121212
leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi, source_bpi, bpi,
12131213
bgp_orig, p,
12141214
debug) == !!CHECK_FLAG(bpi->flags, BGP_PATH_VALID)) {

bgpd/bgp_route.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7505,9 +7505,9 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
75057505
break;
75067506

75077507
if (pi) {
7508-
if (attrhash_cmp(pi->attr, attr_new)
7509-
&& !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
7510-
&& !CHECK_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS)) {
7508+
if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
7509+
!CHECK_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS) &&
7510+
attrhash_cmp(pi->attr, attr_new)) {
75117511
bgp_dest_unlock_node(dest);
75127512
bgp_attr_unintern(&attr_new);
75137513
aspath_unintern(&attr.aspath);
@@ -9759,8 +9759,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
97599759
if (bpi) {
97609760
/* Ensure the (source route) type is updated. */
97619761
bpi->type = type;
9762-
if (attrhash_cmp(bpi->attr, new_attr)
9763-
&& !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
9762+
if (!CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
9763+
attrhash_cmp(bpi->attr, new_attr)) {
97649764
bgp_attr_unintern(&new_attr);
97659765
aspath_unintern(&attr.aspath);
97669766
bgp_dest_unlock_node(bn);

bgpd/rfapi/rfapi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
946946
}
947947
}
948948

949-
if (attrhash_cmp(bpi->attr, new_attr)
950-
&& !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
949+
if (!CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && attrhash_cmp(bpi->attr, new_attr)) {
951950
bgp_attr_unintern(&new_attr);
952951
bgp_dest_unlock_node(bn);
953952

0 commit comments

Comments
 (0)