]> git.proxmox.com Git - mirror_frr.git/blame - bgpd/bgp_attr.h
zebra, bgpd, ospfd: 'redistribute table' to 'redistribute table <table-id>'
[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
52#define BGP_ATTR_NHLEN_VPNV4 12
53#define BGP_ATTR_NHLEN_IPV6_GLOBAL IPV6_MAX_BYTELEN
54#define BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL (IPV6_MAX_BYTELEN * 2)
55
fb982c25
PJ
56/* Additional/uncommon BGP attributes.
57 * lazily allocated as and when a struct attr
58 * requires it.
59 */
60struct attr_extra
718e3744 61{
fb982c25 62 /* Multi-Protocol Nexthop, AFI IPv6 */
718e3744 63#ifdef HAVE_IPV6
64 struct in6_addr mp_nexthop_global;
65 struct in6_addr mp_nexthop_local;
66#endif /* HAVE_IPV6 */
718e3744 67
718e3744 68 /* Extended Communities attribute. */
69 struct ecommunity *ecommunity;
cbdfbaa5
PJ
70
71 /* Route-Reflector Cluster attribute */
72 struct cluster_list *cluster;
73
718e3744 74 /* Unknown transitive attribute. */
75 struct transit *transit;
cbdfbaa5 76
fb982c25
PJ
77 struct in_addr mp_nexthop_global_in;
78 struct in_addr mp_nexthop_local_in;
79
80 /* Aggregator Router ID attribute */
81 struct in_addr aggregator_addr;
82
83 /* Route Reflector Originator attribute */
84 struct in_addr originator_id;
85
86 /* Local weight, not actually an attribute */
87 u_int32_t weight;
88
89 /* Aggregator ASN */
90 as_t aggregator_as;
91
92 /* MP Nexthop length */
93 u_char mp_nexthop_len;
0d9551dc
DS
94
95 /* route tag */
96 u_short tag;
fb982c25
PJ
97};
98
99/* BGP core attribute structure. */
100struct attr
101{
102 /* AS Path structure */
103 struct aspath *aspath;
104
105 /* Community structure */
106 struct community *community;
107
108 /* Lazily allocated pointer to extra attributes */
109 struct attr_extra *extra;
110
cbdfbaa5
PJ
111 /* Reference count of this attribute. */
112 unsigned long refcnt;
113
114 /* Flag of attribute is set or not. */
115 u_int32_t flag;
116
117 /* Apart from in6_addr, the remaining static attributes */
118 struct in_addr nexthop;
119 u_int32_t med;
120 u_int32_t local_pref;
bc413143 121 u_int32_t nh_ifindex;
41367172 122
fb982c25 123 /* Path origin attribute */
cbdfbaa5 124 u_char origin;
3f9c7369
DS
125
126 /* has the route-map changed any attribute?
127 Used on the peer outbound side. */
128 u_int32_t rmap_change_flags;
718e3744 129};
130
3f9c7369
DS
131/* rmap_change_flags definition */
132#define BATTR_RMAP_NEXTHOP_CHANGED (1 << 0)
133#define BATTR_RMAP_NEXTHOP_PEER_ADDRESS (1 << 1)
134#define BATTR_REFLECTED (1 << 2)
316e074d 135#define BATTR_RMAP_NEXTHOP_UNCHANGED (1 << 3)
3f9c7369 136
718e3744 137/* Router Reflector related structure. */
138struct cluster_list
139{
140 unsigned long refcnt;
141 int length;
142 struct in_addr *list;
143};
144
145/* Unknown transit attribute. */
146struct transit
147{
148 unsigned long refcnt;
149 int length;
150 u_char *val;
151};
152
153#define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
154
5e242b0d
DS
155#define BGP_CLUSTER_LIST_LENGTH(attr) \
156 (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) ? \
157 (attr)->extra->cluster->length : 0)
158
b881c707
PJ
159typedef enum {
160 BGP_ATTR_PARSE_PROCEED = 0,
161 BGP_ATTR_PARSE_ERROR = -1,
162 BGP_ATTR_PARSE_WITHDRAW = -2,
f57000c0
DL
163
164 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR */
165 BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
b881c707
PJ
166} bgp_attr_parse_ret_t;
167
3f9c7369
DS
168struct bpacket_attr_vec_arr;
169
718e3744 170/* Prototypes. */
94f2b392 171extern void bgp_attr_init (void);
228da428 172extern void bgp_attr_finish (void);
b881c707
PJ
173extern bgp_attr_parse_ret_t bgp_attr_parse (struct peer *, struct attr *,
174 bgp_size_t, struct bgp_nlri *,
175 struct bgp_nlri *);
94f2b392 176extern int bgp_attr_check (struct peer *, struct attr *);
fb982c25
PJ
177extern struct attr_extra *bgp_attr_extra_get (struct attr *);
178extern void bgp_attr_extra_free (struct attr *);
179extern void bgp_attr_dup (struct attr *, struct attr *);
73ac8160
DS
180extern void bgp_attr_deep_dup (struct attr *, struct attr *);
181extern void bgp_attr_deep_free (struct attr *);
94f2b392 182extern struct attr *bgp_attr_intern (struct attr *attr);
3f9c7369 183extern struct attr *bgp_attr_refcount (struct attr *attr);
b881c707 184extern void bgp_attr_unintern_sub (struct attr *);
f6f434b2 185extern void bgp_attr_unintern (struct attr **);
94f2b392 186extern void bgp_attr_flush (struct attr *);
187extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
188extern struct attr *bgp_attr_default_intern (u_char);
189extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
5228ad27 190 struct aspath *,
42f7e184 191 struct community *, int as_set, u_char);
8c71e481
PM
192extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
193 struct stream *, struct attr *,
3f9c7369 194 struct bpacket_attr_vec_arr *vecarr,
8c71e481
PM
195 struct prefix *, afi_t, safi_t,
196 struct peer *, struct prefix_rd *,
197 u_char *);
94f2b392 198extern void bgp_dump_routes_attr (struct stream *, struct attr *,
199 struct prefix *);
ffe11cfb 200extern int attrhash_cmp (const void *, const void *);
923de654 201extern unsigned int attrhash_key_make (void *);
94f2b392 202extern void attr_show_all (struct vty *);
cbdfbaa5
PJ
203extern unsigned long int attr_count (void);
204extern unsigned long int attr_unknown_count (void);
718e3744 205
206/* Cluster list prototypes. */
94f2b392 207extern int cluster_loop_check (struct cluster_list *, struct in_addr);
208extern void cluster_unintern (struct cluster_list *);
718e3744 209
210/* Transit attribute prototypes. */
211void transit_unintern (struct transit *);
00d252cb 212
835315bf
PJ
213/* Below exported for unit-test purposes only */
214struct bgp_attr_parser_args {
215 struct peer *peer;
216 bgp_size_t length; /* attribute data length; */
217 bgp_size_t total; /* total length, inc header */
218 struct attr *attr;
219 u_int8_t type;
220 u_int8_t flags;
221 u_char *startp;
222};
223extern int bgp_mp_reach_parse (struct bgp_attr_parser_args *args,
224 struct bgp_nlri *);
225extern int bgp_mp_unreach_parse (struct bgp_attr_parser_args *args,
226 struct bgp_nlri *);
03292809 227
8c71e481
PM
228/**
229 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
230 * Typical call sequence is to call _start(), followed by multiple _prefix(),
231 * one for each NLRI that needs to be encoded into the UPDATE message, and
232 * finally the _end() function.
233 */
234extern size_t bgp_packet_mpattr_start(struct stream *s, afi_t afi, safi_t safi,
3f9c7369 235 struct bpacket_attr_vec_arr *vecarr,
8c71e481
PM
236 struct attr *attr);
237extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
238 struct prefix *p, struct prefix_rd *prd,
239 u_char *tag);
240extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
241
242extern size_t bgp_packet_mpunreach_start (struct stream *s, afi_t afi,
243 safi_t safi);
244extern void bgp_packet_mpunreach_prefix (struct stream *s, struct prefix *p,
245 afi_t afi, safi_t safi, struct prefix_rd *prd,
246 u_char *tag);
247extern void bgp_packet_mpunreach_end (struct stream *s, size_t attrlen_pnt);
248
00d252cb 249#endif /* _QUAGGA_BGP_ATTR_H */