1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* E-VPN header for packet handling
3 * Copyright (C) 2016 6WIND
6 #ifndef _QUAGGA_BGP_EVPN_H
7 #define _QUAGGA_BGP_EVPN_H
12 #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
13 #define EVPN_AUTORT_VXLAN 0x10000000
15 #define EVPN_ENABLED(bgp) (bgp)->advertise_all_vni
16 static inline int is_evpn_enabled(void)
18 struct bgp
*bgp
= NULL
;
21 return bgp
? EVPN_ENABLED(bgp
) : 0;
24 static inline int advertise_type5_routes(struct bgp
*bgp_vrf
,
31 && ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
32 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST
))
33 || (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
34 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP
))))
38 && ((CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
39 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST
))
40 || (CHECK_FLAG(bgp_vrf
->af_flags
[AFI_L2VPN
][SAFI_EVPN
],
41 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP
))))
47 /* Flag if the route's parent is a EVPN route. */
48 static inline struct bgp_path_info
*
49 get_route_parent_evpn(struct bgp_path_info
*ri
)
51 struct bgp_path_info
*parent_ri
;
53 /* If not imported (or doesn't have a parent), bail. */
54 if (ri
->sub_type
!= BGP_ROUTE_IMPORTED
||
59 /* Determine parent recursively */
60 for (parent_ri
= ri
->extra
->parent
;
61 parent_ri
->extra
&& parent_ri
->extra
->parent
;
62 parent_ri
= parent_ri
->extra
->parent
)
68 /* Flag if the route's parent is a EVPN route. */
69 static inline int is_route_parent_evpn(struct bgp_path_info
*ri
)
71 struct bgp_path_info
*parent_ri
;
72 struct bgp_table
*table
;
73 struct bgp_dest
*dest
;
75 parent_ri
= get_route_parent_evpn(ri
);
79 /* See if of family L2VPN/EVPN */
80 dest
= parent_ri
->net
;
83 table
= bgp_dest_table(dest
);
85 table
->afi
== AFI_L2VPN
&&
86 table
->safi
== SAFI_EVPN
)
91 /* Flag if the route path's family is EVPN. */
92 static inline bool is_pi_family_evpn(struct bgp_path_info
*pi
)
94 return is_pi_family_matching(pi
, AFI_L2VPN
, SAFI_EVPN
);
97 /* Flag if the route is injectable into EVPN. This would be either a
98 * non-imported route or a non-EVPN imported route.
100 static inline bool is_route_injectable_into_evpn(struct bgp_path_info
*pi
)
102 struct bgp_path_info
*parent_pi
;
103 struct bgp_table
*table
;
104 struct bgp_dest
*dest
;
106 if (pi
->sub_type
!= BGP_ROUTE_IMPORTED
||
111 parent_pi
= (struct bgp_path_info
*)pi
->extra
->parent
;
112 dest
= parent_pi
->net
;
115 table
= bgp_dest_table(dest
);
117 table
->afi
== AFI_L2VPN
&&
118 table
->safi
== SAFI_EVPN
)
123 static inline bool evpn_resolve_overlay_index(void)
125 struct bgp
*bgp
= NULL
;
127 bgp
= bgp_get_evpn();
128 return bgp
? bgp
->resolve_overlay_index
: false;
131 extern void bgp_evpn_advertise_type5_route(struct bgp
*bgp_vrf
,
132 const struct prefix
*p
,
133 struct attr
*src_attr
, afi_t afi
,
135 extern void bgp_evpn_withdraw_type5_route(struct bgp
*bgp_vrf
,
136 const struct prefix
*p
, afi_t afi
,
138 extern void bgp_evpn_withdraw_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
140 extern void bgp_evpn_advertise_type5_routes(struct bgp
*bgp_vrf
, afi_t afi
,
142 extern void bgp_evpn_vrf_delete(struct bgp
*bgp_vrf
);
143 extern void bgp_evpn_handle_router_id_update(struct bgp
*bgp
, int withdraw
);
144 extern char *bgp_evpn_label2str(mpls_label_t
*label
, uint32_t num_labels
,
146 extern void bgp_evpn_route2json(const struct prefix_evpn
*p
, json_object
*json
);
147 extern void bgp_evpn_encode_prefix(struct stream
*s
, const struct prefix
*p
,
148 const struct prefix_rd
*prd
,
149 mpls_label_t
*label
, uint32_t num_labels
,
150 struct attr
*attr
, bool addpath_capable
,
151 uint32_t addpath_tx_id
);
152 extern int bgp_nlri_parse_evpn(struct peer
*peer
, struct attr
*attr
,
153 struct bgp_nlri
*packet
, bool withdraw
);
154 extern int bgp_evpn_import_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
155 const struct prefix
*p
,
156 struct bgp_path_info
*ri
);
157 extern int bgp_evpn_unimport_route(struct bgp
*bgp
, afi_t afi
, safi_t safi
,
158 const struct prefix
*p
,
159 struct bgp_path_info
*ri
);
160 extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp
*bgp
);
161 extern int bgp_evpn_local_macip_del(struct bgp
*bgp
, vni_t vni
,
162 struct ethaddr
*mac
, struct ipaddr
*ip
,
164 extern int bgp_evpn_local_macip_add(struct bgp
*bgp
, vni_t vni
,
165 struct ethaddr
*mac
, struct ipaddr
*ip
,
166 uint8_t flags
, uint32_t seq
, esi_t
*esi
);
167 extern int bgp_evpn_local_l3vni_add(vni_t vni
, vrf_id_t vrf_id
,
168 struct ethaddr
*rmac
,
169 struct ethaddr
*vrr_rmac
,
170 struct in_addr originator_ip
, int filter
,
171 ifindex_t svi_ifindex
, bool is_anycast_mac
);
172 extern int bgp_evpn_local_l3vni_del(vni_t vni
, vrf_id_t vrf_id
);
173 extern int bgp_evpn_local_vni_del(struct bgp
*bgp
, vni_t vni
);
174 extern int bgp_evpn_local_vni_add(struct bgp
*bgp
, vni_t vni
,
175 struct in_addr originator_ip
,
176 vrf_id_t tenant_vrf_id
,
177 struct in_addr mcast_grp
,
178 ifindex_t svi_ifindex
);
179 extern void bgp_evpn_flood_control_change(struct bgp
*bgp
);
180 extern void bgp_evpn_cleanup_on_disable(struct bgp
*bgp
);
181 extern void bgp_evpn_cleanup(struct bgp
*bgp
);
182 extern void bgp_evpn_init(struct bgp
*bgp
);
183 extern int bgp_evpn_get_type5_prefixlen(const struct prefix
*pfx
);
184 extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix
*pfx
);
185 extern void update_advertise_vrf_routes(struct bgp
*bgp_vrf
);
186 extern void bgp_evpn_show_remote_ip_hash(struct hash_bucket
*bucket
,
188 extern void bgp_evpn_show_vni_svi_hash(struct hash_bucket
*bucket
, void *args
);
189 extern bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache
*bnc
);
191 bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket
*bucket
,
194 bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket
*bucket
,
196 extern mpls_label_t
*bgp_evpn_path_info_labels_get_l3vni(mpls_label_t
*labels
,
197 uint32_t num_labels
);
198 extern vni_t
bgp_evpn_path_info_get_l3vni(const struct bgp_path_info
*pi
);
199 extern bool bgp_evpn_mpath_has_dvni(const struct bgp
*bgp_vrf
,
200 struct bgp_path_info
*mpinfo
);
202 #endif /* _QUAGGA_BGP_EVPN_H */