]>
Commit | Line | Data |
---|---|---|
18a7a601 | 1 | /* |
2 | * Zebra VxLAN (EVPN) Data structures and definitions | |
3 | * These are "internal" to this function. | |
4 | * Copyright (C) 2016, 2017 Cumulus Networks, Inc. | |
5 | * | |
6 | * This file is part of FRR. | |
7 | * | |
8 | * FRR is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * FRR is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with FRR; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
21 | * 02111-1307, USA. | |
22 | */ | |
23 | ||
24 | #ifndef _ZEBRA_VXLAN_PRIVATE_H | |
25 | #define _ZEBRA_VXLAN_PRIVATE_H | |
26 | ||
27 | #include <zebra.h> | |
28 | ||
18a7a601 | 29 | #include "if.h" |
30 | #include "linklist.h" | |
655b04d1 | 31 | #include "zebra_vxlan.h" |
18a7a601 | 32 | |
51e94aa7 EDP |
33 | #ifdef __cplusplus |
34 | extern "C" { | |
35 | #endif | |
36 | ||
b7cfce93 MK |
37 | #define ERR_STR_SZ 256 |
38 | ||
18a7a601 | 39 | /* definitions */ |
40 | typedef struct zebra_vni_t_ zebra_vni_t; | |
41 | typedef struct zebra_vtep_t_ zebra_vtep_t; | |
4122e252 | 42 | typedef struct zebra_mac_t_ zebra_mac_t; |
43 | typedef struct zebra_neigh_t_ zebra_neigh_t; | |
b7cfce93 | 44 | typedef struct zebra_l3vni_t_ zebra_l3vni_t; |
18a7a601 | 45 | |
46 | /* | |
47 | * VTEP info | |
48 | * | |
49 | * Right now, this just has each remote VTEP's IP address. | |
50 | */ | |
d62a17ae | 51 | struct zebra_vtep_t_ { |
52 | /* Remote IP. */ | |
53 | /* NOTE: Can only be IPv4 right now. */ | |
54 | struct in_addr vtep_ip; | |
9718c54e AK |
55 | /* Flood mode (one of enum vxlan_flood_control) based on the PMSI |
56 | * tunnel type advertised by the remote VTEP | |
57 | */ | |
58 | int flood_control; | |
d62a17ae | 59 | |
60 | /* Links. */ | |
61 | struct zebra_vtep_t_ *next; | |
62 | struct zebra_vtep_t_ *prev; | |
18a7a601 | 63 | }; |
64 | ||
65 | ||
66 | /* | |
67 | * VNI hash table | |
68 | * | |
69 | * Contains information pertaining to a VNI: | |
70 | * - the list of remote VTEPs (with this VNI) | |
71 | */ | |
d62a17ae | 72 | struct zebra_vni_t_ { |
73 | /* VNI - key */ | |
74 | vni_t vni; | |
18a7a601 | 75 | |
1a98c087 | 76 | /* Flag for advertising gw macip */ |
d7c0a89a | 77 | uint8_t advertise_gw_macip; |
1a98c087 | 78 | |
278e26de CS |
79 | /* Flag for advertising svi macip */ |
80 | uint8_t advertise_svi_macip; | |
81 | ||
31310b25 | 82 | /* Flag for advertising gw macip */ |
d7c0a89a | 83 | uint8_t advertise_subnet; |
31310b25 | 84 | |
d62a17ae | 85 | /* Corresponding VxLAN interface. */ |
86 | struct interface *vxlan_if; | |
18a7a601 | 87 | |
d62a17ae | 88 | /* List of remote VTEPs */ |
89 | zebra_vtep_t *vteps; | |
18a7a601 | 90 | |
d62a17ae | 91 | /* Local IP */ |
92 | struct in_addr local_vtep_ip; | |
4122e252 | 93 | |
3d434f5c AK |
94 | /* PIM-SM MDT group for BUM flooding */ |
95 | struct in_addr mcast_grp; | |
96 | ||
b7cfce93 MK |
97 | /* tenant VRF, if any */ |
98 | vrf_id_t vrf_id; | |
99 | ||
d62a17ae | 100 | /* List of local or remote MAC */ |
101 | struct hash *mac_table; | |
4122e252 | 102 | |
d62a17ae | 103 | /* List of local or remote neighbors (MAC+IP) */ |
104 | struct hash *neigh_table; | |
4122e252 | 105 | }; |
106 | ||
b7cfce93 MK |
107 | /* L3 VNI hash table */ |
108 | struct zebra_l3vni_t_ { | |
109 | ||
110 | /* VNI key */ | |
111 | vni_t vni; | |
112 | ||
113 | /* vrf_id */ | |
114 | vrf_id_t vrf_id; | |
115 | ||
c48d9f5f MK |
116 | uint32_t filter; |
117 | #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */ | |
118 | ||
b67a60d2 | 119 | /* Local IP */ |
120 | struct in_addr local_vtep_ip; | |
121 | ||
b7cfce93 MK |
122 | /* kernel interface for l3vni */ |
123 | struct interface *vxlan_if; | |
124 | ||
125 | /* SVI interface corresponding to the l3vni */ | |
126 | struct interface *svi_if; | |
127 | ||
06d9cde5 CS |
128 | struct interface *mac_vlan_if; |
129 | ||
b7cfce93 MK |
130 | /* list of L2 VNIs associated with the L3 VNI */ |
131 | struct list *l2vnis; | |
132 | ||
133 | /* list of remote router-macs */ | |
134 | struct hash *rmac_table; | |
135 | ||
136 | /* list of remote vtep-ip neigh */ | |
137 | struct hash *nh_table; | |
138 | }; | |
139 | ||
140 | /* get the vx-intf name for l3vni */ | |
141 | static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t *zl3vni) | |
142 | { | |
143 | return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None"; | |
144 | } | |
145 | ||
146 | /* get the svi intf name for l3vni */ | |
147 | static inline const char *zl3vni_svi_if_name(zebra_l3vni_t *zl3vni) | |
148 | { | |
149 | return zl3vni->svi_if ? zl3vni->svi_if->name : "None"; | |
150 | } | |
151 | ||
152 | /* get the vrf name for l3vni */ | |
153 | static inline const char *zl3vni_vrf_name(zebra_l3vni_t *zl3vni) | |
154 | { | |
155 | return vrf_id_to_name(zl3vni->vrf_id); | |
156 | } | |
157 | ||
158 | /* get the rmac string */ | |
159 | static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf, | |
160 | int size) | |
161 | { | |
162 | char *ptr; | |
163 | ||
164 | if (!buf) | |
165 | ptr = (char *)XMALLOC(MTYPE_TMP, | |
166 | ETHER_ADDR_STRLEN * sizeof(char)); | |
167 | else { | |
168 | assert(size >= ETHER_ADDR_STRLEN); | |
169 | ptr = buf; | |
170 | } | |
171 | ||
172 | if (zl3vni->svi_if) | |
173 | snprintf(ptr, (ETHER_ADDR_STRLEN), | |
174 | "%02x:%02x:%02x:%02x:%02x:%02x", | |
175 | (uint8_t)zl3vni->svi_if->hw_addr[0], | |
176 | (uint8_t)zl3vni->svi_if->hw_addr[1], | |
177 | (uint8_t)zl3vni->svi_if->hw_addr[2], | |
178 | (uint8_t)zl3vni->svi_if->hw_addr[3], | |
179 | (uint8_t)zl3vni->svi_if->hw_addr[4], | |
180 | (uint8_t)zl3vni->svi_if->hw_addr[5]); | |
181 | else | |
182 | snprintf(ptr, ETHER_ADDR_STRLEN, "None"); | |
183 | ||
184 | return ptr; | |
185 | } | |
186 | ||
187 | /* | |
188 | * l3-vni is oper up when: | |
655b04d1 | 189 | * 0. if EVPN is enabled (advertise-all-vni cfged) |
b7cfce93 MK |
190 | * 1. it is associated to a vxlan-intf |
191 | * 2. Associated vxlan-intf is oper up | |
192 | * 3. it is associated to an SVI | |
193 | * 4. associated SVI is oper up | |
194 | */ | |
195 | static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni) | |
196 | { | |
996c9314 LB |
197 | return (is_evpn_enabled() && zl3vni && (zl3vni->vrf_id != VRF_UNKNOWN) |
198 | && zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) | |
199 | && zl3vni->svi_if && if_is_operative(zl3vni->svi_if)); | |
b7cfce93 MK |
200 | } |
201 | ||
202 | static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni) | |
203 | { | |
204 | if (!zl3vni) | |
205 | return NULL; | |
206 | ||
207 | if (is_l3vni_oper_up(zl3vni)) | |
208 | return "Up"; | |
209 | else | |
210 | return "Down"; | |
211 | ||
212 | return NULL; | |
213 | } | |
214 | ||
215 | static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni) | |
216 | { | |
217 | return zl3vni->vrf_id; | |
218 | } | |
219 | ||
06d9cde5 CS |
220 | static inline void zl3vni_get_svi_rmac(zebra_l3vni_t *zl3vni, |
221 | struct ethaddr *rmac) | |
b7cfce93 MK |
222 | { |
223 | if (!zl3vni) | |
224 | return; | |
225 | ||
226 | if (!is_l3vni_oper_up(zl3vni)) | |
227 | return; | |
228 | ||
229 | if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if)) | |
230 | memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN); | |
231 | } | |
232 | ||
5e1b0650 DS |
233 | struct host_rb_entry { |
234 | RB_ENTRY(host_rb_entry) hl_entry; | |
235 | ||
236 | struct prefix p; | |
237 | }; | |
238 | ||
85442b09 DS |
239 | RB_HEAD(host_rb_tree_entry, host_rb_entry); |
240 | RB_PROTOTYPE(host_rb_tree_entry, host_rb_entry, hl_entry, | |
5e1b0650 | 241 | host_rb_entry_compare); |
4122e252 | 242 | /* |
243 | * MAC hash table. | |
244 | * | |
245 | * This table contains the MAC addresses pertaining to this VNI. | |
246 | * This includes local MACs learnt on an attached VLAN that maps | |
247 | * to this VNI as well as remote MACs learnt and installed by BGP. | |
248 | * Local MACs will be known either on a VLAN sub-interface or | |
249 | * on (port, VLAN); however, it is sufficient for zebra to maintain | |
250 | * against the VNI i.e., it does not need to retain the local "port" | |
251 | * information. The correct VNI will be obtained as zebra maintains | |
252 | * the mapping (of VLAN to VNI). | |
253 | */ | |
d62a17ae | 254 | struct zebra_mac_t_ { |
255 | /* MAC address. */ | |
256 | struct ethaddr macaddr; | |
4122e252 | 257 | |
d7c0a89a | 258 | uint32_t flags; |
4122e252 | 259 | #define ZEBRA_MAC_LOCAL 0x01 |
260 | #define ZEBRA_MAC_REMOTE 0x02 | |
261 | #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */ | |
c85c03c7 | 262 | #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */ |
b7cfce93 | 263 | #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */ |
ead40654 | 264 | #define ZEBRA_MAC_DEF_GW 0x20 |
51f4dab4 AK |
265 | /* remote VTEP advertised MAC as default GW */ |
266 | #define ZEBRA_MAC_REMOTE_DEF_GW 0x40 | |
e22a946a CS |
267 | #define ZEBRA_MAC_DUPLICATE 0x80 |
268 | ||
269 | /* back pointer to zvni */ | |
270 | zebra_vni_t *zvni; | |
4122e252 | 271 | |
d62a17ae | 272 | /* Local or remote info. */ |
273 | union { | |
274 | struct { | |
275 | ifindex_t ifindex; | |
276 | vlanid_t vid; | |
277 | } local; | |
4122e252 | 278 | |
d62a17ae | 279 | struct in_addr r_vtep_ip; |
280 | } fwd_info; | |
4122e252 | 281 | |
f07e1c99 | 282 | /* Mobility sequence numbers associated with this entry. */ |
283 | uint32_t rem_seq; | |
284 | uint32_t loc_seq; | |
285 | ||
b6938a74 MK |
286 | /* List of neigh associated with this mac */ |
287 | struct list *neigh_list; | |
b7cfce93 | 288 | |
6134fd82 | 289 | /* list of hosts pointing to this remote RMAC */ |
85442b09 | 290 | struct host_rb_tree_entry host_rb; |
e22a946a CS |
291 | |
292 | /* Duplicate mac detection */ | |
293 | uint32_t dad_count; | |
294 | ||
295 | struct thread *dad_mac_auto_recovery_timer; | |
296 | ||
297 | struct timeval detect_start_time; | |
298 | ||
299 | time_t dad_dup_detect_time; | |
4122e252 | 300 | }; |
301 | ||
302 | /* | |
303 | * Context for MAC hash walk - used by callbacks. | |
304 | */ | |
d62a17ae | 305 | struct mac_walk_ctx { |
306 | zebra_vni_t *zvni; /* VNI hash */ | |
307 | struct zebra_vrf *zvrf; /* VRF - for client notification. */ | |
308 | int uninstall; /* uninstall from kernel? */ | |
309 | int upd_client; /* uninstall from client? */ | |
310 | ||
d7c0a89a | 311 | uint32_t flags; |
4122e252 | 312 | #define DEL_LOCAL_MAC 0x1 |
313 | #define DEL_REMOTE_MAC 0x2 | |
314 | #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC) | |
315 | #define DEL_REMOTE_MAC_FROM_VTEP 0x4 | |
316 | #define SHOW_REMOTE_MAC_FROM_VTEP 0x8 | |
317 | ||
d62a17ae | 318 | struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */ |
4122e252 | 319 | |
cd233079 | 320 | struct vty *vty; /* Used by VTY handlers */ |
d7c0a89a | 321 | uint32_t count; /* Used by VTY handlers */ |
cd233079 | 322 | struct json_object *json; /* Used for JSON Output */ |
1374d4db | 323 | bool print_dup; /* Used to print dup addr list */ |
4122e252 | 324 | }; |
325 | ||
b7cfce93 MK |
326 | struct rmac_walk_ctx { |
327 | struct vty *vty; | |
328 | struct json_object *json; | |
329 | }; | |
330 | ||
2c476b72 | 331 | #define IS_ZEBRA_NEIGH_ACTIVE(n) (n->state == ZEBRA_NEIGH_ACTIVE) |
b6938a74 | 332 | |
2c476b72 | 333 | #define IS_ZEBRA_NEIGH_INACTIVE(n) (n->state == ZEBRA_NEIGH_INACTIVE) |
b6938a74 MK |
334 | |
335 | #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE | |
336 | ||
337 | #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE | |
338 | ||
4122e252 | 339 | /* |
340 | * Neighbor hash table. | |
341 | * | |
342 | * This table contains the neighbors (IP to MAC bindings) pertaining to | |
343 | * this VNI. This includes local neighbors learnt on the attached VLAN | |
344 | * device that maps to this VNI as well as remote neighbors learnt and | |
345 | * installed by BGP. | |
346 | * Local neighbors will be known against the VLAN device (SVI); however, | |
347 | * it is sufficient for zebra to maintain against the VNI. The correct | |
348 | * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI). | |
349 | */ | |
d62a17ae | 350 | struct zebra_neigh_t_ { |
351 | /* IP address. */ | |
352 | struct ipaddr ip; | |
4122e252 | 353 | |
d62a17ae | 354 | /* MAC address. */ |
355 | struct ethaddr emac; | |
4122e252 | 356 | |
d62a17ae | 357 | /* Underlying interface. */ |
358 | ifindex_t ifindex; | |
4122e252 | 359 | |
c80a972c CS |
360 | zebra_vni_t *zvni; |
361 | ||
d7c0a89a | 362 | uint32_t flags; |
b6938a74 MK |
363 | #define ZEBRA_NEIGH_LOCAL 0x01 |
364 | #define ZEBRA_NEIGH_REMOTE 0x02 | |
b7cfce93 | 365 | #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */ |
ead40654 | 366 | #define ZEBRA_NEIGH_DEF_GW 0x08 |
68e33151 | 367 | #define ZEBRA_NEIGH_ROUTER_FLAG 0x10 |
e22a946a | 368 | #define ZEBRA_NEIGH_DUPLICATE 0x20 |
b6938a74 MK |
369 | |
370 | enum zebra_neigh_state state; | |
4122e252 | 371 | |
d62a17ae | 372 | /* Remote VTEP IP - applicable only for remote neighbors. */ |
373 | struct in_addr r_vtep_ip; | |
b7cfce93 | 374 | |
f07e1c99 | 375 | /* |
376 | * Mobility sequence numbers associated with this entry. The rem_seq | |
377 | * represents the sequence number from the client (BGP) for the most | |
378 | * recent add or update of this entry while the loc_seq represents | |
379 | * the sequence number informed (or to be informed) by zebra to BGP | |
380 | * for this entry. | |
381 | */ | |
382 | uint32_t rem_seq; | |
383 | uint32_t loc_seq; | |
384 | ||
6134fd82 | 385 | /* list of hosts pointing to this remote NH entry */ |
85442b09 | 386 | struct host_rb_tree_entry host_rb; |
e22a946a CS |
387 | |
388 | /* Duplicate ip detection */ | |
389 | uint32_t dad_count; | |
390 | ||
391 | struct thread *dad_ip_auto_recovery_timer; | |
392 | ||
393 | struct timeval detect_start_time; | |
394 | ||
395 | time_t dad_dup_detect_time; | |
4122e252 | 396 | }; |
397 | ||
398 | /* | |
399 | * Context for neighbor hash walk - used by callbacks. | |
400 | */ | |
d62a17ae | 401 | struct neigh_walk_ctx { |
402 | zebra_vni_t *zvni; /* VNI hash */ | |
403 | struct zebra_vrf *zvrf; /* VRF - for client notification. */ | |
404 | int uninstall; /* uninstall from kernel? */ | |
405 | int upd_client; /* uninstall from client? */ | |
406 | ||
d7c0a89a | 407 | uint32_t flags; |
4122e252 | 408 | #define DEL_LOCAL_NEIGH 0x1 |
409 | #define DEL_REMOTE_NEIGH 0x2 | |
410 | #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH) | |
411 | #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4 | |
412 | #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8 | |
413 | ||
d62a17ae | 414 | struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */ |
4122e252 | 415 | |
cd233079 | 416 | struct vty *vty; /* Used by VTY handlers */ |
d7c0a89a QY |
417 | uint32_t count; /* Used by VTY handlers */ |
418 | uint8_t addr_width; /* Used by VTY handlers */ | |
cd233079 | 419 | struct json_object *json; /* Used for JSON Output */ |
18a7a601 | 420 | }; |
421 | ||
b7cfce93 MK |
422 | /* context for neigh hash walk - update l3vni and rmac */ |
423 | struct neigh_l3info_walk_ctx { | |
424 | ||
425 | zebra_vni_t *zvni; | |
426 | zebra_l3vni_t *zl3vni; | |
427 | int add; | |
428 | }; | |
429 | ||
430 | struct nh_walk_ctx { | |
431 | ||
432 | struct vty *vty; | |
433 | struct json_object *json; | |
434 | }; | |
435 | ||
9d21b7c6 | 436 | extern zebra_l3vni_t *zl3vni_from_vrf(vrf_id_t vrf_id); |
a780a738 AD |
437 | extern struct interface *zl3vni_map_to_vxlan_if(zebra_l3vni_t *zl3vni); |
438 | extern struct interface *zl3vni_map_to_svi_if(zebra_l3vni_t *zl3vni); | |
06d9cde5 | 439 | extern struct interface *zl3vni_map_to_mac_vlan_if(zebra_l3vni_t *zl3vni); |
a780a738 AD |
440 | |
441 | DECLARE_HOOK(zebra_rmac_update, (zebra_mac_t *rmac, zebra_l3vni_t *zl3vni, | |
442 | bool delete, const char *reason), (rmac, zl3vni, delete, reason)) | |
443 | ||
9d21b7c6 | 444 | |
51e94aa7 EDP |
445 | #ifdef __cplusplus |
446 | } | |
447 | #endif | |
448 | ||
8a93734c AK |
449 | /* |
450 | * Multicast hash table. | |
451 | * | |
452 | * This table contains - | |
453 | * 1. The (S, G) entries used for encapsulating and forwarding BUM traffic. | |
454 | * S is the local VTEP-IP and G is a BUM mcast group address. | |
455 | * 2. The (X, G) entries used for terminating a BUM flow. | |
456 | * Multiple L2-VNIs can share the same MDT hence the need to maintain | |
457 | * an aggregated table that pimd can consume without much | |
458 | * re-interpretation. | |
459 | */ | |
460 | typedef struct zebra_vxlan_sg_ { | |
461 | struct zebra_vrf *zvrf; | |
462 | ||
463 | struct prefix_sg sg; | |
464 | char sg_str[PREFIX_SG_STR_LEN]; | |
465 | ||
466 | /* For SG - num of L2 VNIs using this entry for sending BUM traffic */ | |
467 | /* For XG - num of SG using this as parent */ | |
468 | uint32_t ref_cnt; | |
469 | } zebra_vxlan_sg_t; | |
470 | ||
18a7a601 | 471 | #endif /* _ZEBRA_VXLAN_PRIVATE_H */ |