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