]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_evpn.h
bgpd: Refactor subgroup_announce_table() to reuse an existing helpers
[mirror_frr.git] / bgpd / bgp_evpn.h
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* E-VPN header for packet handling
3 * Copyright (C) 2016 6WIND
4 */
5
6 #ifndef _QUAGGA_BGP_EVPN_H
7 #define _QUAGGA_BGP_EVPN_H
8
9 #include "vxlan.h"
10 #include "bgpd.h"
11
12 #define EVPN_ROUTE_STRLEN 200 /* Must be >> MAC + IPv6 strings. */
13 #define EVPN_AUTORT_VXLAN 0x10000000
14
15 #define EVPN_ENABLED(bgp) (bgp)->advertise_all_vni
16 static inline int is_evpn_enabled(void)
17 {
18 struct bgp *bgp = NULL;
19
20 bgp = bgp_get_evpn();
21 return bgp ? EVPN_ENABLED(bgp) : 0;
22 }
23
24 static inline int advertise_type5_routes(struct bgp *bgp_vrf,
25 afi_t afi)
26 {
27 if (!bgp_vrf->l3vni)
28 return 0;
29
30 if ((afi == AFI_IP)
31 && ((CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
32 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST))
33 || (CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
34 BGP_L2VPN_EVPN_ADV_IPV4_UNICAST_GW_IP))))
35 return 1;
36
37 if ((afi == AFI_IP6)
38 && ((CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
39 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST))
40 || (CHECK_FLAG(bgp_vrf->af_flags[AFI_L2VPN][SAFI_EVPN],
41 BGP_L2VPN_EVPN_ADV_IPV6_UNICAST_GW_IP))))
42 return 1;
43
44 return 0;
45 }
46
47 /* Flag if the route's parent is a EVPN route. */
48 static inline struct bgp_path_info *
49 get_route_parent_evpn(struct bgp_path_info *ri)
50 {
51 struct bgp_path_info *parent_ri;
52
53 /* If not imported (or doesn't have a parent), bail. */
54 if (ri->sub_type != BGP_ROUTE_IMPORTED ||
55 !ri->extra ||
56 !ri->extra->parent)
57 return NULL;
58
59 /* Determine parent recursively */
60 for (parent_ri = ri->extra->parent;
61 parent_ri->extra && parent_ri->extra->parent;
62 parent_ri = parent_ri->extra->parent)
63 ;
64
65 return parent_ri;
66 }
67
68 /* Flag if the route's parent is a EVPN route. */
69 static inline int is_route_parent_evpn(struct bgp_path_info *ri)
70 {
71 struct bgp_path_info *parent_ri;
72 struct bgp_table *table;
73 struct bgp_dest *dest;
74
75 parent_ri = get_route_parent_evpn(ri);
76 if (!parent_ri)
77 return 0;
78
79 /* See if of family L2VPN/EVPN */
80 dest = parent_ri->net;
81 if (!dest)
82 return 0;
83 table = bgp_dest_table(dest);
84 if (table &&
85 table->afi == AFI_L2VPN &&
86 table->safi == SAFI_EVPN)
87 return 1;
88 return 0;
89 }
90
91 /* Flag if the route path's family is EVPN. */
92 static inline bool is_pi_family_evpn(struct bgp_path_info *pi)
93 {
94 return is_pi_family_matching(pi, AFI_L2VPN, SAFI_EVPN);
95 }
96
97 /* Flag if the route is injectable into EVPN. This would be either a
98 * non-imported route or a non-EVPN imported route.
99 */
100 static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi)
101 {
102 struct bgp_path_info *parent_pi;
103 struct bgp_table *table;
104 struct bgp_dest *dest;
105
106 if (pi->sub_type != BGP_ROUTE_IMPORTED ||
107 !pi->extra ||
108 !pi->extra->parent)
109 return true;
110
111 parent_pi = (struct bgp_path_info *)pi->extra->parent;
112 dest = parent_pi->net;
113 if (!dest)
114 return true;
115 table = bgp_dest_table(dest);
116 if (table &&
117 table->afi == AFI_L2VPN &&
118 table->safi == SAFI_EVPN)
119 return false;
120 return true;
121 }
122
123 static inline bool evpn_resolve_overlay_index(void)
124 {
125 struct bgp *bgp = NULL;
126
127 bgp = bgp_get_evpn();
128 return bgp ? bgp->resolve_overlay_index : false;
129 }
130
131 extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf,
132 const struct prefix *p,
133 struct attr *src_attr, afi_t afi,
134 safi_t safi);
135 extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf,
136 const struct prefix *p, afi_t afi,
137 safi_t safi);
138 extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi,
139 safi_t safi);
140 extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
141 safi_t safi);
142 extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
143 extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
144 extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
145 char *buf, int len);
146 extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json);
147 extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
148 const struct prefix_rd *prd,
149 mpls_label_t *label, uint32_t num_labels,
150 struct attr *attr, bool addpath_capable,
151 uint32_t addpath_tx_id);
152 extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
153 struct bgp_nlri *packet, bool withdraw);
154 extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi,
155 const struct prefix *p,
156 struct bgp_path_info *ri);
157 extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi,
158 const struct prefix *p,
159 struct bgp_path_info *ri);
160 extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp);
161 extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni,
162 struct ethaddr *mac, struct ipaddr *ip,
163 int state);
164 extern int bgp_evpn_local_macip_add(struct bgp *bgp, vni_t vni,
165 struct ethaddr *mac, struct ipaddr *ip,
166 uint8_t flags, uint32_t seq, esi_t *esi);
167 extern int bgp_evpn_local_l3vni_add(vni_t vni, vrf_id_t vrf_id,
168 struct ethaddr *rmac,
169 struct ethaddr *vrr_rmac,
170 struct in_addr originator_ip, int filter,
171 ifindex_t svi_ifindex, bool is_anycast_mac);
172 extern int bgp_evpn_local_l3vni_del(vni_t vni, vrf_id_t vrf_id);
173 extern int bgp_evpn_local_vni_del(struct bgp *bgp, vni_t vni);
174 extern int bgp_evpn_local_vni_add(struct bgp *bgp, vni_t vni,
175 struct in_addr originator_ip,
176 vrf_id_t tenant_vrf_id,
177 struct in_addr mcast_grp,
178 ifindex_t svi_ifindex);
179 extern void bgp_evpn_flood_control_change(struct bgp *bgp);
180 extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp);
181 extern void bgp_evpn_cleanup(struct bgp *bgp);
182 extern void bgp_evpn_init(struct bgp *bgp);
183 extern int bgp_evpn_get_type5_prefixlen(const struct prefix *pfx);
184 extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx);
185 extern void update_advertise_vrf_routes(struct bgp *bgp_vrf);
186 extern void bgp_evpn_show_remote_ip_hash(struct hash_bucket *bucket,
187 void *args);
188 extern void bgp_evpn_show_vni_svi_hash(struct hash_bucket *bucket, void *args);
189 extern bool bgp_evpn_is_gateway_ip_resolved(struct bgp_nexthop_cache *bnc);
190 extern void
191 bgp_evpn_handle_resolve_overlay_index_set(struct hash_bucket *bucket,
192 void *arg);
193 extern void
194 bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket *bucket,
195 void *arg);
196 extern mpls_label_t *bgp_evpn_path_info_labels_get_l3vni(mpls_label_t *labels,
197 uint32_t num_labels);
198 extern vni_t bgp_evpn_path_info_get_l3vni(const struct bgp_path_info *pi);
199 extern bool bgp_evpn_mpath_has_dvni(const struct bgp *bgp_vrf,
200 struct bgp_path_info *mpinfo);
201
202 #endif /* _QUAGGA_BGP_EVPN_H */