Skip to content

Commit 6e7f305

Browse files
committed
bgpd: Convert from struct bgp_node to struct bgp_dest
This is based on @donaldsharp's work The current code base is the struct bgp_node data structure. The problem with this is that it creates a bunch of extra data per route_node. The table structure generates ‘holder’ nodes that are never going to receive bgp routes, and now the memory of those nodes is allocated as if they are a full bgp_node. After splitting up the bgp_node into bgp_dest and route_node, the memory of ‘holder’ node which does not have any bgp data will be allocated as the route_node, not the bgp_node, and the memory usage is reduced. The memory usage of BGP node will be reduced from 200B to 96B. The total memory usage optimization of this part is ~16.00%. Signed-off-by: Donald Sharp <[email protected]> Signed-off-by: Yuqing Zhao <[email protected]>
1 parent 451fb24 commit 6e7f305

14 files changed

+163
-132
lines changed

bgpd/bgp_bmp.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1307,7 +1307,7 @@ static int bmp_process(struct bgp *bgp, afi_t afi, safi_t safi,
13071307
if (frrtrace_enabled(frr_bgp, bmp_process)) {
13081308
char pfxprint[PREFIX2STR_BUFFER];
13091309

1310-
prefix2str(&bn->p, pfxprint, sizeof(pfxprint));
1310+
prefix2str(&bn->rn->p, pfxprint, sizeof(pfxprint));
13111311
frrtrace(5, frr_bgp, bmp_process, peer, pfxprint, afi, safi,
13121312
withdraw);
13131313
}

bgpd/bgp_evpn.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -1699,7 +1699,7 @@ static void bgp_evpn_get_sync_info(struct bgp *bgp, esi_t *esi,
16991699
int paths_eq;
17001700
struct ethaddr *tmp_mac;
17011701
bool mac_cmp = false;
1702-
struct prefix_evpn *evp = (struct prefix_evpn *)&dest->p;
1702+
struct prefix_evpn *evp = (struct prefix_evpn *)&dest->rn->p;
17031703

17041704

17051705
/* mac comparison is not needed for MAC-only routes */
@@ -2361,15 +2361,15 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
23612361
* VNI table MAC-IP prefixes don't have MAC so make sure it's set from
23622362
* path info here.
23632363
*/
2364-
if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)&dest->p)) {
2364+
if (is_evpn_prefix_ipaddr_none((struct prefix_evpn *)&dest->rn->p)) {
23652365
/* VNI MAC -> Global */
23662366
evpn_type2_prefix_global_copy(
2367-
&evp, (struct prefix_evpn *)&dest->p, NULL /* mac */,
2367+
&evp, (struct prefix_evpn *)&dest->rn->p, NULL /* mac */,
23682368
evpn_type2_path_info_get_ip(local_pi));
23692369
} else {
23702370
/* VNI IP -> Global */
23712371
evpn_type2_prefix_global_copy(
2372-
&evp, (struct prefix_evpn *)&dest->p,
2372+
&evp, (struct prefix_evpn *)&dest->rn->p,
23732373
evpn_type2_path_info_get_mac(local_pi), NULL /* ip */);
23742374
}
23752375

@@ -3091,7 +3091,7 @@ static int install_evpn_route_entry_in_vni_common(
30913091

30923092
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
30933093
zlog_debug("VNI %d path %pFX chg to %s es",
3094-
vpn->vni, &pi->net->p,
3094+
vpn->vni, &pi->net->rn->p,
30953095
new_local_es ? "local"
30963096
: "non-local");
30973097
bgp_path_info_set_flag(dest, pi, BGP_PATH_ATTR_CHANGED);
@@ -4174,7 +4174,7 @@ void bgp_evpn_import_type2_route(struct bgp_path_info *pi, int import)
41744174
return;
41754175

41764176
install_uninstall_evpn_route(bgp_evpn, AFI_L2VPN, SAFI_EVPN,
4177-
&pi->net->p, pi, import);
4177+
&pi->net->rn->p, pi, import);
41784178
}
41794179

41804180
/*
@@ -7259,7 +7259,7 @@ static void bgp_evpn_remote_ip_hash_add(struct bgpevpn *vpn,
72597259
|| !CHECK_FLAG(pi->flags, BGP_PATH_VALID))
72607260
return;
72617261

7262-
evp = (struct prefix_evpn *)&pi->net->p;
7262+
evp = (struct prefix_evpn *)&pi->net->rn->p;
72637263

72647264
if (evp->family != AF_EVPN
72657265
|| evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE
@@ -7292,7 +7292,7 @@ static void bgp_evpn_remote_ip_hash_del(struct bgpevpn *vpn,
72927292
if (!evpn_resolve_overlay_index())
72937293
return;
72947294

7295-
evp = (struct prefix_evpn *)&pi->net->p;
7295+
evp = (struct prefix_evpn *)&pi->net->rn->p;
72967296

72977297
if (evp->family != AF_EVPN
72987298
|| evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE
@@ -7337,7 +7337,7 @@ static void show_remote_ip_entry(struct hash_bucket *bucket, void *args)
73377337
ipaddr2str(&ip->addr, buf, sizeof(buf)));
73387338
vty_out(vty, " Linked MAC/IP routes:\n");
73397339
for (ALL_LIST_ELEMENTS_RO(ip->macip_path_list, node, pi))
7340-
vty_out(vty, " %pFX\n", &pi->net->p);
7340+
vty_out(vty, " %pFX\n", &pi->net->rn->p);
73417341
}
73427342

73437343
void bgp_evpn_show_remote_ip_hash(struct hash_bucket *bucket, void *args)

bgpd/bgp_evpn_mh.c

+21-21
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ int delete_global_ead_evi_routes(struct bgp *bgp, struct bgpevpn *vpn)
527527
{
528528
afi_t afi;
529529
safi_t safi;
530-
struct bgp_dest *rdrn, *rn;
530+
struct bgp_dest *rdrn, *bd;
531531
struct bgp_table *table;
532532
struct bgp_path_info *pi;
533533

@@ -543,15 +543,15 @@ int delete_global_ead_evi_routes(struct bgp *bgp, struct bgpevpn *vpn)
543543
* Iterate over all the routes in this table and delete EAD/EVI
544544
* routes
545545
*/
546-
for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) {
547-
struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p;
546+
for (bd = bgp_table_top(table); bd; bd = bgp_route_next(bd)) {
547+
struct prefix_evpn *evp = (struct prefix_evpn *)&bd->rn->p;
548548

549549
if (evp->prefix.route_type != BGP_EVPN_AD_ROUTE)
550550
continue;
551551

552-
delete_evpn_route_entry(bgp, afi, safi, rn, &pi);
552+
delete_evpn_route_entry(bgp, afi, safi, bd, &pi);
553553
if (pi)
554-
bgp_process(bgp, rn, afi, safi);
554+
bgp_process(bgp, bd, afi, safi);
555555
}
556556
}
557557

@@ -1583,7 +1583,7 @@ static void bgp_evpn_path_es_unlink(struct bgp_path_es_info *es_info)
15831583
pi = es_info->pi;
15841584
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
15851585
zlog_debug("vni %u path %pFX unlinked from es %s", es_info->vni,
1586-
&pi->net->p, es->esi_str);
1586+
&pi->net->rn->p, es->esi_str);
15871587

15881588
if (es_info->vni)
15891589
list_delete_node(es->macip_evi_path_list,
@@ -1641,7 +1641,7 @@ void bgp_evpn_path_es_link(struct bgp_path_info *pi, vni_t vni, esi_t *esi)
16411641
bgp_evpn_path_es_unlink(es_info);
16421642

16431643
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
1644-
zlog_debug("vni %u path %pFX linked to es %s", vni, &pi->net->p,
1644+
zlog_debug("vni %u path %pFX linked to es %s", vni, &pi->net->rn->p,
16451645
es->esi_str);
16461646

16471647
/* link mac-ip path to the new destination ES */
@@ -1661,7 +1661,7 @@ static bool bgp_evpn_is_macip_path(struct bgp_path_info *pi)
16611661
* skipped) as these lists are maintained for managing
16621662
* host routes in the tenant VRF
16631663
*/
1664-
evp = (struct prefix_evpn *)&pi->net->p;
1664+
evp = (struct prefix_evpn *)&pi->net->rn->p;
16651665
return is_evpn_prefix_ipaddr_v4(evp) || is_evpn_prefix_ipaddr_v6(evp);
16661666
}
16671667

@@ -1697,7 +1697,7 @@ bgp_evpn_es_path_update_on_es_vrf_chg(struct bgp_evpn_es_vrf *es_vrf,
16971697
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
16981698
zlog_debug(
16991699
"update path %pFX linked to es %s on vrf chg",
1700-
&pi->net->p, es->esi_str);
1700+
&pi->net->rn->p, es->esi_str);
17011701
bgp_evpn_route_entry_install_if_vrf_match(es_vrf->bgp_vrf, pi,
17021702
1);
17031703
}
@@ -2086,7 +2086,7 @@ static void bgp_evpn_mac_update_on_es_oper_chg(struct bgp_evpn_es *es)
20862086
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
20872087
zlog_debug(
20882088
"update path %d %pFX linked to es %s on oper chg",
2089-
es_info->vni, &pi->net->p, es->esi_str);
2089+
es_info->vni, &pi->net->rn->p, es->esi_str);
20902090

20912091
bgp_evpn_update_type2_route_entry(bgp, vpn, pi->net, pi,
20922092
__func__);
@@ -2135,7 +2135,7 @@ static void bgp_evpn_mac_update_on_es_local_chg(struct bgp_evpn_es *es,
21352135
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
21362136
zlog_debug(
21372137
"update path %pFX linked to es %s on chg to %s",
2138-
&pi->net->p, es->esi_str,
2138+
&pi->net->rn->p, es->esi_str,
21392139
is_local ? "local" : "non-local");
21402140

21412141
attr_tmp = *pi->attr;
@@ -3160,7 +3160,7 @@ bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, struct bgp_path_info *pi,
31603160
esi_t *esi;
31613161
struct bgp_evpn_es_vrf *es_vrf = NULL;
31623162
struct bgp_path_info *parent_pi;
3163-
struct bgp_node *rn;
3163+
struct bgp_dest *bd;
31643164
struct prefix_evpn *evp;
31653165
struct bgp_path_info *mpinfo;
31663166
bool use_l3nhg = false;
@@ -3176,11 +3176,11 @@ bool bgp_evpn_path_es_use_nhg(struct bgp *bgp_vrf, struct bgp_path_info *pi,
31763176
if (!parent_pi)
31773177
return false;
31783178

3179-
rn = parent_pi->net;
3180-
if (!rn)
3179+
bd = parent_pi->net;
3180+
if (!bd)
31813181
return false;
31823182

3183-
evp = (struct prefix_evpn *)&rn->p;
3183+
evp = (struct prefix_evpn *)&bd->rn->p;
31843184
if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE)
31853185
return false;
31863186

@@ -4706,7 +4706,7 @@ static void bgp_evpn_path_nh_unlink(struct bgp_path_evpn_nh_info *nh_info)
47064706
pi = nh_info->pi;
47074707
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
47084708
zlog_debug("path %s unlinked from nh %s %s",
4709-
pi->net ? prefix2str(&pi->net->p, prefix_buf,
4709+
pi->net ? prefix2str(&pi->net->rn->p, prefix_buf,
47104710
sizeof(prefix_buf))
47114711
: "",
47124712
nh->bgp_vrf->name_pretty, nh->nh_str);
@@ -4741,7 +4741,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi)
47414741
if (!bgp_vrf->evpn_nh_table) {
47424742
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
47434743
zlog_debug("path %pFX linked to vrf %s failed",
4744-
&pi->net->p, bgp_vrf->name_pretty);
4744+
&pi->net->rn->p, bgp_vrf->name_pretty);
47454745
return;
47464746
}
47474747

@@ -4764,7 +4764,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi)
47644764

47654765
/* find-create nh */
47664766
memset(&ip, 0, sizeof(ip));
4767-
if (pi->net->p.family == AF_INET6) {
4767+
if (pi->net->rn->p.family == AF_INET6) {
47684768
SET_IPADDR_V6(&ip);
47694769
memcpy(&ip.ipaddr_v6, &pi->attr->mp_nexthop_global,
47704770
sizeof(ip.ipaddr_v6));
@@ -4788,7 +4788,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi)
47884788
bgp_evpn_path_nh_unlink(nh_info);
47894789

47904790
if (BGP_DEBUG(evpn_mh, EVPN_MH_RT))
4791-
zlog_debug("path %pFX linked to nh %s %s", &pi->net->p,
4791+
zlog_debug("path %pFX linked to nh %s %s", &pi->net->rn->p,
47924792
nh->bgp_vrf->name_pretty, nh->nh_str);
47934793

47944794
/* link mac-ip path to the new nh */
@@ -4803,7 +4803,7 @@ static void bgp_evpn_path_nh_link(struct bgp *bgp_vrf, struct bgp_path_info *pi)
48034803
if (!nh->ref_pi)
48044804
zlog_debug(
48054805
"path %pFX linked to nh %s %s with no valid pi",
4806-
&pi->net->p, nh->bgp_vrf->name_pretty,
4806+
&pi->net->rn->p, nh->bgp_vrf->name_pretty,
48074807
nh->nh_str);
48084808
}
48094809
}
@@ -4840,7 +4840,7 @@ static void bgp_evpn_nh_show_entry(struct bgp_evpn_nh *nh, struct vty *vty,
48404840

48414841
prefix_mac2str(&nh->rmac, mac_buf, sizeof(mac_buf));
48424842
if (nh->ref_pi && nh->ref_pi->net)
4843-
prefix2str(&nh->ref_pi->net->p, prefix_buf, sizeof(prefix_buf));
4843+
prefix2str(&nh->ref_pi->net->rn->p, prefix_buf, sizeof(prefix_buf));
48444844
else
48454845
prefix_buf[0] = '\0';
48464846
if (json) {

bgpd/bgp_evpn_private.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,7 @@ bgp_evpn_vni_node_lookup(const struct bgpevpn *vpn, const struct prefix_evpn *p,
750750
extern void bgp_evpn_import_route_in_vrfs(struct bgp_path_info *pi, int import);
751751
extern void bgp_evpn_update_type2_route_entry(struct bgp *bgp,
752752
struct bgpevpn *vpn,
753-
struct bgp_node *rn,
753+
struct bgp_dest *rn,
754754
struct bgp_path_info *local_pi,
755755
const char *caller);
756756
extern int bgp_evpn_route_entry_install_if_vrf_match(struct bgp *bgp_vrf,

bgpd/bgp_evpn_vty.c

+4-4
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
714714
json_object *json, int detail,
715715
bool global_table)
716716
{
717-
struct bgp_node *rn;
717+
struct bgp_dest *bd;
718718
struct bgp_path_info *pi;
719719
int header = detail ? 0 : 1;
720720
uint32_t path_cnt;
@@ -747,7 +747,7 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
747747
json_object *json_path = NULL;
748748

749749
pi = es_info->pi;
750-
rn = pi->net;
750+
bd = pi->net;
751751

752752
if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID))
753753
continue;
@@ -765,11 +765,11 @@ static void bgp_evpn_show_routes_mac_ip_es(struct vty *vty, esi_t *esi,
765765

766766
if (detail)
767767
route_vty_out_detail(
768-
vty, bgp, rn, bgp_dest_get_prefix(rn),
768+
vty, bgp, bd, bgp_dest_get_prefix(bd),
769769
pi, AFI_L2VPN, SAFI_EVPN,
770770
RPKI_NOT_BEING_USED, json_path);
771771
else
772-
route_vty_out(vty, &rn->p, pi, 0, SAFI_EVPN,
772+
route_vty_out(vty, &bd->rn->p, pi, 0, SAFI_EVPN,
773773
json_path, false);
774774

775775
if (json)

bgpd/bgp_fsm.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi)
723723
if (bgp_debug_neighbor_events(peer))
724724
zlog_debug(
725725
"%pBP Long-lived set stale community (LLGR_STALE) for: %pFX",
726-
peer, &dest->p);
726+
peer, &dest->rn->p);
727727

728728
attr = *pi->attr;
729729
bgp_attr_add_llgr_community(&attr);
@@ -751,7 +751,7 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi)
751751
if (bgp_debug_neighbor_events(peer))
752752
zlog_debug(
753753
"%pBP Long-lived set stale community (LLGR_STALE) for: %pFX",
754-
peer, &dest->p);
754+
peer, &dest->rn->p);
755755

756756
attr = *pi->attr;
757757
bgp_attr_add_llgr_community(&attr);

bgpd/bgp_route.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
#include "bgpd/bgp_route_clippy.c"
7878

7979
DEFINE_HOOK(bgp_snmp_update_stats,
80-
(struct bgp_node *rn, struct bgp_path_info *pi, bool added),
80+
(struct bgp_dest *rn, struct bgp_path_info *pi, bool added),
8181
(rn, pi, added));
8282

8383
DEFINE_HOOK(bgp_rpki_prefix_status,
@@ -265,7 +265,7 @@ struct bgp_path_info_extra *bgp_path_info_extra_get(struct bgp_path_info *pi)
265265
{
266266
if (!pi->extra)
267267
pi->extra = bgp_path_info_extra_new();
268-
if (!pi->extra->evpn && pi->net && pi->net->p.family == AF_EVPN)
268+
if (!pi->extra->evpn && pi->net && pi->net->rn->p.family == AF_EVPN)
269269
pi->extra->evpn =
270270
XCALLOC(MTYPE_BGP_ROUTE_EXTRA_EVPN,
271271
sizeof(struct bgp_path_info_extra_evpn));

bgpd/bgp_route.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ static inline bool bgp_check_withdrawal(struct bgp *bgp, struct bgp_dest *dest,
670670

671671
/* called before bgp_process() */
672672
DECLARE_HOOK(bgp_process,
673-
(struct bgp * bgp, afi_t afi, safi_t safi, struct bgp_dest *bn,
673+
(struct bgp *bgp, afi_t afi, safi_t safi, struct bgp_dest *bn,
674674
struct peer *peer, bool withdraw),
675675
(bgp, afi, safi, bn, peer, withdraw));
676676

0 commit comments

Comments
 (0)