]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: keep a backpointer to vrf instance in struct bgpevpn
authorMitesh Kanjariya <mitesh@marvel-07.cumulusnetworks.com>
Fri, 23 Feb 2018 09:16:32 +0000 (01:16 -0800)
committermitesh <mitesh@cumulusnetworks.com>
Tue, 27 Feb 2018 09:14:43 +0000 (01:14 -0800)
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 <mitesh@cumulusnetworks.com>
bgpd/bgp_evpn_private.h

index cc0ec82344b3f2c03cad7cc7a4fd1ca1806d82c5..54e9b014cf4c3a6b408760ba75d135111fd86a13 100644 (file)
@@ -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);
 }