]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn_private.h
*: add indent control files
[mirror_frr.git] / bgpd / bgp_evpn_private.h
CommitLineData
a4168ebc 1/* BGP EVPN internal definitions
2 * Copyright (C) 2017 Cumulus Networks, Inc.
3 *
4 * This file is part of FRR.
5 *
6 * FRR is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * FRR is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with FRR; see the file COPYING. If not, write to the Free
18 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 * 02111-1307, USA.
20 */
21
22#ifndef _BGP_EVPN_PRIVATE_H
23#define _BGP_EVPN_PRIVATE_H
24
25#include "vxlan.h"
26#include "zebra.h"
27
28#include "bgpd/bgpd.h"
29#include "bgpd/bgp_ecommunity.h"
30
31/* EVPN prefix lengths. */
32#define EVPN_TYPE_2_ROUTE_PREFIXLEN 224
33#define EVPN_TYPE_3_ROUTE_PREFIXLEN 224
34
35/* EVPN route types. */
36typedef enum
37{
38 BGP_EVPN_AD_ROUTE = 1, /* Ethernet Auto-Discovery (A-D) route */
39 BGP_EVPN_MAC_IP_ROUTE, /* MAC/IP Advertisement route */
40 BGP_EVPN_IMET_ROUTE, /* Inclusive Multicast Ethernet Tag route */
41 BGP_EVPN_ES_ROUTE, /* Ethernet Segment route */
42 BGP_EVPN_IP_PREFIX_ROUTE, /* IP Prefix route */
43} bgp_evpn_route_type;
44
45/*
46 * Hash table of EVIs. Right now, the only type of EVI supported is with
47 * VxLAN encapsulation, hence each EVI corresponds to a L2 VNI.
48 * The VNIs are not "created" through BGP but through some other interface
49 * on the system. This table stores VNIs that BGP comes to know as present
50 * on the system (through interaction with zebra) as well as pre-configured
51 * VNIs (which need to be defined in the system to become "live").
52 */
53struct bgpevpn
54{
55 vni_t vni;
56 u_int32_t flags;
57#define VNI_FLAG_CFGD 0x1 /* VNI is user configured */
58#define VNI_FLAG_LIVE 0x2 /* VNI is "live" */
59#define VNI_FLAG_RD_CFGD 0x4 /* RD is user configured. */
60#define VNI_FLAG_IMPRT_CFGD 0x8 /* Import RT is user configured */
61#define VNI_FLAG_EXPRT_CFGD 0x10 /* Export RT is user configured */
62
63 /* Id for deriving the RD automatically for this VNI */
64 u_int16_t rd_id;
65
66 /* RD for this VNI. */
67 struct prefix_rd prd;
68
69 /* Route type 3 field */
70 struct in_addr originator_ip;
71
72 /* Import and Export RTs. */
73 struct list *import_rtl;
74 struct list *export_rtl;
75
76 /* Route table for EVPN routes for this VNI. */
77 struct bgp_table *route_table;
78
79 QOBJ_FIELDS
80};
81
82DECLARE_QOBJ_TYPE(bgpevpn)
83
84/* Mapping of Import RT to VNIs.
85 * The Import RTs of all VNIs are maintained in a hash table with each
86 * RT linking to all VNIs that will import routes matching this RT.
87 */
88struct irt_node
89{
90 /* RT */
91 struct ecommunity_val rt;
92
93 /* List of VNIs importing routes matching this RT. */
94 struct list *vnis;
95};
96
128ea8ab 97#define RT_TYPE_IMPORT 1
98#define RT_TYPE_EXPORT 2
99#define RT_TYPE_BOTH 3
100
101static inline int
102is_vni_configured (struct bgpevpn *vpn)
103{
104 return (CHECK_FLAG (vpn->flags, VNI_FLAG_CFGD));
105}
106
107static inline int
108is_vni_live (struct bgpevpn *vpn)
109{
110 return (CHECK_FLAG (vpn->flags, VNI_FLAG_LIVE));
111}
112
113static inline int
114is_rd_configured (struct bgpevpn *vpn)
115{
116 return (CHECK_FLAG (vpn->flags, VNI_FLAG_RD_CFGD));
117}
118
119static inline int
120bgp_evpn_rd_matches_existing (struct bgpevpn *vpn, struct prefix_rd *prd)
121{
122 return(memcmp (&vpn->prd.val, prd->val, ECOMMUNITY_SIZE) == 0);
123}
124
125static inline int
126is_import_rt_configured (struct bgpevpn *vpn)
127{
128 return (CHECK_FLAG (vpn->flags, VNI_FLAG_IMPRT_CFGD));
129}
130
131static inline int
132is_export_rt_configured (struct bgpevpn *vpn)
133{
134 return (CHECK_FLAG (vpn->flags, VNI_FLAG_EXPRT_CFGD));
135}
136
137static inline int
138is_vni_param_configured (struct bgpevpn *vpn)
139{
140 return (is_rd_configured (vpn) ||
141 is_import_rt_configured (vpn) ||
142 is_export_rt_configured (vpn));
143}
144
145static inline void
146vni2label (vni_t vni, mpls_label_t *label)
147{
148 u_char *tag = (u_char *) label;
149 tag[0] = (vni >> 16) & 0xFF;
150 tag[1] = (vni >> 8) & 0xFF;
151 tag[2] = vni & 0xFF;
152}
153
154static inline vni_t
155label2vni (mpls_label_t *label)
156{
157 u_char *tag = (u_char *) label;
158 vni_t vni;
159
160 vni = ((u_int32_t) *tag++ << 16);
161 vni |= (u_int32_t) *tag++ << 8;
162 vni |= (u_int32_t) (*tag & 0xFF);
163
164 return vni;
165}
166
167static inline void
168encode_mac_mobility_extcomm (int static_mac, u_int32_t seq,
169 struct ecommunity_val *eval)
170{
171 memset (eval, 0, sizeof (*eval));
172 eval->val[0] = ECOMMUNITY_ENCODE_EVPN;
173 eval->val[1] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY;
174 if (static_mac)
175 eval->val[2] = ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY_FLAG_STICKY;
176 eval->val[4] = (seq >> 24) & 0xff;
177 eval->val[5] = (seq >> 16) & 0xff;
178 eval->val[6] = (seq >> 8) & 0xff;
179 eval->val[7] = seq & 0xff;
180}
181
182static inline void
183build_evpn_type2_prefix (struct prefix_evpn *p, struct ethaddr *mac,
184 struct ipaddr *ip)
185{
186 memset (p, 0, sizeof (struct prefix_evpn));
187 p->family = AF_ETHERNET;
188 p->prefixlen = EVPN_TYPE_2_ROUTE_PREFIXLEN;
189 p->prefix.route_type = BGP_EVPN_MAC_IP_ROUTE;
190 memcpy(&p->prefix.mac.octet, mac->octet, ETHER_ADDR_LEN);
191 p->prefix.ip.ipa_type = IPADDR_NONE;
192 if (ip)
193 memcpy(&p->prefix.ip, ip, sizeof (*ip));
194}
195
196static inline void
197build_evpn_type3_prefix (struct prefix_evpn *p, struct in_addr originator_ip)
198{
199 memset (p, 0, sizeof (struct prefix_evpn));
200 p->family = AF_ETHERNET;
201 p->prefixlen = EVPN_TYPE_3_ROUTE_PREFIXLEN;
202 p->prefix.route_type = BGP_EVPN_IMET_ROUTE;
203 p->prefix.ip.ipa_type = IPADDR_V4;
204 p->prefix.ip.ipaddr_v4 = originator_ip;
205}
206
207
90e60aa7 208extern int
209bgp_evpn_handle_export_rt_change (struct bgp *bgp, struct bgpevpn *vpn);
210extern void
211bgp_evpn_handle_rd_change (struct bgp *bgp, struct bgpevpn *vpn, int withdraw);
212extern int
213bgp_evpn_install_routes (struct bgp *bgp, struct bgpevpn *vpn);
214extern int
215bgp_evpn_uninstall_routes (struct bgp *bgp, struct bgpevpn *vpn);
128ea8ab 216extern void
217bgp_evpn_map_vni_to_its_rts (struct bgp *bgp, struct bgpevpn *vpn);
218extern void
219bgp_evpn_unmap_vni_from_its_rts (struct bgp *bgp, struct bgpevpn *vpn);
220extern void
221bgp_evpn_derive_auto_rt_import (struct bgp *bgp, struct bgpevpn *vpn);
222extern void
223bgp_evpn_derive_auto_rt_export (struct bgp *bgp, struct bgpevpn *vpn);
224extern void
225bgp_evpn_derive_auto_rd (struct bgp *bgp, struct bgpevpn *vpn);
226extern struct bgpevpn *
227bgp_evpn_lookup_vni (struct bgp *bgp, vni_t vni);
228extern struct bgpevpn *
229bgp_evpn_new (struct bgp *bgp, vni_t vni, struct in_addr originator_ip);
230extern void
231bgp_evpn_free (struct bgp *bgp, struct bgpevpn *vpn);
a4168ebc 232#endif /* _BGP_EVPN_PRIVATE_H */