]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vxlan_private.h
Merge branch 'master' into stylechecker
[mirror_frr.git] / zebra / zebra_vxlan_private.h
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"
33 #include "zebra_vxlan.h"
34
35 #define ERR_STR_SZ 256
36
37 /* definitions */
38 typedef struct zebra_vni_t_ zebra_vni_t;
39 typedef struct zebra_vtep_t_ zebra_vtep_t;
40 typedef struct zebra_mac_t_ zebra_mac_t;
41 typedef struct zebra_neigh_t_ zebra_neigh_t;
42 typedef struct zebra_l3vni_t_ zebra_l3vni_t;
43
44 /*
45 * VTEP info
46 *
47 * Right now, this just has each remote VTEP's IP address.
48 */
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;
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 */
66 struct zebra_vni_t_ {
67 /* VNI - key */
68 vni_t vni;
69
70 /* Flag for advertising gw macip */
71 u_int8_t advertise_gw_macip;
72
73 /* Flag for advertising gw macip */
74 u_int8_t advertise_subnet;
75
76 /* Corresponding VxLAN interface. */
77 struct interface *vxlan_if;
78
79 /* List of remote VTEPs */
80 zebra_vtep_t *vteps;
81
82 /* Local IP */
83 struct in_addr local_vtep_ip;
84
85 /* tenant VRF, if any */
86 vrf_id_t vrf_id;
87
88 /* List of local or remote MAC */
89 struct hash *mac_table;
90
91 /* List of local or remote neighbors (MAC+IP) */
92 struct hash *neigh_table;
93 };
94
95 /* L3 VNI hash table */
96 struct zebra_l3vni_t_ {
97
98 /* VNI key */
99 vni_t vni;
100
101 /* vrf_id */
102 vrf_id_t vrf_id;
103
104 /* Local IP */
105 struct in_addr local_vtep_ip;
106
107 /* kernel interface for l3vni */
108 struct interface *vxlan_if;
109
110 /* SVI interface corresponding to the l3vni */
111 struct interface *svi_if;
112
113 /* list of L2 VNIs associated with the L3 VNI */
114 struct list *l2vnis;
115
116 /* list of remote router-macs */
117 struct hash *rmac_table;
118
119 /* list of remote vtep-ip neigh */
120 struct hash *nh_table;
121 };
122
123 /* get the vx-intf name for l3vni */
124 static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t *zl3vni)
125 {
126 return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None";
127 }
128
129 /* get the svi intf name for l3vni */
130 static inline const char *zl3vni_svi_if_name(zebra_l3vni_t *zl3vni)
131 {
132 return zl3vni->svi_if ? zl3vni->svi_if->name : "None";
133 }
134
135 /* get the vrf name for l3vni */
136 static inline const char *zl3vni_vrf_name(zebra_l3vni_t *zl3vni)
137 {
138 return vrf_id_to_name(zl3vni->vrf_id);
139 }
140
141 /* get the rmac string */
142 static inline const char *zl3vni_rmac2str(zebra_l3vni_t *zl3vni, char *buf,
143 int size)
144 {
145 char *ptr;
146
147 if (!buf)
148 ptr = (char *)XMALLOC(MTYPE_TMP,
149 ETHER_ADDR_STRLEN * sizeof(char));
150 else {
151 assert(size >= ETHER_ADDR_STRLEN);
152 ptr = buf;
153 }
154
155 if (zl3vni->svi_if)
156 snprintf(ptr, (ETHER_ADDR_STRLEN),
157 "%02x:%02x:%02x:%02x:%02x:%02x",
158 (uint8_t)zl3vni->svi_if->hw_addr[0],
159 (uint8_t)zl3vni->svi_if->hw_addr[1],
160 (uint8_t)zl3vni->svi_if->hw_addr[2],
161 (uint8_t)zl3vni->svi_if->hw_addr[3],
162 (uint8_t)zl3vni->svi_if->hw_addr[4],
163 (uint8_t)zl3vni->svi_if->hw_addr[5]);
164 else
165 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
166
167 return ptr;
168 }
169
170 /*
171 * l3-vni is oper up when:
172 * 0. if EVPN is enabled (advertise-all-vni cfged)
173 * 1. it is associated to a vxlan-intf
174 * 2. Associated vxlan-intf is oper up
175 * 3. it is associated to an SVI
176 * 4. associated SVI is oper up
177 */
178 static inline int is_l3vni_oper_up(zebra_l3vni_t *zl3vni)
179 {
180 return (is_evpn_enabled() && zl3vni &&
181 (zl3vni->vrf_id != VRF_UNKNOWN) &&
182 zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if) &&
183 zl3vni->svi_if && if_is_operative(zl3vni->svi_if));
184 }
185
186 static inline const char *zl3vni_state2str(zebra_l3vni_t *zl3vni)
187 {
188 if (!zl3vni)
189 return NULL;
190
191 if (is_l3vni_oper_up(zl3vni))
192 return "Up";
193 else
194 return "Down";
195
196 return NULL;
197 }
198
199 static inline vrf_id_t zl3vni_vrf_id(zebra_l3vni_t *zl3vni)
200 {
201 return zl3vni->vrf_id;
202 }
203
204 static inline void zl3vni_get_rmac(zebra_l3vni_t *zl3vni,
205 struct ethaddr *rmac)
206 {
207 if (!zl3vni)
208 return;
209
210 if (!is_l3vni_oper_up(zl3vni))
211 return;
212
213 if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if))
214 memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN);
215 }
216
217 /*
218 * MAC hash table.
219 *
220 * This table contains the MAC addresses pertaining to this VNI.
221 * This includes local MACs learnt on an attached VLAN that maps
222 * to this VNI as well as remote MACs learnt and installed by BGP.
223 * Local MACs will be known either on a VLAN sub-interface or
224 * on (port, VLAN); however, it is sufficient for zebra to maintain
225 * against the VNI i.e., it does not need to retain the local "port"
226 * information. The correct VNI will be obtained as zebra maintains
227 * the mapping (of VLAN to VNI).
228 */
229 struct zebra_mac_t_ {
230 /* MAC address. */
231 struct ethaddr macaddr;
232
233 u_int32_t flags;
234 #define ZEBRA_MAC_LOCAL 0x01
235 #define ZEBRA_MAC_REMOTE 0x02
236 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
237 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
238 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
239 #define ZEBRA_MAC_DEF_GW 0x20
240
241 /* Local or remote info. */
242 union {
243 struct {
244 ifindex_t ifindex;
245 vlanid_t vid;
246 } local;
247
248 struct in_addr r_vtep_ip;
249 } fwd_info;
250
251 /* List of neigh associated with this mac */
252 struct list *neigh_list;
253
254 /* list of hosts pointing to this remote RMAC */
255 struct list *host_list;
256 };
257
258 /*
259 * Context for MAC hash walk - used by callbacks.
260 */
261 struct mac_walk_ctx {
262 zebra_vni_t *zvni; /* VNI hash */
263 struct zebra_vrf *zvrf; /* VRF - for client notification. */
264 int uninstall; /* uninstall from kernel? */
265 int upd_client; /* uninstall from client? */
266
267 u_int32_t flags;
268 #define DEL_LOCAL_MAC 0x1
269 #define DEL_REMOTE_MAC 0x2
270 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
271 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
272 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
273
274 struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */
275
276 struct vty *vty; /* Used by VTY handlers */
277 u_int32_t count; /* Used by VTY handlers */
278 struct json_object *json; /* Used for JSON Output */
279 };
280
281 struct rmac_walk_ctx {
282 struct vty *vty;
283 struct json_object *json;
284 };
285
286 enum zebra_neigh_state { ZEBRA_NEIGH_INACTIVE = 0, ZEBRA_NEIGH_ACTIVE = 1 };
287
288 #define IS_ZEBRA_NEIGH_ACTIVE(n) n->state == ZEBRA_NEIGH_ACTIVE
289
290 #define IS_ZEBRA_NEIGH_INACTIVE(n) n->state == ZEBRA_NEIGH_INACTIVE
291
292 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
293
294 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
295
296 /*
297 * Neighbor hash table.
298 *
299 * This table contains the neighbors (IP to MAC bindings) pertaining to
300 * this VNI. This includes local neighbors learnt on the attached VLAN
301 * device that maps to this VNI as well as remote neighbors learnt and
302 * installed by BGP.
303 * Local neighbors will be known against the VLAN device (SVI); however,
304 * it is sufficient for zebra to maintain against the VNI. The correct
305 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
306 */
307 struct zebra_neigh_t_ {
308 /* IP address. */
309 struct ipaddr ip;
310
311 /* MAC address. */
312 struct ethaddr emac;
313
314 /* Underlying interface. */
315 ifindex_t ifindex;
316
317 u_int32_t flags;
318 #define ZEBRA_NEIGH_LOCAL 0x01
319 #define ZEBRA_NEIGH_REMOTE 0x02
320 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
321 #define ZEBRA_NEIGH_DEF_GW 0x08
322
323 enum zebra_neigh_state state;
324
325 /* Remote VTEP IP - applicable only for remote neighbors. */
326 struct in_addr r_vtep_ip;
327
328 /* list of hosts pointing to this remote NH entry */
329 struct list *host_list;
330 };
331
332 /*
333 * Context for neighbor hash walk - used by callbacks.
334 */
335 struct neigh_walk_ctx {
336 zebra_vni_t *zvni; /* VNI hash */
337 struct zebra_vrf *zvrf; /* VRF - for client notification. */
338 int uninstall; /* uninstall from kernel? */
339 int upd_client; /* uninstall from client? */
340
341 u_int32_t flags;
342 #define DEL_LOCAL_NEIGH 0x1
343 #define DEL_REMOTE_NEIGH 0x2
344 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
345 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
346 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
347
348 struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */
349
350 struct vty *vty; /* Used by VTY handlers */
351 u_int32_t count; /* Used by VTY handlers */
352 u_char addr_width; /* Used by VTY handlers */
353 struct json_object *json; /* Used for JSON Output */
354 };
355
356 /* context for neigh hash walk - update l3vni and rmac */
357 struct neigh_l3info_walk_ctx {
358
359 zebra_vni_t *zvni;
360 zebra_l3vni_t *zl3vni;
361 int add;
362 };
363
364 struct nh_walk_ctx {
365
366 struct vty *vty;
367 struct json_object *json;
368 };
369
370 #endif /* _ZEBRA_VXLAN_PRIVATE_H */