]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_evpn_neigh.h
Merge pull request #7807 from logbob0401/vrrpd_yang_bug_fix
[mirror_frr.git] / zebra / zebra_evpn_neigh.h
1 /*
2 * Zebra EVPN Neighbor 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_NEIGH_H
26 #define _ZEBRA_EVPN_NEIGH_H
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 typedef struct zebra_neigh_t_ zebra_neigh_t;
33
34 #define IS_ZEBRA_NEIGH_ACTIVE(n) (n->state == ZEBRA_NEIGH_ACTIVE)
35
36 #define IS_ZEBRA_NEIGH_INACTIVE(n) (n->state == ZEBRA_NEIGH_INACTIVE)
37
38 #define ZEBRA_NEIGH_SET_ACTIVE(n) n->state = ZEBRA_NEIGH_ACTIVE
39
40 #define ZEBRA_NEIGH_SET_INACTIVE(n) n->state = ZEBRA_NEIGH_INACTIVE
41
42 /*
43 * Neighbor hash table.
44 *
45 * This table contains the neighbors (IP to MAC bindings) pertaining to
46 * this VNI. This includes local neighbors learnt on the attached VLAN
47 * device that maps to this VNI as well as remote neighbors learnt and
48 * installed by BGP.
49 * Local neighbors will be known against the VLAN device (SVI); however,
50 * it is sufficient for zebra to maintain against the VNI. The correct
51 * VNI will be obtained as zebra maintains the mapping (of VLAN to VNI).
52 */
53 struct zebra_neigh_t_ {
54 /* IP address. */
55 struct ipaddr ip;
56
57 /* MAC address. */
58 struct ethaddr emac;
59
60 /* Back pointer to MAC. Only applicable to hosts in a L2-VNI. */
61 zebra_mac_t *mac;
62
63 /* Underlying interface. */
64 ifindex_t ifindex;
65
66 zebra_evpn_t *zevpn;
67
68 uint32_t flags;
69 #define ZEBRA_NEIGH_LOCAL 0x01
70 #define ZEBRA_NEIGH_REMOTE 0x02
71 #define ZEBRA_NEIGH_REMOTE_NH 0x04 /* neigh entry for remote vtep */
72 #define ZEBRA_NEIGH_DEF_GW 0x08
73 #define ZEBRA_NEIGH_ROUTER_FLAG 0x10
74 #define ZEBRA_NEIGH_DUPLICATE 0x20
75 #define ZEBRA_NEIGH_SVI_IP 0x40
76 /* rxed from an ES peer */
77 #define ZEBRA_NEIGH_ES_PEER_ACTIVE 0x80
78 /* rxed from an ES peer as a proxy advertisement */
79 #define ZEBRA_NEIGH_ES_PEER_PROXY 0x100
80 /* We have not been able to independently establish that the host
81 * is local connected
82 */
83 #define ZEBRA_NEIGH_LOCAL_INACTIVE 0x200
84 #define ZEBRA_NEIGH_ALL_LOCAL_FLAGS \
85 (ZEBRA_NEIGH_LOCAL | ZEBRA_NEIGH_LOCAL_INACTIVE)
86 #define ZEBRA_NEIGH_ALL_PEER_FLAGS \
87 (ZEBRA_NEIGH_ES_PEER_PROXY | ZEBRA_NEIGH_ES_PEER_ACTIVE)
88
89 enum zebra_neigh_state state;
90
91 /* Remote VTEP IP - applicable only for remote neighbors. */
92 struct in_addr r_vtep_ip;
93
94 /*
95 * Mobility sequence numbers associated with this entry. The rem_seq
96 * represents the sequence number from the client (BGP) for the most
97 * recent add or update of this entry while the loc_seq represents
98 * the sequence number informed (or to be informed) by zebra to BGP
99 * for this entry.
100 */
101 uint32_t rem_seq;
102 uint32_t loc_seq;
103
104 /* list of hosts pointing to this remote NH entry */
105 struct host_rb_tree_entry host_rb;
106
107 /* Duplicate ip detection */
108 uint32_t dad_count;
109
110 struct thread *dad_ip_auto_recovery_timer;
111
112 struct timeval detect_start_time;
113
114 time_t dad_dup_detect_time;
115
116 time_t uptime;
117
118 /* used for ageing out the PEER_ACTIVE flag */
119 struct thread *hold_timer;
120 };
121
122 /*
123 * Context for neighbor hash walk - used by callbacks.
124 */
125 struct neigh_walk_ctx {
126 zebra_evpn_t *zevpn; /* VNI hash */
127 struct zebra_vrf *zvrf; /* VRF - for client notification. */
128 int uninstall; /* uninstall from kernel? */
129 int upd_client; /* uninstall from client? */
130
131 uint32_t flags;
132 #define DEL_LOCAL_NEIGH 0x1
133 #define DEL_REMOTE_NEIGH 0x2
134 #define DEL_ALL_NEIGH (DEL_LOCAL_NEIGH | DEL_REMOTE_NEIGH)
135 #define DEL_REMOTE_NEIGH_FROM_VTEP 0x4
136 #define SHOW_REMOTE_NEIGH_FROM_VTEP 0x8
137
138 struct in_addr r_vtep_ip; /* To walk neighbors from specific VTEP */
139
140 struct vty *vty; /* Used by VTY handlers */
141 uint32_t count; /* Used by VTY handlers */
142 uint8_t addr_width; /* Used by VTY handlers */
143 struct json_object *json; /* Used for JSON Output */
144 };
145
146 /**************************** SYNC neigh handling **************************/
147 static inline bool zebra_evpn_neigh_is_static(zebra_neigh_t *neigh)
148 {
149 return !!(neigh->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS);
150 }
151
152 static inline bool zebra_evpn_neigh_is_ready_for_bgp(zebra_neigh_t *n)
153 {
154 bool mac_ready;
155 bool neigh_ready;
156
157 mac_ready = !!(n->mac->flags & ZEBRA_MAC_LOCAL);
158 neigh_ready =
159 ((n->flags & ZEBRA_NEIGH_LOCAL) && IS_ZEBRA_NEIGH_ACTIVE(n)
160 && (!(n->flags & ZEBRA_NEIGH_LOCAL_INACTIVE)
161 || (n->flags & ZEBRA_NEIGH_ES_PEER_ACTIVE)))
162 ? true
163 : false;
164
165 return mac_ready && neigh_ready;
166 }
167
168 static inline void zebra_evpn_neigh_stop_hold_timer(zebra_neigh_t *n)
169 {
170 char macbuf[ETHER_ADDR_STRLEN];
171 char ipbuf[INET6_ADDRSTRLEN];
172
173 if (!n->hold_timer)
174 return;
175
176 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
177 zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x hold stop",
178 n->zevpn->vni,
179 ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
180 prefix_mac2str(&n->emac, macbuf, sizeof(macbuf)),
181 n->flags);
182 THREAD_OFF(n->hold_timer);
183 }
184
185 void zebra_evpn_sync_neigh_static_chg(zebra_neigh_t *n, bool old_n_static,
186 bool new_n_static, bool defer_n_dp,
187 bool defer_mac_dp, const char *caller);
188
189 static inline bool zebra_evpn_neigh_clear_sync_info(zebra_neigh_t *n)
190 {
191 char macbuf[ETHER_ADDR_STRLEN];
192 char ipbuf[INET6_ADDRSTRLEN];
193 bool old_n_static = false;
194 bool new_n_static = false;
195
196 if (n->flags & ZEBRA_NEIGH_ALL_PEER_FLAGS) {
197 if (IS_ZEBRA_DEBUG_EVPN_MH_NEIGH)
198 zlog_debug("sync-neigh vni %u ip %s mac %s 0x%x clear",
199 n->zevpn->vni,
200 ipaddr2str(&n->ip, ipbuf, sizeof(ipbuf)),
201 prefix_mac2str(&n->emac, macbuf,
202 sizeof(macbuf)),
203 n->flags);
204
205 old_n_static = zebra_evpn_neigh_is_static(n);
206 UNSET_FLAG(n->flags, ZEBRA_NEIGH_ALL_PEER_FLAGS);
207 new_n_static = zebra_evpn_neigh_is_static(n);
208 if (old_n_static != new_n_static)
209 zebra_evpn_sync_neigh_static_chg(
210 n, old_n_static, new_n_static,
211 true /*defer_dp)*/, false /*defer_mac_dp*/,
212 __func__);
213 }
214 zebra_evpn_neigh_stop_hold_timer(n);
215
216 /* if the neigh static flag changed inform that a dp
217 * re-install maybe needed
218 */
219 return old_n_static != new_n_static;
220 }
221
222 int remote_neigh_count(zebra_mac_t *zmac);
223
224 int neigh_list_cmp(void *p1, void *p2);
225 struct hash *zebra_neigh_db_create(const char *desc);
226 uint32_t num_dup_detected_neighs(zebra_evpn_t *zevpn);
227 void zebra_evpn_find_neigh_addr_width(struct hash_bucket *bucket, void *ctxt);
228 int remote_neigh_count(zebra_mac_t *zmac);
229 int zebra_evpn_rem_neigh_install(zebra_evpn_t *zevpn, zebra_neigh_t *n,
230 bool was_static);
231 void zebra_evpn_install_neigh_hash(struct hash_bucket *bucket, void *ctxt);
232 int zebra_evpn_neigh_send_add_to_client(vni_t vni, struct ipaddr *ip,
233 struct ethaddr *macaddr,
234 zebra_mac_t *zmac, uint32_t neigh_flags,
235 uint32_t seq);
236 int zebra_evpn_neigh_send_del_to_client(vni_t vni, struct ipaddr *ip,
237 struct ethaddr *macaddr, uint32_t flags,
238 int state, bool force);
239 bool zebra_evpn_neigh_is_bgp_seq_ok(zebra_evpn_t *zevpn, zebra_neigh_t *n,
240 struct ethaddr *macaddr, uint32_t seq,
241 bool sync);
242 int zebra_evpn_neigh_del(zebra_evpn_t *zevpn, zebra_neigh_t *n);
243 void zebra_evpn_sync_neigh_del(zebra_neigh_t *n);
244 zebra_neigh_t *
245 zebra_evpn_proc_sync_neigh_update(zebra_evpn_t *zevpn, zebra_neigh_t *n,
246 uint16_t ipa_len, struct ipaddr *ipaddr,
247 uint8_t flags, uint32_t seq, esi_t *esi,
248 struct sync_mac_ip_ctx *ctx);
249 void zebra_evpn_neigh_del_all(zebra_evpn_t *zevpn, int uninstall,
250 int upd_client, uint32_t flags);
251 zebra_neigh_t *zebra_evpn_neigh_lookup(zebra_evpn_t *zevpn, struct ipaddr *ip);
252
253 int zebra_evpn_rem_neigh_install(zebra_evpn_t *zevpn, zebra_neigh_t *n,
254 bool was_static);
255 void zebra_evpn_process_neigh_on_remote_mac_add(zebra_evpn_t *zevpn,
256 zebra_mac_t *zmac);
257 void zebra_evpn_process_neigh_on_local_mac_del(zebra_evpn_t *zevpn,
258 zebra_mac_t *zmac);
259 void zebra_evpn_process_neigh_on_local_mac_change(zebra_evpn_t *zevpn,
260 zebra_mac_t *zmac,
261 bool seq_change,
262 bool es_change);
263 void zebra_evpn_process_neigh_on_remote_mac_del(zebra_evpn_t *zevpn,
264 zebra_mac_t *zmac);
265 int zebra_evpn_local_neigh_update(zebra_evpn_t *zevpn, struct interface *ifp,
266 struct ipaddr *ip, struct ethaddr *macaddr,
267 bool is_router, bool local_inactive,
268 bool dp_static);
269 int zebra_evpn_remote_neigh_update(zebra_evpn_t *zevpn, struct interface *ifp,
270 struct ipaddr *ip, struct ethaddr *macaddr,
271 uint16_t state);
272 void zebra_evpn_send_neigh_to_client(zebra_evpn_t *zevpn);
273 void zebra_evpn_clear_dup_neigh_hash(struct hash_bucket *bucket, void *ctxt);
274 void zebra_evpn_print_neigh(zebra_neigh_t *n, void *ctxt, json_object *json);
275 void zebra_evpn_print_neigh_hash(struct hash_bucket *bucket, void *ctxt);
276 void zebra_evpn_print_neigh_hdr(struct vty *vty, struct neigh_walk_ctx *wctx);
277 void zebra_evpn_print_neigh_hash_detail(struct hash_bucket *bucket, void *ctxt);
278 void zebra_evpn_print_dad_neigh_hash(struct hash_bucket *bucket, void *ctxt);
279 void zebra_evpn_print_dad_neigh_hash_detail(struct hash_bucket *bucket,
280 void *ctxt);
281 void process_neigh_remote_macip_add(zebra_evpn_t *zevpn, struct zebra_vrf *zvrf,
282 struct ipaddr *ipaddr, zebra_mac_t *mac,
283 struct in_addr vtep_ip, uint8_t flags,
284 uint32_t seq);
285 int zebra_evpn_neigh_gw_macip_add(struct interface *ifp, zebra_evpn_t *zevpn,
286 struct ipaddr *ip, zebra_mac_t *mac);
287 void zebra_evpn_neigh_remote_uninstall(zebra_evpn_t *zevpn,
288 struct zebra_vrf *zvrf, zebra_neigh_t *n,
289 zebra_mac_t *mac, struct ipaddr *ipaddr);
290 int zebra_evpn_neigh_del_ip(zebra_evpn_t *zevpn, struct ipaddr *ip);
291
292
293 #ifdef __cplusplus
294 }
295 #endif
296
297 #endif /*_ZEBRA_EVPN_NEIGH_H */