]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn.h
Merge pull request #3370 from pguibert6WIND/default_vrf_initialization
[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
94c2f693
MK
30static 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
b57ba6d2
MK
38static inline void vni2label(vni_t vni, mpls_label_t *label)
39{
d7c0a89a 40 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
41
42 tag[0] = (vni >> 16) & 0xFF;
43 tag[1] = (vni >> 8) & 0xFF;
44 tag[2] = vni & 0xFF;
45}
46
47static inline vni_t label2vni(mpls_label_t *label)
48{
d7c0a89a 49 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
50 vni_t vni;
51
d7c0a89a
QY
52 vni = ((uint32_t)*tag++ << 16);
53 vni |= (uint32_t)*tag++ << 8;
54 vni |= (uint32_t)(*tag & 0xFF);
b57ba6d2
MK
55
56 return vni;
57}
58
fdf19f06
MK
59static 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 &&
154faa50
MK
66 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
67 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST))
fdf19f06
MK
68 return 1;
69
70 if (afi == AFI_IP6 &&
154faa50
MK
71 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
72 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))
fdf19f06
MK
73 return 1;
74
75 return 0;
76}
77
88493076 78/* Flag if the route's parent is a EVPN route. */
4b7e6066 79static inline int is_route_parent_evpn(struct bgp_path_info *ri)
88493076 80{
4b7e6066 81 struct bgp_path_info *parent_ri;
88493076 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 /* See if the parent is of family L2VPN/EVPN */
4b7e6066 92 parent_ri = (struct bgp_path_info *)ri->extra->parent;
88493076 93 rn = parent_ri->net;
94 if (!rn)
95 return 0;
96 table = bgp_node_table(rn);
97 if (table &&
98 table->afi == AFI_L2VPN &&
99 table->safi == SAFI_EVPN)
100 return 1;
101 return 0;
102}
103
5424b7ba 104extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
31310b25 105 struct prefix *p,
996c9314
LB
106 struct attr *src_attr, afi_t afi,
107 safi_t safi);
108extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p,
5424b7ba 109 afi_t afi, safi_t safi);
053905d2
MK
110extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
111 safi_t safi);
112extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
113 safi_t safi);
523cafc4 114extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
d62a17ae 115extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
d7c0a89a 116extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
b57ba6d2 117 char *buf, int len);
d62a17ae 118extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len);
b682f6de 119extern void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json);
d62a17ae 120extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p,
996c9314 121 struct prefix_rd *prd, mpls_label_t *label,
d7c0a89a
QY
122 uint32_t num_labels, struct attr *attr,
123 int addpath_encode, uint32_t addpath_tx_id);
128ea8ab 124extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
125 struct bgp_nlri *packet, int withdraw);
d62a17ae 126extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
4b7e6066 127 struct prefix *p, struct bgp_path_info *ri);
d62a17ae 128extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
4b7e6066 129 struct prefix *p, struct bgp_path_info *ri);
db0e1937 130extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
d62a17ae 131extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
132 struct ethaddr *mac, struct ipaddr *ip);
133extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
134 struct ethaddr *mac, struct ipaddr *ip,
f07e1c99 135 uint8_t flags, uint32_t seq);
523cafc4 136extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
137 struct ethaddr *rmac,
996c9314 138 struct in_addr originator_ip, int filter);
523cafc4 139extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
d62a17ae 140extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
141extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
29c53922
MK
142 struct in_addr originator_ip,
143 vrf_id_t tenant_vrf_id);
50f74cf1 144extern int bgp_evpn_local_es_add(struct bgp *bgp, esi_t *esi,
145 struct ipaddr *originator_ip);
146extern int bgp_evpn_local_es_del(struct bgp *bgp, esi_t *esi,
147 struct ipaddr *originator_ip);
fd069644 148extern void bgp_evpn_flood_control_change(struct bgp *bgp);
d62a17ae 149extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
150extern void bgp_evpn_cleanup(struct bgp *bgp);
151extern void bgp_evpn_init(struct bgp *bgp);
14c1a7bf 152
128ea8ab 153#endif /* _QUAGGA_BGP_EVPN_H */