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