]>
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 | ||
59 | uint32_t flags; | |
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 | |
74 | */ | |
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 | |
80 | */ | |
81 | #define ZEBRA_MAC_LOCAL_INACTIVE 0x800 | |
82 | ||
83 | #define ZEBRA_MAC_ALL_LOCAL_FLAGS (ZEBRA_MAC_LOCAL | ZEBRA_MAC_LOCAL_INACTIVE) | |
84 | #define ZEBRA_MAC_ALL_PEER_FLAGS \ | |
85 | (ZEBRA_MAC_ES_PEER_PROXY | ZEBRA_MAC_ES_PEER_ACTIVE) | |
86 | ||
87 | /* back pointer to zevpn */ | |
88 | zebra_evpn_t *zevpn; | |
89 | ||
90 | /* Local or remote info. */ | |
91 | union { | |
92 | struct { | |
93 | ifindex_t ifindex; | |
47c58929 | 94 | ns_id_t ns_id; |
b2998086 PR |
95 | vlanid_t vid; |
96 | } local; | |
97 | ||
98 | struct in_addr r_vtep_ip; | |
99 | } fwd_info; | |
100 | ||
101 | /* Local or remote ES */ | |
102 | struct zebra_evpn_es *es; | |
103 | /* memory used to link the mac to the es */ | |
104 | struct listnode es_listnode; | |
105 | ||
106 | /* Mobility sequence numbers associated with this entry. */ | |
107 | uint32_t rem_seq; | |
108 | uint32_t loc_seq; | |
109 | ||
110 | /* List of neigh associated with this mac */ | |
111 | struct list *neigh_list; | |
112 | ||
113 | /* list of hosts pointing to this remote RMAC */ | |
114 | struct host_rb_tree_entry host_rb; | |
115 | ||
116 | /* Duplicate mac detection */ | |
117 | uint32_t dad_count; | |
118 | ||
119 | struct thread *dad_mac_auto_recovery_timer; | |
120 | ||
121 | struct timeval detect_start_time; | |
122 | ||
123 | time_t dad_dup_detect_time; | |
124 | ||
125 | /* used for ageing out the PEER_ACTIVE flag */ | |
126 | struct thread *hold_timer; | |
127 | ||
128 | /* number of neigh entries (using this mac) that have | |
129 | * ZEBRA_MAC_ES_PEER_ACTIVE or ZEBRA_NEIGH_ES_PEER_PROXY | |
130 | */ | |
131 | uint32_t sync_neigh_cnt; | |
132 | }; | |
133 | ||
134 | /* | |
135 | * Context for MAC hash walk - used by callbacks. | |
136 | */ | |
137 | struct mac_walk_ctx { | |
138 | zebra_evpn_t *zevpn; /* EVPN hash */ | |
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 | ||
158 | struct rmac_walk_ctx { | |
159 | struct vty *vty; | |
160 | struct json_object *json; | |
161 | }; | |
162 | ||
163 | /* temporary datastruct to pass info between the mac-update and | |
164 | * neigh-update while handling mac-ip routes | |
165 | */ | |
166 | struct sync_mac_ip_ctx { | |
167 | bool ignore_macip; | |
168 | bool mac_created; | |
169 | bool mac_inactive; | |
170 | bool mac_dp_update_deferred; | |
171 | zebra_mac_t *mac; | |
172 | }; | |
173 | ||
19fdd1be | 174 | /**************************** SYNC MAC handling *****************************/ |
b2998086 PR |
175 | /**************************** SYNC MAC handling *****************************/ |
176 | /* if the mac has been added of a mac-route from the peer | |
177 | * or if it is being referenced by a neigh added by the | |
178 | * peer we cannot let it age out i.e. we set the static bit | |
179 | * in the dataplane | |
180 | */ | |
b2998086 PR |
181 | static inline bool zebra_evpn_mac_is_static(zebra_mac_t *mac) |
182 | { | |
183 | return ((mac->flags & ZEBRA_MAC_ALL_PEER_FLAGS) || mac->sync_neigh_cnt); | |
184 | } | |
185 | ||
186 | /* mac needs to be locally active or active on an ES peer */ | |
187 | static inline bool zebra_evpn_mac_is_ready_for_bgp(uint32_t flags) | |
188 | { | |
189 | return (flags & ZEBRA_MAC_LOCAL) | |
190 | && (!(flags & ZEBRA_MAC_LOCAL_INACTIVE) | |
191 | || (flags & ZEBRA_MAC_ES_PEER_ACTIVE)); | |
192 | } | |
193 | ||
19fdd1be PR |
194 | void zebra_evpn_mac_stop_hold_timer(zebra_mac_t *mac); |
195 | ||
b2998086 PR |
196 | static inline void zebra_evpn_mac_clear_sync_info(zebra_mac_t *mac) |
197 | { | |
198 | UNSET_FLAG(mac->flags, ZEBRA_MAC_ALL_PEER_FLAGS); | |
199 | zebra_evpn_mac_stop_hold_timer(mac); | |
200 | } | |
201 | ||
202 | struct hash *zebra_mac_db_create(const char *desc); | |
203 | uint32_t num_valid_macs(zebra_evpn_t *zevi); | |
204 | uint32_t num_dup_detected_macs(zebra_evpn_t *zevi); | |
205 | int zebra_evpn_rem_mac_uninstall(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
206 | int zebra_evpn_rem_mac_install(zebra_evpn_t *zevi, zebra_mac_t *mac, | |
207 | bool was_static); | |
208 | void zebra_evpn_deref_ip2mac(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
b2998086 PR |
209 | zebra_mac_t *zebra_evpn_mac_lookup(zebra_evpn_t *zevi, struct ethaddr *mac); |
210 | zebra_mac_t *zebra_evpn_mac_add(zebra_evpn_t *zevi, struct ethaddr *macaddr); | |
211 | int zebra_evpn_mac_del(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
212 | int zebra_evpn_macip_send_msg_to_client(uint32_t id, struct ethaddr *macaddr, | |
213 | struct ipaddr *ip, uint8_t flags, | |
214 | uint32_t seq, int state, | |
215 | struct zebra_evpn_es *es, uint16_t cmd); | |
b2998086 PR |
216 | void zebra_evpn_print_mac(zebra_mac_t *mac, void *ctxt, json_object *json); |
217 | void zebra_evpn_print_mac_hash(struct hash_bucket *bucket, void *ctxt); | |
218 | void zebra_evpn_print_mac_hash_detail(struct hash_bucket *bucket, void *ctxt); | |
219 | void zebra_evpn_sync_mac_dp_install(zebra_mac_t *mac, bool set_inactive, | |
220 | bool force_clear_static, | |
221 | const char *caller); | |
d9d3455e PR |
222 | void zebra_evpn_mac_send_add_del_to_client(zebra_mac_t *mac, bool old_bgp_ready, |
223 | bool new_bgp_ready); | |
b2998086 PR |
224 | |
225 | void zebra_evpn_mac_del_all(zebra_evpn_t *zevi, int uninstall, int upd_client, | |
226 | uint32_t flags); | |
227 | int zebra_evpn_mac_send_add_to_client(vni_t vni, struct ethaddr *macaddr, | |
228 | uint32_t mac_flags, uint32_t seq, | |
229 | struct zebra_evpn_es *es); | |
230 | int zebra_evpn_mac_send_del_to_client(vni_t vni, struct ethaddr *macaddr, | |
231 | uint32_t flags, bool force); | |
232 | void zebra_evpn_send_mac_list_to_client(zebra_evpn_t *zevi); | |
233 | zebra_mac_t * | |
234 | zebra_evpn_proc_sync_mac_update(zebra_evpn_t *zevi, struct ethaddr *macaddr, | |
235 | uint16_t ipa_len, struct ipaddr *ipaddr, | |
236 | uint8_t flags, uint32_t seq, esi_t *esi, | |
237 | struct sync_mac_ip_ctx *ctx); | |
238 | void zebra_evpn_sync_mac_del(zebra_mac_t *mac); | |
239 | void zebra_evpn_rem_mac_del(zebra_evpn_t *zevi, zebra_mac_t *mac); | |
240 | void zebra_evpn_print_dad_mac_hash(struct hash_bucket *bucket, void *ctxt); | |
241 | void zebra_evpn_print_dad_mac_hash_detail(struct hash_bucket *bucket, | |
242 | void *ctxt); | |
19fdd1be PR |
243 | int process_mac_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf, |
244 | struct ethaddr *macaddr, uint16_t ipa_len, | |
245 | struct ipaddr *ipaddr, zebra_mac_t **macp, | |
246 | struct in_addr vtep_ip, uint8_t flags, | |
247 | uint32_t seq, esi_t *esi); | |
b2998086 | 248 | |
d9d3455e PR |
249 | int zebra_evpn_add_update_local_mac(struct zebra_vrf *zvrf, zebra_evpn_t *zevpn, |
250 | struct interface *ifp, | |
251 | struct ethaddr *macaddr, vlanid_t vid, | |
252 | bool sticky, bool local_inactive, | |
253 | bool dp_static); | |
ad6ca5f4 PR |
254 | int zebra_evpn_del_local_mac(zebra_evpn_t *zevpn, struct ethaddr *macaddr, |
255 | struct interface *ifp); | |
7bce3535 PR |
256 | int zebra_evpn_mac_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn, |
257 | struct ipaddr *ip, zebra_mac_t **macp, | |
258 | struct ethaddr *macaddr, vlanid_t vlan_id); | |
ad6ca5f4 | 259 | |
b2998086 PR |
260 | #ifdef __cplusplus |
261 | } | |
262 | #endif | |
263 | ||
264 | #endif /*_ZEBRA_EVPN_MAC_H */ |