]>
Commit | Line | Data |
---|---|---|
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 | |
29 | extern "C" { | |
30 | #endif | |
31 | ||
32 | typedef struct zebra_mac_t_ zebra_mac_t; | |
33 | ||
34 | struct host_rb_entry { | |
35 | RB_ENTRY(host_rb_entry) hl_entry; | |
36 | ||
37 | struct prefix p; | |
38 | }; | |
39 | ||
40 | RB_HEAD(host_rb_tree_entry, host_rb_entry); | |
41 | RB_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 | */ | |
55 | struct 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 */ | |
91 | zebra_evpn_t *zevpn; | |
92 | ||
93 | /* Local or remote info. */ | |
94 | union { | |
95 | struct { | |
96 | ifindex_t ifindex; | |
47c58929 | 97 | ns_id_t ns_id; |
b2998086 PR |
98 | vlanid_t vid; |
99 | } local; | |
100 | ||
101 | struct in_addr r_vtep_ip; | |
102 | } fwd_info; | |
103 | ||
104 | /* Local or remote ES */ | |
105 | struct zebra_evpn_es *es; | |
106 | /* memory used to link the mac to the es */ | |
107 | struct listnode es_listnode; | |
108 | ||
109 | /* Mobility sequence numbers associated with this entry. */ | |
110 | uint32_t rem_seq; | |
111 | uint32_t loc_seq; | |
112 | ||
113 | /* List of neigh associated with this mac */ | |
114 | struct list *neigh_list; | |
115 | ||
116 | /* list of hosts pointing to this remote RMAC */ | |
117 | struct host_rb_tree_entry host_rb; | |
118 | ||
119 | /* Duplicate mac detection */ | |
120 | uint32_t dad_count; | |
121 | ||
122 | struct thread *dad_mac_auto_recovery_timer; | |
123 | ||
124 | struct timeval detect_start_time; | |
125 | ||
126 | time_t dad_dup_detect_time; | |
127 | ||
128 | /* used for ageing out the PEER_ACTIVE flag */ | |
129 | struct thread *hold_timer; | |
130 | ||
131 | /* number of neigh entries (using this mac) that have | |
132 | * ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY | |
133 | */ | |
134 | uint32_t sync_neigh_cnt; | |
f1dbb1c7 DS |
135 | |
136 | time_t uptime; | |
b2998086 PR |
137 | }; |
138 | ||
139 | /* | |
140 | * Context for MAC hash walk - used by callbacks. | |
141 | */ | |
142 | struct mac_walk_ctx { | |
143 | zebra_evpn_t *zevpn; /* EVPN hash */ | |
144 | struct zebra_vrf *zvrf; /* VRF - for client notification. */ | |
145 | int uninstall; /* uninstall from kernel? */ | |
146 | int upd_client; /* uninstall from client? */ | |
147 | ||
148 | uint32_t flags; | |
149 | #define DEL_LOCAL_MAC 0x1 | |
150 | #define DEL_REMOTE_MAC 0x2 | |
151 | #define DEL_ALL_MAC (DEL_LOCAL_MAC | DEL_REMOTE_MAC) | |
152 | #define DEL_REMOTE_MAC_FROM_VTEP 0x4 | |
153 | #define SHOW_REMOTE_MAC_FROM_VTEP 0x8 | |
154 | ||
155 | struct in_addr r_vtep_ip; /* To walk MACs from specific VTEP */ | |
156 | ||
157 | struct vty *vty; /* Used by VTY handlers */ | |
158 | uint32_t count; /* Used by VTY handlers */ | |
159 | struct json_object *json; /* Used for JSON Output */ | |
160 | bool print_dup; /* Used to print dup addr list */ | |
161 | }; | |
162 | ||
163 | struct rmac_walk_ctx { | |
164 | struct vty *vty; | |
165 | struct json_object *json; | |
166 | }; | |
167 | ||
168 | /* temporary datastruct to pass info between the mac-update and | |
169 | * neigh-update while handling mac-ip routes | |
170 | */ | |
171 | struct sync_mac_ip_ctx { | |
172 | bool ignore_macip; | |
173 | bool mac_created; | |
174 | bool mac_inactive; | |
175 | bool mac_dp_update_deferred; | |
176 | zebra_mac_t *mac; | |
177 | }; | |
178 | ||
179 | /**************************** SYNC MAC handling *****************************/ | |
180 | /* if the mac has been added of a mac-route from the peer | |
181 | * or if it is being referenced by a neigh added by the | |
182 | * peer we cannot let it age out i.e. we set the static bit | |
183 | * in the dataplane | |
184 | */ | |
b2998086 PR |
185 | static inline bool zebra_evpn_mac_is_static(zebra_mac_t *mac) |
186 | { | |
187 | return ((mac->flags & ZEBRA_MAC_ALL_PEER_FLAGS) || mac->sync_neigh_cnt); | |
188 | } | |
189 | ||
190 | /* mac needs to be locally active or active on an ES peer */ | |
191 | static inline bool zebra_evpn_mac_is_ready_for_bgp(uint32_t flags) | |
192 | { | |
193 | return (flags & ZEBRA_MAC_LOCAL) | |
194 | && (!(flags & ZEBRA_MAC_LOCAL_INACTIVE) | |
195 | || (flags & ZEBRA_MAC_ES_PEER_ACTIVE)); | |
196 | } | |
197 | ||
19fdd1be PR |
198 | void zebra_evpn_mac_stop_hold_timer(zebra_mac_t *mac); |
199 | ||
b2998086 PR |
200 | static inline void zebra_evpn_mac_clear_sync_info(zebra_mac_t *mac) |
201 | { | |
202 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_PEER_FLAGS); | |
203 | zebra_evpn_mac_stop_hold_timer(mac); | |
204 | } | |
205 | ||
243b74ed AK |
206 | static inline bool zebra_evpn_mac_in_use(zebra_mac_t *mac) |
207 | { | |
208 | return !list_isempty(mac->neigh_list) | |
209 | || CHECK_FLAG(mac->flags, ZEBRA_MAC_SVI); | |
210 | } | |
211 | ||
b2998086 PR |
212 | struct hash *zebra_mac_db_create(const char *desc); |
213 | uint32_t num_valid_macs(zebra_evpn_t *zevi); | |
214 | uint32_t num_dup_detected_macs(zebra_evpn_t *zevi); | |
f3722826 AK |
215 | int zebra_evpn_rem_mac_uninstall(zebra_evpn_t *zevi, zebra_mac_t *mac, |
216 | bool force); | |
b2998086 PR |
217 | int zebra_evpn_rem_mac_install(zebra_evpn_t *zevi, zebra_mac_t *mac, |
218 | bool was_static); | |
219 | void zebra_evpn_deref_ip2mac(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
b2998086 PR |
220 | zebra_mac_t *zebra_evpn_mac_lookup(zebra_evpn_t *zevi, struct ethaddr *mac); |
221 | zebra_mac_t *zebra_evpn_mac_add(zebra_evpn_t *zevi, struct ethaddr *macaddr); | |
222 | int zebra_evpn_mac_del(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
223 | int zebra_evpn_macip_send_msg_to_client(uint32_t id, struct ethaddr *macaddr, | |
224 | struct ipaddr *ip, uint8_t flags, | |
225 | uint32_t seq, int state, | |
226 | struct zebra_evpn_es *es, uint16_t cmd); | |
b2998086 PR |
227 | void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json); |
228 | void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt); | |
229 | void zebra_evpn_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt); | |
15400f95 AK |
230 | int zebra_evpn_sync_mac_dp_install(zebra_mac_t *mac, bool set_inactive, |
231 | bool force_clear_static, const char *caller); | |
d9d3455e PR |
232 | void zebra_evpn_mac_send_add_del_to_client(zebra_mac_t *mac, bool old_bgp_ready, |
233 | bool new_bgp_ready); | |
b2998086 PR |
234 | |
235 | void zebra_evpn_mac_del_all(zebra_evpn_t *zevi, int uninstall, int upd_client, | |
236 | uint32_t flags); | |
237 | int zebra_evpn_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, | |
238 | uint32_t mac_flags, uint32_t seq, | |
239 | struct zebra_evpn_es *es); | |
240 | int zebra_evpn_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, | |
241 | uint32_t flags, bool force); | |
242 | void zebra_evpn_send_mac_list_to_client(zebra_evpn_t *zevi); | |
243 | zebra_mac_t * | |
244 | zebra_evpn_proc_sync_mac_update(zebra_evpn_t *zevi, struct ethaddr *macaddr, | |
245 | uint16_t ipa_len, struct ipaddr *ipaddr, | |
246 | uint8_t flags, uint32_t seq, esi_t *esi, | |
247 | struct sync_mac_ip_ctx *ctx); | |
248 | void zebra_evpn_sync_mac_del(zebra_mac_t *mac); | |
249 | void zebra_evpn_rem_mac_del(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
250 | void zebra_evpn_print_dad_mac_hash(struct hash_bucket *bucket, void *ctxt); | |
251 | void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket *bucket, | |
252 | void *ctxt); | |
19fdd1be PR |
253 | int process_mac_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf, |
254 | struct ethaddr *macaddr, uint16_t ipa_len, | |
255 | struct ipaddr *ipaddr, zebra_mac_t **macp, | |
256 | struct in_addr vtep_ip, uint8_t flags, | |
257 | uint32_t seq, esi_t *esi); | |
b2998086 | 258 | |
d9d3455e PR |
259 | int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf, zebra_evpn_t *zevpn, |
260 | struct interface *ifp, | |
261 | struct ethaddr *macaddr, vlanid_t vid, | |
262 | bool sticky, bool local_inactive, | |
263 | bool dp_static); | |
46d6f5a2 | 264 | int zebra_evpn_del_local_mac(zebra_evpn_t *zevpn, zebra_mac_t *mac); |
7bce3535 PR |
265 | int zebra_evpn_mac_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, |
266 | struct ipaddr *ip, zebra_mac_t **macp, | |
e4c3ece6 AK |
267 | struct ethaddr *macaddr, vlanid_t vlan_id, |
268 | bool def_gw); | |
243b74ed AK |
269 | void zebra_evpn_mac_svi_add(struct interface *ifp, zebra_evpn_t *zevpn); |
270 | void zebra_evpn_mac_svi_del(struct interface *ifp, zebra_evpn_t *zevpn); | |
ad6ca5f4 | 271 | |
b2998086 PR |
272 | #ifdef __cplusplus |
273 | } | |
274 | #endif | |
275 | ||
276 | #endif /*_ZEBRA_EVPN_MAC_H */ |