1 /* BGP EVPN internal definitions
2 * Copyright (C) 2017 Cumulus Networks, Inc.
4 * This file is part of FRR.
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 #ifndef _BGP_EVPN_PRIVATE_H
23 #define _BGP_EVPN_PRIVATE_H
28 #include "bgpd/bgpd.h"
29 #include "bgpd/bgp_ecommunity.h"
31 /* EVPN prefix lengths. */
32 #define EVPN_TYPE_2_ROUTE_PREFIXLEN 224
33 #define EVPN_TYPE_3_ROUTE_PREFIXLEN 224
35 /* EVPN route types. */
37 BGP_EVPN_AD_ROUTE
= 1, /* Ethernet Auto-Discovery (A-D) route */
38 BGP_EVPN_MAC_IP_ROUTE
, /* MAC/IP Advertisement route */
39 BGP_EVPN_IMET_ROUTE
, /* Inclusive Multicast Ethernet Tag route */
40 BGP_EVPN_ES_ROUTE
, /* Ethernet Segment route */
41 BGP_EVPN_IP_PREFIX_ROUTE
, /* IP Prefix route */
42 } bgp_evpn_route_type
;
45 * Hash table of EVIs. Right now, the only type of EVI supported is with
46 * VxLAN encapsulation, hence each EVI corresponds to a L2 VNI.
47 * The VNIs are not "created" through BGP but through some other interface
48 * on the system. This table stores VNIs that BGP comes to know as present
49 * on the system (through interaction with zebra) as well as pre-configured
50 * VNIs (which need to be defined in the system to become "live").
55 #define VNI_FLAG_CFGD 0x1 /* VNI is user configured */
56 #define VNI_FLAG_LIVE 0x2 /* VNI is "live" */
57 #define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */
58 #define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */
59 #define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */
61 /* Id for deriving the RD automatically for this VNI */
64 /* RD for this VNI. */
67 /* Route type 3 field */
68 struct in_addr originator_ip
;
70 /* Import and Export RTs. */
71 struct list
*import_rtl
;
72 struct list
*export_rtl
;
74 /* Route table for EVPN routes for this VNI. */
75 struct bgp_table
*route_table
;
80 DECLARE_QOBJ_TYPE(bgpevpn
)
82 /* Mapping of Import RT to VNIs.
83 * The Import RTs of all VNIs are maintained in a hash table with each
84 * RT linking to all VNIs that will import routes matching this RT.
88 struct ecommunity_val rt
;
90 /* List of VNIs importing routes matching this RT. */
94 #define RT_TYPE_IMPORT 1
95 #define RT_TYPE_EXPORT 2
96 #define RT_TYPE_BOTH 3
98 static inline int is_vni_configured(struct bgpevpn
*vpn
)
100 return (CHECK_FLAG(vpn
->flags
, VNI_FLAG_CFGD
));
103 static inline int is_vni_live(struct bgpevpn
*vpn
)
105 return (CHECK_FLAG(vpn
->flags
, VNI_FLAG_LIVE
));
108 static inline int is_rd_configured(struct bgpevpn
*vpn
)
110 return (CHECK_FLAG(vpn
->flags
, VNI_FLAG_RD_CFGD
));
113 static inline int bgp_evpn_rd_matches_existing(struct bgpevpn
*vpn
,
114 struct prefix_rd
*prd
)
116 return (memcmp(&vpn
->prd
.val
, prd
->val
, ECOMMUNITY_SIZE
) == 0);
119 static inline int is_import_rt_configured(struct bgpevpn
*vpn
)
121 return (CHECK_FLAG(vpn
->flags
, VNI_FLAG_IMPRT_CFGD
));
124 static inline int is_export_rt_configured(struct bgpevpn
*vpn
)
126 return (CHECK_FLAG(vpn
->flags
, VNI_FLAG_EXPRT_CFGD
));
129 static inline int is_vni_param_configured(struct bgpevpn
*vpn
)
131 return (is_rd_configured(vpn
) || is_import_rt_configured(vpn
)
132 || is_export_rt_configured(vpn
));
135 static inline void vni2label(vni_t vni
, mpls_label_t
*label
)
137 u_char
*tag
= (u_char
*)label
;
138 tag
[0] = (vni
>> 16) & 0xFF;
139 tag
[1] = (vni
>> 8) & 0xFF;
143 static inline vni_t
label2vni(mpls_label_t
*label
)
145 u_char
*tag
= (u_char
*)label
;
148 vni
= ((u_int32_t
)*tag
++ << 16);
149 vni
|= (u_int32_t
)*tag
++ << 8;
150 vni
|= (u_int32_t
)(*tag
& 0xFF);
155 static inline void encode_mac_mobility_extcomm(int static_mac
, u_int32_t seq
,
156 struct ecommunity_val
*eval
)
158 memset(eval
, 0, sizeof(*eval
));
159 eval
->val
[0] = ECOMMUNITY_ENCODE_EVPN
;
160 eval
->val
[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY
;
162 eval
->val
[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY
;
163 eval
->val
[4] = (seq
>> 24) & 0xff;
164 eval
->val
[5] = (seq
>> 16) & 0xff;
165 eval
->val
[6] = (seq
>> 8) & 0xff;
166 eval
->val
[7] = seq
& 0xff;
169 static inline void build_evpn_type2_prefix(struct prefix_evpn
*p
,
173 memset(p
, 0, sizeof(struct prefix_evpn
));
174 p
->family
= AF_ETHERNET
;
175 p
->prefixlen
= EVPN_TYPE_2_ROUTE_PREFIXLEN
;
176 p
->prefix
.route_type
= BGP_EVPN_MAC_IP_ROUTE
;
177 memcpy(&p
->prefix
.mac
.octet
, mac
->octet
, ETHER_ADDR_LEN
);
178 p
->prefix
.ip
.ipa_type
= IPADDR_NONE
;
180 memcpy(&p
->prefix
.ip
, ip
, sizeof(*ip
));
183 static inline void build_evpn_type3_prefix(struct prefix_evpn
*p
,
184 struct in_addr originator_ip
)
186 memset(p
, 0, sizeof(struct prefix_evpn
));
187 p
->family
= AF_ETHERNET
;
188 p
->prefixlen
= EVPN_TYPE_3_ROUTE_PREFIXLEN
;
189 p
->prefix
.route_type
= BGP_EVPN_IMET_ROUTE
;
190 p
->prefix
.ip
.ipa_type
= IPADDR_V4
;
191 p
->prefix
.ip
.ipaddr_v4
= originator_ip
;
195 extern int bgp_evpn_handle_export_rt_change(struct bgp
*bgp
,
196 struct bgpevpn
*vpn
);
197 extern void bgp_evpn_handle_rd_change(struct bgp
*bgp
, struct bgpevpn
*vpn
,
199 extern int bgp_evpn_install_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
);
200 extern int bgp_evpn_uninstall_routes(struct bgp
*bgp
, struct bgpevpn
*vpn
);
201 extern void bgp_evpn_map_vni_to_its_rts(struct bgp
*bgp
, struct bgpevpn
*vpn
);
202 extern void bgp_evpn_unmap_vni_from_its_rts(struct bgp
*bgp
,
203 struct bgpevpn
*vpn
);
204 extern void bgp_evpn_derive_auto_rt_import(struct bgp
*bgp
,
205 struct bgpevpn
*vpn
);
206 extern void bgp_evpn_derive_auto_rt_export(struct bgp
*bgp
,
207 struct bgpevpn
*vpn
);
208 extern void bgp_evpn_derive_auto_rd(struct bgp
*bgp
, struct bgpevpn
*vpn
);
209 extern struct bgpevpn
*bgp_evpn_lookup_vni(struct bgp
*bgp
, vni_t vni
);
210 extern struct bgpevpn
*bgp_evpn_new(struct bgp
*bgp
, vni_t vni
,
211 struct in_addr originator_ip
);
212 extern void bgp_evpn_free(struct bgp
*bgp
, struct bgpevpn
*vpn
);
213 #endif /* _BGP_EVPN_PRIVATE_H */