]>
Commit | Line | Data |
---|---|---|
d62a17ae | 1 | /* BGP attributes. |
896014f4 DL |
2 | * Copyright (C) 1996, 97, 98 Kunihiro Ishiguro |
3 | * | |
4 | * This file is part of GNU Zebra. | |
5 | * | |
6 | * GNU Zebra 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 | * GNU Zebra 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 | */ | |
718e3744 | 20 | |
00d252cb | 21 | #ifndef _QUAGGA_BGP_ATTR_H |
22 | #define _QUAGGA_BGP_ATTR_H | |
23 | ||
9bedbb1e | 24 | #include "mpls.h" |
684a7227 | 25 | #include "bgp_attr_evpn.h" |
f4bd90c5 | 26 | #include "bgpd/bgp_encap_types.h" |
684a7227 | 27 | |
718e3744 | 28 | /* Simple bit mapping. */ |
29 | #define BITMAP_NBBY 8 | |
30 | ||
d62a17ae | 31 | #define SET_BITMAP(MAP, NUM) \ |
32 | SET_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY)) | |
718e3744 | 33 | |
d62a17ae | 34 | #define CHECK_BITMAP(MAP, NUM) \ |
35 | CHECK_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY)) | |
718e3744 | 36 | |
3b424979 | 37 | #define BGP_MED_MAX UINT32_MAX |
38 | ||
718e3744 | 39 | /* BGP Attribute type range. */ |
40 | #define BGP_ATTR_TYPE_RANGE 256 | |
41 | #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY) | |
42 | ||
43 | /* BGP Attribute flags. */ | |
44 | #define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */ | |
45 | #define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */ | |
46 | #define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */ | |
47 | #define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */ | |
48 | ||
49 | /* BGP attribute header must bigger than 2. */ | |
370b64a2 | 50 | #define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */ |
03e214c8 PJ |
51 | #define BGP_ATTR_DEFAULT_WEIGHT 32768 |
52 | ||
801a9bcc DS |
53 | /* Valid lengths for mp_nexthop_len */ |
54 | #define BGP_ATTR_NHLEN_IPV4 IPV4_MAX_BYTELEN | |
945c8fe9 | 55 | #define BGP_ATTR_NHLEN_VPNV4 8+IPV4_MAX_BYTELEN |
801a9bcc DS |
56 | #define BGP_ATTR_NHLEN_IPV6_GLOBAL IPV6_MAX_BYTELEN |
57 | #define BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL (IPV6_MAX_BYTELEN * 2) | |
945c8fe9 LB |
58 | #define BGP_ATTR_NHLEN_VPNV6_GLOBAL 8+IPV6_MAX_BYTELEN |
59 | #define BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL ((8+IPV6_MAX_BYTELEN) * 2) | |
801a9bcc | 60 | |
c5a543b4 DW |
61 | /* Prefix SID types */ |
62 | #define BGP_PREFIX_SID_LABEL_INDEX 1 | |
63 | #define BGP_PREFIX_SID_IPV6 2 | |
64 | #define BGP_PREFIX_SID_ORIGINATOR_SRGB 3 | |
e496b420 | 65 | #define BGP_PREFIX_SID_VPN_SID 4 |
c6ca155d HS |
66 | #define BGP_PREFIX_SID_SRV6_L3_SERVICE 5 |
67 | #define BGP_PREFIX_SID_SRV6_L2_SERVICE 6 | |
c5a543b4 DW |
68 | |
69 | #define BGP_PREFIX_SID_LABEL_INDEX_LENGTH 7 | |
70 | #define BGP_PREFIX_SID_IPV6_LENGTH 19 | |
71 | #define BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH 6 | |
e496b420 HS |
72 | #define BGP_PREFIX_SID_VPN_SID_LENGTH 19 |
73 | #define BGP_PREFIX_SID_SRV6_L3_SERVICE_LENGTH 21 | |
f4c89855 | 74 | |
7c312383 AD |
75 | #define BGP_ATTR_NH_AFI(afi, attr) \ |
76 | ((afi != AFI_L2VPN) ? afi : \ | |
77 | ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ? AFI_IP : AFI_IP6)) | |
78 | ||
7fd077aa | 79 | /* PMSI tunnel types (RFC 6514) */ |
80 | ||
f4c89855 | 81 | struct bgp_attr_encap_subtlv { |
d62a17ae | 82 | struct bgp_attr_encap_subtlv *next; /* for chaining */ |
83 | /* Reference count of this attribute. */ | |
84 | unsigned long refcnt; | |
85 | uint16_t type; | |
86 | uint16_t length; | |
8c9cc7bb | 87 | uint8_t value[0]; /* will be extended */ |
f4c89855 LB |
88 | }; |
89 | ||
65efcfce LB |
90 | #if ENABLE_BGP_VNC |
91 | /* | |
92 | * old rfp<->rfapi representation | |
93 | */ | |
94 | struct bgp_tea_options { | |
d62a17ae | 95 | struct bgp_tea_options *next; |
96 | uint8_t options_count; | |
97 | uint16_t options_length; /* each TLV may be 256 in length */ | |
98 | uint8_t type; | |
99 | uint8_t length; | |
100 | void *value; /* pointer to data */ | |
65efcfce LB |
101 | }; |
102 | ||
103 | #endif | |
104 | ||
7fd077aa | 105 | enum pta_type { |
b7d08f5a | 106 | PMSI_TNLTYPE_NO_INFO = 0, |
7fd077aa | 107 | PMSI_TNLTYPE_RSVP_TE_P2MP, |
108 | PMSI_TNLTYPE_MLDP_P2MP, | |
109 | PMSI_TNLTYPE_PIM_SSM, | |
110 | PMSI_TNLTYPE_PIM_SM, | |
111 | PMSI_TNLTYPE_PIM_BIDIR, | |
112 | PMSI_TNLTYPE_INGR_REPL, | |
113 | PMSI_TNLTYPE_MLDP_MP2MP, | |
114 | PMSI_TNLTYPE_MAX = PMSI_TNLTYPE_MLDP_MP2MP | |
115 | }; | |
116 | ||
e496b420 HS |
117 | /* |
118 | * Prefix-SID type-4 | |
119 | * SRv6-VPN-SID-TLV | |
120 | * draft-dawra-idr-srv6-vpn-04 | |
121 | */ | |
122 | struct bgp_attr_srv6_vpn { | |
123 | unsigned long refcnt; | |
124 | uint8_t sid_flags; | |
125 | struct in6_addr sid; | |
126 | }; | |
127 | ||
128 | /* | |
129 | * Prefix-SID type-5 | |
130 | * SRv6-L3VPN-Service-TLV | |
131 | * draft-dawra-idr-srv6-vpn-05 | |
132 | */ | |
133 | struct bgp_attr_srv6_l3vpn { | |
134 | unsigned long refcnt; | |
135 | uint8_t sid_flags; | |
136 | uint16_t endpoint_behavior; | |
137 | struct in6_addr sid; | |
138 | }; | |
139 | ||
aadc0905 | 140 | /* BGP core attribute structure. */ |
d62a17ae | 141 | struct attr { |
142 | /* AS Path structure */ | |
143 | struct aspath *aspath; | |
144 | ||
145 | /* Community structure */ | |
146 | struct community *community; | |
147 | ||
148 | /* Reference count of this attribute. */ | |
149 | unsigned long refcnt; | |
150 | ||
151 | /* Flag of attribute is set or not. */ | |
152 | uint64_t flag; | |
153 | ||
154 | /* Apart from in6_addr, the remaining static attributes */ | |
155 | struct in_addr nexthop; | |
d7c0a89a QY |
156 | uint32_t med; |
157 | uint32_t local_pref; | |
d62a17ae | 158 | ifindex_t nh_ifindex; |
159 | ||
160 | /* Path origin attribute */ | |
d7c0a89a | 161 | uint8_t origin; |
d62a17ae | 162 | |
7fd077aa | 163 | /* PMSI tunnel type (RFC 6514). */ |
164 | enum pta_type pmsi_tnl_type; | |
165 | ||
d62a17ae | 166 | /* has the route-map changed any attribute? |
167 | Used on the peer outbound side. */ | |
d7c0a89a | 168 | uint32_t rmap_change_flags; |
d62a17ae | 169 | |
170 | /* Multi-Protocol Nexthop, AFI IPv6 */ | |
171 | struct in6_addr mp_nexthop_global; | |
172 | struct in6_addr mp_nexthop_local; | |
173 | ||
77e62f2b | 174 | /* ifIndex corresponding to mp_nexthop_local. */ |
175 | ifindex_t nh_lla_ifindex; | |
176 | ||
d62a17ae | 177 | /* Extended Communities attribute. */ |
178 | struct ecommunity *ecommunity; | |
179 | ||
180 | /* Large Communities attribute. */ | |
181 | struct lcommunity *lcommunity; | |
182 | ||
183 | /* Route-Reflector Cluster attribute */ | |
184 | struct cluster_list *cluster; | |
185 | ||
186 | /* Unknown transitive attribute. */ | |
187 | struct transit *transit; | |
188 | ||
189 | struct in_addr mp_nexthop_global_in; | |
190 | ||
191 | /* Aggregator Router ID attribute */ | |
192 | struct in_addr aggregator_addr; | |
193 | ||
194 | /* Route Reflector Originator attribute */ | |
195 | struct in_addr originator_id; | |
196 | ||
197 | /* Local weight, not actually an attribute */ | |
d7c0a89a | 198 | uint32_t weight; |
d62a17ae | 199 | |
200 | /* Aggregator ASN */ | |
201 | as_t aggregator_as; | |
202 | ||
203 | /* MP Nexthop length */ | |
d7c0a89a | 204 | uint8_t mp_nexthop_len; |
d62a17ae | 205 | |
206 | /* MP Nexthop preference */ | |
d7c0a89a | 207 | uint8_t mp_nexthop_prefer_global; |
d62a17ae | 208 | |
209 | /* Static MAC for EVPN */ | |
d7c0a89a | 210 | uint8_t sticky; |
d62a17ae | 211 | |
ead40654 | 212 | /* Flag for default gateway extended community in EVPN */ |
d7c0a89a | 213 | uint8_t default_gw; |
ead40654 | 214 | |
68e33151 CS |
215 | /* NA router flag (R-bit) support in EVPN */ |
216 | uint8_t router_flag; | |
217 | ||
d62a17ae | 218 | /* route tag */ |
219 | route_tag_t tag; | |
220 | ||
221 | /* Label index */ | |
d7c0a89a | 222 | uint32_t label_index; |
d62a17ae | 223 | |
224 | /* MPLS label */ | |
225 | mpls_label_t label; | |
226 | ||
e496b420 HS |
227 | /* SRv6 VPN SID */ |
228 | struct bgp_attr_srv6_vpn *srv6_vpn; | |
229 | ||
230 | /* SRv6 L3VPN SID */ | |
231 | struct bgp_attr_srv6_l3vpn *srv6_l3vpn; | |
232 | ||
d62a17ae | 233 | uint16_t encap_tunneltype; /* grr */ |
234 | struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */ | |
65efcfce LB |
235 | |
236 | #if ENABLE_BGP_VNC | |
d62a17ae | 237 | struct bgp_attr_encap_subtlv *vnc_subtlvs; /* VNC-specific */ |
65efcfce | 238 | #endif |
d62a17ae | 239 | /* EVPN */ |
ea7741a0 | 240 | struct bgp_route_evpn evpn_overlay; |
128ea8ab | 241 | |
d62a17ae | 242 | /* EVPN MAC Mobility sequence number, if any. */ |
d7c0a89a | 243 | uint32_t mm_seqnum; |
bc59a672 MK |
244 | |
245 | /* EVPN local router-mac */ | |
246 | struct ethaddr rmac; | |
7b7d48e5 DS |
247 | |
248 | /* Distance as applied by Route map */ | |
249 | uint8_t distance; | |
951745bd PG |
250 | |
251 | /* rmap set table */ | |
252 | uint32_t rmap_table_id; | |
d901dc13 | 253 | |
254 | /* Link bandwidth value, if any. */ | |
255 | uint32_t link_bw; | |
fb982c25 PJ |
256 | }; |
257 | ||
3f9c7369 | 258 | /* rmap_change_flags definition */ |
3811f1e2 | 259 | #define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0) |
3f9c7369 DS |
260 | #define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1) |
261 | #define BATTR_REFLECTED (1 << 2) | |
316e074d | 262 | #define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3) |
3811f1e2 DS |
263 | #define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4) |
264 | #define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5) | |
b2e03f7a | 265 | #define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6) |
3f9c7369 | 266 | |
718e3744 | 267 | /* Router Reflector related structure. */ |
d62a17ae | 268 | struct cluster_list { |
269 | unsigned long refcnt; | |
270 | int length; | |
271 | struct in_addr *list; | |
718e3744 | 272 | }; |
273 | ||
274 | /* Unknown transit attribute. */ | |
d62a17ae | 275 | struct transit { |
276 | unsigned long refcnt; | |
277 | int length; | |
d7c0a89a | 278 | uint8_t *val; |
718e3744 | 279 | }; |
280 | ||
96099b40 DL |
281 | /* "(void) 0" will generate a compiler error. this is a safety check to |
282 | * ensure we're not using a value that exceeds the bit size of attr->flag. */ | |
996c9314 LB |
283 | #define ATTR_FLAG_BIT(X) \ |
284 | __builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0) | |
718e3744 | 285 | |
d62a17ae | 286 | #define BGP_CLUSTER_LIST_LENGTH(attr) \ |
287 | (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \ | |
288 | ? (attr)->cluster->length \ | |
289 | : 0) | |
5e242b0d | 290 | |
b881c707 | 291 | typedef enum { |
d62a17ae | 292 | BGP_ATTR_PARSE_PROCEED = 0, |
293 | BGP_ATTR_PARSE_ERROR = -1, | |
294 | BGP_ATTR_PARSE_WITHDRAW = -2, | |
f57000c0 | 295 | |
d62a17ae | 296 | /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR |
9d303b37 | 297 | */ |
d62a17ae | 298 | BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3, |
9b9df989 | 299 | BGP_ATTR_PARSE_EOR = -4, |
b881c707 PJ |
300 | } bgp_attr_parse_ret_t; |
301 | ||
3f9c7369 DS |
302 | struct bpacket_attr_vec_arr; |
303 | ||
718e3744 | 304 | /* Prototypes. */ |
d62a17ae | 305 | extern void bgp_attr_init(void); |
306 | extern void bgp_attr_finish(void); | |
307 | extern bgp_attr_parse_ret_t bgp_attr_parse(struct peer *, struct attr *, | |
308 | bgp_size_t, struct bgp_nlri *, | |
309 | struct bgp_nlri *); | |
f46d8e1e | 310 | extern void bgp_attr_undup(struct attr *new, struct attr *old); |
d62a17ae | 311 | extern struct attr *bgp_attr_intern(struct attr *attr); |
d62a17ae | 312 | extern void bgp_attr_unintern_sub(struct attr *); |
313 | extern void bgp_attr_unintern(struct attr **); | |
314 | extern void bgp_attr_flush(struct attr *); | |
d7c0a89a | 315 | extern struct attr *bgp_attr_default_set(struct attr *attr, uint8_t); |
5f040085 DS |
316 | extern struct attr *bgp_attr_aggregate_intern( |
317 | struct bgp *bgp, uint8_t origin, struct aspath *aspath, | |
318 | struct community *community, struct ecommunity *ecommunity, | |
319 | struct lcommunity *lcommunity, struct bgp_aggregate *aggregate, | |
320 | uint8_t atomic_aggregate, const struct prefix *p); | |
d62a17ae | 321 | extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *, |
322 | struct stream *, struct attr *, | |
323 | struct bpacket_attr_vec_arr *vecarr, | |
324 | struct prefix *, afi_t, safi_t, | |
325 | struct peer *, struct prefix_rd *, | |
d7c0a89a | 326 | mpls_label_t *, uint32_t, int, uint32_t); |
bd494ec5 DS |
327 | extern void bgp_dump_routes_attr(struct stream *s, struct attr *attr, |
328 | const struct prefix *p); | |
74df8d6d | 329 | extern bool attrhash_cmp(const void *arg1, const void *arg2); |
d8b87afe | 330 | extern unsigned int attrhash_key_make(const void *); |
d62a17ae | 331 | extern void attr_show_all(struct vty *); |
332 | extern unsigned long int attr_count(void); | |
333 | extern unsigned long int attr_unknown_count(void); | |
718e3744 | 334 | |
335 | /* Cluster list prototypes. */ | |
3dc339cd | 336 | extern bool cluster_loop_check(struct cluster_list *, struct in_addr); |
d62a17ae | 337 | extern void cluster_unintern(struct cluster_list *); |
718e3744 | 338 | |
835315bf PJ |
339 | /* Below exported for unit-test purposes only */ |
340 | struct bgp_attr_parser_args { | |
d62a17ae | 341 | struct peer *peer; |
342 | bgp_size_t length; /* attribute data length; */ | |
343 | bgp_size_t total; /* total length, inc header */ | |
344 | struct attr *attr; | |
d7c0a89a QY |
345 | uint8_t type; |
346 | uint8_t flags; | |
347 | uint8_t *startp; | |
835315bf | 348 | }; |
d62a17ae | 349 | extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, |
350 | struct bgp_nlri *); | |
351 | extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, | |
352 | struct bgp_nlri *); | |
30adbd4e | 353 | extern bgp_attr_parse_ret_t |
45a06b11 | 354 | bgp_attr_prefix_sid(struct bgp_attr_parser_args *args); |
03292809 | 355 | |
f4c89855 LB |
356 | extern struct bgp_attr_encap_subtlv * |
357 | encap_tlv_dup(struct bgp_attr_encap_subtlv *orig); | |
358 | ||
d62a17ae | 359 | extern void bgp_attr_flush_encap(struct attr *attr); |
f4c89855 | 360 | |
f4bd90c5 LK |
361 | extern void bgp_attr_extcom_tunnel_type(struct attr *attr, |
362 | bgp_encap_types *tunnel_type); | |
363 | ||
8c71e481 PM |
364 | /** |
365 | * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes. | |
366 | * Typical call sequence is to call _start(), followed by multiple _prefix(), | |
367 | * one for each NLRI that needs to be encoded into the UPDATE message, and | |
368 | * finally the _end() function. | |
369 | */ | |
2b26882d | 370 | extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, |
d62a17ae | 371 | afi_t afi, safi_t safi, |
372 | struct bpacket_attr_vec_arr *vecarr, | |
8c71e481 PM |
373 | struct attr *attr); |
374 | extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, | |
5f040085 DS |
375 | const struct prefix *p, |
376 | const struct prefix_rd *prd, | |
d7c0a89a QY |
377 | mpls_label_t *label, uint32_t num_labels, |
378 | int addpath_encode, uint32_t addpath_tx_id, | |
379 | struct attr *); | |
93b73dfa | 380 | extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi, |
5f040085 | 381 | const struct prefix *p); |
8c71e481 PM |
382 | extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep); |
383 | ||
d62a17ae | 384 | extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, |
385 | safi_t safi); | |
5f040085 DS |
386 | extern void bgp_packet_mpunreach_prefix( |
387 | struct stream *s, const struct prefix *p, afi_t afi, safi_t safi, | |
388 | const struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels, | |
389 | int addpath_encode, uint32_t addpath_tx_id, struct attr *attr); | |
d62a17ae | 390 | extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt); |
8c71e481 | 391 | |
9738e9aa | 392 | extern bgp_attr_parse_ret_t bgp_attr_nexthop_valid(struct peer *peer, |
393 | struct attr *attr); | |
394 | ||
d7c0a89a QY |
395 | static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags, |
396 | uint32_t in_rmap_flags) | |
3811f1e2 | 397 | { |
d62a17ae | 398 | return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) |
399 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) | |
400 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED) | |
401 | || CHECK_FLAG(out_rmap_flags, | |
402 | BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED) | |
403 | || CHECK_FLAG(out_rmap_flags, | |
404 | BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED) | |
405 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED) | |
406 | || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) | |
407 | ? 1 | |
408 | : 0); | |
3811f1e2 DS |
409 | } |
410 | ||
d7c0a89a | 411 | static inline uint32_t mac_mobility_seqnum(struct attr *attr) |
128ea8ab | 412 | { |
d62a17ae | 413 | return (attr) ? attr->mm_seqnum : 0; |
128ea8ab | 414 | } |
00d252cb | 415 | #endif /* _QUAGGA_BGP_ATTR_H */ |