#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;
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);
}