2 * Zebra VxLAN (EVPN) Data structures and definitions
3 * These are "internal" to this function.
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
6 * This file is part of FRR.
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
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.
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
24 #ifndef _ZEBRA_VXLAN_PRIVATE_H
25 #define _ZEBRA_VXLAN_PRIVATE_H
33 #include "zebra_vxlan.h"
35 #define ERR_STR_SZ 256
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
;
47 * Right now, this just has each remote VTEP's IP address.
49 struct zebra_vtep_t_
{
51 /* NOTE: Can only be IPv4 right now. */
52 struct in_addr vtep_ip
;
55 struct zebra_vtep_t_
*next
;
56 struct zebra_vtep_t_
*prev
;
63 * Contains information pertaining to a VNI:
64 * - the list of remote VTEPs (with this VNI)
70 /* Flag for advertising gw macip */
71 u_int8_t advertise_gw_macip
;
73 /* Flag for advertising gw macip */
74 u_int8_t advertise_subnet
;
76 /* Corresponding VxLAN interface. */
77 struct interface
*vxlan_if
;
79 /* List of remote VTEPs */
83 struct in_addr local_vtep_ip
;
85 /* tenant VRF, if any */
88 /* List of local or remote MAC */
89 struct hash
*mac_table
;
91 /* List of local or remote neighbors (MAC+IP) */
92 struct hash
*neigh_table
;
95 /* L3 VNI hash table */
96 struct zebra_l3vni_t_
{
105 #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */
108 struct in_addr local_vtep_ip
;
110 /* kernel interface for l3vni */
111 struct interface
*vxlan_if
;
113 /* SVI interface corresponding to the l3vni */
114 struct interface
*svi_if
;
116 /* list of L2 VNIs associated with the L3 VNI */
119 /* list of remote router-macs */
120 struct hash
*rmac_table
;
122 /* list of remote vtep-ip neigh */
123 struct hash
*nh_table
;
126 /* get the vx-intf name for l3vni */
127 static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t
*zl3vni
)
129 return zl3vni
->vxlan_if
? zl3vni
->vxlan_if
->name
: "None";
132 /* get the svi intf name for l3vni */
133 static inline const char *zl3vni_svi_if_name(zebra_l3vni_t
*zl3vni
)
135 return zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "None";
138 /* get the vrf name for l3vni */
139 static inline const char *zl3vni_vrf_name(zebra_l3vni_t
*zl3vni
)
141 return vrf_id_to_name(zl3vni
->vrf_id
);
144 /* get the rmac string */
145 static inline const char *zl3vni_rmac2str(zebra_l3vni_t
*zl3vni
, char *buf
,
151 ptr
= (char *)XMALLOC(MTYPE_TMP
,
152 ETHER_ADDR_STRLEN
* sizeof(char));
154 assert(size
>= ETHER_ADDR_STRLEN
);
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]);
168 snprintf(ptr
, ETHER_ADDR_STRLEN
, "None");
174 * l3-vni is oper up when:
175 * 0. if EVPN is enabled (advertise-all-vni cfged)
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
181 static inline int is_l3vni_oper_up(zebra_l3vni_t
*zl3vni
)
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
));
188 static inline const char *zl3vni_state2str(zebra_l3vni_t
*zl3vni
)
193 if (is_l3vni_oper_up(zl3vni
))
201 static inline vrf_id_t
zl3vni_vrf_id(zebra_l3vni_t
*zl3vni
)
203 return zl3vni
->vrf_id
;
206 static inline void zl3vni_get_rmac(zebra_l3vni_t
*zl3vni
, struct ethaddr
*rmac
)
211 if (!is_l3vni_oper_up(zl3vni
))
214 if (zl3vni
->svi_if
&& if_is_operative(zl3vni
->svi_if
))
215 memcpy(rmac
->octet
, zl3vni
->svi_if
->hw_addr
, ETH_ALEN
);
221 * This table contains the MAC addresses pertaining to this VNI.
222 * This includes local MACs learnt on an attached VLAN that maps
223 * to this VNI as well as remote MACs learnt and installed by BGP.
224 * Local MACs will be known either on a VLAN sub-interface or
225 * on (port, VLAN); however, it is sufficient for zebra to maintain
226 * against the VNI i.e., it does not need to retain the local "port"
227 * information. The correct VNI will be obtained as zebra maintains
228 * the mapping (of VLAN to VNI).
230 struct zebra_mac_t_
{
232 struct ethaddr macaddr
;
235 #define ZEBRA_MAC_LOCAL 0x01
236 #define ZEBRA_MAC_REMOTE 0x02
237 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
238 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
239 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
240 #define ZEBRA_MAC_DEF_GW 0x20
242 /* Local or remote info. */
249 struct in_addr r_vtep_ip
;
252 /* List of neigh associated with this mac */
253 struct list
*neigh_list
;
255 /* list of hosts pointing to this remote RMAC */
256 struct list
*host_list
;
260 * Context for MAC hash walk - used by callbacks.
262 struct mac_walk_ctx
{
263 zebra_vni_t
*zvni
; /* VNI hash */
264 struct zebra_vrf
*zvrf
; /* VRF - for client notification. */
265 int uninstall
; /* uninstall from kernel? */
266 int upd_client
; /* uninstall from client? */
269 #define DEL_LOCAL_MAC 0x1
270 #define DEL_REMOTE_MAC 0x2
271 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
272 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
273 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
275 struct in_addr r_vtep_ip
; /* To walk MACs from specific VTEP */
277 struct vty
*vty
; /* Used by VTY handlers */
278 u_int32_t count
; /* Used by VTY handlers */
279 struct json_object
*json
; /* Used for JSON Output */
282 struct rmac_walk_ctx
{
284 struct json_object
*json
;
287 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
289 #define IS_ZEBRA_NEIGH_ACTIVE(n) n->state == ZEBRA_NEIGH_ACTIVE
291 #define IS_ZEBRA_NEIGH_INACTIVE(n) n->state == ZEBRA_NEIGH_INACTIVE
293 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
295 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
298 * Neighbor hash table.
300 * This table contains the neighbors (IP to MAC bindings) pertaining to
301 * this VNI. This includes local neighbors learnt on the attached VLAN
302 * device that maps to this VNI as well as remote neighbors learnt and
304 * Local neighbors will be known against the VLAN device (SVI); however,
305 * it is sufficient for zebra to maintain against the VNI. The correct
306 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
308 struct zebra_neigh_t_
{
315 /* Underlying interface. */
319 #define ZEBRA_NEIGH_LOCAL 0x01
320 #define ZEBRA_NEIGH_REMOTE 0x02
321 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
322 #define ZEBRA_NEIGH_DEF_GW 0x08
324 enum zebra_neigh_state state
;
326 /* Remote VTEP IP - applicable only for remote neighbors. */
327 struct in_addr r_vtep_ip
;
329 /* list of hosts pointing to this remote NH entry */
330 struct list
*host_list
;
334 * Context for neighbor hash walk - used by callbacks.
336 struct neigh_walk_ctx
{
337 zebra_vni_t
*zvni
; /* VNI hash */
338 struct zebra_vrf
*zvrf
; /* VRF - for client notification. */
339 int uninstall
; /* uninstall from kernel? */
340 int upd_client
; /* uninstall from client? */
343 #define DEL_LOCAL_NEIGH 0x1
344 #define DEL_REMOTE_NEIGH 0x2
345 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
346 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
347 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
349 struct in_addr r_vtep_ip
; /* To walk neighbors from specific VTEP */
351 struct vty
*vty
; /* Used by VTY handlers */
352 u_int32_t count
; /* Used by VTY handlers */
353 u_char addr_width
; /* Used by VTY handlers */
354 struct json_object
*json
; /* Used for JSON Output */
357 /* context for neigh hash walk - update l3vni and rmac */
358 struct neigh_l3info_walk_ctx
{
361 zebra_l3vni_t
*zl3vni
;
368 struct json_object
*json
;
371 #endif /* _ZEBRA_VXLAN_PRIVATE_H */