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