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