1 /* E-VPN header for packet handling
2 * Copyright (C) 2016 6WIND
4 * This file is part of FRRouting.
6 * FRRouting 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 * FRRouting 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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 #ifndef _QUAGGA_BGP_EVPN_H
22 #define _QUAGGA_BGP_EVPN_H
27 #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
28 #define EVPN_AUTORT_VXLAN 0x10000000
30 #define EVPN_ENABLED(bgp) (bgp)->advertise_all_vni
31 static inline int is_evpn_enabled(void)
33 struct bgp
*bgp
= NULL
;
36 return bgp
? EVPN_ENABLED(bgp
) : 0;
39 static inline void vni2label(vni_t vni
, mpls_label_t
*label
)
41 uint8_t *tag
= (uint8_t *)label
;
43 tag
[0] = (vni
>> 16) & 0xFF;
44 tag
[1] = (vni
>> 8) & 0xFF;
48 static inline vni_t
label2vni(mpls_label_t
*label
)
50 uint8_t *tag
= (uint8_t *)label
;
53 vni
= ((uint32_t)*tag
++ << 16);
54 vni
|= (uint32_t)*tag
++ << 8;
55 vni
|= (uint32_t)(*tag
& 0xFF);
60 static inline int advertise_type5_routes(struct bgp
*bgp_vrf
,
67 && ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
68 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
))
69 || (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
70 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
))))
74 && ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
75 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
))
76 || (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
77 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
))))
83 /* Flag if the route's parent is a EVPN route. */
84 static inline struct bgp_path_info
*
85 get_route_parent_evpn(struct bgp_path_info
*ri
)
87 struct bgp_path_info
*parent_ri
;
89 /* If not imported (or doesn't have a parent), bail. */
90 if (ri
->sub_type
!= BGP_ROUTE_IMPORTED
||
95 /* Determine parent recursively */
96 for (parent_ri
= ri
->extra
->parent
;
97 parent_ri
->extra
&& parent_ri
->extra
->parent
;
98 parent_ri
= parent_ri
->extra
->parent
)
104 /* Flag if the route's parent is a EVPN route. */
105 static inline int is_route_parent_evpn(struct bgp_path_info
*ri
)
107 struct bgp_path_info
*parent_ri
;
108 struct bgp_table
*table
;
109 struct bgp_dest
*dest
;
111 parent_ri
= get_route_parent_evpn(ri
);
115 /* See if of family L2VPN/EVPN */
116 dest
= parent_ri
->net
;
119 table
= bgp_dest_table(dest
);
121 table
->afi
== AFI_L2VPN
&&
122 table
->safi
== SAFI_EVPN
)
127 /* Flag if the route path's family is EVPN. */
128 static inline bool is_pi_family_evpn(struct bgp_path_info
*pi
)
130 return is_pi_family_matching(pi
, AFI_L2VPN
, SAFI_EVPN
);
133 /* Flag if the route is injectable into EVPN. This would be either a
134 * non-imported route or a non-EVPN imported route.
136 static inline bool is_route_injectable_into_evpn(struct bgp_path_info
*pi
)
138 struct bgp_path_info
*parent_pi
;
139 struct bgp_table
*table
;
140 struct bgp_dest
*dest
;
142 if (pi
->sub_type
!= BGP_ROUTE_IMPORTED
||
147 parent_pi
= (struct bgp_path_info
*)pi
->extra
->parent
;
148 dest
= parent_pi
->net
;
151 table
= bgp_dest_table(dest
);
153 table
->afi
== AFI_L2VPN
&&
154 table
->safi
== SAFI_EVPN
)
159 extern void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
,
160 const struct prefix
*p
,
161 struct attr
*src_attr
, afi_t afi
,
163 extern void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
,
164 const struct prefix
*p
, afi_t afi
,
166 extern void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
168 extern void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
170 extern void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
);
171 extern void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
);
172 extern char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
,
174 extern void bgp_evpn_route2json(const struct prefix_evpn
*p
, json_object
*json
);
175 extern void bgp_evpn_encode_prefix(struct stream
*s
, const struct prefix
*p
,
176 const struct prefix_rd
*prd
,
177 mpls_label_t
*label
, uint32_t num_labels
,
178 struct attr
*attr
, int addpath_encode
,
179 uint32_t addpath_tx_id
);
180 extern int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
181 struct bgp_nlri
*packet
, int withdraw
);
182 extern int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
183 const struct prefix
*p
,
184 struct bgp_path_info
*ri
);
185 extern int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
186 const struct prefix
*p
,
187 struct bgp_path_info
*ri
);
188 extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
);
189 extern int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
,
190 struct ethaddr
*mac
, struct ipaddr
*ip
,
192 extern int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
,
193 struct ethaddr
*mac
, struct ipaddr
*ip
,
194 uint8_t flags
, uint32_t seq
, esi_t
*esi
);
195 extern int bgp_evpn_local_l3vni_add(vni_t vni
, vrf_id_t vrf_id
,
196 struct ethaddr
*rmac
,
197 struct ethaddr
*vrr_rmac
,
198 struct in_addr originator_ip
, int filter
,
199 ifindex_t svi_ifindex
, bool is_anycast_mac
);
200 extern int bgp_evpn_local_l3vni_del(vni_t vni
, vrf_id_t vrf_id
);
201 extern int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
);
202 extern int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
203 struct in_addr originator_ip
,
204 vrf_id_t tenant_vrf_id
,
205 struct in_addr mcast_grp
,
206 ifindex_t svi_ifindex
);
207 extern void bgp_evpn_flood_control_change(struct bgp
*bgp
);
208 extern void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
);
209 extern void bgp_evpn_cleanup(struct bgp
*bgp
);
210 extern void bgp_evpn_init(struct bgp
*bgp
);
211 extern int bgp_evpn_get_type5_prefixlen(const struct prefix
*pfx
);
212 extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix
*pfx
);
213 extern void update_advertise_vrf_routes(struct bgp
*bgp_vrf
);
214 #endif /* _QUAGGA_BGP_EVPN_H */