]>
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 | ||
29 | #include <zebra.h> | |
30 | ||
31 | #include "if.h" | |
32 | #include "linklist.h" | |
655b04d1 | 33 | #include "zebra_vxlan.h" |
18a7a601 | 34 | |
b7cfce93 MK |
35 | #define ERR_STR_SZ 256 |
36 | ||
18a7a601 | 37 | /* definitions */ |
38 | typedef struct zebra_vni_t_ zebra_vni_t; | |
39 | typedef struct zebra_vtep_t_ zebra_vtep_t; | |
4122e252 | 40 | typedef struct zebra_mac_t_ zebra_mac_t; |
41 | typedef struct zebra_neigh_t_ zebra_neigh_t; | |
b7cfce93 | 42 | typedef struct zebra_l3vni_t_ zebra_l3vni_t; |
18a7a601 | 43 | |
44 | /* | |
45 | * VTEP info | |
46 | * | |
47 | * Right now, this just has each remote VTEP's IP address. | |
48 | */ | |
d62a17ae | 49 | struct zebra_vtep_t_ { |
50 | /* Remote IP. */ | |
51 | /* NOTE: Can only be IPv4 right now. */ | |
52 | struct in_addr vtep_ip; | |
53 | ||
54 | /* Links. */ | |
55 | struct zebra_vtep_t_ *next; | |
56 | struct zebra_vtep_t_ *prev; | |
18a7a601 | 57 | }; |
58 | ||
59 | ||
60 | /* | |
61 | * VNI hash table | |
62 | * | |
63 | * Contains information pertaining to a VNI: | |
64 | * - the list of remote VTEPs (with this VNI) | |
65 | */ | |
d62a17ae | 66 | struct zebra_vni_t_ { |
67 | /* VNI - key */ | |
68 | vni_t vni; | |
18a7a601 | 69 | |
1a98c087 | 70 | /* Flag for advertising gw macip */ |
d7c0a89a | 71 | uint8_t advertise_gw_macip; |
1a98c087 | 72 | |
278e26de CS |
73 | /* Flag for advertising svi macip */ |
74 | uint8_t advertise_svi_macip; | |
75 | ||
31310b25 | 76 | /* Flag for advertising gw macip */ |
d7c0a89a | 77 | uint8_t advertise_subnet; |
31310b25 | 78 | |
d62a17ae | 79 | /* Corresponding VxLAN interface. */ |
80 | struct interface *vxlan_if; | |
18a7a601 | 81 | |
d62a17ae | 82 | /* List of remote VTEPs */ |
83 | zebra_vtep_t *vteps; | |
18a7a601 | 84 | |
d62a17ae | 85 | /* Local IP */ |
86 | struct in_addr local_vtep_ip; | |
4122e252 | 87 | |
b7cfce93 MK |
88 | /* tenant VRF, if any */ |
89 | vrf_id_t vrf_id; | |
90 | ||
d62a17ae | 91 | /* List of local or remote MAC */ |
92 | struct hash *mac_table; | |
4122e252 | 93 | |
d62a17ae | 94 | /* List of local or remote neighbors (MAC+IP) */ |
95 | struct hash *neigh_table; | |
4122e252 | 96 | }; |
97 | ||
b7cfce93 MK |
98 | /* L3 VNI hash table */ |
99 | struct zebra_l3vni_t_ { | |
100 | ||
101 | /* VNI key */ | |
102 | vni_t vni; | |
103 | ||
104 | /* vrf_id */ | |
105 | vrf_id_t vrf_id; | |
106 | ||
c48d9f5f MK |
107 | uint32_t filter; |
108 | #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */ | |
109 | ||
b67a60d2 | 110 | /* Local IP */ |
111 | struct in_addr local_vtep_ip; | |
112 | ||
b7cfce93 MK |
113 | /* kernel interface for l3vni */ |
114 | struct interface *vxlan_if; | |
115 | ||
116 | /* SVI interface corresponding to the l3vni */ | |
117 | struct interface *svi_if; | |
118 | ||
119 | /* list of L2 VNIs associated with the L3 VNI */ | |
120 | struct list *l2vnis; | |
121 | ||
122 | /* list of remote router-macs */ | |
123 | struct hash *rmac_table; | |
124 | ||
125 | /* list of remote vtep-ip neigh */ | |
126 | struct hash *nh_table; | |
127 | }; | |
128 | ||
129 | /* get the vx-intf name for l3vni */ | |
130 | static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t *zl3vni) | |
131 | { | |
132 | return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None"; | |
133 | } | |
134 | ||
135 | /* get the svi intf name for l3vni */ | |
136 | static inline const char *zl3vni_svi_if_name(zebra_l3vni_t *zl3vni) | |
137 | { | |
138 | return zl3vni->svi_if ? zl3vni->svi_if->name : "None"; | |
139 | } | |
140 | ||
141 | /* get the vrf name for l3vni */ | |
142 | static inline const char *zl3vni_vrf_name(zebra_l3vni_t *zl3vni) | |
143 | { | |
144 | return vrf_id_to_name(zl3vni->vrf_id); | |
145 | } | |
146 | ||
147 | /* get the rmac string */ | |
148 | static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf, | |
149 | int size) | |
150 | { | |
151 | char *ptr; | |
152 | ||
153 | if (!buf) | |
154 | ptr = (char *)XMALLOC(MTYPE_TMP, | |
155 | ETHER_ADDR_STRLEN * sizeof(char)); | |
156 | else { | |
157 | assert(size >= ETHER_ADDR_STRLEN); | |
158 | ptr = buf; | |
159 | } | |
160 | ||
161 | if (zl3vni->svi_if) | |
162 | snprintf(ptr, (ETHER_ADDR_STRLEN), | |
163 | "%02x:%02x:%02x:%02x:%02x:%02x", | |
164 | (uint8_t)zl3vni->svi_if->hw_addr[0], | |
165 | (uint8_t)zl3vni->svi_if->hw_addr[1], | |
166 | (uint8_t)zl3vni->svi_if->hw_addr[2], | |
167 | (uint8_t)zl3vni->svi_if->hw_addr[3], | |
168 | (uint8_t)zl3vni->svi_if->hw_addr[4], | |
169 | (uint8_t)zl3vni->svi_if->hw_addr[5]); | |
170 | else | |
171 | snprintf(ptr, ETHER_ADDR_STRLEN, "None"); | |
172 | ||
173 | return ptr; | |
174 | } | |
175 | ||
176 | /* | |
177 | * l3-vni is oper up when: | |
655b04d1 | 178 | * 0. if EVPN is enabled (advertise-all-vni cfged) |
b7cfce93 MK |
179 | * 1. it is associated to a vxlan-intf |
180 | * 2. Associated vxlan-intf is oper up | |
181 | * 3. it is associated to an SVI | |
182 | * 4. associated SVI is oper up | |
183 | */ | |
184 | static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni) | |
185 | { | |
996c9314 LB |
186 | return (is_evpn_enabled() && zl3vni && (zl3vni->vrf_id != VRF_UNKNOWN) |
187 | && zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) | |
188 | && zl3vni->svi_if && if_is_operative(zl3vni->svi_if)); | |
b7cfce93 MK |
189 | } |
190 | ||
191 | static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni) | |
192 | { | |
193 | if (!zl3vni) | |
194 | return NULL; | |
195 | ||
196 | if (is_l3vni_oper_up(zl3vni)) | |
197 | return "Up"; | |
198 | else | |
199 | return "Down"; | |
200 | ||
201 | return NULL; | |
202 | } | |
203 | ||
204 | static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni) | |
205 | { | |
206 | return zl3vni->vrf_id; | |
207 | } | |
208 | ||
996c9314 | 209 | static inline void zl3vni_get_rmac(zebra_l3vni_t *zl3vni, struct ethaddr *rmac) |
b7cfce93 MK |
210 | { |
211 | if (!zl3vni) | |
212 | return; | |
213 | ||
214 | if (!is_l3vni_oper_up(zl3vni)) | |
215 | return; | |
216 | ||
217 | if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if)) | |
218 | memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN); | |
219 | } | |
220 | ||
5e1b0650 DS |
221 | struct host_rb_entry { |
222 | RB_ENTRY(host_rb_entry) hl_entry; | |
223 | ||
224 | struct prefix p; | |
225 | }; | |
226 | ||
85442b09 DS |
227 | RB_HEAD(host_rb_tree_entry, host_rb_entry); |
228 | RB_PROTOTYPE(host_rb_tree_entry, host_rb_entry, hl_entry, | |
5e1b0650 | 229 | host_rb_entry_compare); |
4122e252 | 230 | /* |
231 | * MAC hash table. | |
232 | * | |
233 | * This table contains the MAC addresses pertaining to this VNI. | |
234 | * This includes local MACs learnt on an attached VLAN that maps | |
235 | * to this VNI as well as remote MACs learnt and installed by BGP. | |
236 | * Local MACs will be known either on a VLAN sub-interface or | |
237 | * on (port, VLAN); however, it is sufficient for zebra to maintain | |
238 | * against the VNI i.e., it does not need to retain the local "port" | |
239 | * information. The correct VNI will be obtained as zebra maintains | |
240 | * the mapping (of VLAN to VNI). | |
241 | */ | |
d62a17ae | 242 | struct zebra_mac_t_ { |
243 | /* MAC address. */ | |
244 | struct ethaddr macaddr; | |
4122e252 | 245 | |
d7c0a89a | 246 | uint32_t flags; |
4122e252 | 247 | #define ZEBRA_MAC_LOCAL 0x01 |
248 | #define ZEBRA_MAC_REMOTE 0x02 | |
249 | #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */ | |
c85c03c7 | 250 | #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */ |
b7cfce93 | 251 | #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */ |
ead40654 | 252 | #define ZEBRA_MAC_DEF_GW 0x20 |
51f4dab4 AK |
253 | /* remote VTEP advertised MAC as default GW */ |
254 | #define ZEBRA_MAC_REMOTE_DEF_GW 0x40 | |
e22a946a CS |
255 | #define ZEBRA_MAC_DUPLICATE 0x80 |
256 | ||
257 | /* back pointer to zvni */ | |
258 | zebra_vni_t *zvni; | |
4122e252 | 259 | |
d62a17ae | 260 | /* Local or remote info. */ |
261 | union { | |
262 | struct { | |
263 | ifindex_t ifindex; | |
264 | vlanid_t vid; | |
265 | } local; | |
4122e252 | 266 | |
d62a17ae | 267 | struct in_addr r_vtep_ip; |
268 | } fwd_info; | |
4122e252 | 269 | |
f07e1c99 | 270 | /* Mobility sequence numbers associated with this entry. */ |
271 | uint32_t rem_seq; | |
272 | uint32_t loc_seq; | |
273 | ||
b6938a74 MK |
274 | /* List of neigh associated with this mac */ |
275 | struct list *neigh_list; | |
b7cfce93 | 276 | |
6134fd82 | 277 | /* list of hosts pointing to this remote RMAC */ |
85442b09 | 278 | struct host_rb_tree_entry host_rb; |
e22a946a CS |
279 | |
280 | /* Duplicate mac detection */ | |
281 | uint32_t dad_count; | |
282 | ||
283 | struct thread *dad_mac_auto_recovery_timer; | |
284 | ||
285 | struct timeval detect_start_time; | |
286 | ||
287 | time_t dad_dup_detect_time; | |
4122e252 | 288 | }; |
289 | ||
290 | /* | |
291 | * Context for MAC hash walk - used by callbacks. | |
292 | */ | |
d62a17ae | 293 | struct mac_walk_ctx { |
294 | zebra_vni_t *zvni; /* VNI hash */ | |
295 | struct zebra_vrf *zvrf; /* VRF - for client notification. */ | |
296 | int uninstall; /* uninstall from kernel? */ | |
297 | int upd_client; /* uninstall from client? */ | |
298 | ||
d7c0a89a | 299 | uint32_t flags; |
4122e252 | 300 | #define DEL_LOCAL_MAC 0x1 |
301 | #define DEL_REMOTE_MAC 0x2 | |
302 | #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC) | |
303 | #define DEL_REMOTE_MAC_FROM_VTEP 0x4 | |
304 | #define SHOW_REMOTE_MAC_FROM_VTEP 0x8 | |
305 | ||
d62a17ae | 306 | struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */ |
4122e252 | 307 | |
cd233079 | 308 | struct vty *vty; /* Used by VTY handlers */ |
d7c0a89a | 309 | uint32_t count; /* Used by VTY handlers */ |
cd233079 | 310 | struct json_object *json; /* Used for JSON Output */ |
1374d4db | 311 | bool print_dup; /* Used to print dup addr list */ |
4122e252 | 312 | }; |
313 | ||
b7cfce93 MK |
314 | struct rmac_walk_ctx { |
315 | struct vty *vty; | |
316 | struct json_object *json; | |
317 | }; | |
318 | ||
2c476b72 | 319 | #define IS_ZEBRA_NEIGH_ACTIVE(n) (n->state == ZEBRA_NEIGH_ACTIVE) |
b6938a74 | 320 | |
2c476b72 | 321 | #define IS_ZEBRA_NEIGH_INACTIVE(n) (n->state == ZEBRA_NEIGH_INACTIVE) |
b6938a74 MK |
322 | |
323 | #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE | |
324 | ||
325 | #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE | |
326 | ||
4122e252 | 327 | /* |
328 | * Neighbor hash table. | |
329 | * | |
330 | * This table contains the neighbors (IP to MAC bindings) pertaining to | |
331 | * this VNI. This includes local neighbors learnt on the attached VLAN | |
332 | * device that maps to this VNI as well as remote neighbors learnt and | |
333 | * installed by BGP. | |
334 | * Local neighbors will be known against the VLAN device (SVI); however, | |
335 | * it is sufficient for zebra to maintain against the VNI. The correct | |
336 | * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI). | |
337 | */ | |
d62a17ae | 338 | struct zebra_neigh_t_ { |
339 | /* IP address. */ | |
340 | struct ipaddr ip; | |
4122e252 | 341 | |
d62a17ae | 342 | /* MAC address. */ |
343 | struct ethaddr emac; | |
4122e252 | 344 | |
d62a17ae | 345 | /* Underlying interface. */ |
346 | ifindex_t ifindex; | |
4122e252 | 347 | |
c80a972c CS |
348 | zebra_vni_t *zvni; |
349 | ||
d7c0a89a | 350 | uint32_t flags; |
b6938a74 MK |
351 | #define ZEBRA_NEIGH_LOCAL 0x01 |
352 | #define ZEBRA_NEIGH_REMOTE 0x02 | |
b7cfce93 | 353 | #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */ |
ead40654 | 354 | #define ZEBRA_NEIGH_DEF_GW 0x08 |
68e33151 | 355 | #define ZEBRA_NEIGH_ROUTER_FLAG 0x10 |
e22a946a | 356 | #define ZEBRA_NEIGH_DUPLICATE 0x20 |
b6938a74 MK |
357 | |
358 | enum zebra_neigh_state state; | |
4122e252 | 359 | |
d62a17ae | 360 | /* Remote VTEP IP - applicable only for remote neighbors. */ |
361 | struct in_addr r_vtep_ip; | |
b7cfce93 | 362 | |
f07e1c99 | 363 | /* |
364 | * Mobility sequence numbers associated with this entry. The rem_seq | |
365 | * represents the sequence number from the client (BGP) for the most | |
366 | * recent add or update of this entry while the loc_seq represents | |
367 | * the sequence number informed (or to be informed) by zebra to BGP | |
368 | * for this entry. | |
369 | */ | |
370 | uint32_t rem_seq; | |
371 | uint32_t loc_seq; | |
372 | ||
6134fd82 | 373 | /* list of hosts pointing to this remote NH entry */ |
85442b09 | 374 | struct host_rb_tree_entry host_rb; |
e22a946a CS |
375 | |
376 | /* Duplicate ip detection */ | |
377 | uint32_t dad_count; | |
378 | ||
379 | struct thread *dad_ip_auto_recovery_timer; | |
380 | ||
381 | struct timeval detect_start_time; | |
382 | ||
383 | time_t dad_dup_detect_time; | |
4122e252 | 384 | }; |
385 | ||
386 | /* | |
387 | * Context for neighbor hash walk - used by callbacks. | |
388 | */ | |
d62a17ae | 389 | struct neigh_walk_ctx { |
390 | zebra_vni_t *zvni; /* VNI hash */ | |
391 | struct zebra_vrf *zvrf; /* VRF - for client notification. */ | |
392 | int uninstall; /* uninstall from kernel? */ | |
393 | int upd_client; /* uninstall from client? */ | |
394 | ||
d7c0a89a | 395 | uint32_t flags; |
4122e252 | 396 | #define DEL_LOCAL_NEIGH 0x1 |
397 | #define DEL_REMOTE_NEIGH 0x2 | |
398 | #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH) | |
399 | #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4 | |
400 | #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8 | |
401 | ||
d62a17ae | 402 | struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */ |
4122e252 | 403 | |
cd233079 | 404 | struct vty *vty; /* Used by VTY handlers */ |
d7c0a89a QY |
405 | uint32_t count; /* Used by VTY handlers */ |
406 | uint8_t addr_width; /* Used by VTY handlers */ | |
cd233079 | 407 | struct json_object *json; /* Used for JSON Output */ |
18a7a601 | 408 | }; |
409 | ||
b7cfce93 MK |
410 | /* context for neigh hash walk - update l3vni and rmac */ |
411 | struct neigh_l3info_walk_ctx { | |
412 | ||
413 | zebra_vni_t *zvni; | |
414 | zebra_l3vni_t *zl3vni; | |
415 | int add; | |
416 | }; | |
417 | ||
418 | struct nh_walk_ctx { | |
419 | ||
420 | struct vty *vty; | |
421 | struct json_object *json; | |
422 | }; | |
423 | ||
18a7a601 | 424 | #endif /* _ZEBRA_VXLAN_PRIVATE_H */ |