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 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
21 #ifndef _QUAGGA_BGP_ATTR_H
22 #define _QUAGGA_BGP_ATTR_H
25 #include "bgp_attr_evpn.h"
27 /* Simple bit mapping. */
30 #define SET_BITMAP(MAP, NUM) \
31 SET_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
33 #define CHECK_BITMAP(MAP, NUM) \
34 CHECK_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
36 #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)
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
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
69 /* PMSI tunnel types (RFC 6514) */
71 struct bgp_attr_encap_subtlv
{
72 struct bgp_attr_encap_subtlv
*next
; /* for chaining */
73 /* Reference count of this attribute. */
77 uint8_t value
[0]; /* will be extended */
82 * old rfp<->rfapi representation
84 struct bgp_tea_options
{
85 struct bgp_tea_options
*next
;
86 uint8_t options_count
;
87 uint16_t options_length
; /* each TLV may be 256 in length */
90 void *value
; /* pointer to data */
96 PMSI_TNLTYPE_NO_INFO
= 0,
97 PMSI_TNLTYPE_RSVP_TE_P2MP
,
98 PMSI_TNLTYPE_MLDP_P2MP
,
101 PMSI_TNLTYPE_PIM_BIDIR
,
102 PMSI_TNLTYPE_INGR_REPL
,
103 PMSI_TNLTYPE_MLDP_MP2MP
,
104 PMSI_TNLTYPE_MAX
= PMSI_TNLTYPE_MLDP_MP2MP
107 /* BGP core attribute structure. */
109 /* AS Path structure */
110 struct aspath
*aspath
;
112 /* Community structure */
113 struct community
*community
;
115 /* Reference count of this attribute. */
116 unsigned long refcnt
;
118 /* Flag of attribute is set or not. */
121 /* Apart from in6_addr, the remaining static attributes */
122 struct in_addr nexthop
;
125 ifindex_t nh_ifindex
;
127 /* Path origin attribute */
130 /* PMSI tunnel type (RFC 6514). */
131 enum pta_type pmsi_tnl_type
;
133 /* has the route-map changed any attribute?
134 Used on the peer outbound side. */
135 uint32_t rmap_change_flags
;
137 /* Multi-Protocol Nexthop, AFI IPv6 */
138 struct in6_addr mp_nexthop_global
;
139 struct in6_addr mp_nexthop_local
;
141 /* ifIndex corresponding to mp_nexthop_local. */
142 ifindex_t nh_lla_ifindex
;
144 /* Extended Communities attribute. */
145 struct ecommunity
*ecommunity
;
147 /* Large Communities attribute. */
148 struct lcommunity
*lcommunity
;
150 /* Route-Reflector Cluster attribute */
151 struct cluster_list
*cluster
;
153 /* Unknown transitive attribute. */
154 struct transit
*transit
;
156 struct in_addr mp_nexthop_global_in
;
158 /* Aggregator Router ID attribute */
159 struct in_addr aggregator_addr
;
161 /* Route Reflector Originator attribute */
162 struct in_addr originator_id
;
164 /* Local weight, not actually an attribute */
170 /* MP Nexthop length */
171 uint8_t mp_nexthop_len
;
173 /* MP Nexthop preference */
174 uint8_t mp_nexthop_prefer_global
;
176 /* Static MAC for EVPN */
179 /* Flag for default gateway extended community in EVPN */
182 /* NA router flag (R-bit) support in EVPN */
189 uint32_t label_index
;
194 uint16_t encap_tunneltype
; /* grr */
195 struct bgp_attr_encap_subtlv
*encap_subtlvs
; /* rfc5512 */
198 struct bgp_attr_encap_subtlv
*vnc_subtlvs
; /* VNC-specific */
201 struct bgp_route_evpn evpn_overlay
;
203 /* EVPN MAC Mobility sequence number, if any. */
206 /* EVPN local router-mac */
210 /* rmap_change_flags definition */
211 #define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0)
212 #define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1)
213 #define BATTR_REFLECTED (1 << 2)
214 #define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3)
215 #define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4)
216 #define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5)
217 #define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6)
219 /* Router Reflector related structure. */
220 struct cluster_list
{
221 unsigned long refcnt
;
223 struct in_addr
*list
;
226 /* Unknown transit attribute. */
228 unsigned long refcnt
;
233 /* "(void) 0" will generate a compiler error. this is a safety check to
234 * ensure we're not using a value that exceeds the bit size of attr->flag. */
235 #define ATTR_FLAG_BIT(X) \
236 __builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0)
238 #define BGP_CLUSTER_LIST_LENGTH(attr) \
239 (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \
240 ? (attr)->cluster->length \
244 BGP_ATTR_PARSE_PROCEED
= 0,
245 BGP_ATTR_PARSE_ERROR
= -1,
246 BGP_ATTR_PARSE_WITHDRAW
= -2,
248 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR
250 BGP_ATTR_PARSE_ERROR_NOTIFYPLS
= -3,
251 BGP_ATTR_PARSE_EOR
= -4,
252 } bgp_attr_parse_ret_t
;
254 struct bpacket_attr_vec_arr
;
257 extern void bgp_attr_init(void);
258 extern void bgp_attr_finish(void);
259 extern bgp_attr_parse_ret_t
bgp_attr_parse(struct peer
*, struct attr
*,
260 bgp_size_t
, struct bgp_nlri
*,
262 extern void bgp_attr_dup(struct attr
*, struct attr
*);
263 extern void bgp_attr_undup(struct attr
*new, struct attr
*old
);
264 extern struct attr
*bgp_attr_intern(struct attr
*attr
);
265 extern void bgp_attr_unintern_sub(struct attr
*);
266 extern void bgp_attr_unintern(struct attr
**);
267 extern void bgp_attr_flush(struct attr
*);
268 extern struct attr
*bgp_attr_default_set(struct attr
*attr
, uint8_t);
269 extern struct attr
*bgp_attr_aggregate_intern(struct bgp
*bgp
, uint8_t origin
,
270 struct aspath
*aspath
,
271 struct community
*community
,
272 struct ecommunity
*ecommunity
,
273 struct lcommunity
*lcommunity
,
275 uint8_t atomic_aggregate
);
276 extern bgp_size_t
bgp_packet_attribute(struct bgp
*bgp
, struct peer
*,
277 struct stream
*, struct attr
*,
278 struct bpacket_attr_vec_arr
*vecarr
,
279 struct prefix
*, afi_t
, safi_t
,
280 struct peer
*, struct prefix_rd
*,
281 mpls_label_t
*, uint32_t, int, uint32_t);
282 extern void bgp_dump_routes_attr(struct stream
*, struct attr
*,
284 extern bool attrhash_cmp(const void *arg1
, const void *arg2
);
285 extern unsigned int attrhash_key_make(void *);
286 extern void attr_show_all(struct vty
*);
287 extern unsigned long int attr_count(void);
288 extern unsigned long int attr_unknown_count(void);
290 /* Cluster list prototypes. */
291 extern int cluster_loop_check(struct cluster_list
*, struct in_addr
);
292 extern void cluster_unintern(struct cluster_list
*);
294 /* Transit attribute prototypes. */
295 void transit_unintern(struct transit
*);
297 /* Below exported for unit-test purposes only */
298 struct bgp_attr_parser_args
{
300 bgp_size_t length
; /* attribute data length; */
301 bgp_size_t total
; /* total length, inc header */
307 extern int bgp_mp_reach_parse(struct bgp_attr_parser_args
*args
,
309 extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args
*args
,
311 extern bgp_attr_parse_ret_t
312 bgp_attr_prefix_sid(int32_t tlength
, struct bgp_attr_parser_args
*args
,
313 struct bgp_nlri
*mp_update
);
315 extern struct bgp_attr_encap_subtlv
*
316 encap_tlv_dup(struct bgp_attr_encap_subtlv
*orig
);
318 extern void bgp_attr_flush_encap(struct attr
*attr
);
321 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
322 * Typical call sequence is to call _start(), followed by multiple _prefix(),
323 * one for each NLRI that needs to be encoded into the UPDATE message, and
324 * finally the _end() function.
326 extern size_t bgp_packet_mpattr_start(struct stream
*s
, struct peer
*peer
,
327 afi_t afi
, safi_t safi
,
328 struct bpacket_attr_vec_arr
*vecarr
,
330 extern void bgp_packet_mpattr_prefix(struct stream
*s
, afi_t afi
, safi_t safi
,
331 struct prefix
*p
, struct prefix_rd
*prd
,
332 mpls_label_t
*label
, uint32_t num_labels
,
333 int addpath_encode
, uint32_t addpath_tx_id
,
335 extern size_t bgp_packet_mpattr_prefix_size(afi_t afi
, safi_t safi
,
337 extern void bgp_packet_mpattr_end(struct stream
*s
, size_t sizep
);
339 extern size_t bgp_packet_mpunreach_start(struct stream
*s
, afi_t afi
,
341 extern void bgp_packet_mpunreach_prefix(struct stream
*s
, struct prefix
*p
,
342 afi_t afi
, safi_t safi
,
343 struct prefix_rd
*prd
, mpls_label_t
*,
344 uint32_t, int, uint32_t, struct attr
*);
345 extern void bgp_packet_mpunreach_end(struct stream
*s
, size_t attrlen_pnt
);
347 extern bgp_attr_parse_ret_t
bgp_attr_nexthop_valid(struct peer
*peer
,
350 static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags
,
351 uint32_t in_rmap_flags
)
353 return ((CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_NEXTHOP_PEER_ADDRESS
)
354 || CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_NEXTHOP_UNCHANGED
)
355 || CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV4_NHOP_CHANGED
)
356 || CHECK_FLAG(out_rmap_flags
,
357 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED
)
358 || CHECK_FLAG(out_rmap_flags
,
359 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED
)
360 || CHECK_FLAG(out_rmap_flags
, BATTR_RMAP_IPV6_LL_NHOP_CHANGED
)
361 || CHECK_FLAG(in_rmap_flags
, BATTR_RMAP_NEXTHOP_UNCHANGED
))
366 static inline uint32_t mac_mobility_seqnum(struct attr
*attr
)
368 return (attr
) ? attr
->mm_seqnum
: 0;
371 #endif /* _QUAGGA_BGP_ATTR_H */