]>
git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vxlan_private.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Zebra VxLAN (EVPN) Data structures and definitions
4 * These are "internal" to this function.
5 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
8 #ifndef _ZEBRA_VXLAN_PRIVATE_H
9 #define _ZEBRA_VXLAN_PRIVATE_H
15 #include "zebra_vxlan.h"
16 #include "zebra_vxlan_if.h"
17 #include "zebra_evpn.h"
18 #include "zebra_evpn_mac.h"
24 #define ERR_STR_SZ 256
26 /* L3 VNI hash table */
36 #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */
38 /* Corresponding Bridge information */
40 struct interface
*bridge_if
;
43 struct in_addr local_vtep_ip
;
45 /* kernel interface for l3vni */
46 struct interface
*vxlan_if
;
48 /* SVI interface corresponding to the l3vni */
49 struct interface
*svi_if
;
51 struct interface
*mac_vlan_if
;
53 /* list of L2 VNIs associated with the L3 VNI */
56 /* list of remote router-macs */
57 struct hash
*rmac_table
;
59 /* list of remote vtep-ip neigh */
60 struct hash
*nh_table
;
63 #define IS_ZL3VNI_SVD_BACKED(zl3vni) \
64 (zl3vni->vxlan_if && zl3vni->vxlan_if->info && \
65 IS_ZEBRA_VXLAN_IF_SVD((struct zebra_if *)zl3vni->vxlan_if->info))
67 /* get the vx-intf name for l3vni */
68 static inline const char *zl3vni_vxlan_if_name(struct zebra_l3vni
*zl3vni
)
70 return zl3vni
->vxlan_if
? zl3vni
->vxlan_if
->name
: "None";
73 /* get the svi intf name for l3vni */
74 static inline const char *zl3vni_svi_if_name(struct zebra_l3vni
*zl3vni
)
76 return zl3vni
->svi_if
? zl3vni
->svi_if
->name
: "None";
79 /* get the vrf name for l3vni */
80 static inline const char *zl3vni_vrf_name(struct zebra_l3vni
*zl3vni
)
82 return vrf_id_to_name(zl3vni
->vrf_id
);
85 /* get the rmac string */
86 static inline const char *zl3vni_rmac2str(struct zebra_l3vni
*zl3vni
, char *buf
,
92 ptr
= XMALLOC(MTYPE_TMP
, ETHER_ADDR_STRLEN
* sizeof(char));
94 assert(size
>= ETHER_ADDR_STRLEN
);
98 if (zl3vni
->mac_vlan_if
)
99 snprintf(ptr
, (ETHER_ADDR_STRLEN
),
100 "%02x:%02x:%02x:%02x:%02x:%02x",
101 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[0],
102 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[1],
103 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[2],
104 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[3],
105 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[4],
106 (uint8_t)zl3vni
->mac_vlan_if
->hw_addr
[5]);
107 else if (zl3vni
->svi_if
)
108 snprintf(ptr
, (ETHER_ADDR_STRLEN
),
109 "%02x:%02x:%02x:%02x:%02x:%02x",
110 (uint8_t)zl3vni
->svi_if
->hw_addr
[0],
111 (uint8_t)zl3vni
->svi_if
->hw_addr
[1],
112 (uint8_t)zl3vni
->svi_if
->hw_addr
[2],
113 (uint8_t)zl3vni
->svi_if
->hw_addr
[3],
114 (uint8_t)zl3vni
->svi_if
->hw_addr
[4],
115 (uint8_t)zl3vni
->svi_if
->hw_addr
[5]);
117 snprintf(ptr
, ETHER_ADDR_STRLEN
, "None");
122 /* get the sys mac string */
123 static inline const char *zl3vni_sysmac2str(struct zebra_l3vni
*zl3vni
,
129 ptr
= XMALLOC(MTYPE_TMP
, ETHER_ADDR_STRLEN
* sizeof(char));
131 assert(size
>= ETHER_ADDR_STRLEN
);
136 snprintf(ptr
, (ETHER_ADDR_STRLEN
),
137 "%02x:%02x:%02x:%02x:%02x:%02x",
138 (uint8_t)zl3vni
->svi_if
->hw_addr
[0],
139 (uint8_t)zl3vni
->svi_if
->hw_addr
[1],
140 (uint8_t)zl3vni
->svi_if
->hw_addr
[2],
141 (uint8_t)zl3vni
->svi_if
->hw_addr
[3],
142 (uint8_t)zl3vni
->svi_if
->hw_addr
[4],
143 (uint8_t)zl3vni
->svi_if
->hw_addr
[5]);
145 snprintf(ptr
, ETHER_ADDR_STRLEN
, "None");
151 * l3-vni is oper up when:
152 * 0. if EVPN is enabled (advertise-all-vni cfged)
153 * 1. it is associated to a vxlan-intf
154 * 2. Associated vxlan-intf is oper up
155 * 3. it is associated to an SVI
156 * 4. associated SVI is oper up
158 static inline int is_l3vni_oper_up(struct zebra_l3vni
*zl3vni
)
160 return (is_evpn_enabled() && zl3vni
&& (zl3vni
->vrf_id
!= VRF_UNKNOWN
)
161 && zl3vni
->vxlan_if
&& if_is_operative(zl3vni
->vxlan_if
)
162 && zl3vni
->svi_if
&& if_is_operative(zl3vni
->svi_if
));
165 static inline const char *zl3vni_state2str(struct zebra_l3vni
*zl3vni
)
170 if (is_l3vni_oper_up(zl3vni
))
178 static inline vrf_id_t
zl3vni_vrf_id(struct zebra_l3vni
*zl3vni
)
180 return zl3vni
->vrf_id
;
183 static inline void zl3vni_get_svi_rmac(struct zebra_l3vni
*zl3vni
,
184 struct ethaddr
*rmac
)
189 if (!is_l3vni_oper_up(zl3vni
))
192 if (zl3vni
->svi_if
&& if_is_operative(zl3vni
->svi_if
))
193 memcpy(rmac
->octet
, zl3vni
->svi_if
->hw_addr
, ETH_ALEN
);
197 /* context for neigh hash walk - update l3vni and rmac */
198 struct neigh_l3info_walk_ctx
{
200 struct zebra_evpn
*zevpn
;
201 struct zebra_l3vni
*zl3vni
;
208 struct json_object
*json
;
211 extern struct zebra_l3vni
*zl3vni_from_vrf(vrf_id_t vrf_id
);
212 extern struct interface
*zl3vni_map_to_vxlan_if(struct zebra_l3vni
*zl3vni
);
213 extern struct interface
*zl3vni_map_to_svi_if(struct zebra_l3vni
*zl3vni
);
214 extern struct interface
*zl3vni_map_to_mac_vlan_if(struct zebra_l3vni
*zl3vni
);
215 extern struct zebra_l3vni
*zl3vni_lookup(vni_t vni
);
216 extern vni_t
vni_id_from_svi(struct interface
*ifp
, struct interface
*br_if
);
218 DECLARE_HOOK(zebra_rmac_update
,
219 (struct zebra_mac
* rmac
, struct zebra_l3vni
*zl3vni
, bool delete,
221 (rmac
, zl3vni
, delete, reason
));
229 * Multicast hash table.
231 * This table contains -
232 * 1. The (S, G) entries used for encapsulating and forwarding BUM traffic.
233 * S is the local VTEP-IP and G is a BUM mcast group address.
234 * 2. The (X, G) entries used for terminating a BUM flow.
235 * Multiple L2-VNIs can share the same MDT hence the need to maintain
236 * an aggregated table that pimd can consume without much
239 struct zebra_vxlan_sg
{
240 struct zebra_vrf
*zvrf
;
243 char sg_str
[PREFIX_SG_STR_LEN
];
245 /* For SG - num of L2 VNIs using this entry for sending BUM traffic */
246 /* For XG - num of SG using this as parent */
250 extern struct zebra_evpn
*zevpn_lookup(vni_t vni
);
251 extern void zebra_vxlan_sync_mac_dp_install(struct zebra_mac
*mac
,
253 bool force_clear_static
,
255 extern bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf
*zvrf
);
256 extern void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip
,
257 struct in_addr mcast_grp
);
258 extern void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip
,
259 struct in_addr mcast_grp
);
260 extern void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni
*zl3vni
);
261 extern void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni
*zl3vni
);
262 extern int zebra_evpn_vxlan_del(struct zebra_evpn
*zevpn
);
264 #endif /* _ZEBRA_VXLAN_PRIVATE_H */