]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_evpn.h
bgpd: Fix params/checks for route leaking and L3VPN
[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. */
28
94c2f693
MK
29static inline int is_evpn_enabled(void)
30{
31 struct bgp *bgp = NULL;
32
33 bgp = bgp_get_default();
34 return bgp ? bgp->advertise_all_vni : 0;
35}
36
b57ba6d2
MK
37static inline void vni2label(vni_t vni, mpls_label_t *label)
38{
d7c0a89a 39 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
40
41 tag[0] = (vni >> 16) & 0xFF;
42 tag[1] = (vni >> 8) & 0xFF;
43 tag[2] = vni & 0xFF;
44}
45
46static inline vni_t label2vni(mpls_label_t *label)
47{
d7c0a89a 48 uint8_t *tag = (uint8_t *)label;
b57ba6d2
MK
49 vni_t vni;
50
d7c0a89a
QY
51 vni = ((uint32_t)*tag++ << 16);
52 vni |= (uint32_t)*tag++ << 8;
53 vni |= (uint32_t)(*tag & 0xFF);
b57ba6d2
MK
54
55 return vni;
56}
57
fdf19f06
MK
58static inline int advertise_type5_routes(struct bgp *bgp_vrf,
59 afi_t afi)
60{
61 if (!bgp_vrf->l3vni)
62 return 0;
63
64 if (afi == AFI_IP &&
154faa50
MK
65 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
66 BGP_L2VPN_EVPN_ADVERTISE_IPV4_UNICAST))
fdf19f06
MK
67 return 1;
68
69 if (afi == AFI_IP6 &&
154faa50
MK
70 CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
71 BGP_L2VPN_EVPN_ADVERTISE_IPV6_UNICAST))
fdf19f06
MK
72 return 1;
73
74 return 0;
75}
76
88493076 77/* Flag if the route's parent is a EVPN route. */
78static inline int is_route_parent_evpn(struct bgp_info *ri)
79{
80 struct bgp_info *parent_ri;
81 struct bgp_table *table;
82 struct bgp_node *rn;
83
84 /* If not imported (or doesn't have a parent), bail. */
85 if (ri->sub_type != BGP_ROUTE_IMPORTED ||
86 !ri->extra ||
87 !ri->extra->parent)
88 return 0;
89
90 /* See if the parent is of family L2VPN/EVPN */
91 parent_ri = (struct bgp_info *)ri->extra->parent;
92 rn = parent_ri->net;
93 if (!rn)
94 return 0;
95 table = bgp_node_table(rn);
96 if (table &&
97 table->afi == AFI_L2VPN &&
98 table->safi == SAFI_EVPN)
99 return 1;
100 return 0;
101}
102
5424b7ba 103extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
31310b25 104 struct prefix *p,
996c9314
LB
105 struct attr *src_attr, afi_t afi,
106 safi_t safi);
107extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p,
5424b7ba 108 afi_t afi, safi_t safi);
053905d2
MK
109extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
110 safi_t safi);
111extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
112 safi_t safi);
523cafc4 113extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
d62a17ae 114extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
d7c0a89a 115extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
b57ba6d2 116 char *buf, int len);
d62a17ae 117extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len);
b682f6de 118extern void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json);
d62a17ae 119extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p,
996c9314 120 struct prefix_rd *prd, mpls_label_t *label,
d7c0a89a
QY
121 uint32_t num_labels, struct attr *attr,
122 int addpath_encode, uint32_t addpath_tx_id);
128ea8ab 123extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
124 struct bgp_nlri *packet, int withdraw);
d62a17ae 125extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
126 struct prefix *p, struct bgp_info *ri);
127extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
128 struct prefix *p, struct bgp_info *ri);
db0e1937 129extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
d62a17ae 130extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
131 struct ethaddr *mac, struct ipaddr *ip);
132extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
133 struct ethaddr *mac, struct ipaddr *ip,
d7c0a89a 134 uint8_t flags);
523cafc4 135extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
136 struct ethaddr *rmac,
996c9314 137 struct in_addr originator_ip, int filter);
523cafc4 138extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
d62a17ae 139extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
140extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
29c53922
MK
141 struct in_addr originator_ip,
142 vrf_id_t tenant_vrf_id);
d62a17ae 143extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
144extern void bgp_evpn_cleanup(struct bgp *bgp);
145extern void bgp_evpn_init(struct bgp *bgp);
14c1a7bf 146
128ea8ab 147#endif /* _QUAGGA_BGP_EVPN_H */