2 * Zebra EVPN MAC Data structures and definitions
3 * These are "internal" to this function.
4 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
5 * Copyright (C) 2020 Volta Networks.
7 * This file is part of FRR.
9 * FRR is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * FRR is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with FRR; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #ifndef _ZEBRA_EVPN_MAC_H
26 #define _ZEBRA_EVPN_MAC_H
33 struct host_rb_entry
{
34 RB_ENTRY(host_rb_entry
) hl_entry
;
39 RB_HEAD(host_rb_tree_entry
, host_rb_entry
);
40 RB_PROTOTYPE(host_rb_tree_entry
, host_rb_entry
, hl_entry
,
41 host_rb_entry_compare
);
45 * This table contains the MAC addresses pertaining to this VNI.
46 * This includes local MACs learnt on an attached VLAN that maps
47 * to this VNI as well as remote MACs learnt and installed by BGP.
48 * Local MACs will be known either on a VLAN sub-interface or
49 * on (port, VLAN); however, it is sufficient for zebra to maintain
50 * against the VNI i.e., it does not need to retain the local "port"
51 * information. The correct VNI will be obtained as zebra maintains
52 * the mapping (of VLAN to VNI).
56 struct ethaddr macaddr
;
58 /* When modifying flags please fixup zebra_evpn_zebra_mac_flag_dump */
60 #define ZEBRA_MAC_LOCAL 0x01
61 #define ZEBRA_MAC_REMOTE 0x02
62 #define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
63 #define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
64 #define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
65 #define ZEBRA_MAC_DEF_GW 0x20
66 /* remote VTEP advertised MAC as default GW */
67 #define ZEBRA_MAC_REMOTE_DEF_GW 0x40
68 #define ZEBRA_MAC_DUPLICATE 0x80
69 #define ZEBRA_MAC_FPM_SENT 0x100 /* whether or not this entry was sent. */
70 /* MAC is locally active on an ethernet segment peer */
71 #define ZEBRA_MAC_ES_PEER_ACTIVE 0x200
72 /* MAC has been proxy-advertised by peers. This means we need to
73 * keep the entry for forwarding but cannot advertise it
75 #define ZEBRA_MAC_ES_PEER_PROXY 0x400
76 /* We have not been able to independently establish that the host is
77 * local connected but one or more ES peers claims it is.
78 * We will maintain the entry for forwarding purposes and continue
79 * to advertise it as locally attached but with a "proxy" flag
81 #define ZEBRA_MAC_LOCAL_INACTIVE 0x800
82 /* The MAC entry was created because of advertise_svi_mac */
83 #define ZEBRA_MAC_SVI 0x1000
85 #define ZEBRA_MAC_ALL_LOCAL_FLAGS (ZEBRA_MAC_LOCAL | ZEBRA_MAC_LOCAL_INACTIVE)
86 #define ZEBRA_MAC_ALL_PEER_FLAGS \
87 (ZEBRA_MAC_ES_PEER_PROXY | ZEBRA_MAC_ES_PEER_ACTIVE)
89 /* back pointer to zevpn */
90 struct zebra_evpn
*zevpn
;
92 /* Local or remote info.
93 * Note: fwd_info is only relevant if mac->es is NULL.
102 struct in_addr r_vtep_ip
;
105 /* Local or remote ES */
106 struct zebra_evpn_es
*es
;
107 /* memory used to link the mac to the es */
108 struct listnode es_listnode
;
110 /* access-port/bridge member. only relevant for local macs that
111 * are associated with a zero-ESI,
112 * XXX - this belongs in fwd_info.local; however fwd_info is
113 * being cleared and memset to zero in different ways that can
116 struct interface
*ifp
;
117 /* memory used to link the mac to the ifp */
118 struct listnode ifp_listnode
;
120 /* Mobility sequence numbers associated with this entry. */
124 /* List of neigh associated with this mac */
125 struct list
*neigh_list
;
127 /* list of hosts pointing to this remote RMAC */
128 struct host_rb_tree_entry host_rb
;
130 /* List of nexthop associated with this RMAC */
131 struct list
*nh_list
;
133 /* Duplicate mac detection */
136 struct thread
*dad_mac_auto_recovery_timer
;
138 struct timeval detect_start_time
;
140 time_t dad_dup_detect_time
;
142 /* used for ageing out the PEER_ACTIVE flag */
143 struct thread
*hold_timer
;
145 /* number of neigh entries (using this mac) that have
146 * ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY
148 uint32_t sync_neigh_cnt
;
154 * Context for MAC hash walk - used by callbacks.
156 struct mac_walk_ctx
{
157 struct zebra_evpn
*zevpn
; /* EVPN hash */
158 struct zebra_vrf
*zvrf
; /* VRF - for client notification. */
159 int uninstall
; /* uninstall from kernel? */
160 int upd_client
; /* uninstall from client? */
163 #define DEL_LOCAL_MAC 0x1
164 #define DEL_REMOTE_MAC 0x2
165 #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
166 #define DEL_REMOTE_MAC_FROM_VTEP 0x4
167 #define SHOW_REMOTE_MAC_FROM_VTEP 0x8
169 struct in_addr r_vtep_ip
; /* To walk MACs from specific VTEP */
171 struct vty
*vty
; /* Used by VTY handlers */
172 uint32_t count
; /* Used by VTY handlers */
173 struct json_object
*json
; /* Used for JSON Output */
174 bool print_dup
; /* Used to print dup addr list */
177 struct rmac_walk_ctx
{
179 struct json_object
*json
;
182 /* temporary datastruct to pass info between the mac-update and
183 * neigh-update while handling mac-ip routes
185 struct sync_mac_ip_ctx
{
189 bool mac_dp_update_deferred
;
190 struct zebra_mac
*mac
;
193 /**************************** SYNC MAC handling *****************************/
194 /* if the mac has been added of a mac-route from the peer
195 * or if it is being referenced by a neigh added by the
196 * peer we cannot let it age out i.e. we set the static bit
199 static inline bool zebra_evpn_mac_is_static(struct zebra_mac
*mac
)
201 return ((mac
->flags
& ZEBRA_MAC_ALL_PEER_FLAGS
) || mac
->sync_neigh_cnt
);
204 /* mac needs to be locally active or active on an ES peer */
205 static inline bool zebra_evpn_mac_is_ready_for_bgp(uint32_t flags
)
207 return (flags
& ZEBRA_MAC_LOCAL
)
208 && (!(flags
& ZEBRA_MAC_LOCAL_INACTIVE
)
209 || (flags
& ZEBRA_MAC_ES_PEER_ACTIVE
));
212 void zebra_evpn_mac_stop_hold_timer(struct zebra_mac
*mac
);
214 static inline void zebra_evpn_mac_clear_sync_info(struct zebra_mac
*mac
)
216 UNSET_FLAG(mac
->flags
, ZEBRA_MAC_ALL_PEER_FLAGS
);
217 zebra_evpn_mac_stop_hold_timer(mac
);
220 static inline bool zebra_evpn_mac_in_use(struct zebra_mac
*mac
)
222 return !list_isempty(mac
->neigh_list
)
223 || CHECK_FLAG(mac
->flags
, ZEBRA_MAC_SVI
);
226 struct hash
*zebra_mac_db_create(const char *desc
);
227 uint32_t num_valid_macs(struct zebra_evpn
*zevi
);
228 uint32_t num_dup_detected_macs(struct zebra_evpn
*zevi
);
229 int zebra_evpn_rem_mac_uninstall(struct zebra_evpn
*zevi
, struct zebra_mac
*mac
,
231 int zebra_evpn_rem_mac_install(struct zebra_evpn
*zevi
, struct zebra_mac
*mac
,
233 void zebra_evpn_deref_ip2mac(struct zebra_evpn
*zevi
, struct zebra_mac
*mac
);
234 struct zebra_mac
*zebra_evpn_mac_lookup(struct zebra_evpn
*zevi
,
235 const struct ethaddr
*mac
);
236 struct zebra_mac
*zebra_evpn_mac_add(struct zebra_evpn
*zevi
,
237 const struct ethaddr
*macaddr
);
238 int zebra_evpn_mac_del(struct zebra_evpn
*zevi
, struct zebra_mac
*mac
);
239 int zebra_evpn_macip_send_msg_to_client(uint32_t id
,
240 const struct ethaddr
*macaddr
,
241 const struct ipaddr
*ip
, uint8_t flags
,
242 uint32_t seq
, int state
,
243 struct zebra_evpn_es
*es
, uint16_t cmd
);
244 void zebra_evpn_print_mac(struct zebra_mac
*mac
, void *ctxt
, json_object
*json
);
245 void zebra_evpn_print_mac_hash(struct hash_bucket
*bucket
, void *ctxt
);
246 void zebra_evpn_print_mac_hash_detail(struct hash_bucket
*bucket
, void *ctxt
);
247 int zebra_evpn_sync_mac_dp_install(struct zebra_mac
*mac
, bool set_inactive
,
248 bool force_clear_static
, const char *caller
);
249 void zebra_evpn_mac_send_add_del_to_client(struct zebra_mac
*mac
,
253 void zebra_evpn_mac_del_all(struct zebra_evpn
*zevi
, int uninstall
,
254 int upd_client
, uint32_t flags
);
255 int zebra_evpn_mac_send_add_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
256 uint32_t mac_flags
, uint32_t seq
,
257 struct zebra_evpn_es
*es
);
258 int zebra_evpn_mac_send_del_to_client(vni_t vni
, const struct ethaddr
*macaddr
,
259 uint32_t flags
, bool force
);
260 void zebra_evpn_send_mac_list_to_client(struct zebra_evpn
*zevi
);
261 struct zebra_mac
*zebra_evpn_proc_sync_mac_update(
262 struct zebra_evpn
*zevi
, const struct ethaddr
*macaddr
,
263 uint16_t ipa_len
, const struct ipaddr
*ipaddr
, uint8_t flags
,
264 uint32_t seq
, const esi_t
*esi
, struct sync_mac_ip_ctx
*ctx
);
265 void zebra_evpn_sync_mac_del(struct zebra_mac
*mac
);
266 void zebra_evpn_rem_mac_del(struct zebra_evpn
*zevi
, struct zebra_mac
*mac
);
267 void zebra_evpn_print_dad_mac_hash(struct hash_bucket
*bucket
, void *ctxt
);
268 void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket
*bucket
,
270 int zebra_evpn_mac_remote_macip_add(
271 struct zebra_evpn
*zevpn
, struct zebra_vrf
*zvrf
,
272 const struct ethaddr
*macaddr
, uint16_t ipa_len
,
273 const struct ipaddr
*ipaddr
, struct zebra_mac
**macp
,
274 struct in_addr vtep_ip
, uint8_t flags
, uint32_t seq
, const esi_t
*esi
);
276 int zebra_evpn_add_update_local_mac(struct zebra_vrf
*zvrf
,
277 struct zebra_evpn
*zevpn
,
278 struct interface
*ifp
,
279 const struct ethaddr
*macaddr
, vlanid_t vid
,
280 bool sticky
, bool local_inactive
,
281 bool dp_static
, struct zebra_mac
*mac
);
282 int zebra_evpn_del_local_mac(struct zebra_evpn
*zevpn
, struct zebra_mac
*mac
,
284 int zebra_evpn_mac_gw_macip_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
,
285 const struct ipaddr
*ip
,
286 struct zebra_mac
**macp
,
287 const struct ethaddr
*macaddr
, vlanid_t vlan_id
,
289 void zebra_evpn_mac_svi_add(struct interface
*ifp
, struct zebra_evpn
*zevpn
);
290 void zebra_evpn_mac_svi_del(struct interface
*ifp
, struct zebra_evpn
*zevpn
);
291 void zebra_evpn_mac_ifp_del(struct interface
*ifp
);
292 void zebra_evpn_mac_clear_fwd_info(struct zebra_mac
*zmac
);
298 #endif /*_ZEBRA_EVPN_MAC_H */