]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_attr.h
Merge pull request #5321 from sworleys/Zebra-Dplane-Thread-Cancel-Async
[mirror_frr.git] / bgpd / bgp_attr.h
CommitLineData
d62a17ae 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 25#include "bgp_attr_evpn.h"
f4bd90c5 26#include "bgpd/bgp_encap_types.h"
684a7227 27
718e3744 28/* Simple bit mapping. */
29#define BITMAP_NBBY 8
30
d62a17ae 31#define SET_BITMAP(MAP, NUM) \
32 SET_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
718e3744 33
d62a17ae 34#define CHECK_BITMAP(MAP, NUM) \
35 CHECK_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
718e3744 36
3b424979 37#define BGP_MED_MAX UINT32_MAX
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
c6ca155d
HS
65#define BGP_PREFIX_SID_SRV6_L3_SERVICE 5
66#define BGP_PREFIX_SID_SRV6_L2_SERVICE 6
c5a543b4
DW
67
68#define BGP_PREFIX_SID_LABEL_INDEX_LENGTH 7
69#define BGP_PREFIX_SID_IPV6_LENGTH 19
70#define BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH 6
f4c89855 71
7fd077aa 72/* PMSI tunnel types (RFC 6514) */
73
f4c89855 74struct bgp_attr_encap_subtlv {
d62a17ae 75 struct bgp_attr_encap_subtlv *next; /* for chaining */
76 /* Reference count of this attribute. */
77 unsigned long refcnt;
78 uint16_t type;
79 uint16_t length;
8c9cc7bb 80 uint8_t value[0]; /* will be extended */
f4c89855
LB
81};
82
65efcfce
LB
83#if ENABLE_BGP_VNC
84/*
85 * old rfp<->rfapi representation
86 */
87struct bgp_tea_options {
d62a17ae 88 struct bgp_tea_options *next;
89 uint8_t options_count;
90 uint16_t options_length; /* each TLV may be 256 in length */
91 uint8_t type;
92 uint8_t length;
93 void *value; /* pointer to data */
65efcfce
LB
94};
95
96#endif
97
7fd077aa 98enum pta_type {
b7d08f5a 99 PMSI_TNLTYPE_NO_INFO = 0,
7fd077aa 100 PMSI_TNLTYPE_RSVP_TE_P2MP,
101 PMSI_TNLTYPE_MLDP_P2MP,
102 PMSI_TNLTYPE_PIM_SSM,
103 PMSI_TNLTYPE_PIM_SM,
104 PMSI_TNLTYPE_PIM_BIDIR,
105 PMSI_TNLTYPE_INGR_REPL,
106 PMSI_TNLTYPE_MLDP_MP2MP,
107 PMSI_TNLTYPE_MAX = PMSI_TNLTYPE_MLDP_MP2MP
108};
109
aadc0905 110/* BGP core attribute structure. */
d62a17ae 111struct attr {
112 /* AS Path structure */
113 struct aspath *aspath;
114
115 /* Community structure */
116 struct community *community;
117
118 /* Reference count of this attribute. */
119 unsigned long refcnt;
120
121 /* Flag of attribute is set or not. */
122 uint64_t flag;
123
124 /* Apart from in6_addr, the remaining static attributes */
125 struct in_addr nexthop;
d7c0a89a
QY
126 uint32_t med;
127 uint32_t local_pref;
d62a17ae 128 ifindex_t nh_ifindex;
129
130 /* Path origin attribute */
d7c0a89a 131 uint8_t origin;
d62a17ae 132
7fd077aa 133 /* PMSI tunnel type (RFC 6514). */
134 enum pta_type pmsi_tnl_type;
135
d62a17ae 136 /* has the route-map changed any attribute?
137 Used on the peer outbound side. */
d7c0a89a 138 uint32_t rmap_change_flags;
d62a17ae 139
140 /* Multi-Protocol Nexthop, AFI IPv6 */
141 struct in6_addr mp_nexthop_global;
142 struct in6_addr mp_nexthop_local;
143
77e62f2b 144 /* ifIndex corresponding to mp_nexthop_local. */
145 ifindex_t nh_lla_ifindex;
146
d62a17ae 147 /* Extended Communities attribute. */
148 struct ecommunity *ecommunity;
149
150 /* Large Communities attribute. */
151 struct lcommunity *lcommunity;
152
153 /* Route-Reflector Cluster attribute */
154 struct cluster_list *cluster;
155
156 /* Unknown transitive attribute. */
157 struct transit *transit;
158
159 struct in_addr mp_nexthop_global_in;
160
161 /* Aggregator Router ID attribute */
162 struct in_addr aggregator_addr;
163
164 /* Route Reflector Originator attribute */
165 struct in_addr originator_id;
166
167 /* Local weight, not actually an attribute */
d7c0a89a 168 uint32_t weight;
d62a17ae 169
170 /* Aggregator ASN */
171 as_t aggregator_as;
172
173 /* MP Nexthop length */
d7c0a89a 174 uint8_t mp_nexthop_len;
d62a17ae 175
176 /* MP Nexthop preference */
d7c0a89a 177 uint8_t mp_nexthop_prefer_global;
d62a17ae 178
179 /* Static MAC for EVPN */
d7c0a89a 180 uint8_t sticky;
d62a17ae 181
ead40654 182 /* Flag for default gateway extended community in EVPN */
d7c0a89a 183 uint8_t default_gw;
ead40654 184
68e33151
CS
185 /* NA router flag (R-bit) support in EVPN */
186 uint8_t router_flag;
187
d62a17ae 188 /* route tag */
189 route_tag_t tag;
190
191 /* Label index */
d7c0a89a 192 uint32_t label_index;
d62a17ae 193
194 /* MPLS label */
195 mpls_label_t label;
196
197 uint16_t encap_tunneltype; /* grr */
198 struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */
65efcfce
LB
199
200#if ENABLE_BGP_VNC
d62a17ae 201 struct bgp_attr_encap_subtlv *vnc_subtlvs; /* VNC-specific */
65efcfce 202#endif
d62a17ae 203 /* EVPN */
ea7741a0 204 struct bgp_route_evpn evpn_overlay;
128ea8ab 205
d62a17ae 206 /* EVPN MAC Mobility sequence number, if any. */
d7c0a89a 207 uint32_t mm_seqnum;
bc59a672
MK
208
209 /* EVPN local router-mac */
210 struct ethaddr rmac;
7b7d48e5
DS
211
212 /* Distance as applied by Route map */
213 uint8_t distance;
951745bd
PG
214
215 /* rmap set table */
216 uint32_t rmap_table_id;
fb982c25
PJ
217};
218
3f9c7369 219/* rmap_change_flags definition */
3811f1e2 220#define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0)
3f9c7369
DS
221#define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1)
222#define BATTR_REFLECTED (1 << 2)
316e074d 223#define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3)
3811f1e2
DS
224#define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4)
225#define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5)
b2e03f7a 226#define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6)
3f9c7369 227
718e3744 228/* Router Reflector related structure. */
d62a17ae 229struct cluster_list {
230 unsigned long refcnt;
231 int length;
232 struct in_addr *list;
718e3744 233};
234
235/* Unknown transit attribute. */
d62a17ae 236struct transit {
237 unsigned long refcnt;
238 int length;
d7c0a89a 239 uint8_t *val;
718e3744 240};
241
96099b40
DL
242/* "(void) 0" will generate a compiler error. this is a safety check to
243 * ensure we're not using a value that exceeds the bit size of attr->flag. */
996c9314
LB
244#define ATTR_FLAG_BIT(X) \
245 __builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0)
718e3744 246
d62a17ae 247#define BGP_CLUSTER_LIST_LENGTH(attr) \
248 (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \
249 ? (attr)->cluster->length \
250 : 0)
5e242b0d 251
b881c707 252typedef enum {
d62a17ae 253 BGP_ATTR_PARSE_PROCEED = 0,
254 BGP_ATTR_PARSE_ERROR = -1,
255 BGP_ATTR_PARSE_WITHDRAW = -2,
f57000c0 256
d62a17ae 257 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR
9d303b37 258 */
d62a17ae 259 BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
9b9df989 260 BGP_ATTR_PARSE_EOR = -4,
b881c707
PJ
261} bgp_attr_parse_ret_t;
262
3f9c7369
DS
263struct bpacket_attr_vec_arr;
264
718e3744 265/* Prototypes. */
d62a17ae 266extern void bgp_attr_init(void);
267extern void bgp_attr_finish(void);
268extern bgp_attr_parse_ret_t bgp_attr_parse(struct peer *, struct attr *,
269 bgp_size_t, struct bgp_nlri *,
270 struct bgp_nlri *);
271extern void bgp_attr_dup(struct attr *, struct attr *);
f46d8e1e 272extern void bgp_attr_undup(struct attr *new, struct attr *old);
d62a17ae 273extern struct attr *bgp_attr_intern(struct attr *attr);
d62a17ae 274extern void bgp_attr_unintern_sub(struct attr *);
275extern void bgp_attr_unintern(struct attr **);
276extern void bgp_attr_flush(struct attr *);
d7c0a89a 277extern struct attr *bgp_attr_default_set(struct attr *attr, uint8_t);
3da2cc32
DS
278extern struct attr *bgp_attr_aggregate_intern(struct bgp *bgp, uint8_t origin,
279 struct aspath *aspath,
280 struct community *community,
281 struct ecommunity *ecommunity,
dd18c5a9 282 struct lcommunity *lcommunity,
20894f50
DA
283 struct bgp_aggregate *aggregate,
284 uint8_t atomic_aggregate,
285 struct prefix *p);
d62a17ae 286extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *,
287 struct stream *, struct attr *,
288 struct bpacket_attr_vec_arr *vecarr,
289 struct prefix *, afi_t, safi_t,
290 struct peer *, struct prefix_rd *,
d7c0a89a 291 mpls_label_t *, uint32_t, int, uint32_t);
d62a17ae 292extern void bgp_dump_routes_attr(struct stream *, struct attr *,
293 struct prefix *);
74df8d6d 294extern bool attrhash_cmp(const void *arg1, const void *arg2);
d8b87afe 295extern unsigned int attrhash_key_make(const void *);
d62a17ae 296extern void attr_show_all(struct vty *);
297extern unsigned long int attr_count(void);
298extern unsigned long int attr_unknown_count(void);
718e3744 299
300/* Cluster list prototypes. */
d62a17ae 301extern int cluster_loop_check(struct cluster_list *, struct in_addr);
302extern void cluster_unintern(struct cluster_list *);
718e3744 303
304/* Transit attribute prototypes. */
d62a17ae 305void transit_unintern(struct transit *);
00d252cb 306
835315bf
PJ
307/* Below exported for unit-test purposes only */
308struct bgp_attr_parser_args {
d62a17ae 309 struct peer *peer;
310 bgp_size_t length; /* attribute data length; */
311 bgp_size_t total; /* total length, inc header */
312 struct attr *attr;
d7c0a89a
QY
313 uint8_t type;
314 uint8_t flags;
315 uint8_t *startp;
835315bf 316};
d62a17ae 317extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
318 struct bgp_nlri *);
319extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args,
320 struct bgp_nlri *);
30adbd4e
DS
321extern bgp_attr_parse_ret_t
322bgp_attr_prefix_sid(int32_t tlength, struct bgp_attr_parser_args *args,
323 struct bgp_nlri *mp_update);
03292809 324
f4c89855
LB
325extern struct bgp_attr_encap_subtlv *
326encap_tlv_dup(struct bgp_attr_encap_subtlv *orig);
327
d62a17ae 328extern void bgp_attr_flush_encap(struct attr *attr);
f4c89855 329
f4bd90c5
LK
330extern void bgp_attr_extcom_tunnel_type(struct attr *attr,
331 bgp_encap_types *tunnel_type);
332
8c71e481
PM
333/**
334 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
335 * Typical call sequence is to call _start(), followed by multiple _prefix(),
336 * one for each NLRI that needs to be encoded into the UPDATE message, and
337 * finally the _end() function.
338 */
2b26882d 339extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer,
d62a17ae 340 afi_t afi, safi_t safi,
341 struct bpacket_attr_vec_arr *vecarr,
8c71e481
PM
342 struct attr *attr);
343extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
344 struct prefix *p, struct prefix_rd *prd,
d7c0a89a
QY
345 mpls_label_t *label, uint32_t num_labels,
346 int addpath_encode, uint32_t addpath_tx_id,
347 struct attr *);
93b73dfa 348extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
d62a17ae 349 struct prefix *p);
8c71e481
PM
350extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
351
d62a17ae 352extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi,
353 safi_t safi);
354extern void bgp_packet_mpunreach_prefix(struct stream *s, struct prefix *p,
355 afi_t afi, safi_t safi,
996c9314 356 struct prefix_rd *prd, mpls_label_t *,
d7c0a89a 357 uint32_t, int, uint32_t, struct attr *);
d62a17ae 358extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt);
8c71e481 359
9738e9aa 360extern bgp_attr_parse_ret_t bgp_attr_nexthop_valid(struct peer *peer,
361 struct attr *attr);
362
d7c0a89a
QY
363static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags,
364 uint32_t in_rmap_flags)
3811f1e2 365{
d62a17ae 366 return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS)
367 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)
368 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED)
369 || CHECK_FLAG(out_rmap_flags,
370 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED)
371 || CHECK_FLAG(out_rmap_flags,
372 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED)
373 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED)
374 || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED))
375 ? 1
376 : 0);
3811f1e2
DS
377}
378
d7c0a89a 379static inline uint32_t mac_mobility_seqnum(struct attr *attr)
128ea8ab 380{
d62a17ae 381 return (attr) ? attr->mm_seqnum : 0;
128ea8ab 382}
383
00d252cb 384#endif /* _QUAGGA_BGP_ATTR_H */