]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_evpn_private.h
Merge pull request #3367 from karamalla0406/frr3333
[mirror_frr.git] / bgpd / bgp_evpn_private.h
index 1efde3a71934c0c56312fd55b92dc9d7faeb9537..f0017f3533fac2d7f57edc1b752040e1978a48f4 100644 (file)
@@ -31,9 +31,7 @@
 #define RT_ADDRSTRLEN 28
 
 /* EVPN prefix lengths. This reprsent the sizeof struct prefix_evpn  */
-#define EVPN_TYPE_2_ROUTE_PREFIXLEN      224
-#define EVPN_TYPE_3_ROUTE_PREFIXLEN      224
-#define EVPN_TYPE_5_ROUTE_PREFIXLEN      224
+#define EVPN_ROUTE_PREFIXLEN     224
 
 /* EVPN route types. */
 typedef enum {
@@ -98,6 +96,42 @@ struct bgpevpn {
 
 DECLARE_QOBJ_TYPE(bgpevpn)
 
+struct evpnes {
+
+       /* Ethernet Segment Identifier */
+       esi_t esi;
+
+       /* es flags */
+       uint16_t flags;
+#define EVPNES_LOCAL   0x01
+#define EVPNES_REMOTE  0x02
+
+       /*
+        * Id for deriving the RD
+        * automatically for this ESI
+        */
+       uint16_t rd_id;
+
+       /* RD for this VNI. */
+       struct prefix_rd prd;
+
+       /* originator ip address  */
+       struct ipaddr originator_ip;
+
+       /* list of VTEPs in the same site */
+       struct list *vtep_list;
+
+       /*
+        * Route table for EVPN routes for
+        * this ESI. - type4 routes
+        */
+       struct bgp_table *route_table;
+
+       QOBJ_FIELDS
+};
+
+DECLARE_QOBJ_TYPE(evpnes)
+
 /* Mapping of Import RT to VNIs.
  * The Import RTs of all VNIs are maintained in a hash table with each
  * RT linking to all VNIs that will import routes matching this RT.
@@ -238,6 +272,15 @@ static inline int is_vni_param_configured(struct bgpevpn *vpn)
                || is_export_rt_configured(vpn));
 }
 
+static inline void encode_es_rt_extcomm(struct ecommunity_val *eval,
+                                       struct ethaddr *mac)
+{
+       memset(eval, 0, sizeof(struct ecommunity_val));
+       eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
+       eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ES_IMPORT_RT;
+       memcpy(&eval->val[2], mac, ETH_ALEN);
+}
+
 static inline void encode_rmac_extcomm(struct ecommunity_val *eval,
                                       struct ethaddr *rmac)
 {
@@ -268,6 +311,16 @@ static inline void encode_mac_mobility_extcomm(int static_mac, uint32_t seq,
        eval->val[7] = seq & 0xff;
 }
 
+static inline void encode_na_flag_extcomm(struct ecommunity_val *eval,
+                                         uint8_t na_flag)
+{
+       memset(eval, 0, sizeof(*eval));
+       eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
+       eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_ND;
+       if (na_flag)
+               eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG;
+}
+
 static inline void ip_prefix_from_type5_prefix(struct prefix_evpn *evp,
                                               struct prefix *ip)
 {
@@ -285,7 +338,7 @@ static inline void ip_prefix_from_type5_prefix(struct prefix_evpn *evp,
        }
 }
 
-static inline int is_evpn_prefix_default(struct prefix *evp)
+static inline int is_evpn_prefix_default(const struct prefix *evp)
 {
        if (evp->family != AF_EVPN)
                return 0;
@@ -326,7 +379,7 @@ static inline void build_evpn_type2_prefix(struct prefix_evpn *p,
 {
        memset(p, 0, sizeof(struct prefix_evpn));
        p->family = AF_EVPN;
-       p->prefixlen = EVPN_TYPE_2_ROUTE_PREFIXLEN;
+       p->prefixlen = EVPN_ROUTE_PREFIXLEN;
        p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
        memcpy(&p->prefix.macip_addr.mac.octet, mac->octet, ETH_ALEN);
        p->prefix.macip_addr.ip.ipa_type = IPADDR_NONE;
@@ -352,7 +405,7 @@ static inline void build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp,
 
        memset(evp, 0, sizeof(struct prefix_evpn));
        evp->family = AF_EVPN;
-       evp->prefixlen = EVPN_TYPE_5_ROUTE_PREFIXLEN;
+       evp->prefixlen = EVPN_ROUTE_PREFIXLEN;
        evp->prefix.route_type = BGP_EVPN_IP_PREFIX_ROUTE;
        evp->prefix.prefix_addr.ip_prefix_length = ip_prefix->prefixlen;
        evp->prefix.prefix_addr.ip.ipa_type = ip.ipa_type;
@@ -364,12 +417,26 @@ static inline void build_evpn_type3_prefix(struct prefix_evpn *p,
 {
        memset(p, 0, sizeof(struct prefix_evpn));
        p->family = AF_EVPN;
-       p->prefixlen = EVPN_TYPE_3_ROUTE_PREFIXLEN;
+       p->prefixlen = EVPN_ROUTE_PREFIXLEN;
        p->prefix.route_type = BGP_EVPN_IMET_ROUTE;
        p->prefix.imet_addr.ip.ipa_type = IPADDR_V4;
        p->prefix.imet_addr.ip.ipaddr_v4 = originator_ip;
 }
 
+static inline void build_evpn_type4_prefix(struct prefix_evpn *p,
+                                          esi_t *esi,
+                                          struct in_addr originator_ip)
+{
+       memset(p, 0, sizeof(struct prefix_evpn));
+       p->family = AF_EVPN;
+       p->prefixlen = EVPN_ROUTE_PREFIXLEN;
+       p->prefix.route_type = BGP_EVPN_ES_ROUTE;
+       p->prefix.es_addr.ip_prefix_length = IPV4_MAX_BITLEN;
+       p->prefix.es_addr.ip.ipa_type = IPADDR_V4;
+       p->prefix.es_addr.ip.ipaddr_v4 = originator_ip;
+       memcpy(&p->prefix.es_addr.esi, esi, sizeof(esi_t));
+}
+
 static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
                                             safi_t safi)
 {
@@ -384,6 +451,21 @@ static inline int evpn_default_originate_set(struct bgp *bgp, afi_t afi,
        return 0;
 }
 
+static inline void es_get_system_mac(esi_t *esi,
+                                    struct ethaddr *mac)
+{
+       /*
+        * for type-1 and type-3 ESIs,
+        * the system mac starts at val[1]
+        */
+       memcpy(mac, &esi->val[1], ETH_ALEN);
+}
+
+static inline int is_es_local(struct evpnes *es)
+{
+       return CHECK_FLAG(es->flags, EVPNES_LOCAL) ? 1 : 0;
+}
+
 extern void evpn_rt_delete_auto(struct bgp *, vni_t, struct list *);
 extern void bgp_evpn_configure_export_rt_for_vrf(struct bgp *bgp_vrf,
                                                 struct ecommunity *ecomadd);
@@ -395,6 +477,7 @@ extern void bgp_evpn_unconfigure_import_rt_for_vrf(struct bgp *bgp_vrf,
                                                   struct ecommunity *ecomdel);
 extern int bgp_evpn_handle_export_rt_change(struct bgp *bgp,
                                            struct bgpevpn *vpn);
+extern void bgp_evpn_handle_autort_change(struct bgp *bgp);
 extern void bgp_evpn_handle_vrf_rd_change(struct bgp *bgp_vrf, int withdraw);
 extern void bgp_evpn_handle_rd_change(struct bgp *bgp, struct bgpevpn *vpn,
                                      int withdraw);
@@ -416,4 +499,9 @@ extern struct bgpevpn *bgp_evpn_new(struct bgp *bgp, vni_t vni,
                                    struct in_addr originator_ip,
                                    vrf_id_t tenant_vrf_id);
 extern void bgp_evpn_free(struct bgp *bgp, struct bgpevpn *vpn);
+extern struct evpnes *bgp_evpn_lookup_es(struct bgp *bgp, esi_t *esi);
+extern struct evpnes *bgp_evpn_es_new(struct bgp *bgp, esi_t *esi,
+                                     struct ipaddr *originator_ip);
+extern void bgp_evpn_es_free(struct bgp *bgp, struct evpnes *es);
+extern bool bgp_evpn_lookup_l3vni_l2vni_table(vni_t vni);
 #endif /* _BGP_EVPN_PRIVATE_H */