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