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