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 /* Corresponding VxLAN interface. */
74 struct interface
*vxlan_if
;
76 /* List of remote VTEPs */
80 struct in_addr local_vtep_ip
;
82 /* tenant VRF, if any */
85 /* List of local or remote MAC */
86 struct hash
*mac_table
;
88 /* List of local or remote neighbors (MAC+IP) */
89 struct hash
*neigh_table
;
92 /* L3 VNI hash table */
93 struct zebra_l3vni_t_
{
102 struct in_addr local_vtep_ip
;
104 /* kernel interface for l3vni */
105 struct interface
*vxlan_if
;
107 /* SVI interface corresponding to the l3vni */
108 struct interface
*svi_if
;
110 /* list of L2 VNIs associated with the L3 VNI */
113 /* list of remote router-macs */
114 struct hash
*rmac_table
;
116 /* list of remote vtep-ip neigh */
117 struct hash
*nh_table
;
120 /* get the vx-intf name for l3vni */
121 static inline const char *zl3vni_vxlan_if_name(zebra_l3vni_t
*zl3vni
)
123 return zl3vni
->vxlan_if
? zl3vni
->vxlan_if
->name
: "None";
126 /* get the svi intf name for l3vni */
127 static inline const char *zl3vni_svi_if_name(zebra_l3vni_t
*zl3vni
)
129 return zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "None";
132 /* get the vrf name for l3vni */
133 static inline const char *zl3vni_vrf_name(zebra_l3vni_t
*zl3vni
)
135 return vrf_id_to_name(zl3vni
->vrf_id
);
138 /* get the rmac string */
139 static inline const char *zl3vni_rmac2str(zebra_l3vni_t
*zl3vni
, char *buf
,
145 ptr
= (char *)XMALLOC(MTYPE_TMP
,
146 ETHER_ADDR_STRLEN
* sizeof(char));
148 assert(size
>= ETHER_ADDR_STRLEN
);
153 snprintf(ptr
, (ETHER_ADDR_STRLEN
),
154 "%02x:%02x:%02x:%02x:%02x:%02x",
155 (uint8_t)zl3vni
->svi_if
->hw_addr
[0],
156 (uint8_t)zl3vni
->svi_if
->hw_addr
[1],
157 (uint8_t)zl3vni
->svi_if
->hw_addr
[2],
158 (uint8_t)zl3vni
->svi_if
->hw_addr
[3],
159 (uint8_t)zl3vni
->svi_if
->hw_addr
[4],
160 (uint8_t)zl3vni
->svi_if
->hw_addr
[5]);
162 snprintf(ptr
, ETHER_ADDR_STRLEN
, "None");
168 * l3-vni is oper up when:
169 * 0. if EVPN is enabled (advertise-all-vni cfged)
170 * 1. it is associated to a vxlan-intf
171 * 2. Associated vxlan-intf is oper up
172 * 3. it is associated to an SVI
173 * 4. associated SVI is oper up
175 static inline int is_l3vni_oper_up(zebra_l3vni_t
*zl3vni
)
177 return (is_evpn_enabled() && zl3vni
&&
178 (zl3vni
->vrf_id
!= VRF_UNKNOWN
) &&
179 zl3vni
->vxlan_if
&& if_is_operative(zl3vni
->vxlan_if
) &&
180 zl3vni
->svi_if
&& if_is_operative(zl3vni
->svi_if
));
183 static inline const char *zl3vni_state2str(zebra_l3vni_t
*zl3vni
)
188 if (is_l3vni_oper_up(zl3vni
))
196 static inline vrf_id_t
zl3vni_vrf_id(zebra_l3vni_t
*zl3vni
)
198 return zl3vni
->vrf_id
;
201 static inline void zl3vni_get_rmac(zebra_l3vni_t
*zl3vni
,
202 struct ethaddr
*rmac
)
207 if (!is_l3vni_oper_up(zl3vni
))
210 if (zl3vni
->svi_if
&& if_is_operative(zl3vni
->svi_if
))
211 memcpy(rmac
->octet
, zl3vni
->svi_if
->hw_addr
, ETH_ALEN
);
217 * This table contains the MAC addresses pertaining to this VNI.
218 * This includes local MACs learnt on an attached VLAN that maps
219 * to this VNI as well as remote MACs learnt and installed by BGP.
220 * Local MACs will be known either on a VLAN sub-interface or
221 * on (port, VLAN); however, it is sufficient for zebra to maintain
222 * against the VNI i.e., it does not need to retain the local "port"
223 * information. The correct VNI will be obtained as zebra maintains
224 * the mapping (of VLAN to VNI).
226 struct zebra_mac_t_
{
228 struct ethaddr macaddr
;
231 #define ZEBRA_MAC_LOCAL 0x01
232 #define ZEBRA_MAC_REMOTE 0x02
233 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
234 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
235 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
237 /* Local or remote info. */
244 struct in_addr r_vtep_ip
;
247 /* List of neigh associated with this mac */
248 struct list
*neigh_list
;
250 /* list of hosts pointing to this remote RMAC */
251 struct list
*host_list
;
255 * Context for MAC hash walk - used by callbacks.
257 struct mac_walk_ctx
{
258 zebra_vni_t
*zvni
; /* VNI hash */
259 struct zebra_vrf
*zvrf
; /* VRF - for client notification. */
260 int uninstall
; /* uninstall from kernel? */
261 int upd_client
; /* uninstall from client? */
264 #define DEL_LOCAL_MAC 0x1
265 #define DEL_REMOTE_MAC 0x2
266 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
267 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
268 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
270 struct in_addr r_vtep_ip
; /* To walk MACs from specific VTEP */
272 struct vty
*vty
; /* Used by VTY handlers */
273 u_int32_t count
; /* Used by VTY handlers */
274 struct json_object
*json
; /* Used for JSON Output */
277 struct rmac_walk_ctx
{
279 struct json_object
*json
;
282 enum zebra_neigh_state
{ ZEBRA_NEIGH_INACTIVE
= 0, ZEBRA_NEIGH_ACTIVE
= 1 };
284 #define IS_ZEBRA_NEIGH_ACTIVE(n) n->state == ZEBRA_NEIGH_ACTIVE
286 #define IS_ZEBRA_NEIGH_INACTIVE(n) n->state == ZEBRA_NEIGH_INACTIVE
288 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
290 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
293 * Neighbor hash table.
295 * This table contains the neighbors (IP to MAC bindings) pertaining to
296 * this VNI. This includes local neighbors learnt on the attached VLAN
297 * device that maps to this VNI as well as remote neighbors learnt and
299 * Local neighbors will be known against the VLAN device (SVI); however,
300 * it is sufficient for zebra to maintain against the VNI. The correct
301 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
303 struct zebra_neigh_t_
{
310 /* Underlying interface. */
314 #define ZEBRA_NEIGH_LOCAL 0x01
315 #define ZEBRA_NEIGH_REMOTE 0x02
316 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
318 enum zebra_neigh_state state
;
320 /* Remote VTEP IP - applicable only for remote neighbors. */
321 struct in_addr r_vtep_ip
;
323 /* list of hosts pointing to this remote NH entry */
324 struct list
*host_list
;
328 * Context for neighbor hash walk - used by callbacks.
330 struct neigh_walk_ctx
{
331 zebra_vni_t
*zvni
; /* VNI hash */
332 struct zebra_vrf
*zvrf
; /* VRF - for client notification. */
333 int uninstall
; /* uninstall from kernel? */
334 int upd_client
; /* uninstall from client? */
337 #define DEL_LOCAL_NEIGH 0x1
338 #define DEL_REMOTE_NEIGH 0x2
339 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
340 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
341 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
343 struct in_addr r_vtep_ip
; /* To walk neighbors from specific VTEP */
345 struct vty
*vty
; /* Used by VTY handlers */
346 u_int32_t count
; /* Used by VTY handlers */
347 u_char addr_width
; /* Used by VTY handlers */
348 struct json_object
*json
; /* Used for JSON Output */
351 /* context for neigh hash walk - update l3vni and rmac */
352 struct neigh_l3info_walk_ctx
{
355 zebra_l3vni_t
*zl3vni
;
362 struct json_object
*json
;
365 #endif /* _ZEBRA_VXLAN_PRIVATE_H */