]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: move the label per nexthop structs of bgp_path to an union
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 24 May 2023 15:26:13 +0000 (17:26 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Fri, 16 Jun 2023 08:54:58 +0000 (10:54 +0200)
The label per nexthop attributes take 24 bytes per bgp path
entry on AMD64 platform, and are only used for unicast paths.
The current patch-set introduces a similar attributes, but that
will be used only for l3vpn paths. To gain some memory on the
bgp_path_info structure in the next commit, do some changes.

Create an 'mplsvpn' union structure that will either include the
label per nexthop structs for ipv4 paths, or the l3vpn paths
structures. The 'label_nexthop_cache' and the 'label_nh_thread'
attributes of the 'bgp_path_info' structure are moved into an
union under a new structure called 'bgp_mplsvpn_label_nh_blnc'.
The flags attribute of 'bgp_path_info' is increased from 16 bits
to 32 bits, and the BGP_PATH_MPLSVPN_LABEL_NH flag is added to
know the 'mplsvpn' usage.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
bgpd/bgp_labelpool.c
bgpd/bgp_mplsvpn.c
bgpd/bgp_route.h

index 91763b85a0d598098fbe2831a15275ec6745d656..3afb3db06b33572b193ecc600024fd1867ef4770 100644 (file)
@@ -1147,7 +1147,8 @@ static void show_bgp_nexthop_label_afi(struct vty *vty, afi_t afi,
                if (!detail)
                        continue;
                vty_out(vty, "  Paths:\n");
-               LIST_FOREACH (path, &(iter->paths), label_nh_thread) {
+               LIST_FOREACH (path, &(iter->paths),
+                             mplsvpn.blnc.label_nh_thread) {
                        dest = path->net;
                        table = bgp_dest_table(dest);
                        assert(dest && table);
index 0ac76c48b471e88ae5d1851a0f6896d8db6d430f..4b8aa1ee702bd28ff6bb546835d8674406568288 100644 (file)
@@ -1341,14 +1341,18 @@ void bgp_mplsvpn_path_nh_label_unlink(struct bgp_path_info *pi)
        if (!pi)
                return;
 
-       blnc = pi->label_nexthop_cache;
+       if (!CHECK_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH))
+               return;
+
+       blnc = pi->mplsvpn.blnc.label_nexthop_cache;
 
        if (!blnc)
                return;
 
-       LIST_REMOVE(pi, label_nh_thread);
-       pi->label_nexthop_cache->path_count--;
-       pi->label_nexthop_cache = NULL;
+       LIST_REMOVE(pi, mplsvpn.blnc.label_nh_thread);
+       pi->mplsvpn.blnc.label_nexthop_cache->path_count--;
+       pi->mplsvpn.blnc.label_nexthop_cache = NULL;
+       UNSET_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH);
 
        if (LIST_EMPTY(&(blnc->paths)))
                bgp_label_per_nexthop_free(blnc);
@@ -1390,7 +1394,7 @@ static int bgp_mplsvpn_get_label_per_nexthop_cb(mpls_label_t label,
                        ZEBRA_MPLS_LABELS_ADD, blnc->label, blnc->nh->ifindex,
                        blnc->nh->vrf_id, ZEBRA_LSP_BGP, &blnc->nexthop);
 
-       LIST_FOREACH (pi, &(blnc->paths), label_nh_thread) {
+       LIST_FOREACH (pi, &(blnc->paths), mplsvpn.blnc.label_nh_thread) {
                if (!pi->net)
                        continue;
                table = bgp_dest_table(pi->net);
@@ -1457,7 +1461,7 @@ _vpn_leak_from_vrf_get_per_nexthop_label(struct bgp_path_info *pi,
                           bgp_mplsvpn_get_label_per_nexthop_cb);
        }
 
-       if (pi->label_nexthop_cache == blnc)
+       if (pi->mplsvpn.blnc.label_nexthop_cache == blnc)
                /* no change */
                return blnc->label;
 
@@ -1466,9 +1470,10 @@ _vpn_leak_from_vrf_get_per_nexthop_label(struct bgp_path_info *pi,
        bgp_mplsvpn_path_nh_label_unlink(pi);
 
        /* updates NHT pi list reference */
-       LIST_INSERT_HEAD(&(blnc->paths), pi, label_nh_thread);
-       pi->label_nexthop_cache = blnc;
-       pi->label_nexthop_cache->path_count++;
+       LIST_INSERT_HEAD(&(blnc->paths), pi, mplsvpn.blnc.label_nh_thread);
+       pi->mplsvpn.blnc.label_nexthop_cache = blnc;
+       pi->mplsvpn.blnc.label_nexthop_cache->path_count++;
+       SET_FLAG(pi->flags, BGP_PATH_MPLSVPN_LABEL_NH);
        blnc->last_update = monotime(NULL);
 
        /* then add or update the selected nexthop */
index 9bd9e48e22775da60de921ede5bfbba3d60c72e0..96aa98c277fe7262f9b77b7a3ed18a7ad8f0c17c 100644 (file)
@@ -246,6 +246,14 @@ struct bgp_path_info_extra {
        struct bgp_path_mh_info *mh_info;
 };
 
+struct bgp_mplsvpn_label_nh {
+       /* For nexthop per label linked list */
+       LIST_ENTRY(bgp_path_info) label_nh_thread;
+
+       /* Back pointer to the bgp label per nexthop structure */
+       struct bgp_label_per_nexthop_cache *label_nexthop_cache;
+};
+
 struct bgp_path_info {
        /* For linked list. */
        struct bgp_path_info *next;
@@ -298,6 +306,7 @@ struct bgp_path_info {
 #define BGP_PATH_ANNC_NH_SELF (1 << 14)
 #define BGP_PATH_LINK_BW_CHG (1 << 15)
 #define BGP_PATH_ACCEPT_OWN (1 << 16)
+#define BGP_PATH_MPLSVPN_LABEL_NH (1 << 17)
 
        /* BGP route type.  This can be static, RIP, OSPF, BGP etc.  */
        uint8_t type;
@@ -320,11 +329,9 @@ struct bgp_path_info {
        uint32_t addpath_rx_id;
        struct bgp_addpath_info_data tx_addpath;
 
-       /* For nexthop per label linked list */
-       LIST_ENTRY(bgp_path_info) label_nh_thread;
-
-       /* Back pointer to the bgp label per nexthop structure */
-       struct bgp_label_per_nexthop_cache *label_nexthop_cache;
+       union {
+               struct bgp_mplsvpn_label_nh blnc;
+       } mplsvpn;
 };
 
 /* Structure used in BGP path selection */