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