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