]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_attr.h
Merge pull request #12187 from mjstapp/mjs_fix_bgp_allowas
[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"
ef3e0d04 27#include "srte.h"
684a7227 28
718e3744 29/* Simple bit mapping. */
30#define BITMAP_NBBY 8
31
d62a17ae 32#define SET_BITMAP(MAP, NUM) \
33 SET_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
718e3744 34
d62a17ae 35#define CHECK_BITMAP(MAP, NUM) \
36 CHECK_FLAG(MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
718e3744 37
3b424979 38#define BGP_MED_MAX UINT32_MAX
39
718e3744 40/* BGP Attribute type range. */
41#define BGP_ATTR_TYPE_RANGE 256
42#define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
43
44/* BGP Attribute flags. */
45#define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */
46#define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */
47#define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */
48#define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */
49
50/* BGP attribute header must bigger than 2. */
370b64a2 51#define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */
03e214c8
PJ
52#define BGP_ATTR_DEFAULT_WEIGHT 32768
53
801a9bcc
DS
54/* Valid lengths for mp_nexthop_len */
55#define BGP_ATTR_NHLEN_IPV4 IPV4_MAX_BYTELEN
945c8fe9 56#define BGP_ATTR_NHLEN_VPNV4 8+IPV4_MAX_BYTELEN
801a9bcc
DS
57#define BGP_ATTR_NHLEN_IPV6_GLOBAL IPV6_MAX_BYTELEN
58#define BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL (IPV6_MAX_BYTELEN * 2)
945c8fe9
LB
59#define BGP_ATTR_NHLEN_VPNV6_GLOBAL 8+IPV6_MAX_BYTELEN
60#define BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL ((8+IPV6_MAX_BYTELEN) * 2)
801a9bcc 61
c5a543b4
DW
62/* Prefix SID types */
63#define BGP_PREFIX_SID_LABEL_INDEX 1
64#define BGP_PREFIX_SID_IPV6 2
65#define BGP_PREFIX_SID_ORIGINATOR_SRGB 3
e496b420 66#define BGP_PREFIX_SID_VPN_SID 4
c6ca155d
HS
67#define BGP_PREFIX_SID_SRV6_L3_SERVICE 5
68#define BGP_PREFIX_SID_SRV6_L2_SERVICE 6
c5a543b4
DW
69
70#define BGP_PREFIX_SID_LABEL_INDEX_LENGTH 7
71#define BGP_PREFIX_SID_IPV6_LENGTH 19
72#define BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH 6
e496b420 73#define BGP_PREFIX_SID_VPN_SID_LENGTH 19
a3e3b5b0
RS
74
75/* SRv6 Service Sub-TLV types */
76#define BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_INFO 1
77#define BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_INFO_LENGTH 21
f4c89855 78
73604f82
RS
79/* SRv6 Service Data Sub-Sub-TLV types */
80#define BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_STRUCTURE 1
a1a51008 81#define BGP_PREFIX_SID_SRV6_L3_SERVICE_SID_STRUCTURE_LENGTH 6
73604f82 82
7c312383
AD
83#define BGP_ATTR_NH_AFI(afi, attr) \
84 ((afi != AFI_L2VPN) ? afi : \
85 ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ? AFI_IP : AFI_IP6))
86
7fd077aa 87/* PMSI tunnel types (RFC 6514) */
88
f4c89855 89struct bgp_attr_encap_subtlv {
d62a17ae 90 struct bgp_attr_encap_subtlv *next; /* for chaining */
91 /* Reference count of this attribute. */
92 unsigned long refcnt;
93 uint16_t type;
94 uint16_t length;
8c9cc7bb 95 uint8_t value[0]; /* will be extended */
f4c89855
LB
96};
97
49e5a4a0 98#ifdef ENABLE_BGP_VNC
65efcfce
LB
99/*
100 * old rfp<->rfapi representation
101 */
102struct bgp_tea_options {
d62a17ae 103 struct bgp_tea_options *next;
104 uint8_t options_count;
105 uint16_t options_length; /* each TLV may be 256 in length */
106 uint8_t type;
107 uint8_t length;
108 void *value; /* pointer to data */
65efcfce
LB
109};
110
111#endif
112
7fd077aa 113enum pta_type {
b7d08f5a 114 PMSI_TNLTYPE_NO_INFO = 0,
7fd077aa 115 PMSI_TNLTYPE_RSVP_TE_P2MP,
116 PMSI_TNLTYPE_MLDP_P2MP,
117 PMSI_TNLTYPE_PIM_SSM,
118 PMSI_TNLTYPE_PIM_SM,
119 PMSI_TNLTYPE_PIM_BIDIR,
120 PMSI_TNLTYPE_INGR_REPL,
121 PMSI_TNLTYPE_MLDP_MP2MP,
122 PMSI_TNLTYPE_MAX = PMSI_TNLTYPE_MLDP_MP2MP
123};
124
e496b420
HS
125/*
126 * Prefix-SID type-4
127 * SRv6-VPN-SID-TLV
128 * draft-dawra-idr-srv6-vpn-04
129 */
130struct bgp_attr_srv6_vpn {
131 unsigned long refcnt;
132 uint8_t sid_flags;
133 struct in6_addr sid;
134};
135
136/*
137 * Prefix-SID type-5
138 * SRv6-L3VPN-Service-TLV
139 * draft-dawra-idr-srv6-vpn-05
140 */
141struct bgp_attr_srv6_l3vpn {
142 unsigned long refcnt;
143 uint8_t sid_flags;
144 uint16_t endpoint_behavior;
145 struct in6_addr sid;
9299fd00
RS
146 uint8_t loc_block_len;
147 uint8_t loc_node_len;
148 uint8_t func_len;
149 uint8_t arg_len;
150 uint8_t transposition_len;
151 uint8_t transposition_offset;
e496b420
HS
152};
153
aadc0905 154/* BGP core attribute structure. */
d62a17ae 155struct attr {
156 /* AS Path structure */
157 struct aspath *aspath;
158
159 /* Community structure */
160 struct community *community;
161
162 /* Reference count of this attribute. */
163 unsigned long refcnt;
164
165 /* Flag of attribute is set or not. */
166 uint64_t flag;
167
168 /* Apart from in6_addr, the remaining static attributes */
169 struct in_addr nexthop;
d7c0a89a
QY
170 uint32_t med;
171 uint32_t local_pref;
d62a17ae 172 ifindex_t nh_ifindex;
173
174 /* Path origin attribute */
d7c0a89a 175 uint8_t origin;
d62a17ae 176
adde1db9
IR
177 /* PMSI tunnel type (RFC 6514). */
178 enum pta_type pmsi_tnl_type;
179
d62a17ae 180 /* has the route-map changed any attribute?
181 Used on the peer outbound side. */
d7c0a89a 182 uint32_t rmap_change_flags;
d62a17ae 183
184 /* Multi-Protocol Nexthop, AFI IPv6 */
185 struct in6_addr mp_nexthop_global;
186 struct in6_addr mp_nexthop_local;
187
77e62f2b 188 /* ifIndex corresponding to mp_nexthop_local. */
189 ifindex_t nh_lla_ifindex;
190
d62a17ae 191 /* Extended Communities attribute. */
192 struct ecommunity *ecommunity;
193
a2d3103a
IR
194 /* Extended Communities attribute. */
195 struct ecommunity *ipv6_ecommunity;
9a659715 196
d62a17ae 197 /* Large Communities attribute. */
198 struct lcommunity *lcommunity;
199
200 /* Route-Reflector Cluster attribute */
779fee93 201 struct cluster_list *cluster1;
d62a17ae 202
203 /* Unknown transitive attribute. */
204 struct transit *transit;
205
206 struct in_addr mp_nexthop_global_in;
207
208 /* Aggregator Router ID attribute */
209 struct in_addr aggregator_addr;
210
211 /* Route Reflector Originator attribute */
212 struct in_addr originator_id;
213
214 /* Local weight, not actually an attribute */
d7c0a89a 215 uint32_t weight;
d62a17ae 216
217 /* Aggregator ASN */
218 as_t aggregator_as;
219
220 /* MP Nexthop length */
d7c0a89a 221 uint8_t mp_nexthop_len;
d62a17ae 222
223 /* MP Nexthop preference */
d7c0a89a 224 uint8_t mp_nexthop_prefer_global;
d62a17ae 225
226 /* Static MAC for EVPN */
d7c0a89a 227 uint8_t sticky;
d62a17ae 228
ead40654 229 /* Flag for default gateway extended community in EVPN */
d7c0a89a 230 uint8_t default_gw;
ead40654 231
68e33151
CS
232 /* NA router flag (R-bit) support in EVPN */
233 uint8_t router_flag;
234
7904e9fd
AK
235 /* ES info */
236 uint8_t es_flags;
237 /* Path is not "locally-active" on the advertising VTEP. This is
238 * translated into an ARP-ND ECOM.
239 */
240#define ATTR_ES_PROXY_ADVERT (1 << 0)
241 /* Destination ES is present locally. This flag is set on local
242 * paths and sync paths
243 */
244#define ATTR_ES_IS_LOCAL (1 << 1)
245 /* There are one or more non-best paths from ES peers. Note that
246 * this flag is only set on the local MAC-IP paths in the VNI
247 * route table (not set in the global routing table). And only
248 * non-proxy advertisements from an ES peer can result in this
249 * flag being set.
250 */
251#define ATTR_ES_PEER_ACTIVE (1 << 2)
252 /* There are one or more non-best proxy paths from ES peers */
253#define ATTR_ES_PEER_PROXY (1 << 3)
254 /* An ES peer has router bit set - only applicable if
255 * ATTR_ES_PEER_ACTIVE is set
256 */
257#define ATTR_ES_PEER_ROUTER (1 << 4)
258
58bff4d1
AK
259 /* These two flags are only set on L3 routes installed in a
260 * VRF as a result of EVPN MAC-IP route
261 * XXX - while splitting up per-family attrs these need to be
262 * classified as non-EVPN
263 */
264#define ATTR_ES_L3_NHG_USE (1 << 5)
265#define ATTR_ES_L3_NHG_ACTIVE (1 << 6)
266#define ATTR_ES_L3_NHG (ATTR_ES_L3_NHG_USE | ATTR_ES_L3_NHG_ACTIVE)
267
d62a17ae 268 /* route tag */
269 route_tag_t tag;
270
271 /* Label index */
d7c0a89a 272 uint32_t label_index;
d62a17ae 273
274 /* MPLS label */
275 mpls_label_t label;
276
e496b420
HS
277 /* SRv6 VPN SID */
278 struct bgp_attr_srv6_vpn *srv6_vpn;
279
280 /* SRv6 L3VPN SID */
281 struct bgp_attr_srv6_l3vpn *srv6_l3vpn;
282
d62a17ae 283 uint16_t encap_tunneltype; /* grr */
284 struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */
65efcfce 285
49e5a4a0 286#ifdef ENABLE_BGP_VNC
d62a17ae 287 struct bgp_attr_encap_subtlv *vnc_subtlvs; /* VNC-specific */
65efcfce 288#endif
d62a17ae 289 /* EVPN */
ea7741a0 290 struct bgp_route_evpn evpn_overlay;
128ea8ab 291
d62a17ae 292 /* EVPN MAC Mobility sequence number, if any. */
d7c0a89a 293 uint32_t mm_seqnum;
7904e9fd
AK
294 /* highest MM sequence number rxed in a MAC-IP route from an
295 * ES peer (this includes both proxy and non-proxy MAC-IP
296 * advertisements from ES peers).
297 * This is only applicable to local paths in the VNI routing
298 * table and derived from other imported/non-best paths.
299 */
300 uint32_t mm_sync_seqnum;
bc59a672
MK
301
302 /* EVPN local router-mac */
303 struct ethaddr rmac;
7b7d48e5
DS
304
305 /* Distance as applied by Route map */
306 uint8_t distance;
951745bd
PG
307
308 /* rmap set table */
309 uint32_t rmap_table_id;
d901dc13 310
311 /* Link bandwidth value, if any. */
312 uint32_t link_bw;
0a50c248
AK
313
314 /* EVPN ES */
315 esi_t esi;
ef3e0d04
SM
316
317 /* SR-TE Color */
318 uint32_t srte_color;
74e2bd89
AK
319
320 /* EVPN DF preference and algorithm for DF election on local ESs */
321 uint16_t df_pref;
322 uint8_t df_alg;
0789eb69
KM
323
324 /* Nexthop type */
325 enum nexthop_types_t nh_type;
326
327 /* If NEXTHOP_TYPE_BLACKHOLE, then blackhole type */
328 enum blackhole_type bh_type;
d864dd9e
EB
329
330 /* OTC value if set */
331 uint32_t otc;
fb982c25
PJ
332};
333
3f9c7369 334/* rmap_change_flags definition */
3811f1e2 335#define BATTR_RMAP_IPV4_NHOP_CHANGED (1 << 0)
3f9c7369
DS
336#define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1)
337#define BATTR_REFLECTED (1 << 2)
316e074d 338#define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3)
3811f1e2
DS
339#define BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED (1 << 4)
340#define BATTR_RMAP_IPV6_LL_NHOP_CHANGED (1 << 5)
b2e03f7a 341#define BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED (1 << 6)
7b651a32 342#define BATTR_RMAP_LINK_BW_SET (1 << 7)
1bb550b6 343#define BATTR_RMAP_L3VPN_ACCEPT_GRE (1 << 8)
3f9c7369 344
718e3744 345/* Router Reflector related structure. */
d62a17ae 346struct cluster_list {
347 unsigned long refcnt;
348 int length;
349 struct in_addr *list;
718e3744 350};
351
352/* Unknown transit attribute. */
d62a17ae 353struct transit {
354 unsigned long refcnt;
355 int length;
d7c0a89a 356 uint8_t *val;
718e3744 357};
358
96099b40
DL
359/* "(void) 0" will generate a compiler error. this is a safety check to
360 * ensure we're not using a value that exceeds the bit size of attr->flag. */
996c9314
LB
361#define ATTR_FLAG_BIT(X) \
362 __builtin_choose_expr((X) >= 1 && (X) <= 64, 1ULL << ((X)-1), (void)0)
718e3744 363
d62a17ae 364#define BGP_CLUSTER_LIST_LENGTH(attr) \
365 (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \
779fee93 366 ? bgp_attr_get_cluster((attr))->length \
d62a17ae 367 : 0)
5e242b0d 368
79288e4c 369enum bgp_attr_parse_ret {
d62a17ae 370 BGP_ATTR_PARSE_PROCEED = 0,
371 BGP_ATTR_PARSE_ERROR = -1,
372 BGP_ATTR_PARSE_WITHDRAW = -2,
f57000c0 373
d62a17ae 374 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR
682abee1 375 */
d62a17ae 376 BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
9b9df989 377 BGP_ATTR_PARSE_EOR = -4,
79288e4c 378};
b881c707 379
3f9c7369
DS
380struct bpacket_attr_vec_arr;
381
718e3744 382/* Prototypes. */
d62a17ae 383extern void bgp_attr_init(void);
384extern void bgp_attr_finish(void);
d7db24db
DS
385extern enum bgp_attr_parse_ret
386bgp_attr_parse(struct peer *peer, struct attr *attr, bgp_size_t size,
387 struct bgp_nlri *mp_update, struct bgp_nlri *mp_withdraw);
d62a17ae 388extern struct attr *bgp_attr_intern(struct attr *attr);
d7db24db
DS
389extern void bgp_attr_unintern_sub(struct attr *attr);
390extern void bgp_attr_unintern(struct attr **pattr);
391extern void bgp_attr_flush(struct attr *attr);
0f05ea43
DA
392extern struct attr *bgp_attr_default_set(struct attr *attr, struct bgp *bgp,
393 uint8_t origin);
5f040085
DS
394extern struct attr *bgp_attr_aggregate_intern(
395 struct bgp *bgp, uint8_t origin, struct aspath *aspath,
396 struct community *community, struct ecommunity *ecommunity,
397 struct lcommunity *lcommunity, struct bgp_aggregate *aggregate,
398 uint8_t atomic_aggregate, const struct prefix *p);
be92fc9f
DA
399extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
400 struct stream *s, struct attr *attr,
d62a17ae 401 struct bpacket_attr_vec_arr *vecarr,
be92fc9f
DA
402 struct prefix *p, afi_t afi, safi_t safi,
403 struct peer *from, struct prefix_rd *prd,
404 mpls_label_t *label, uint32_t num_labels,
405 bool addpath_capable,
406 uint32_t addpath_tx_id);
bd494ec5
DS
407extern void bgp_dump_routes_attr(struct stream *s, struct attr *attr,
408 const struct prefix *p);
74df8d6d 409extern bool attrhash_cmp(const void *arg1, const void *arg2);
d7db24db
DS
410extern unsigned int attrhash_key_make(const void *p);
411extern void attr_show_all(struct vty *vty);
d62a17ae 412extern unsigned long int attr_count(void);
413extern unsigned long int attr_unknown_count(void);
718e3744 414
415/* Cluster list prototypes. */
d7db24db
DS
416extern bool cluster_loop_check(struct cluster_list *cluster,
417 struct in_addr originator);
718e3744 418
835315bf
PJ
419/* Below exported for unit-test purposes only */
420struct bgp_attr_parser_args {
d62a17ae 421 struct peer *peer;
422 bgp_size_t length; /* attribute data length; */
423 bgp_size_t total; /* total length, inc header */
424 struct attr *attr;
d7c0a89a
QY
425 uint8_t type;
426 uint8_t flags;
427 uint8_t *startp;
835315bf 428};
d62a17ae 429extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args,
d7db24db 430 struct bgp_nlri *mp_update);
d62a17ae 431extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args,
d7db24db 432 struct bgp_nlri *mp_withdraw);
79288e4c 433extern enum bgp_attr_parse_ret
45a06b11 434bgp_attr_prefix_sid(struct bgp_attr_parser_args *args);
03292809 435
f4c89855
LB
436extern struct bgp_attr_encap_subtlv *
437encap_tlv_dup(struct bgp_attr_encap_subtlv *orig);
438
d62a17ae 439extern void bgp_attr_flush_encap(struct attr *attr);
f4c89855 440
f4bd90c5
LK
441extern void bgp_attr_extcom_tunnel_type(struct attr *attr,
442 bgp_encap_types *tunnel_type);
443
8c71e481
PM
444/**
445 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
446 * Typical call sequence is to call _start(), followed by multiple _prefix(),
447 * one for each NLRI that needs to be encoded into the UPDATE message, and
448 * finally the _end() function.
449 */
2b26882d 450extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer,
d62a17ae 451 afi_t afi, safi_t safi,
452 struct bpacket_attr_vec_arr *vecarr,
8c71e481
PM
453 struct attr *attr);
454extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
5f040085
DS
455 const struct prefix *p,
456 const struct prefix_rd *prd,
d7c0a89a 457 mpls_label_t *label, uint32_t num_labels,
be92fc9f
DA
458 bool addpath_capable,
459 uint32_t addpath_tx_id, struct attr *);
93b73dfa 460extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
5f040085 461 const struct prefix *p);
8c71e481
PM
462extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
463
d62a17ae 464extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi,
465 safi_t safi);
5f040085
DS
466extern void bgp_packet_mpunreach_prefix(
467 struct stream *s, const struct prefix *p, afi_t afi, safi_t safi,
468 const struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels,
be92fc9f 469 bool addpath_capable, uint32_t addpath_tx_id, struct attr *attr);
d62a17ae 470extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt);
8c71e481 471
79288e4c
DA
472extern enum bgp_attr_parse_ret bgp_attr_nexthop_valid(struct peer *peer,
473 struct attr *attr);
9738e9aa 474
d7c0a89a
QY
475static inline int bgp_rmap_nhop_changed(uint32_t out_rmap_flags,
476 uint32_t in_rmap_flags)
3811f1e2 477{
d62a17ae 478 return ((CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_PEER_ADDRESS)
479 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED)
480 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV4_NHOP_CHANGED)
481 || CHECK_FLAG(out_rmap_flags,
482 BATTR_RMAP_IPV6_GLOBAL_NHOP_CHANGED)
483 || CHECK_FLAG(out_rmap_flags,
484 BATTR_RMAP_IPV6_PREFER_GLOBAL_CHANGED)
485 || CHECK_FLAG(out_rmap_flags, BATTR_RMAP_IPV6_LL_NHOP_CHANGED)
486 || CHECK_FLAG(in_rmap_flags, BATTR_RMAP_NEXTHOP_UNCHANGED))
487 ? 1
488 : 0);
3811f1e2
DS
489}
490
d7c0a89a 491static inline uint32_t mac_mobility_seqnum(struct attr *attr)
128ea8ab 492{
d62a17ae 493 return (attr) ? attr->mm_seqnum : 0;
128ea8ab 494}
2a3f51cf 495
adde1db9 496static inline enum pta_type bgp_attr_get_pmsi_tnl_type(struct attr *attr)
2a3f51cf 497{
adde1db9 498 return attr->pmsi_tnl_type;
2a3f51cf
DS
499}
500
501static inline void bgp_attr_set_pmsi_tnl_type(struct attr *attr,
502 enum pta_type pmsi_tnl_type)
503{
adde1db9 504 attr->pmsi_tnl_type = pmsi_tnl_type;
2a3f51cf
DS
505}
506
b53e67a3
DA
507static inline struct ecommunity *
508bgp_attr_get_ecommunity(const struct attr *attr)
509{
510 return attr->ecommunity;
511}
512
513static inline void bgp_attr_set_ecommunity(struct attr *attr,
514 struct ecommunity *ecomm)
515{
516 attr->ecommunity = ecomm;
58cf5c08
DA
517
518 if (ecomm)
519 SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
520 else
521 UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
b53e67a3
DA
522}
523
1bcf3a96
DA
524static inline struct lcommunity *
525bgp_attr_get_lcommunity(const struct attr *attr)
526{
527 return attr->lcommunity;
528}
529
530static inline void bgp_attr_set_lcommunity(struct attr *attr,
531 struct lcommunity *lcomm)
532{
533 attr->lcommunity = lcomm;
9d34440b
DA
534
535 if (lcomm)
536 SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
537 else
538 UNSET_FLAG(attr->flag,
539 ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
1bcf3a96
DA
540}
541
9a706b42
DA
542static inline struct community *bgp_attr_get_community(const struct attr *attr)
543{
544 return attr->community;
545}
546
547static inline void bgp_attr_set_community(struct attr *attr,
548 struct community *comm)
549{
550 attr->community = comm;
9d34440b
DA
551
552 if (comm)
553 SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
554 else
555 UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
9a706b42
DA
556}
557
d04ac434
DS
558static inline struct ecommunity *
559bgp_attr_get_ipv6_ecommunity(const struct attr *attr)
560{
a2d3103a 561 return attr->ipv6_ecommunity;
d04ac434
DS
562}
563
564static inline void bgp_attr_set_ipv6_ecommunity(struct attr *attr,
565 struct ecommunity *ipv6_ecomm)
566{
a2d3103a 567 attr->ipv6_ecommunity = ipv6_ecomm;
58cf5c08
DA
568
569 if (ipv6_ecomm)
570 SET_FLAG(attr->flag,
571 ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES));
572 else
573 UNSET_FLAG(attr->flag,
574 ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES));
d04ac434
DS
575}
576
04fb21e2
DS
577static inline struct transit *bgp_attr_get_transit(const struct attr *attr)
578{
579 return attr->transit;
580}
581
582static inline void bgp_attr_set_transit(struct attr *attr,
583 struct transit *transit)
584{
585 attr->transit = transit;
586}
779fee93
DS
587
588static inline struct cluster_list *bgp_attr_get_cluster(const struct attr *attr)
589{
590 return attr->cluster1;
591}
592
593static inline void bgp_attr_set_cluster(struct attr *attr,
594 struct cluster_list *cl)
595{
596 attr->cluster1 = cl;
597}
6c924775
DS
598
599static inline const struct bgp_route_evpn *
600bgp_attr_get_evpn_overlay(const struct attr *attr)
601{
602 return &attr->evpn_overlay;
603}
604
605static inline void bgp_attr_set_evpn_overlay(struct attr *attr,
606 struct bgp_route_evpn *eo)
607{
608 memcpy(&attr->evpn_overlay, eo, sizeof(struct bgp_route_evpn));
609}
610
91ebf12c
DS
611static inline struct bgp_attr_encap_subtlv *
612bgp_attr_get_vnc_subtlvs(const struct attr *attr)
613{
614#ifdef ENABLE_BGP_VNC
615 return attr->vnc_subtlvs;
616#else
617 return NULL;
618#endif
619}
620
621static inline void
622bgp_attr_set_vnc_subtlvs(struct attr *attr,
623 struct bgp_attr_encap_subtlv *vnc_subtlvs)
624{
625#ifdef ENABLE_BGP_VNC
626 attr->vnc_subtlvs = vnc_subtlvs;
627#endif
628}
629
00d252cb 630#endif /* _QUAGGA_BGP_ATTR_H */