2 Copyright (C) 1996, 97, 98 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 #ifndef _QUAGGA_BGP_ATTR_H
22 #define _QUAGGA_BGP_ATTR_H
24 #include "bgp_attr_evpn.h"
26 /* Simple bit mapping. */
29 #define SET_BITMAP(MAP, NUM) \
30 SET_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
32 #define CHECK_BITMAP(MAP, NUM) \
33 CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
35 #define BGP_MED_MAX UINT32_MAX
38 /* BGP Attribute type range. */
39 #define BGP_ATTR_TYPE_RANGE 256
40 #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
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. */
48 /* BGP attribute header must bigger than 2. */
49 #define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */
50 #define BGP_ATTR_DEFAULT_WEIGHT 32768
52 /* Valid lengths for mp_nexthop_len */
53 #define BGP_ATTR_NHLEN_IPV4 IPV4_MAX_BYTELEN
54 #define BGP_ATTR_NHLEN_VPNV4 8+IPV4_MAX_BYTELEN
55 #define BGP_ATTR_NHLEN_IPV6_GLOBAL IPV6_MAX_BYTELEN
56 #define BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL (IPV6_MAX_BYTELEN * 2)
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)
61 struct bgp_attr_encap_subtlv
{
62 struct bgp_attr_encap_subtlv
*next
; /* for chaining */
63 /* Reference count of this attribute. */
67 uint8_t value
[1]; /* will be extended */
72 * old rfp<->rfapi representation
74 struct bgp_tea_options
{
75 struct bgp_tea_options
*next
;
76 uint8_t options_count
;
77 uint16_t options_length
; /* each TLV may be 256 in length */
80 void *value
; /* pointer to data */
85 /* Overlay Index Info */
88 struct eth_segment_id eth_s_id
;
92 /* Additional/uncommon BGP attributes.
93 * lazily allocated as and when a struct attr
98 /* Multi-Protocol Nexthop, AFI IPv6 */
99 struct in6_addr mp_nexthop_global
;
100 struct in6_addr mp_nexthop_local
;
102 /* Extended Communities attribute. */
103 struct ecommunity
*ecommunity
;
105 /* Large Communities attribute. */
106 struct lcommunity
*lcommunity
;
108 /* Route-Reflector Cluster attribute */
109 struct cluster_list
*cluster
;
111 /* Unknown transitive attribute. */
112 struct transit
*transit
;
114 struct in_addr mp_nexthop_global_in
;
116 /* Aggregator Router ID attribute */
117 struct in_addr aggregator_addr
;
119 /* Route Reflector Originator attribute */
120 struct in_addr originator_id
;
122 /* Local weight, not actually an attribute */
128 /* MP Nexthop length */
129 u_char mp_nexthop_len
;
131 /* MP Nexthop preference */
132 u_char mp_nexthop_prefer_global
;
137 uint16_t encap_tunneltype
; /* grr */
138 struct bgp_attr_encap_subtlv
*encap_subtlvs
; /* rfc5512 */
141 struct bgp_attr_encap_subtlv
*vnc_subtlvs
; /* VNC-specific */
144 struct overlay_index evpn_overlay
;
147 /* BGP core attribute structure. */
150 /* AS Path structure */
151 struct aspath
*aspath
;
153 /* Community structure */
154 struct community
*community
;
156 /* Lazily allocated pointer to extra attributes */
157 struct attr_extra
*extra
;
159 /* Reference count of this attribute. */
160 unsigned long refcnt
;
162 /* Flag of attribute is set or not. */
165 /* Apart from in6_addr, the remaining static attributes */
166 struct in_addr nexthop
;
168 u_int32_t local_pref
;
169 ifindex_t nh_ifindex
;
171 /* Path origin attribute */
174 /* has the route-map changed any attribute?
175 Used on the peer outbound side. */
176 u_int32_t rmap_change_flags
;
179 /* rmap_change_flags definition */
180 #define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0)
181 #define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1)
182 #define BATTR_REFLECTED (1 << 2)
183 #define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3)
184 #define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4)
185 #define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5)
186 #define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6)
188 /* Router Reflector related structure. */
191 unsigned long refcnt
;
193 struct in_addr
*list
;
196 /* Unknown transit attribute. */
199 unsigned long refcnt
;
204 #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
206 #define BGP_CLUSTER_LIST_LENGTH(attr) \
207 (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) ? \
208 (attr)->extra->cluster->length : 0)
211 BGP_ATTR_PARSE_PROCEED
= 0,
212 BGP_ATTR_PARSE_ERROR
= -1,
213 BGP_ATTR_PARSE_WITHDRAW
= -2,
215 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR */
216 BGP_ATTR_PARSE_ERROR_NOTIFYPLS
= -3,
217 } bgp_attr_parse_ret_t
;
219 struct bpacket_attr_vec_arr
;
222 extern void bgp_attr_init (void);
223 extern void bgp_attr_finish (void);
224 extern bgp_attr_parse_ret_t
bgp_attr_parse (struct peer
*, struct attr
*,
225 bgp_size_t
, struct bgp_nlri
*,
227 extern struct attr_extra
*bgp_attr_extra_get (struct attr
*);
228 extern void bgp_attr_extra_free (struct attr
*);
229 extern void bgp_attr_dup (struct attr
*, struct attr
*);
230 extern void bgp_attr_deep_dup (struct attr
*, struct attr
*);
231 extern void bgp_attr_deep_free (struct attr
*);
232 extern struct attr
*bgp_attr_intern (struct attr
*attr
);
233 extern struct attr
*bgp_attr_refcount (struct attr
*attr
);
234 extern void bgp_attr_unintern_sub (struct attr
*);
235 extern void bgp_attr_unintern (struct attr
**);
236 extern void bgp_attr_flush (struct attr
*);
237 extern struct attr
*bgp_attr_default_set (struct attr
*attr
, u_char
);
238 extern struct attr
*bgp_attr_default_intern (u_char
);
239 extern struct attr
*bgp_attr_aggregate_intern (struct bgp
*, u_char
,
241 struct community
*, int as_set
, u_char
);
242 extern bgp_size_t
bgp_packet_attribute (struct bgp
*bgp
, struct peer
*,
243 struct stream
*, struct attr
*,
244 struct bpacket_attr_vec_arr
*vecarr
,
245 struct prefix
*, afi_t
, safi_t
,
246 struct peer
*, struct prefix_rd
*,
247 u_char
*, int, u_int32_t
);
248 extern void bgp_dump_routes_attr (struct stream
*, struct attr
*,
250 extern int attrhash_cmp (const void *, const void *);
251 extern unsigned int attrhash_key_make (void *);
252 extern void attr_show_all (struct vty
*);
253 extern unsigned long int attr_count (void);
254 extern unsigned long int attr_unknown_count (void);
256 /* Cluster list prototypes. */
257 extern int cluster_loop_check (struct cluster_list
*, struct in_addr
);
258 extern void cluster_unintern (struct cluster_list
*);
260 /* Transit attribute prototypes. */
261 void transit_unintern (struct transit
*);
263 /* Below exported for unit-test purposes only */
264 struct bgp_attr_parser_args
{
266 bgp_size_t length
; /* attribute data length; */
267 bgp_size_t total
; /* total length, inc header */
273 extern int bgp_mp_reach_parse (struct bgp_attr_parser_args
*args
,
275 extern int bgp_mp_unreach_parse (struct bgp_attr_parser_args
*args
,
278 extern struct bgp_attr_encap_subtlv
*
279 encap_tlv_dup(struct bgp_attr_encap_subtlv
*orig
);
282 bgp_attr_flush_encap(struct attr
*attr
);
285 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
286 * Typical call sequence is to call _start(), followed by multiple _prefix(),
287 * one for each NLRI that needs to be encoded into the UPDATE message, and
288 * finally the _end() function.
290 extern size_t bgp_packet_mpattr_start(struct stream
*s
, afi_t afi
, safi_t safi
,
292 struct bpacket_attr_vec_arr
*vecarr
,
294 extern void bgp_packet_mpattr_prefix(struct stream
*s
, afi_t afi
, safi_t safi
,
295 struct prefix
*p
, struct prefix_rd
*prd
,
296 u_char
*tag
, int addpath_encode
,
297 u_int32_t addpath_tx_id
,
299 extern size_t bgp_packet_mpattr_prefix_size(afi_t afi
, safi_t safi
,
301 extern void bgp_packet_mpattr_end(struct stream
*s
, size_t sizep
);
303 extern size_t bgp_packet_mpunreach_start (struct stream
*s
, afi_t afi
,
305 extern void bgp_packet_mpunreach_prefix (struct stream
*s
, struct prefix
*p
,
306 afi_t afi
, safi_t safi
, struct prefix_rd
*prd
,
307 u_char
*tag
, int, u_int32_t
, struct attr
*);
308 extern void bgp_packet_mpunreach_end (struct stream
*s
, size_t attrlen_pnt
);
311 bgp_rmap_nhop_changed(u_int32_t out_rmap_flags
, u_int32_t in_rmap_flags
)
313 return ((CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_NEXTHOP_PEER_ADDRESS
) ||
314 CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_NEXTHOP_UNCHANGED
) ||
315 CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV4_NHOP_CHANGED
) ||
316 CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
) ||
317 CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
) ||
318 CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV6_LL_NHOP_CHANGED
) ||
319 CHECK_FLAG(in_rmap_flags
, BATTR_RMAP_NEXTHOP_UNCHANGED
)) ? 1 : 0);
322 #endif /* _QUAGGA_BGP_ATTR_H */