]> git.proxmox.com Git - mirror_frr.git/blame - zebra/zebra_evpn_mac.h
zebra: Convert to `struct zebra_vtep` as per our internal standard
[mirror_frr.git] / zebra / zebra_evpn_mac.h
CommitLineData
b2998086
PR
1/*
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.
6 *
7 * This file is part of FRR.
8 *
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
12 * later version.
13 *
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.
18 *
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
22 * 02111-1307, USA.
23 */
24
25#ifndef _ZEBRA_EVPN_MAC_H
26#define _ZEBRA_EVPN_MAC_H
27
28#ifdef __cplusplus
29extern "C" {
30#endif
31
32typedef struct zebra_mac_t_ zebra_mac_t;
33
34struct host_rb_entry {
35 RB_ENTRY(host_rb_entry) hl_entry;
36
37 struct prefix p;
38};
39
40RB_HEAD(host_rb_tree_entry, host_rb_entry);
41RB_PROTOTYPE(host_rb_tree_entry, host_rb_entry, hl_entry,
42 host_rb_entry_compare);
43/*
44 * MAC hash table.
45 *
46 * This table contains the MAC addresses pertaining to this VNI.
47 * This includes local MACs learnt on an attached VLAN that maps
48 * to this VNI as well as remote MACs learnt and installed by BGP.
49 * Local MACs will be known either on a VLAN sub-interface or
50 * on (port, VLAN); however, it is sufficient for zebra to maintain
51 * against the VNI i.e., it does not need to retain the local "port"
52 * information. The correct VNI will be obtained as zebra maintains
53 * the mapping (of VLAN to VNI).
54 */
55struct zebra_mac_t_ {
56 /* MAC address. */
57 struct ethaddr macaddr;
58
b16e8004 59 /* When modifying flags please fixup zebra_evpn_zebra_mac_flag_dump */
b2998086
PR
60 uint32_t flags;
61#define ZEBRA_MAC_LOCAL 0x01
62#define ZEBRA_MAC_REMOTE 0x02
63#define ZEBRA_MAC_AUTO 0x04 /* Auto created for neighbor. */
64#define ZEBRA_MAC_STICKY 0x08 /* Static MAC */
65#define ZEBRA_MAC_REMOTE_RMAC 0x10 /* remote router mac */
66#define ZEBRA_MAC_DEF_GW 0x20
67/* remote VTEP advertised MAC as default GW */
68#define ZEBRA_MAC_REMOTE_DEF_GW 0x40
69#define ZEBRA_MAC_DUPLICATE 0x80
70#define ZEBRA_MAC_FPM_SENT 0x100 /* whether or not this entry was sent. */
71/* MAC is locally active on an ethernet segment peer */
72#define ZEBRA_MAC_ES_PEER_ACTIVE 0x200
73/* MAC has been proxy-advertised by peers. This means we need to
74 * keep the entry for forwarding but cannot advertise it
75 */
76#define ZEBRA_MAC_ES_PEER_PROXY 0x400
77/* We have not been able to independently establish that the host is
78 * local connected but one or more ES peers claims it is.
79 * We will maintain the entry for forwarding purposes and continue
80 * to advertise it as locally attached but with a "proxy" flag
81 */
82#define ZEBRA_MAC_LOCAL_INACTIVE 0x800
243b74ed
AK
83/* The MAC entry was created because of advertise_svi_mac */
84#define ZEBRA_MAC_SVI 0x1000
b2998086
PR
85
86#define ZEBRA_MAC_ALL_LOCAL_FLAGS (ZEBRA_MAC_LOCAL | ZEBRA_MAC_LOCAL_INACTIVE)
87#define ZEBRA_MAC_ALL_PEER_FLAGS \
88 (ZEBRA_MAC_ES_PEER_PROXY | ZEBRA_MAC_ES_PEER_ACTIVE)
89
90 /* back pointer to zevpn */
f6371c34 91 struct zebra_evpn *zevpn;
b2998086 92
8b07f173
AK
93 /* Local or remote info.
94 * Note: fwd_info is only relevant if mac->es is NULL.
95 */
b2998086
PR
96 union {
97 struct {
98 ifindex_t ifindex;
47c58929 99 ns_id_t ns_id;
b2998086
PR
100 vlanid_t vid;
101 } local;
102
103 struct in_addr r_vtep_ip;
104 } fwd_info;
105
106 /* Local or remote ES */
107 struct zebra_evpn_es *es;
108 /* memory used to link the mac to the es */
109 struct listnode es_listnode;
110
8b07f173
AK
111 /* access-port/bridge member. only relevant for local macs that
112 * are associated with a zero-ESI,
113 * XXX - this belongs in fwd_info.local; however fwd_info is
114 * being cleared and memset to zero in different ways that can
115 * mess up the links.
116 */
117 struct interface *ifp;
118 /* memory used to link the mac to the ifp */
119 struct listnode ifp_listnode;
120
b2998086
PR
121 /* Mobility sequence numbers associated with this entry. */
122 uint32_t rem_seq;
123 uint32_t loc_seq;
124
125 /* List of neigh associated with this mac */
126 struct list *neigh_list;
127
128 /* list of hosts pointing to this remote RMAC */
129 struct host_rb_tree_entry host_rb;
130
131 /* Duplicate mac detection */
132 uint32_t dad_count;
133
134 struct thread *dad_mac_auto_recovery_timer;
135
136 struct timeval detect_start_time;
137
138 time_t dad_dup_detect_time;
139
140 /* used for ageing out the PEER_ACTIVE flag */
141 struct thread *hold_timer;
142
143 /* number of neigh entries (using this mac) that have
144 * ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY
145 */
146 uint32_t sync_neigh_cnt;
f1dbb1c7
DS
147
148 time_t uptime;
b2998086
PR
149};
150
151/*
152 * Context for MAC hash walk - used by callbacks.
153 */
154struct mac_walk_ctx {
f6371c34 155 struct zebra_evpn *zevpn; /* EVPN hash */
b2998086
PR
156 struct zebra_vrf *zvrf; /* VRF - for client notification. */
157 int uninstall; /* uninstall from kernel? */
158 int upd_client; /* uninstall from client? */
159
160 uint32_t flags;
161#define DEL_LOCAL_MAC 0x1
162#define DEL_REMOTE_MAC 0x2
163#define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC)
164#define DEL_REMOTE_MAC_FROM_VTEP 0x4
165#define SHOW_REMOTE_MAC_FROM_VTEP 0x8
166
167 struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */
168
169 struct vty *vty; /* Used by VTY handlers */
170 uint32_t count; /* Used by VTY handlers */
171 struct json_object *json; /* Used for JSON Output */
172 bool print_dup; /* Used to print dup addr list */
173};
174
175struct rmac_walk_ctx {
176 struct vty *vty;
177 struct json_object *json;
178};
179
180/* temporary datastruct to pass info between the mac-update and
181 * neigh-update while handling mac-ip routes
182 */
183struct sync_mac_ip_ctx {
184 bool ignore_macip;
185 bool mac_created;
186 bool mac_inactive;
187 bool mac_dp_update_deferred;
188 zebra_mac_t *mac;
189};
190
191/**************************** SYNC MAC handling *****************************/
192/* if the mac has been added of a mac-route from the peer
193 * or if it is being referenced by a neigh added by the
194 * peer we cannot let it age out i.e. we set the static bit
195 * in the dataplane
196 */
b2998086
PR
197static inline bool zebra_evpn_mac_is_static(zebra_mac_t *mac)
198{
199 return ((mac->flags & ZEBRA_MAC_ALL_PEER_FLAGS) || mac->sync_neigh_cnt);
200}
201
202/* mac needs to be locally active or active on an ES peer */
203static inline bool zebra_evpn_mac_is_ready_for_bgp(uint32_t flags)
204{
205 return (flags & ZEBRA_MAC_LOCAL)
206 && (!(flags & ZEBRA_MAC_LOCAL_INACTIVE)
207 || (flags & ZEBRA_MAC_ES_PEER_ACTIVE));
208}
209
19fdd1be
PR
210void zebra_evpn_mac_stop_hold_timer(zebra_mac_t *mac);
211
b2998086
PR
212static inline void zebra_evpn_mac_clear_sync_info(zebra_mac_t *mac)
213{
214 UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_PEER_FLAGS);
215 zebra_evpn_mac_stop_hold_timer(mac);
216}
217
243b74ed
AK
218static inline bool zebra_evpn_mac_in_use(zebra_mac_t *mac)
219{
220 return !list_isempty(mac->neigh_list)
221 || CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI);
222}
223
b2998086 224struct hash *zebra_mac_db_create(const char *desc);
f6371c34
DS
225uint32_t num_valid_macs(struct zebra_evpn *zevi);
226uint32_t num_dup_detected_macs(struct zebra_evpn *zevi);
227int zebra_evpn_rem_mac_uninstall(struct zebra_evpn *zevi, zebra_mac_t *mac,
f3722826 228 bool force);
f6371c34 229int zebra_evpn_rem_mac_install(struct zebra_evpn *zevi, zebra_mac_t *mac,
b2998086 230 bool was_static);
f6371c34
DS
231void zebra_evpn_deref_ip2mac(struct zebra_evpn *zevi, zebra_mac_t *mac);
232zebra_mac_t *zebra_evpn_mac_lookup(struct zebra_evpn *zevi,
1a3bd37f 233 const struct ethaddr *mac);
f6371c34 234zebra_mac_t *zebra_evpn_mac_add(struct zebra_evpn *zevi,
1a3bd37f 235 const struct ethaddr *macaddr);
f6371c34 236int zebra_evpn_mac_del(struct zebra_evpn *zevi, zebra_mac_t *mac);
1a3bd37f
MS
237int zebra_evpn_macip_send_msg_to_client(uint32_t id,
238 const struct ethaddr *macaddr,
239 const struct ipaddr *ip, uint8_t flags,
b2998086
PR
240 uint32_t seq, int state,
241 struct zebra_evpn_es *es, uint16_t cmd);
b2998086
PR
242void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json);
243void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt);
244void zebra_evpn_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt);
15400f95
AK
245int zebra_evpn_sync_mac_dp_install(zebra_mac_t *mac, bool set_inactive,
246 bool force_clear_static, const char *caller);
d9d3455e
PR
247void zebra_evpn_mac_send_add_del_to_client(zebra_mac_t *mac, bool old_bgp_ready,
248 bool new_bgp_ready);
b2998086 249
f6371c34
DS
250void zebra_evpn_mac_del_all(struct zebra_evpn *zevi, int uninstall,
251 int upd_client, uint32_t flags);
1a3bd37f 252int zebra_evpn_mac_send_add_to_client(vni_t vni, const struct ethaddr *macaddr,
b2998086
PR
253 uint32_t mac_flags, uint32_t seq,
254 struct zebra_evpn_es *es);
1a3bd37f 255int zebra_evpn_mac_send_del_to_client(vni_t vni, const struct ethaddr *macaddr,
b2998086 256 uint32_t flags, bool force);
f6371c34 257void zebra_evpn_send_mac_list_to_client(struct zebra_evpn *zevi);
1a3bd37f 258zebra_mac_t *zebra_evpn_proc_sync_mac_update(
f6371c34
DS
259 struct zebra_evpn *zevi, const struct ethaddr *macaddr,
260 uint16_t ipa_len, const struct ipaddr *ipaddr, uint8_t flags,
261 uint32_t seq, const esi_t *esi, struct sync_mac_ip_ctx *ctx);
b2998086 262void zebra_evpn_sync_mac_del(zebra_mac_t *mac);
f6371c34 263void zebra_evpn_rem_mac_del(struct zebra_evpn *zevi, zebra_mac_t *mac);
b2998086
PR
264void zebra_evpn_print_dad_mac_hash(struct hash_bucket *bucket, void *ctxt);
265void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket *bucket,
266 void *ctxt);
f6371c34
DS
267int zebra_evpn_mac_remote_macip_add(
268 struct zebra_evpn *zevpn, struct zebra_vrf *zvrf,
269 const struct ethaddr *macaddr, uint16_t ipa_len,
270 const struct ipaddr *ipaddr, zebra_mac_t **macp, struct in_addr vtep_ip,
271 uint8_t flags, uint32_t seq, const esi_t *esi);
272
273int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf,
274 struct zebra_evpn *zevpn,
d9d3455e 275 struct interface *ifp,
1a3bd37f 276 const struct ethaddr *macaddr, vlanid_t vid,
d9d3455e 277 bool sticky, bool local_inactive,
00a7710c 278 bool dp_static, zebra_mac_t *mac);
f6371c34 279int zebra_evpn_del_local_mac(struct zebra_evpn *zevpn, zebra_mac_t *mac,
00a7710c 280 bool clear_static);
f6371c34 281int zebra_evpn_mac_gw_macip_add(struct interface *ifp, struct zebra_evpn *zevpn,
1a3bd37f
MS
282 const struct ipaddr *ip, zebra_mac_t **macp,
283 const struct ethaddr *macaddr, vlanid_t vlan_id,
e4c3ece6 284 bool def_gw);
f6371c34
DS
285void zebra_evpn_mac_svi_add(struct interface *ifp, struct zebra_evpn *zevpn);
286void zebra_evpn_mac_svi_del(struct interface *ifp, struct zebra_evpn *zevpn);
8b07f173
AK
287void zebra_evpn_mac_ifp_del(struct interface *ifp);
288void zebra_evpn_mac_clear_fwd_info(zebra_mac_t *zmac);
ad6ca5f4 289
b2998086
PR
290#ifdef __cplusplus
291}
292#endif
293
294#endif /*_ZEBRA_EVPN_MAC_H */