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