]>
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 PG |
25 | #include "bgp_attr_evpn.h" |
26 | ||
718e3744 | 27 | /* Simple bit mapping. */ |
28 | #define BITMAP_NBBY 8 | |
29 | ||
d62a17ae | 30 | #define SET_BITMAP(MAP, NUM) \ |
31 | SET_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY)) | |
718e3744 | 32 | |
d62a17ae | 33 | #define CHECK_BITMAP(MAP, NUM) \ |
34 | CHECK_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY)) | |
718e3744 | 35 | |
3b424979 | 36 | #define BGP_MED_MAX UINT32_MAX |
37 | ||
718e3744 | 38 | /* BGP Attribute type range. */ |
39 | #define BGP_ATTR_TYPE_RANGE 256 | |
40 | #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY) | |
41 | ||
42 | /* BGP Attribute flags. */ | |
43 | #define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */ | |
44 | #define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */ | |
45 | #define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */ | |
46 | #define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */ | |
47 | ||
48 | /* BGP attribute header must bigger than 2. */ | |
370b64a2 | 49 | #define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */ |
03e214c8 PJ |
50 | #define BGP_ATTR_DEFAULT_WEIGHT 32768 |
51 | ||
801a9bcc DS |
52 | /* Valid lengths for mp_nexthop_len */ |
53 | #define BGP_ATTR_NHLEN_IPV4 IPV4_MAX_BYTELEN | |
945c8fe9 | 54 | #define BGP_ATTR_NHLEN_VPNV4 8+IPV4_MAX_BYTELEN |
801a9bcc DS |
55 | #define BGP_ATTR_NHLEN_IPV6_GLOBAL IPV6_MAX_BYTELEN |
56 | #define BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL (IPV6_MAX_BYTELEN * 2) | |
945c8fe9 LB |
57 | #define BGP_ATTR_NHLEN_VPNV6_GLOBAL 8+IPV6_MAX_BYTELEN |
58 | #define BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL ((8+IPV6_MAX_BYTELEN) * 2) | |
801a9bcc | 59 | |
c5a543b4 DW |
60 | /* Prefix SID types */ |
61 | #define BGP_PREFIX_SID_LABEL_INDEX 1 | |
62 | #define BGP_PREFIX_SID_IPV6 2 | |
63 | #define BGP_PREFIX_SID_ORIGINATOR_SRGB 3 | |
64 | ||
65 | #define BGP_PREFIX_SID_LABEL_INDEX_LENGTH 7 | |
66 | #define BGP_PREFIX_SID_IPV6_LENGTH 19 | |
67 | #define BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH 6 | |
f4c89855 LB |
68 | |
69 | struct bgp_attr_encap_subtlv { | |
d62a17ae | 70 | struct bgp_attr_encap_subtlv *next; /* for chaining */ |
71 | /* Reference count of this attribute. */ | |
72 | unsigned long refcnt; | |
73 | uint16_t type; | |
74 | uint16_t length; | |
8c9cc7bb | 75 | uint8_t value[0]; /* will be extended */ |
f4c89855 LB |
76 | }; |
77 | ||
65efcfce LB |
78 | #if ENABLE_BGP_VNC |
79 | /* | |
80 | * old rfp<->rfapi representation | |
81 | */ | |
82 | struct bgp_tea_options { | |
d62a17ae | 83 | struct bgp_tea_options *next; |
84 | uint8_t options_count; | |
85 | uint16_t options_length; /* each TLV may be 256 in length */ | |
86 | uint8_t type; | |
87 | uint8_t length; | |
88 | void *value; /* pointer to data */ | |
65efcfce LB |
89 | }; |
90 | ||
91 | #endif | |
92 | ||
684a7227 | 93 | /* Overlay Index Info */ |
d62a17ae | 94 | struct overlay_index { |
95 | struct eth_segment_id eth_s_id; | |
96 | union gw_addr gw_ip; | |
684a7227 PG |
97 | }; |
98 | ||
aadc0905 | 99 | /* BGP core attribute structure. */ |
d62a17ae | 100 | struct attr { |
101 | /* AS Path structure */ | |
102 | struct aspath *aspath; | |
103 | ||
104 | /* Community structure */ | |
105 | struct community *community; | |
106 | ||
107 | /* Reference count of this attribute. */ | |
108 | unsigned long refcnt; | |
109 | ||
110 | /* Flag of attribute is set or not. */ | |
111 | uint64_t flag; | |
112 | ||
113 | /* Apart from in6_addr, the remaining static attributes */ | |
114 | struct in_addr nexthop; | |
115 | u_int32_t med; | |
116 | u_int32_t local_pref; | |
117 | ifindex_t nh_ifindex; | |
118 | ||
119 | /* Path origin attribute */ | |
120 | u_char origin; | |
121 | ||
122 | /* has the route-map changed any attribute? | |
123 | Used on the peer outbound side. */ | |
124 | u_int32_t rmap_change_flags; | |
125 | ||
126 | /* Multi-Protocol Nexthop, AFI IPv6 */ | |
127 | struct in6_addr mp_nexthop_global; | |
128 | struct in6_addr mp_nexthop_local; | |
129 | ||
130 | /* Extended Communities attribute. */ | |
131 | struct ecommunity *ecommunity; | |
132 | ||
133 | /* Large Communities attribute. */ | |
134 | struct lcommunity *lcommunity; | |
135 | ||
136 | /* Route-Reflector Cluster attribute */ | |
137 | struct cluster_list *cluster; | |
138 | ||
139 | /* Unknown transitive attribute. */ | |
140 | struct transit *transit; | |
141 | ||
142 | struct in_addr mp_nexthop_global_in; | |
143 | ||
144 | /* Aggregator Router ID attribute */ | |
145 | struct in_addr aggregator_addr; | |
146 | ||
147 | /* Route Reflector Originator attribute */ | |
148 | struct in_addr originator_id; | |
149 | ||
150 | /* Local weight, not actually an attribute */ | |
151 | u_int32_t weight; | |
152 | ||
153 | /* Aggregator ASN */ | |
154 | as_t aggregator_as; | |
155 | ||
156 | /* MP Nexthop length */ | |
157 | u_char mp_nexthop_len; | |
158 | ||
159 | /* MP Nexthop preference */ | |
160 | u_char mp_nexthop_prefer_global; | |
161 | ||
162 | /* Static MAC for EVPN */ | |
163 | u_char sticky; | |
164 | ||
165 | /* route tag */ | |
166 | route_tag_t tag; | |
167 | ||
168 | /* Label index */ | |
169 | u_int32_t label_index; | |
170 | ||
171 | /* MPLS label */ | |
172 | mpls_label_t label; | |
173 | ||
174 | uint16_t encap_tunneltype; /* grr */ | |
175 | struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */ | |
65efcfce LB |
176 | |
177 | #if ENABLE_BGP_VNC | |
d62a17ae | 178 | struct bgp_attr_encap_subtlv *vnc_subtlvs; /* VNC-specific */ |
65efcfce | 179 | #endif |
d62a17ae | 180 | /* EVPN */ |
181 | struct overlay_index evpn_overlay; | |
128ea8ab | 182 | |
d62a17ae | 183 | /* EVPN MAC Mobility sequence number, if any. */ |
184 | u_int32_t mm_seqnum; | |
fb982c25 PJ |
185 | }; |
186 | ||
3f9c7369 | 187 | /* rmap_change_flags definition */ |
3811f1e2 | 188 | #define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0) |
3f9c7369 DS |
189 | #define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1) |
190 | #define BATTR_REFLECTED (1 << 2) | |
316e074d | 191 | #define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3) |
3811f1e2 DS |
192 | #define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4) |
193 | #define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5) | |
b2e03f7a | 194 | #define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6) |
3f9c7369 | 195 | |
718e3744 | 196 | /* Router Reflector related structure. */ |
d62a17ae | 197 | struct cluster_list { |
198 | unsigned long refcnt; | |
199 | int length; | |
200 | struct in_addr *list; | |
718e3744 | 201 | }; |
202 | ||
203 | /* Unknown transit attribute. */ | |
d62a17ae | 204 | struct transit { |
205 | unsigned long refcnt; | |
206 | int length; | |
207 | u_char *val; | |
718e3744 | 208 | }; |
209 | ||
02cd9458 | 210 | #define ATTR_FLAG_BIT(X) (1ULL << ((X) - 1)) |
718e3744 | 211 | |
d62a17ae | 212 | #define BGP_CLUSTER_LIST_LENGTH(attr) \ |
213 | (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \ | |
214 | ? (attr)->cluster->length \ | |
215 | : 0) | |
5e242b0d | 216 | |
b881c707 | 217 | typedef enum { |
d62a17ae | 218 | BGP_ATTR_PARSE_PROCEED = 0, |
219 | BGP_ATTR_PARSE_ERROR = -1, | |
220 | BGP_ATTR_PARSE_WITHDRAW = -2, | |
f57000c0 | 221 | |
d62a17ae | 222 | /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR |
9d303b37 | 223 | */ |
d62a17ae | 224 | BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3, |
b881c707 PJ |
225 | } bgp_attr_parse_ret_t; |
226 | ||
3f9c7369 DS |
227 | struct bpacket_attr_vec_arr; |
228 | ||
718e3744 | 229 | /* Prototypes. */ |
d62a17ae | 230 | extern void bgp_attr_init(void); |
231 | extern void bgp_attr_finish(void); | |
232 | extern bgp_attr_parse_ret_t bgp_attr_parse(struct peer *, struct attr *, | |
233 | bgp_size_t, struct bgp_nlri *, | |
234 | struct bgp_nlri *); | |
235 | extern void bgp_attr_dup(struct attr *, struct attr *); | |
236 | extern void bgp_attr_deep_dup(struct attr *, struct attr *); | |
237 | extern void bgp_attr_deep_free(struct attr *); | |
238 | extern struct attr *bgp_attr_intern(struct attr *attr); | |
239 | extern struct attr *bgp_attr_refcount(struct attr *attr); | |
240 | extern void bgp_attr_unintern_sub(struct attr *); | |
241 | extern void bgp_attr_unintern(struct attr **); | |
242 | extern void bgp_attr_flush(struct attr *); | |
243 | extern struct attr *bgp_attr_default_set(struct attr *attr, u_char); | |
244 | extern struct attr *bgp_attr_aggregate_intern(struct bgp *, u_char, | |
245 | struct aspath *, | |
246 | struct community *, int as_set, | |
247 | u_char); | |
248 | extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *, | |
249 | struct stream *, struct attr *, | |
250 | struct bpacket_attr_vec_arr *vecarr, | |
251 | struct prefix *, afi_t, safi_t, | |
252 | struct peer *, struct prefix_rd *, | |
253 | mpls_label_t *, int, u_int32_t); | |
254 | extern void bgp_dump_routes_attr(struct stream *, struct attr *, | |
255 | struct prefix *); | |
256 | extern int attrhash_cmp(const void *, const void *); | |
257 | extern unsigned int attrhash_key_make(void *); | |
258 | extern void attr_show_all(struct vty *); | |
259 | extern unsigned long int attr_count(void); | |
260 | extern unsigned long int attr_unknown_count(void); | |
718e3744 | 261 | |
262 | /* Cluster list prototypes. */ | |
d62a17ae | 263 | extern int cluster_loop_check(struct cluster_list *, struct in_addr); |
264 | extern void cluster_unintern(struct cluster_list *); | |
718e3744 | 265 | |
266 | /* Transit attribute prototypes. */ | |
d62a17ae | 267 | void transit_unintern(struct transit *); |
00d252cb | 268 | |
835315bf PJ |
269 | /* Below exported for unit-test purposes only */ |
270 | struct bgp_attr_parser_args { | |
d62a17ae | 271 | struct peer *peer; |
272 | bgp_size_t length; /* attribute data length; */ | |
273 | bgp_size_t total; /* total length, inc header */ | |
274 | struct attr *attr; | |
275 | u_int8_t type; | |
276 | u_int8_t flags; | |
277 | u_char *startp; | |
835315bf | 278 | }; |
d62a17ae | 279 | extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, |
280 | struct bgp_nlri *); | |
281 | extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, | |
282 | struct bgp_nlri *); | |
03292809 | 283 | |
f4c89855 LB |
284 | extern struct bgp_attr_encap_subtlv * |
285 | encap_tlv_dup(struct bgp_attr_encap_subtlv *orig); | |
286 | ||
d62a17ae | 287 | extern void bgp_attr_flush_encap(struct attr *attr); |
f4c89855 | 288 | |
8c71e481 PM |
289 | /** |
290 | * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes. | |
291 | * Typical call sequence is to call _start(), followed by multiple _prefix(), | |
292 | * one for each NLRI that needs to be encoded into the UPDATE message, and | |
293 | * finally the _end() function. | |
294 | */ | |
2b26882d | 295 | extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, |
d62a17ae | 296 | afi_t afi, safi_t safi, |
297 | struct bpacket_attr_vec_arr *vecarr, | |
8c71e481 PM |
298 | struct attr *attr); |
299 | extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi, | |
300 | struct prefix *p, struct prefix_rd *prd, | |
9bedbb1e | 301 | mpls_label_t *label, int addpath_encode, |
d62a17ae | 302 | u_int32_t addpath_tx_id, struct attr *); |
93b73dfa | 303 | extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi, |
d62a17ae | 304 | struct prefix *p); |
8c71e481 PM |
305 | extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep); |
306 | ||
d62a17ae | 307 | extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, |
308 | safi_t safi); | |
309 | extern void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p, | |
310 | afi_t afi, safi_t safi, | |
311 | struct prefix_rd *prd, mpls_label_t *, | |
312 | int, u_int32_t, struct attr *); | |
313 | extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt); | |
8c71e481 | 314 | |
d62a17ae | 315 | static inline int bgp_rmap_nhop_changed(u_int32_t out_rmap_flags, |
316 | u_int32_t in_rmap_flags) | |
3811f1e2 | 317 | { |
d62a17ae | 318 | return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS) |
319 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED) | |
320 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED) | |
321 | || CHECK_FLAG(out_rmap_flags, | |
322 | BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED) | |
323 | || CHECK_FLAG(out_rmap_flags, | |
324 | BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED) | |
325 | || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED) | |
326 | || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)) | |
327 | ? 1 | |
328 | : 0); | |
3811f1e2 DS |
329 | } |
330 | ||
d62a17ae | 331 | static inline u_int32_t mac_mobility_seqnum(struct attr *attr) |
128ea8ab | 332 | { |
d62a17ae | 333 | return (attr) ? attr->mm_seqnum : 0; |
128ea8ab | 334 | } |
335 | ||
00d252cb | 336 | #endif /* _QUAGGA_BGP_ATTR_H */ |