]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_evpn.h
Merge pull request #3931 from chiragshah6/evpn_dev1
[mirror_frr.git] / bgpd / bgp_evpn.h
1 /* E-VPN header for packet handling
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 */
20
21 #ifndef _QUAGGA_BGP_EVPN_H
22 #define _QUAGGA_BGP_EVPN_H
23
24 #include "vxlan.h"
25 #include "bgpd.h"
26
27 #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
28 #define EVPN_AUTORT_VXLAN 0x10000000
29
30 static inline int is_evpn_enabled(void)
31 {
32 struct bgp *bgp = NULL;
33
34 bgp = bgp_get_default();
35 return bgp ? bgp->advertise_all_vni : 0;
36 }
37
38 static inline void vni2label(vni_t vni, mpls_label_t *label)
39 {
40 uint8_t *tag = (uint8_t *)label;
41
42 tag[0] = (vni >> 16) & 0xFF;
43 tag[1] = (vni >> 8) & 0xFF;
44 tag[2] = vni & 0xFF;
45 }
46
47 static inline vni_t label2vni(mpls_label_t *label)
48 {
49 uint8_t *tag = (uint8_t *)label;
50 vni_t vni;
51
52 vni = ((uint32_t)*tag++ << 16);
53 vni |= (uint32_t)*tag++ << 8;
54 vni |= (uint32_t)(*tag & 0xFF);
55
56 return vni;
57 }
58
59 static inline int advertise_type5_routes(struct bgp *bgp_vrf,
60 afi_t afi)
61 {
62 if (!bgp_vrf->l3vni)
63 return 0;
64
65 if (afi == AFI_IP &&
66 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
67 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST))
68 return 1;
69
70 if (afi == AFI_IP6 &&
71 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
72 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))
73 return 1;
74
75 return 0;
76 }
77
78 /* Flag if the route's parent is a EVPN route. */
79 static inline int is_route_parent_evpn(struct bgp_path_info *ri)
80 {
81 struct bgp_path_info *parent_ri;
82 struct bgp_table *table;
83 struct bgp_node *rn;
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)
89 return 0;
90
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
97 /* See if of family L2VPN/EVPN */
98 rn = parent_ri->net;
99 if (!rn)
100 return 0;
101 table = bgp_node_table(rn);
102 if (table &&
103 table->afi == AFI_L2VPN &&
104 table->safi == SAFI_EVPN)
105 return 1;
106 return 0;
107 }
108
109 /* Flag if the route path's family is EVPN. */
110 static inline bool is_pi_family_evpn(struct bgp_path_info *pi)
111 {
112 return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN);
113 }
114
115 /* Flag if the route is injectable into EVPN. This would be either a
116 * non-imported route or a non-EVPN imported route.
117 */
118 static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi)
119 {
120 struct bgp_path_info *parent_pi;
121 struct bgp_table *table;
122 struct bgp_node *rn;
123
124 if (pi->sub_type != BGP_ROUTE_IMPORTED ||
125 !pi->extra ||
126 !pi->extra->parent)
127 return true;
128
129 parent_pi = (struct bgp_path_info *)pi->extra->parent;
130 rn = parent_pi->net;
131 if (!rn)
132 return true;
133 table = bgp_node_table(rn);
134 if (table &&
135 table->afi == AFI_L2VPN &&
136 table->safi == SAFI_EVPN)
137 return false;
138 return true;
139 }
140
141 extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
142 struct prefix *p,
143 struct attr *src_attr, afi_t afi,
144 safi_t safi);
145 extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p,
146 afi_t afi, safi_t safi);
147 extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
148 safi_t safi);
149 extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
150 safi_t safi);
151 extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
152 extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
153 extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
154 char *buf, int len);
155 extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len);
156 extern void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json);
157 extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p,
158 struct prefix_rd *prd, mpls_label_t *label,
159 uint32_t num_labels, struct attr *attr,
160 int addpath_encode, uint32_t addpath_tx_id);
161 extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
162 struct bgp_nlri *packet, int withdraw);
163 extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
164 struct prefix *p, struct bgp_path_info *ri);
165 extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
166 struct prefix *p, struct bgp_path_info *ri);
167 extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
168 extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
169 struct ethaddr *mac, struct ipaddr *ip,
170 int state);
171 extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
172 struct ethaddr *mac, struct ipaddr *ip,
173 uint8_t flags, uint32_t seq);
174 extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
175 struct ethaddr *rmac,
176 struct in_addr originator_ip, int filter,
177 ifindex_t svi_ifindex);
178 extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
179 extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
180 extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
181 struct in_addr originator_ip,
182 vrf_id_t tenant_vrf_id);
183 extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
184 struct ipaddr *originator_ip);
185 extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi,
186 struct ipaddr *originator_ip);
187 extern void bgp_evpn_flood_control_change(struct bgp *bgp);
188 extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
189 extern void bgp_evpn_cleanup(struct bgp *bgp);
190 extern void bgp_evpn_init(struct bgp *bgp);
191
192 #endif /* _QUAGGA_BGP_EVPN_H */