]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: optimize attrhash_cmp calls
authorLouis Scalbert <louis.scalbert@6wind.com>
Tue, 11 Feb 2025 16:00:25 +0000 (17:00 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Tue, 1 Apr 2025 14:52:58 +0000 (16:52 +0200)
Only call attrhash_cmp when necessary.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
bgpd/bgp_evpn.c
bgpd/bgp_evpn_mh.c
bgpd/bgp_mplsvpn.c
bgpd/bgp_route.c
bgpd/rfapi/rfapi.c

index 488f635b81e5a957ef1dd844bb3d4f1993fa5c3e..ecb61dad55ad6ca4967ddeb766c58a8006029b44 100644 (file)
@@ -2062,8 +2062,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
                bgp_path_info_add(dest, tmp_pi);
        } else {
                tmp_pi = local_pi;
-               if (attrhash_cmp(tmp_pi->attr, attr)
-                   && !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
+               if (!CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(tmp_pi->attr, attr))
                        route_change = 0;
                else {
                        /*
@@ -3154,8 +3153,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf,
                pi = bgp_create_evpn_bgp_path_info(parent_pi, dest, &attr);
                new_pi = true;
        } else {
-               if (attrhash_cmp(pi->attr, &attr)
-                   && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
+               if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(pi->attr, &attr)) {
                        bgp_dest_unlock_node(dest);
                        return 0;
                }
@@ -3278,8 +3276,8 @@ static int install_evpn_route_entry_in_vni_common(
                 * install_evpn_route_entry_in_vni_mac() or
                 * install_evpn_route_entry_in_vni_ip()
                 */
-               if (attrhash_cmp(pi->attr, parent_pi->attr) &&
-                   !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED))
+               if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
+                   attrhash_cmp(pi->attr, parent_pi->attr))
                        return 0;
                /* The attribute has changed. */
                /* Add (or update) attribute to hash. */
index 0ef3740d880d46775f9548c94923a5a4b636be9a..bffbda75f79565209d1031e1194e4dbab65519af 100644 (file)
@@ -212,8 +212,8 @@ static int bgp_evpn_es_route_install(struct bgp *bgp,
                bgp_dest_lock_node((struct bgp_dest *)parent_pi->net);
                bgp_path_info_add(dest, pi);
        } else {
-               if (attrhash_cmp(pi->attr, parent_pi->attr)
-                               && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) {
+               if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
+                   attrhash_cmp(pi->attr, parent_pi->attr)) {
                        bgp_dest_unlock_node(dest);
                        return 0;
                }
@@ -421,8 +421,7 @@ int bgp_evpn_mh_route_update(struct bgp *bgp, struct bgp_evpn_es *es,
                bgp_path_info_add(dest, tmp_pi);
        } else {
                tmp_pi = local_pi;
-               if (attrhash_cmp(tmp_pi->attr, attr)
-                               && !CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED))
+               if (!CHECK_FLAG(tmp_pi->flags, BGP_PATH_REMOVED) && attrhash_cmp(tmp_pi->attr, attr))
                        *route_changed = 0;
                else {
                        /* The attribute has changed.
index d1d4c5af68c180ec101ed93a13d2a7dc3c0b7f9f..7a454d81096c29498970acc58d33c02ff2631232 100644 (file)
@@ -1207,8 +1207,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
                        return NULL;
                }
 
-               if (attrhash_cmp(bpi->attr, new_attr) && labelssame &&
-                   !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
+               if (labelssame && !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
+                   attrhash_cmp(bpi->attr, new_attr) &&
                    leak_update_nexthop_valid(to_bgp, bn, new_attr, afi, safi, source_bpi, bpi,
                                              bgp_orig, p,
                                              debug) == !!CHECK_FLAG(bpi->flags, BGP_PATH_VALID)) {
index 0c3f983f42bb2e95da7c48b95bdfb417e5d54ee2..4e458fbe4b01e50bac90e5799c9ff09fe6d3b3e7 100644 (file)
@@ -7505,9 +7505,9 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
                        break;
 
        if (pi) {
-               if (attrhash_cmp(pi->attr, attr_new)
-                   && !CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)
-                   && !CHECK_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS)) {
+               if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) &&
+                   !CHECK_FLAG(bgp->flags, BGP_FLAG_FORCE_STATIC_PROCESS) &&
+                   attrhash_cmp(pi->attr, attr_new)) {
                        bgp_dest_unlock_node(dest);
                        bgp_attr_unintern(&attr_new);
                        aspath_unintern(&attr.aspath);
@@ -9759,8 +9759,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p,
                if (bpi) {
                        /* Ensure the (source route) type is updated. */
                        bpi->type = type;
-                       if (attrhash_cmp(bpi->attr, new_attr)
-                           && !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
+                       if (!CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) &&
+                           attrhash_cmp(bpi->attr, new_attr)) {
                                bgp_attr_unintern(&new_attr);
                                aspath_unintern(&attr.aspath);
                                bgp_dest_unlock_node(bn);
index 241cbcb35992f49472b589e8f0dd715b7b729710..ae147e4b90ba01db17b2d36857f56d458a2d3876 100644 (file)
@@ -946,8 +946,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
                        }
                }
 
-               if (attrhash_cmp(bpi->attr, new_attr)
-                   && !CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
+               if (!CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED) && attrhash_cmp(bpi->attr, new_attr)) {
                        bgp_attr_unintern(&new_attr);
                        bgp_dest_unlock_node(bn);