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