From bc4606bd1ac5c34dc1f735898e0ad37a862e2892 Mon Sep 17 00:00:00 2001 From: Mitesh Kanjariya Date: Fri, 23 Feb 2018 01:16:32 -0800 Subject: [PATCH] bgpd: keep a backpointer to vrf instance in struct bgpevpn We will keep a backpointer to bgp vrf instance in bgpevpn. struct bgpevpn denotes a l2vni and bgp_vrf corresponds to l3vni. A back pointer to the vrf will provide efficient access to vrf when needed. Signed-off-by: Mitesh Kanjariya --- bgpd/bgp_evpn_private.h | 50 +++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index cc0ec82344..54e9b014cf 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -62,6 +62,8 @@ struct bgpevpn { #define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */ #define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */ + struct bgp *bgp_vrf; /* back pointer to the vrf instance */ + /* Flag to indicate if we are advertising the g/w mac ip for this VNI*/ u_int8_t advertise_gw_macip; @@ -132,65 +134,59 @@ static inline int bgp_evpn_vrf_rd_matches_existing(struct bgp *bgp_vrf, static inline vni_t bgpevpn_get_l3vni(struct bgpevpn *vpn) { - struct bgp *bgp_vrf = NULL; - - bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); - if (!bgp_vrf) - return 0; - - return bgp_vrf->l3vni; + return vpn->bgp_vrf ? vpn->bgp_vrf->l3vni : 0; } static inline void bgpevpn_get_rmac(struct bgpevpn *vpn, struct ethaddr *rmac) { - struct bgp *bgp_vrf = NULL; - memset(rmac, 0, sizeof(struct ethaddr)); - bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); - if (!bgp_vrf) + if (!vpn->bgp_vrf) return; - memcpy(rmac, &bgp_vrf->rmac, sizeof(struct ethaddr)); + memcpy(rmac, &vpn->bgp_vrf->rmac, sizeof(struct ethaddr)); } static inline struct list *bgpevpn_get_vrf_export_rtl(struct bgpevpn *vpn) { - struct bgp *bgp_vrf = NULL; - - bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); - if (!bgp_vrf) + if (!vpn->bgp_vrf) return NULL; - return bgp_vrf->vrf_export_rtl; + return vpn->bgp_vrf->vrf_export_rtl; } static inline struct list *bgpevpn_get_vrf_import_rtl(struct bgpevpn *vpn) { - struct bgp *bgp_vrf = NULL; - - bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); - if (!bgp_vrf) + if (!vpn->bgp_vrf) return NULL; - return bgp_vrf->vrf_import_rtl; + return vpn->bgp_vrf->vrf_import_rtl; } static inline void bgpevpn_unlink_from_l3vni(struct bgpevpn *vpn) { - struct bgp *bgp_vrf = NULL; - - bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); - if (!bgp_vrf || !bgp_vrf->l2vnis) + /* bail if vpn is not associated to bgp_vrf */ + if (!vpn->bgp_vrf) return; - listnode_delete(bgp_vrf->l2vnis, vpn); + + listnode_delete(vpn->bgp_vrf->l2vnis, vpn); + + /* remove the backpointer to the vrf instance */ + vpn->bgp_vrf = NULL; } static inline void bgpevpn_link_to_l3vni(struct bgpevpn *vpn) { struct bgp *bgp_vrf = NULL; + /* bail if vpn is already associated to vrf */ + if (vpn->bgp_vrf) + return; + bgp_vrf = bgp_lookup_by_vrf_id(vpn->tenant_vrf_id); if (!bgp_vrf || !bgp_vrf->l2vnis) return; + + /* associate the vpn to the bgp_vrf instance */ + vpn->bgp_vrf = bgp_vrf; listnode_add_sort(bgp_vrf->l2vnis, vpn); } -- 2.39.5