Line data Source code
1 : /*
2 : * Zebra EVPN 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_H
26 : #define _ZEBRA_EVPN_H
27 :
28 : #include <zebra.h>
29 :
30 : #include "if.h"
31 : #include "linklist.h"
32 : #include "bitfield.h"
33 :
34 : #include "zebra/zebra_l2.h"
35 : #include "zebra/interface.h"
36 :
37 : #ifdef __cplusplus
38 : extern "C" {
39 : #endif
40 :
41 : RB_HEAD(zebra_es_evi_rb_head, zebra_evpn_es_evi);
42 0 : RB_PROTOTYPE(zebra_es_evi_rb_head, zebra_evpn_es_evi, rb_node,
43 : zebra_es_evi_rb_cmp);
44 :
45 : /* Private Structure to pass callback data for hash iterator */
46 : struct zebra_evpn_show {
47 : struct vty *vty;
48 : json_object *json;
49 : struct zebra_vrf *zvrf;
50 : bool use_json;
51 : };
52 :
53 : /*
54 : * VTEP info
55 : *
56 : * Right now, this just has each remote VTEP's IP address.
57 : */
58 : struct zebra_vtep {
59 : /* Remote IP. */
60 : /* NOTE: Can only be IPv4 right now. */
61 : struct in_addr vtep_ip;
62 : /* Flood mode (one of enum vxlan_flood_control) based on the PMSI
63 : * tunnel type advertised by the remote VTEP
64 : */
65 : int flood_control;
66 :
67 : /* Links. */
68 : struct zebra_vtep *next;
69 : struct zebra_vtep *prev;
70 : };
71 :
72 : /*
73 : * VNI hash table
74 : *
75 : * Contains information pertaining to a VNI:
76 : * - the list of remote VTEPs (with this VNI)
77 : */
78 : struct zebra_evpn {
79 : /* VNI - key */
80 : vni_t vni;
81 :
82 : /* ES flags */
83 : uint32_t flags;
84 : #define ZEVPN_READY_FOR_BGP (1 << 0) /* ready to be sent to BGP */
85 :
86 : /* Flag for advertising gw macip */
87 : uint8_t advertise_gw_macip;
88 :
89 : /* Flag for advertising svi macip */
90 : uint8_t advertise_svi_macip;
91 :
92 : /* Flag for advertising gw macip */
93 : uint8_t advertise_subnet;
94 :
95 : /* Corresponding VxLAN interface. */
96 : struct interface *vxlan_if;
97 :
98 : /* Corresponding SVI interface. */
99 : struct interface *svi_if;
100 :
101 : /* List of remote VTEPs */
102 : struct zebra_vtep *vteps;
103 :
104 : /* Local IP */
105 : struct in_addr local_vtep_ip;
106 :
107 : /* PIM-SM MDT group for BUM flooding */
108 : struct in_addr mcast_grp;
109 :
110 : /* tenant VRF, if any */
111 : vrf_id_t vrf_id;
112 :
113 : /* List of local or remote MAC */
114 : struct hash *mac_table;
115 :
116 : /* List of local or remote neighbors (MAC+IP) */
117 : struct hash *neigh_table;
118 :
119 : /* RB tree of ES-EVIs */
120 : struct zebra_es_evi_rb_head es_evi_rb_tree;
121 :
122 : /* List of local ESs */
123 : struct list *local_es_evi_list;
124 : };
125 :
126 : /* for parsing evpn and vni contexts */
127 : struct zebra_from_svi_param {
128 : struct interface *br_if;
129 : struct interface *svi_if;
130 : struct zebra_if *zif;
131 : uint8_t bridge_vlan_aware;
132 : vlanid_t vid;
133 : };
134 :
135 : struct interface *zvni_map_to_svi(vlanid_t vid, struct interface *br_if);
136 :
137 0 : static inline struct interface *zevpn_map_to_svi(struct zebra_evpn *zevpn)
138 : {
139 0 : struct interface *ifp;
140 0 : struct zebra_if *zif = NULL;
141 0 : struct zebra_l2info_vxlan zl2_info;
142 :
143 0 : ifp = zevpn->vxlan_if;
144 0 : if (!ifp)
145 : return NULL;
146 0 : zif = ifp->info;
147 0 : if (!zif)
148 : return NULL;
149 :
150 : /* If down or not mapped to a bridge, we're done. */
151 0 : if (!if_is_operative(ifp) || !zif->brslave_info.br_if)
152 : return NULL;
153 0 : zl2_info = zif->l2info.vxl;
154 0 : return zvni_map_to_svi(zl2_info.access_vlan, zif->brslave_info.br_if);
155 : }
156 :
157 : int advertise_gw_macip_enabled(struct zebra_evpn *zevpn);
158 : int advertise_svi_macip_enabled(struct zebra_evpn *zevpn);
159 : void zebra_evpn_print(struct zebra_evpn *zevpn, void **ctxt);
160 : void zebra_evpn_print_hash(struct hash_bucket *bucket, void *ctxt[]);
161 : void zebra_evpn_print_hash_detail(struct hash_bucket *bucket, void *data);
162 : int zebra_evpn_add_macip_for_intf(struct interface *ifp,
163 : struct zebra_evpn *zevpn);
164 : int zebra_evpn_del_macip_for_intf(struct interface *ifp,
165 : struct zebra_evpn *zevpn);
166 : int zebra_evpn_advertise_subnet(struct zebra_evpn *zevpn, struct interface *ifp,
167 : int advertise);
168 : int zebra_evpn_gw_macip_add(struct interface *ifp, struct zebra_evpn *zevpn,
169 : struct ethaddr *macaddr, struct ipaddr *ip);
170 : int zebra_evpn_gw_macip_del(struct interface *ifp, struct zebra_evpn *zevpn,
171 : struct ipaddr *ip);
172 : void zebra_evpn_gw_macip_del_for_evpn_hash(struct hash_bucket *bucket,
173 : void *ctxt);
174 : void zebra_evpn_gw_macip_add_for_evpn_hash(struct hash_bucket *bucket,
175 : void *ctxt);
176 : void zebra_evpn_svi_macip_del_for_evpn_hash(struct hash_bucket *bucket,
177 : void *ctxt);
178 : struct zebra_evpn *zebra_evpn_map_vlan(struct interface *ifp,
179 : struct interface *br_if, vlanid_t vid);
180 : struct zebra_evpn *zebra_evpn_from_svi(struct interface *ifp,
181 : struct interface *br_if);
182 : struct interface *zebra_evpn_map_to_macvlan(struct interface *br_if,
183 : struct interface *svi_if);
184 : void zebra_evpn_install_mac_hash(struct hash_bucket *bucket, void *ctxt);
185 : void zebra_evpn_read_mac_neigh(struct zebra_evpn *zevpn, struct interface *ifp);
186 : unsigned int zebra_evpn_hash_keymake(const void *p);
187 : bool zebra_evpn_hash_cmp(const void *p1, const void *p2);
188 : int zebra_evpn_list_cmp(void *p1, void *p2);
189 : void *zebra_evpn_alloc(void *p);
190 : struct zebra_evpn *zebra_evpn_lookup(vni_t vni);
191 : struct zebra_evpn *zebra_evpn_add(vni_t vni);
192 : int zebra_evpn_del(struct zebra_evpn *zevpn);
193 : int zebra_evpn_send_add_to_client(struct zebra_evpn *zevpn);
194 : int zebra_evpn_send_del_to_client(struct zebra_evpn *zevpn);
195 : struct zebra_vtep *zebra_evpn_vtep_find(struct zebra_evpn *zevpn,
196 : struct in_addr *vtep_ip);
197 : struct zebra_vtep *zebra_evpn_vtep_add(struct zebra_evpn *zevpn,
198 : struct in_addr *vtep_ip,
199 : int flood_control);
200 : int zebra_evpn_vtep_del(struct zebra_evpn *zevpn, struct zebra_vtep *zvtep);
201 : int zebra_evpn_vtep_del_all(struct zebra_evpn *zevpn, int uninstall);
202 : int zebra_evpn_vtep_install(struct zebra_evpn *zevpn, struct zebra_vtep *zvtep);
203 : int zebra_evpn_vtep_uninstall(struct zebra_evpn *zevpn,
204 : struct in_addr *vtep_ip);
205 : void zebra_evpn_handle_flooding_remote_vteps(struct hash_bucket *bucket,
206 : void *zvrf);
207 : void zebra_evpn_cleanup_all(struct hash_bucket *bucket, void *arg);
208 : void zebra_evpn_rem_macip_add(vni_t vni, const struct ethaddr *macaddr,
209 : uint16_t ipa_len, const struct ipaddr *ipaddr,
210 : uint8_t flags, uint32_t seq,
211 : struct in_addr vtep_ip, const esi_t *esi);
212 : void zebra_evpn_rem_macip_del(vni_t vni, const struct ethaddr *macaddr,
213 : uint16_t ipa_len, const struct ipaddr *ipaddr,
214 : struct in_addr vtep_ip);
215 : void zebra_evpn_cfg_cleanup(struct hash_bucket *bucket, void *ctxt);
216 :
217 : #ifdef __cplusplus
218 : }
219 : #endif
220 :
221 : #endif /*_ZEBRA_EVPN_H */
|