2 Copyright (C) 1996, 97, 98 Kunihiro Ishiguro
4 This file is part of GNU Zebra.
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
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.
16 You should have received a copy of the GNU General Public License
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21 #ifndef _QUAGGA_BGP_ATTR_H
22 #define _QUAGGA_BGP_ATTR_H
24 /* Simple bit mapping. */
27 #define SET_BITMAP(MAP, NUM) \
28 SET_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
30 #define CHECK_BITMAP(MAP, NUM) \
31 CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
33 #define BGP_MED_MAX UINT32_MAX
36 /* BGP Attribute type range. */
37 #define BGP_ATTR_TYPE_RANGE 256
38 #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
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. */
46 /* BGP attribute header must bigger than 2. */
47 #define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */
48 #define BGP_ATTR_DEFAULT_WEIGHT 32768
50 struct bgp_attr_encap_subtlv {
51 struct bgp_attr_encap_subtlv *next; /* for chaining */
54 uint8_t value[1]; /* will be extended */
57 /* Additional/uncommon BGP attributes.
58 * lazily allocated as and when a struct attr
63 /* Multi-Protocol Nexthop, AFI IPv6 */
64 struct in6_addr mp_nexthop_global;
65 struct in6_addr mp_nexthop_local;
67 /* Extended Communities attribute. */
68 struct ecommunity *ecommunity;
70 /* Large Communities attribute. */
71 struct lcommunity *lcommunity;
73 /* Route-Reflector Cluster attribute */
74 struct cluster_list *cluster;
76 /* Unknown transitive attribute. */
77 struct transit *transit;
79 struct in_addr mp_nexthop_global_in;
81 /* Aggregator Router ID attribute */
82 struct in_addr aggregator_addr;
84 /* Route Reflector Originator attribute */
85 struct in_addr originator_id;
87 /* Local weight, not actually an attribute */
93 /* MP Nexthop length */
94 u_char mp_nexthop_len;
96 uint16_t encap_tunneltype; /* grr */
97 struct bgp_attr_encap_subtlv *encap_subtlvs; /* rfc5512 */
103 /* BGP core attribute structure. */
106 /* AS Path structure */
107 struct aspath *aspath;
109 /* Community structure */
110 struct community *community;
112 /* Lazily allocated pointer to extra attributes */
113 struct attr_extra *extra;
115 /* Reference count of this attribute. */
116 unsigned long refcnt;
118 /* Flag of attribute is set or not. */
121 /* Apart from in6_addr, the remaining static attributes */
122 struct in_addr nexthop;
124 u_int32_t local_pref;
126 /* Path origin attribute */
130 /* Router Reflector related structure. */
133 unsigned long refcnt;
135 struct in_addr *list;
138 /* Unknown transit attribute. */
141 unsigned long refcnt;
146 #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
149 BGP_ATTR_PARSE_PROCEED = 0,
150 BGP_ATTR_PARSE_ERROR = -1,
151 BGP_ATTR_PARSE_WITHDRAW = -2,
153 /* only used internally, send notify + convert to BGP_ATTR_PARSE_ERROR */
154 BGP_ATTR_PARSE_ERROR_NOTIFYPLS = -3,
155 } bgp_attr_parse_ret_t;
158 extern void bgp_attr_init (void);
159 extern void bgp_attr_finish (void);
160 extern bgp_attr_parse_ret_t bgp_attr_parse (struct peer *, struct attr *,
161 bgp_size_t, struct bgp_nlri *,
163 extern struct attr_extra *bgp_attr_extra_get (struct attr *);
164 extern void bgp_attr_extra_free (struct attr *);
165 extern void bgp_attr_dup (struct attr *, struct attr *);
166 extern struct attr *bgp_attr_intern (struct attr *attr);
167 extern void bgp_attr_unintern_sub (struct attr *);
168 extern void bgp_attr_unintern (struct attr **);
169 extern void bgp_attr_flush (struct attr *);
170 extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
171 extern struct attr *bgp_attr_default_intern (u_char);
172 extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
174 struct community *, int as_set, u_char);
175 extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
176 struct stream *, struct attr *,
177 struct prefix *, afi_t, safi_t,
178 struct peer *, struct prefix_rd *,
180 extern void bgp_dump_routes_attr (struct stream *, struct attr *,
182 extern int attrhash_cmp (const void *, const void *);
183 extern unsigned int attrhash_key_make (void *);
184 extern void attr_show_all (struct vty *);
185 extern unsigned long int attr_count (void);
186 extern unsigned long int attr_unknown_count (void);
188 /* Cluster list prototypes. */
189 extern int cluster_loop_check (struct cluster_list *, struct in_addr);
190 extern void cluster_unintern (struct cluster_list **);
192 /* Transit attribute prototypes. */
193 void transit_unintern (struct transit **);
195 /* Below exported for unit-test purposes only */
196 struct bgp_attr_parser_args {
198 bgp_size_t length; /* attribute data length; */
199 bgp_size_t total; /* total length, inc header */
205 extern int bgp_mp_reach_parse (struct bgp_attr_parser_args *args,
207 extern int bgp_mp_unreach_parse (struct bgp_attr_parser_args *args,
210 extern struct bgp_attr_encap_subtlv *
211 encap_tlv_dup(struct bgp_attr_encap_subtlv *orig);
214 bgp_attr_flush_encap(struct attr *attr);
217 * Set of functions to encode MP_REACH_NLRI and MP_UNREACH_NLRI attributes.
218 * Typical call sequence is to call _start(), followed by multiple _prefix(),
219 * one for each NLRI that needs to be encoded into the UPDATE message, and
220 * finally the _end() function.
222 extern size_t bgp_packet_mpattr_start(struct stream *s, afi_t afi, safi_t safi,
224 extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
225 struct prefix *p, struct prefix_rd *prd,
227 extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
229 extern void bgp_packet_mpattr_end(struct stream *s, size_t sizep);
231 extern size_t bgp_packet_mpunreach_start (struct stream *s, afi_t afi,
233 extern void bgp_packet_mpunreach_prefix (struct stream *s, struct prefix *p,
234 afi_t afi, safi_t safi, struct prefix_rd *prd,
236 extern void bgp_packet_mpunreach_end (struct stream *s, size_t attrlen_pnt);
238 #endif /* _QUAGGA_BGP_ATTR_H */