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