]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: move mp_nexthop_prefer_global boolean attribute to nh_flag
authorLouis Scalbert <louis.scalbert@6wind.com>
Fri, 29 Apr 2022 17:41:57 +0000 (19:41 +0200)
committerLouis Scalbert <louis.scalbert@6wind.com>
Fri, 16 Dec 2022 14:07:00 +0000 (15:07 +0100)
Previous commits have introduced a new 8 bits nh_flag in the attr
struct that has increased the memory footprint.

Move the mp_nexthop_prefer_global boolean in the attr structure that
takes 8 bits to the new nh_flag in order to go back to the previous
memory utilization.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
bgpd/bgp_attr.h
bgpd/bgp_mpath.c
bgpd/bgp_nht.c
bgpd/bgp_route.c
bgpd/bgp_routemap.c
bgpd/bgp_snmp_bgp4v2.c
bgpd/bgp_zebra.c

index 67677f999d68d77842016e3481381e2a8a295515..4eb742422d09d2b91eefcf9f4e3f9ae1a5dfe06c 100644 (file)
@@ -174,6 +174,7 @@ struct attr {
 
 #define BGP_ATTR_NH_VALID 0x01
 #define BGP_ATTR_NH_IF_OPERSTATE 0x02
+#define BGP_ATTR_NH_MP_PREFER_GLOBAL 0x04 /* MP Nexthop preference */
 
        /* Path origin attribute */
        uint8_t origin;
@@ -224,9 +225,6 @@ struct attr {
        /* MP Nexthop length */
        uint8_t mp_nexthop_len;
 
-       /* MP Nexthop preference */
-       uint8_t mp_nexthop_prefer_global;
-
        /* Static MAC for EVPN */
        uint8_t sticky;
 
index 32a5e14b1158580998b8820084e34c8be928fff3..84c847d79647001578de896f3e171dfa28c68f38 100644 (file)
@@ -142,15 +142,21 @@ int bgp_path_info_nexthop_cmp(struct bgp_path_info *bpi1,
                                        &bpi2->attr->mp_nexthop_global);
                                break;
                        case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
-                               addr1 = (bpi1->attr->mp_nexthop_prefer_global)
+                               addr1 = (CHECK_FLAG(
+                                               bpi1->attr->nh_flag,
+                                               BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                                ? bpi1->attr->mp_nexthop_global
                                                : bpi1->attr->mp_nexthop_local;
-                               addr2 = (bpi2->attr->mp_nexthop_prefer_global)
+                               addr2 = (CHECK_FLAG(
+                                               bpi2->attr->nh_flag,
+                                               BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                                ? bpi2->attr->mp_nexthop_global
                                                : bpi2->attr->mp_nexthop_local;
 
-                               if (!bpi1->attr->mp_nexthop_prefer_global
-                                   && !bpi2->attr->mp_nexthop_prefer_global)
+                               if (!CHECK_FLAG(bpi1->attr->nh_flag,
+                                               BGP_ATTR_NH_MP_PREFER_GLOBAL) &&
+                                   !CHECK_FLAG(bpi2->attr->nh_flag,
+                                               BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                        compare = !bgp_interface_same(
                                                bpi1->peer->ifp,
                                                bpi2->peer->ifp);
index a192b037aca253396601f9f55ecb018b40f1bddf..b6b0c584d73860573d40223f9332615204a4965e 100644 (file)
@@ -1005,7 +1005,8 @@ static int make_prefix(int afi, struct bgp_path_info *pi, struct prefix *p)
                         */
                        else if (pi->attr->mp_nexthop_len
                                 == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) {
-                               if (pi->attr->mp_nexthop_prefer_global)
+                               if (CHECK_FLAG(pi->attr->nh_flag,
+                                              BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                        p->u.prefix6 =
                                                pi->attr->mp_nexthop_global;
                                else
index bfb74e9379ae90b5ab4fa47a0950990ad8013a15..4370c304763f3a85540aae91b76b917cd54aad69 100644 (file)
@@ -9416,9 +9416,10 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
                                                       "link-local");
 
                                if ((IPV6_ADDR_CMP(&attr->mp_nexthop_global,
-                                                  &attr->mp_nexthop_local)
-                                    != 0)
-                                   && !attr->mp_nexthop_prefer_global)
+                                                  &attr->mp_nexthop_local) !=
+                                    0) &&
+                                   !CHECK_FLAG(attr->nh_flag,
+                                               BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                        json_object_boolean_true_add(
                                                json_nexthop_ll, "used");
                                else
@@ -9430,10 +9431,11 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
                } else {
                        /* Display LL if LL/Global both in table unless
                         * prefer-global is set */
-                       if (((attr->mp_nexthop_len
-                             == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL)
-                            && !attr->mp_nexthop_prefer_global)
-                           || (path->peer->conf_if)) {
+                       if (((attr->mp_nexthop_len ==
+                             BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) &&
+                            !CHECK_FLAG(attr->nh_flag,
+                                        BGP_ATTR_NH_MP_PREFER_GLOBAL)) ||
+                           (path->peer->conf_if)) {
                                if (path->peer->conf_if) {
                                        len = vty_out(vty, "%s",
                                                      path->peer->conf_if);
@@ -10695,7 +10697,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
                        json_object_boolean_true_add(json_nexthop_ll,
                                                     "accessible");
 
-                       if (!attr->mp_nexthop_prefer_global)
+                       if (!CHECK_FLAG(attr->nh_flag,
+                                       BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                json_object_boolean_true_add(json_nexthop_ll,
                                                             "used");
                        else
@@ -10705,7 +10708,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
                        vty_out(vty, "    (%s) %s\n",
                                inet_ntop(AF_INET6, &attr->mp_nexthop_local,
                                          buf, INET6_ADDRSTRLEN),
-                               attr->mp_nexthop_prefer_global
+                               CHECK_FLAG(attr->nh_flag,
+                                          BGP_ATTR_NH_MP_PREFER_GLOBAL)
                                        ? "(prefer-global)"
                                        : "(used)");
                }
index 1ce2eb435266a6bab6b219887bd3851a88fa80cd..f779b34371e13ff5bb7207b933c4dbe7ae2b9643 100644 (file)
@@ -3531,11 +3531,11 @@ route_set_ipv6_nexthop_prefer_global(void *rule, const struct prefix *prefix,
        if (CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IN)
            || CHECK_FLAG(peer->rmap_type, PEER_RMAP_TYPE_IMPORT)) {
                /* Set next hop preference to global */
-               path->attr->mp_nexthop_prefer_global = true;
+               SET_FLAG(path->attr->nh_flag, BGP_ATTR_NH_MP_PREFER_GLOBAL);
                SET_FLAG(path->attr->rmap_change_flags,
                         BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED);
        } else {
-               path->attr->mp_nexthop_prefer_global = false;
+               UNSET_FLAG(path->attr->nh_flag, BGP_ATTR_NH_MP_PREFER_GLOBAL);
                SET_FLAG(path->attr->rmap_change_flags,
                         BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED);
        }
index 2d70aa94d35b0c7ea1f4b02db03f0c296abf856b..467a33694a813beeca89866c67d2dca82ffbeebd 100644 (file)
@@ -684,7 +684,8 @@ static uint8_t *bgp4v2PathAttrTable(struct variable *v, oid name[],
                case BGP_ATTR_NHLEN_IPV6_GLOBAL:
                        return SNMP_INTEGER(2);
                case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
-                       if (path->attr->mp_nexthop_prefer_global)
+                       if (CHECK_FLAG(path->attr->nh_flag,
+                                      BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                return SNMP_INTEGER(2);
                        else
                                return SNMP_INTEGER(4);
@@ -698,7 +699,8 @@ static uint8_t *bgp4v2PathAttrTable(struct variable *v, oid name[],
                case BGP_ATTR_NHLEN_IPV6_GLOBAL:
                        return SNMP_IP6ADDRESS(path->attr->mp_nexthop_global);
                case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL:
-                       if (path->attr->mp_nexthop_prefer_global)
+                       if (CHECK_FLAG(path->attr->nh_flag,
+                                      BGP_ATTR_NH_MP_PREFER_GLOBAL))
                                return SNMP_IP6ADDRESS(
                                        path->attr->mp_nexthop_global);
                        else
index 4f1808829c66938583d447d196e3091bad137f6a..82fdce3b44e648b1545bd7707a923679f6538b0b 100644 (file)
@@ -1025,7 +1025,8 @@ bgp_path_info_to_ipv6_nexthop(struct bgp_path_info *path, ifindex_t *ifindex)
            || path->attr->mp_nexthop_len
                       == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) {
                /* Check if route-map is set to prefer global over link-local */
-               if (path->attr->mp_nexthop_prefer_global) {
+               if (CHECK_FLAG(path->attr->nh_flag,
+                              BGP_ATTR_NH_MP_PREFER_GLOBAL)) {
                        nexthop = &path->attr->mp_nexthop_global;
                        if (IN6_IS_ADDR_LINKLOCAL(nexthop))
                                *ifindex = path->attr->nh_ifindex;