]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zebra_vxlan_private.h
Merge pull request #13395 from LabNConsulting/chopps/mgmtd-debug-flags
[mirror_frr.git] / zebra / zebra_vxlan_private.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Zebra VxLAN (EVPN) Data structures and definitions
4 * These are "internal" to this function.
5 * Copyright (C) 2016, 2017 Cumulus Networks, Inc.
6 */
7
8 #ifndef _ZEBRA_VXLAN_PRIVATE_H
9 #define _ZEBRA_VXLAN_PRIVATE_H
10
11 #include <zebra.h>
12
13 #include "if.h"
14 #include "linklist.h"
15 #include "zebra_vxlan.h"
16 #include "zebra_vxlan_if.h"
17 #include "zebra_evpn.h"
18 #include "zebra_evpn_mac.h"
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 #define ERR_STR_SZ 256
25
26 /* L3 VNI hash table */
27 struct zebra_l3vni {
28
29 /* VNI key */
30 vni_t vni;
31
32 /* vrf_id */
33 vrf_id_t vrf_id;
34
35 uint32_t filter;
36 #define PREFIX_ROUTES_ONLY (1 << 0) /* l3-vni used for prefix routes only */
37
38 /* Corresponding Bridge information */
39 vlanid_t vid;
40 struct interface *bridge_if;
41
42 /* Local IP */
43 struct in_addr local_vtep_ip;
44
45 /* kernel interface for l3vni */
46 struct interface *vxlan_if;
47
48 /* SVI interface corresponding to the l3vni */
49 struct interface *svi_if;
50
51 struct interface *mac_vlan_if;
52
53 /* list of L2 VNIs associated with the L3 VNI */
54 struct list *l2vnis;
55
56 /* list of remote router-macs */
57 struct hash *rmac_table;
58
59 /* list of remote vtep-ip neigh */
60 struct hash *nh_table;
61 };
62
63 #define IS_ZL3VNI_SVD_BACKED(zl3vni) \
64 (zl3vni->vxlan_if && zl3vni->vxlan_if->info && \
65 IS_ZEBRA_VXLAN_IF_SVD((struct zebra_if *)zl3vni->vxlan_if->info))
66
67 /* get the vx-intf name for l3vni */
68 static inline const char *zl3vni_vxlan_if_name(struct zebra_l3vni *zl3vni)
69 {
70 return zl3vni->vxlan_if ? zl3vni->vxlan_if->name : "None";
71 }
72
73 /* get the svi intf name for l3vni */
74 static inline const char *zl3vni_svi_if_name(struct zebra_l3vni *zl3vni)
75 {
76 return zl3vni->svi_if ? zl3vni->svi_if->name : "None";
77 }
78
79 /* get the vrf name for l3vni */
80 static inline const char *zl3vni_vrf_name(struct zebra_l3vni *zl3vni)
81 {
82 return vrf_id_to_name(zl3vni->vrf_id);
83 }
84
85 /* get the rmac string */
86 static inline const char *zl3vni_rmac2str(struct zebra_l3vni *zl3vni, char *buf,
87 int size)
88 {
89 char *ptr;
90
91 if (!buf)
92 ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char));
93 else {
94 assert(size >= ETHER_ADDR_STRLEN);
95 ptr = buf;
96 }
97
98 if (zl3vni->mac_vlan_if)
99 snprintf(ptr, (ETHER_ADDR_STRLEN),
100 "%02x:%02x:%02x:%02x:%02x:%02x",
101 (uint8_t)zl3vni->mac_vlan_if->hw_addr[0],
102 (uint8_t)zl3vni->mac_vlan_if->hw_addr[1],
103 (uint8_t)zl3vni->mac_vlan_if->hw_addr[2],
104 (uint8_t)zl3vni->mac_vlan_if->hw_addr[3],
105 (uint8_t)zl3vni->mac_vlan_if->hw_addr[4],
106 (uint8_t)zl3vni->mac_vlan_if->hw_addr[5]);
107 else if (zl3vni->svi_if)
108 snprintf(ptr, (ETHER_ADDR_STRLEN),
109 "%02x:%02x:%02x:%02x:%02x:%02x",
110 (uint8_t)zl3vni->svi_if->hw_addr[0],
111 (uint8_t)zl3vni->svi_if->hw_addr[1],
112 (uint8_t)zl3vni->svi_if->hw_addr[2],
113 (uint8_t)zl3vni->svi_if->hw_addr[3],
114 (uint8_t)zl3vni->svi_if->hw_addr[4],
115 (uint8_t)zl3vni->svi_if->hw_addr[5]);
116 else
117 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
118
119 return ptr;
120 }
121
122 /* get the sys mac string */
123 static inline const char *zl3vni_sysmac2str(struct zebra_l3vni *zl3vni,
124 char *buf, int size)
125 {
126 char *ptr;
127
128 if (!buf)
129 ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char));
130 else {
131 assert(size >= ETHER_ADDR_STRLEN);
132 ptr = buf;
133 }
134
135 if (zl3vni->svi_if)
136 snprintf(ptr, (ETHER_ADDR_STRLEN),
137 "%02x:%02x:%02x:%02x:%02x:%02x",
138 (uint8_t)zl3vni->svi_if->hw_addr[0],
139 (uint8_t)zl3vni->svi_if->hw_addr[1],
140 (uint8_t)zl3vni->svi_if->hw_addr[2],
141 (uint8_t)zl3vni->svi_if->hw_addr[3],
142 (uint8_t)zl3vni->svi_if->hw_addr[4],
143 (uint8_t)zl3vni->svi_if->hw_addr[5]);
144 else
145 snprintf(ptr, ETHER_ADDR_STRLEN, "None");
146
147 return ptr;
148 }
149
150 /*
151 * l3-vni is oper up when:
152 * 0. if EVPN is enabled (advertise-all-vni cfged)
153 * 1. it is associated to a vxlan-intf
154 * 2. Associated vxlan-intf is oper up
155 * 3. it is associated to an SVI
156 * 4. associated SVI is oper up
157 */
158 static inline int is_l3vni_oper_up(struct zebra_l3vni *zl3vni)
159 {
160 return (is_evpn_enabled() && zl3vni && (zl3vni->vrf_id != VRF_UNKNOWN)
161 && zl3vni->vxlan_if && if_is_operative(zl3vni->vxlan_if)
162 && zl3vni->svi_if && if_is_operative(zl3vni->svi_if));
163 }
164
165 static inline const char *zl3vni_state2str(struct zebra_l3vni *zl3vni)
166 {
167 if (!zl3vni)
168 return NULL;
169
170 if (is_l3vni_oper_up(zl3vni))
171 return "Up";
172 else
173 return "Down";
174
175 return NULL;
176 }
177
178 static inline vrf_id_t zl3vni_vrf_id(struct zebra_l3vni *zl3vni)
179 {
180 return zl3vni->vrf_id;
181 }
182
183 static inline void zl3vni_get_svi_rmac(struct zebra_l3vni *zl3vni,
184 struct ethaddr *rmac)
185 {
186 if (!zl3vni)
187 return;
188
189 if (!is_l3vni_oper_up(zl3vni))
190 return;
191
192 if (zl3vni->svi_if && if_is_operative(zl3vni->svi_if))
193 memcpy(rmac->octet, zl3vni->svi_if->hw_addr, ETH_ALEN);
194 }
195
196
197 /* context for neigh hash walk - update l3vni and rmac */
198 struct neigh_l3info_walk_ctx {
199
200 struct zebra_evpn *zevpn;
201 struct zebra_l3vni *zl3vni;
202 int add;
203 };
204
205 struct nh_walk_ctx {
206
207 struct vty *vty;
208 struct json_object *json;
209 };
210
211 extern struct zebra_l3vni *zl3vni_from_vrf(vrf_id_t vrf_id);
212 extern struct interface *zl3vni_map_to_vxlan_if(struct zebra_l3vni *zl3vni);
213 extern struct interface *zl3vni_map_to_svi_if(struct zebra_l3vni *zl3vni);
214 extern struct interface *zl3vni_map_to_mac_vlan_if(struct zebra_l3vni *zl3vni);
215 extern struct zebra_l3vni *zl3vni_lookup(vni_t vni);
216 extern vni_t vni_id_from_svi(struct interface *ifp, struct interface *br_if);
217
218 DECLARE_HOOK(zebra_rmac_update,
219 (struct zebra_mac * rmac, struct zebra_l3vni *zl3vni, bool delete,
220 const char *reason),
221 (rmac, zl3vni, delete, reason));
222
223
224 #ifdef __cplusplus
225 }
226 #endif
227
228 /*
229 * Multicast hash table.
230 *
231 * This table contains -
232 * 1. The (S, G) entries used for encapsulating and forwarding BUM traffic.
233 * S is the local VTEP-IP and G is a BUM mcast group address.
234 * 2. The (X, G) entries used for terminating a BUM flow.
235 * Multiple L2-VNIs can share the same MDT hence the need to maintain
236 * an aggregated table that pimd can consume without much
237 * re-interpretation.
238 */
239 struct zebra_vxlan_sg {
240 struct zebra_vrf *zvrf;
241
242 struct prefix_sg sg;
243 char sg_str[PREFIX_SG_STR_LEN];
244
245 /* For SG - num of L2 VNIs using this entry for sending BUM traffic */
246 /* For XG - num of SG using this as parent */
247 uint32_t ref_cnt;
248 };
249
250 extern struct zebra_evpn *zevpn_lookup(vni_t vni);
251 extern void zebra_vxlan_sync_mac_dp_install(struct zebra_mac *mac,
252 bool set_inactive,
253 bool force_clear_static,
254 const char *caller);
255 extern bool zebra_evpn_do_dup_addr_detect(struct zebra_vrf *zvrf);
256 extern void zebra_vxlan_sg_ref(struct in_addr local_vtep_ip,
257 struct in_addr mcast_grp);
258 extern void zebra_vxlan_sg_deref(struct in_addr local_vtep_ip,
259 struct in_addr mcast_grp);
260 extern void zebra_vxlan_process_l3vni_oper_up(struct zebra_l3vni *zl3vni);
261 extern void zebra_vxlan_process_l3vni_oper_down(struct zebra_l3vni *zl3vni);
262 extern int zebra_evpn_vxlan_del(struct zebra_evpn *zevpn);
263
264 #endif /* _ZEBRA_VXLAN_PRIVATE_H */