]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
7ef5a232 | 2 | /* E-VPN header for packet handling |
896014f4 | 3 | * Copyright (C) 2016 6WIND |
896014f4 | 4 | */ |
7ef5a232 PG |
5 | |
6 | #ifndef _QUAGGA_BGP_EVPN_H | |
7 | #define _QUAGGA_BGP_EVPN_H | |
8 | ||
128ea8ab | 9 | #include "vxlan.h" |
94c2f693 | 10 | #include "bgpd.h" |
7ef5a232 | 11 | |
520d5d76 | 12 | #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */ |
bf1061d8 | 13 | #define EVPN_AUTORT_VXLAN 0x10000000 |
520d5d76 | 14 | |
f920dd6d | 15 | #define EVPN_ENABLED(bgp) (bgp)->advertise_all_vni |
94c2f693 MK |
16 | static inline int is_evpn_enabled(void) |
17 | { | |
18 | struct bgp *bgp = NULL; | |
19 | ||
e2f3a930 | 20 | bgp = bgp_get_evpn(); |
f920dd6d | 21 | return bgp ? EVPN_ENABLED(bgp) : 0; |
94c2f693 MK |
22 | } |
23 | ||
fdf19f06 MK |
24 | static inline int advertise_type5_routes(struct bgp *bgp_vrf, |
25 | afi_t afi) | |
26 | { | |
27 | if (!bgp_vrf->l3vni) | |
28 | return 0; | |
29 | ||
d4a88de3 AD |
30 | if ((afi == AFI_IP) |
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)))) | |
fdf19f06 MK |
35 | return 1; |
36 | ||
d4a88de3 AD |
37 | if ((afi == AFI_IP6) |
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)))) | |
fdf19f06 MK |
42 | return 1; |
43 | ||
44 | return 0; | |
45 | } | |
46 | ||
88493076 | 47 | /* Flag if the route's parent is a EVPN route. */ |
6348981a AK |
48 | static inline struct bgp_path_info * |
49 | get_route_parent_evpn(struct bgp_path_info *ri) | |
88493076 | 50 | { |
4b7e6066 | 51 | struct bgp_path_info *parent_ri; |
88493076 | 52 | |
53 | /* If not imported (or doesn't have a parent), bail. */ | |
54 | if (ri->sub_type != BGP_ROUTE_IMPORTED || | |
55 | !ri->extra || | |
56 | !ri->extra->parent) | |
6348981a | 57 | return NULL; |
88493076 | 58 | |
08e68f92 | 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) | |
63 | ; | |
64 | ||
6348981a AK |
65 | return parent_ri; |
66 | } | |
67 | ||
68 | /* Flag if the route's parent is a EVPN route. */ | |
69 | static inline int is_route_parent_evpn(struct bgp_path_info *ri) | |
70 | { | |
71 | struct bgp_path_info *parent_ri; | |
72 | struct bgp_table *table; | |
73 | struct bgp_dest *dest; | |
74 | ||
75 | parent_ri = get_route_parent_evpn(ri); | |
76 | if (!parent_ri) | |
77 | return 0; | |
78 | ||
08e68f92 | 79 | /* See if of family L2VPN/EVPN */ |
9bcb3eef DS |
80 | dest = parent_ri->net; |
81 | if (!dest) | |
88493076 | 82 | return 0; |
9bcb3eef | 83 | table = bgp_dest_table(dest); |
88493076 | 84 | if (table && |
85 | table->afi == AFI_L2VPN && | |
86 | table->safi == SAFI_EVPN) | |
87 | return 1; | |
88 | return 0; | |
89 | } | |
90 | ||
0a2f9ac1 | 91 | /* Flag if the route path's family is EVPN. */ |
92 | static inline bool is_pi_family_evpn(struct bgp_path_info *pi) | |
93 | { | |
94 | return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN); | |
95 | } | |
96 | ||
f106e3a7 | 97 | /* Flag if the route is injectable into EVPN. This would be either a |
98 | * non-imported route or a non-EVPN imported route. | |
99 | */ | |
100 | static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi) | |
101 | { | |
102 | struct bgp_path_info *parent_pi; | |
103 | struct bgp_table *table; | |
9bcb3eef | 104 | struct bgp_dest *dest; |
f106e3a7 | 105 | |
106 | if (pi->sub_type != BGP_ROUTE_IMPORTED || | |
107 | !pi->extra || | |
108 | !pi->extra->parent) | |
109 | return true; | |
110 | ||
111 | parent_pi = (struct bgp_path_info *)pi->extra->parent; | |
9bcb3eef DS |
112 | dest = parent_pi->net; |
113 | if (!dest) | |
f106e3a7 | 114 | return true; |
9bcb3eef | 115 | table = bgp_dest_table(dest); |
f106e3a7 | 116 | if (table && |
117 | table->afi == AFI_L2VPN && | |
118 | table->safi == SAFI_EVPN) | |
119 | return false; | |
120 | return true; | |
121 | } | |
122 | ||
dc6cef73 AD |
123 | static inline bool evpn_resolve_overlay_index(void) |
124 | { | |
125 | struct bgp *bgp = NULL; | |
126 | ||
127 | bgp = bgp_get_evpn(); | |
128 | return bgp ? bgp->resolve_overlay_index : false; | |
129 | } | |
130 | ||
5424b7ba | 131 | extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, |
bd494ec5 | 132 | const struct prefix *p, |
996c9314 LB |
133 | struct attr *src_attr, afi_t afi, |
134 | safi_t safi); | |
bd494ec5 DS |
135 | extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, |
136 | const struct prefix *p, afi_t afi, | |
137 | safi_t safi); | |
053905d2 MK |
138 | extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi, |
139 | safi_t safi); | |
140 | extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, | |
141 | safi_t safi); | |
523cafc4 | 142 | extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf); |
d62a17ae | 143 | extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw); |
d7c0a89a | 144 | extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, |
b57ba6d2 | 145 | char *buf, int len); |
bd494ec5 | 146 | extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json); |
5f040085 DS |
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, | |
be92fc9f | 150 | struct attr *attr, bool addpath_capable, |
5f040085 | 151 | uint32_t addpath_tx_id); |
128ea8ab | 152 | extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, |
aa056a2a | 153 | struct bgp_nlri *packet, bool withdraw); |
d62a17ae | 154 | extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, |
5a1ae2c2 DS |
155 | const struct prefix *p, |
156 | struct bgp_path_info *ri); | |
d62a17ae | 157 | extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi, |
5a1ae2c2 DS |
158 | const struct prefix *p, |
159 | struct bgp_path_info *ri); | |
db0e1937 | 160 | extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp); |
d62a17ae | 161 | extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, |
ec0ab544 AK |
162 | struct ethaddr *mac, struct ipaddr *ip, |
163 | int state); | |
d62a17ae | 164 | extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni, |
165 | struct ethaddr *mac, struct ipaddr *ip, | |
c44ab6f1 | 166 | uint8_t flags, uint32_t seq, esi_t *esi); |
523cafc4 | 167 | extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id, |
168 | struct ethaddr *rmac, | |
14e814ea | 169 | struct ethaddr *vrr_rmac, |
0483af6e | 170 | struct in_addr originator_ip, int filter, |
14e814ea | 171 | ifindex_t svi_ifindex, bool is_anycast_mac); |
523cafc4 | 172 | extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id); |
d62a17ae | 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, | |
29c53922 | 175 | struct in_addr originator_ip, |
76d07c7a | 176 | vrf_id_t tenant_vrf_id, |
9daa5d47 AD |
177 | struct in_addr mcast_grp, |
178 | ifindex_t svi_ifindex); | |
fd069644 | 179 | extern void bgp_evpn_flood_control_change(struct bgp *bgp); |
d62a17ae | 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); | |
5f040085 | 183 | extern int bgp_evpn_get_type5_prefixlen(const struct prefix *pfx); |
5a1ae2c2 | 184 | extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx); |
5394a276 | 185 | extern void update_advertise_vrf_routes(struct bgp *bgp_vrf); |
021b6596 AD |
186 | extern void bgp_evpn_show_remote_ip_hash(struct hash_bucket *bucket, |
187 | void *args); | |
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); | |
dc6cef73 AD |
190 | extern void |
191 | bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket *bucket, | |
192 | void *arg); | |
193 | extern void | |
194 | bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket *bucket, | |
195 | void *arg); | |
742341e1 SW |
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); | |
021b6596 | 201 | |
128ea8ab | 202 | #endif /* _QUAGGA_BGP_EVPN_H */ |