]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn.h
Merge pull request #7636 from AnuradhaKaruppiah/type-0-esi
[mirror_frr.git] / bgpd / bgp_evpn.h
CommitLineData
7ef5a232 1/* E-VPN header for packet handling
896014f4
DL
2 * Copyright (C) 2016 6WIND
3 *
4 * This file is part of FRRouting.
5 *
6 * FRRouting 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 * FRRouting 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 along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
7ef5a232
PG
20
21#ifndef _QUAGGA_BGP_EVPN_H
22#define _QUAGGA_BGP_EVPN_H
23
128ea8ab 24#include "vxlan.h"
94c2f693 25#include "bgpd.h"
7ef5a232 26
520d5d76 27#define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
bf1061d8 28#define EVPN_AUTORT_VXLAN 0x10000000
520d5d76 29
f920dd6d 30#define EVPN_ENABLED(bgp) (bgp)->advertise_all_vni
94c2f693
MK
31static inline int is_evpn_enabled(void)
32{
33 struct bgp *bgp = NULL;
34
e2f3a930 35 bgp = bgp_get_evpn();
f920dd6d 36 return bgp ? EVPN_ENABLED(bgp) : 0;
94c2f693
MK
37}
38
b57ba6d2
MK
39static inline void vni2label(vni_t vni, mpls_label_t *label)
40{
d7c0a89a 41 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
42
43 tag[0] = (vni >> 16) & 0xFF;
44 tag[1] = (vni >> 8) & 0xFF;
45 tag[2] = vni & 0xFF;
46}
47
48static inline vni_t label2vni(mpls_label_t *label)
49{
d7c0a89a 50 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
51 vni_t vni;
52
d7c0a89a
QY
53 vni = ((uint32_t)*tag++ << 16);
54 vni |= (uint32_t)*tag++ << 8;
55 vni |= (uint32_t)(*tag & 0xFF);
b57ba6d2
MK
56
57 return vni;
58}
59
fdf19f06
MK
60static inline int advertise_type5_routes(struct bgp *bgp_vrf,
61 afi_t afi)
62{
63 if (!bgp_vrf->l3vni)
64 return 0;
65
66 if (afi == AFI_IP &&
154faa50
MK
67 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
68 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST))
fdf19f06
MK
69 return 1;
70
71 if (afi == AFI_IP6 &&
154faa50
MK
72 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
73 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))
fdf19f06
MK
74 return 1;
75
76 return 0;
77}
78
88493076 79/* Flag if the route's parent is a EVPN route. */
6348981a
AK
80static inline struct bgp_path_info *
81get_route_parent_evpn(struct bgp_path_info *ri)
88493076 82{
4b7e6066 83 struct bgp_path_info *parent_ri;
88493076 84
85 /* If not imported (or doesn't have a parent), bail. */
86 if (ri->sub_type != BGP_ROUTE_IMPORTED ||
87 !ri->extra ||
88 !ri->extra->parent)
6348981a 89 return NULL;
88493076 90
08e68f92 91 /* Determine parent recursively */
92 for (parent_ri = ri->extra->parent;
93 parent_ri->extra && parent_ri->extra->parent;
94 parent_ri = parent_ri->extra->parent)
95 ;
96
6348981a
AK
97 return parent_ri;
98}
99
100/* Flag if the route's parent is a EVPN route. */
101static inline int is_route_parent_evpn(struct bgp_path_info *ri)
102{
103 struct bgp_path_info *parent_ri;
104 struct bgp_table *table;
105 struct bgp_dest *dest;
106
107 parent_ri = get_route_parent_evpn(ri);
108 if (!parent_ri)
109 return 0;
110
08e68f92 111 /* See if of family L2VPN/EVPN */
9bcb3eef
DS
112 dest = parent_ri->net;
113 if (!dest)
88493076 114 return 0;
9bcb3eef 115 table = bgp_dest_table(dest);
88493076 116 if (table &&
117 table->afi == AFI_L2VPN &&
118 table->safi == SAFI_EVPN)
119 return 1;
120 return 0;
121}
122
0a2f9ac1 123/* Flag if the route path's family is EVPN. */
124static inline bool is_pi_family_evpn(struct bgp_path_info *pi)
125{
126 return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN);
127}
128
f106e3a7 129/* Flag if the route is injectable into EVPN. This would be either a
130 * non-imported route or a non-EVPN imported route.
131 */
132static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi)
133{
134 struct bgp_path_info *parent_pi;
135 struct bgp_table *table;
9bcb3eef 136 struct bgp_dest *dest;
f106e3a7 137
138 if (pi->sub_type != BGP_ROUTE_IMPORTED ||
139 !pi->extra ||
140 !pi->extra->parent)
141 return true;
142
143 parent_pi = (struct bgp_path_info *)pi->extra->parent;
9bcb3eef
DS
144 dest = parent_pi->net;
145 if (!dest)
f106e3a7 146 return true;
9bcb3eef 147 table = bgp_dest_table(dest);
f106e3a7 148 if (table &&
149 table->afi == AFI_L2VPN &&
150 table->safi == SAFI_EVPN)
151 return false;
152 return true;
153}
154
5424b7ba 155extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
bd494ec5 156 const struct prefix *p,
996c9314
LB
157 struct attr *src_attr, afi_t afi,
158 safi_t safi);
bd494ec5
DS
159extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf,
160 const struct prefix *p, afi_t afi,
161 safi_t safi);
053905d2
MK
162extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
163 safi_t safi);
164extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
165 safi_t safi);
523cafc4 166extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
d62a17ae 167extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
d7c0a89a 168extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
b57ba6d2 169 char *buf, int len);
bd494ec5 170extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json);
5f040085
DS
171extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
172 const struct prefix_rd *prd,
173 mpls_label_t *label, uint32_t num_labels,
174 struct attr *attr, int addpath_encode,
175 uint32_t addpath_tx_id);
128ea8ab 176extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
177 struct bgp_nlri *packet, int withdraw);
d62a17ae 178extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
5a1ae2c2
DS
179 const struct prefix *p,
180 struct bgp_path_info *ri);
d62a17ae 181extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
5a1ae2c2
DS
182 const struct prefix *p,
183 struct bgp_path_info *ri);
db0e1937 184extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
d62a17ae 185extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
ec0ab544
AK
186 struct ethaddr *mac, struct ipaddr *ip,
187 int state);
d62a17ae 188extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
189 struct ethaddr *mac, struct ipaddr *ip,
c44ab6f1 190 uint8_t flags, uint32_t seq, esi_t *esi);
523cafc4 191extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
192 struct ethaddr *rmac,
14e814ea 193 struct ethaddr *vrr_rmac,
0483af6e 194 struct in_addr originator_ip, int filter,
14e814ea 195 ifindex_t svi_ifindex, bool is_anycast_mac);
523cafc4 196extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
d62a17ae 197extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
198extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
29c53922 199 struct in_addr originator_ip,
76d07c7a
AK
200 vrf_id_t tenant_vrf_id,
201 struct in_addr mcast_grp);
fd069644 202extern void bgp_evpn_flood_control_change(struct bgp *bgp);
d62a17ae 203extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
204extern void bgp_evpn_cleanup(struct bgp *bgp);
205extern void bgp_evpn_init(struct bgp *bgp);
5f040085 206extern int bgp_evpn_get_type5_prefixlen(const struct prefix *pfx);
5a1ae2c2 207extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx);
5394a276 208extern void update_advertise_vrf_routes(struct bgp *bgp_vrf);
14c1a7bf 209
128ea8ab 210#endif /* _QUAGGA_BGP_EVPN_H */