blob: 4cb706784d107fa79c8d72d6f3085b8b9939235d [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* 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
paul00d252c2005-05-23 14:19:54 +000021#ifndef _QUAGGA_BGP_ATTR_H
22#define _QUAGGA_BGP_ATTR_H
23
paul718e3742002-12-13 20:15:29 +000024/* 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
paul3b424972003-10-13 09:47:32 +000033#define BGP_MED_MAX UINT32_MAX
34
Paul Jakma03e214c2007-04-29 18:31:07 +000035
paul718e3742002-12-13 20:15:29 +000036/* 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. */
Paul Jakma370b64a2007-12-22 16:49:52 +000047#define BGP_ATTR_MIN_LEN 3 /* Attribute flag, type length. */
Paul Jakma03e214c2007-04-29 18:31:07 +000048#define BGP_ATTR_DEFAULT_WEIGHT 32768
49
Paul Jakmafb982c22007-05-04 20:15:47 +000050/* Additional/uncommon BGP attributes.
51 * lazily allocated as and when a struct attr
52 * requires it.
53 */
54struct attr_extra
paul718e3742002-12-13 20:15:29 +000055{
Paul Jakmafb982c22007-05-04 20:15:47 +000056 /* Multi-Protocol Nexthop, AFI IPv6 */
paul718e3742002-12-13 20:15:29 +000057#ifdef HAVE_IPV6
58 struct in6_addr mp_nexthop_global;
59 struct in6_addr mp_nexthop_local;
60#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000061
paul718e3742002-12-13 20:15:29 +000062 /* Extended Communities attribute. */
63 struct ecommunity *ecommunity;
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000064
65 /* Route-Reflector Cluster attribute */
66 struct cluster_list *cluster;
67
paul718e3742002-12-13 20:15:29 +000068 /* Unknown transitive attribute. */
69 struct transit *transit;
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000070
Paul Jakmafb982c22007-05-04 20:15:47 +000071 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
90/* BGP core attribute structure. */
91struct attr
92{
93 /* AS Path structure */
94 struct aspath *aspath;
95
96 /* Community structure */
97 struct community *community;
98
99 /* Lazily allocated pointer to extra attributes */
100 struct attr_extra *extra;
101
Paul Jakmacbdfbaa2006-03-30 13:20:48 +0000102 /* Reference count of this attribute. */
103 unsigned long refcnt;
104
105 /* Flag of attribute is set or not. */
106 u_int32_t flag;
107
108 /* Apart from in6_addr, the remaining static attributes */
109 struct in_addr nexthop;
110 u_int32_t med;
111 u_int32_t local_pref;
Paul Jakma41367172007-08-06 15:24:51 +0000112
Paul Jakmafb982c22007-05-04 20:15:47 +0000113 /* Path origin attribute */
Paul Jakmacbdfbaa2006-03-30 13:20:48 +0000114 u_char origin;
paul718e3742002-12-13 20:15:29 +0000115};
116
117/* Router Reflector related structure. */
118struct cluster_list
119{
120 unsigned long refcnt;
121 int length;
122 struct in_addr *list;
123};
124
125/* Unknown transit attribute. */
126struct transit
127{
128 unsigned long refcnt;
129 int length;
130 u_char *val;
131};
132
133#define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
134
135/* Prototypes. */
paul94f2b392005-06-28 12:44:16 +0000136extern void bgp_attr_init (void);
Chris Caputo228da422009-07-18 05:44:03 +0000137extern void bgp_attr_finish (void);
paul94f2b392005-06-28 12:44:16 +0000138extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
paul718e3742002-12-13 20:15:29 +0000139 struct bgp_nlri *, struct bgp_nlri *);
paul94f2b392005-06-28 12:44:16 +0000140extern int bgp_attr_check (struct peer *, struct attr *);
Paul Jakmafb982c22007-05-04 20:15:47 +0000141extern struct attr_extra *bgp_attr_extra_get (struct attr *);
142extern void bgp_attr_extra_free (struct attr *);
143extern void bgp_attr_dup (struct attr *, struct attr *);
paul94f2b392005-06-28 12:44:16 +0000144extern struct attr *bgp_attr_intern (struct attr *attr);
145extern void bgp_attr_unintern (struct attr *);
146extern void bgp_attr_flush (struct attr *);
147extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
148extern struct attr *bgp_attr_default_intern (u_char);
149extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
paul5228ad22004-06-04 17:58:18 +0000150 struct aspath *,
151 struct community *, int as_set);
paul94f2b392005-06-28 12:44:16 +0000152extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
paul5228ad22004-06-04 17:58:18 +0000153 struct stream *, struct attr *,
154 struct prefix *, afi_t, safi_t,
Paul Jakmaa3b6ea52006-05-04 07:52:12 +0000155 struct peer *, struct prefix_rd *, u_char *);
paul94f2b392005-06-28 12:44:16 +0000156extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
paul5228ad22004-06-04 17:58:18 +0000157 struct prefix *p, afi_t, safi_t,
Paul Jakmaa3b6ea52006-05-04 07:52:12 +0000158 struct prefix_rd *, u_char *);
paul94f2b392005-06-28 12:44:16 +0000159extern void bgp_dump_routes_attr (struct stream *, struct attr *,
160 struct prefix *);
Stephen Hemmingerffe11cf2008-08-14 16:25:25 +0100161extern int attrhash_cmp (const void *, const void *);
Paul Jakma923de652007-04-29 18:25:17 +0000162extern unsigned int attrhash_key_make (void *);
paul94f2b392005-06-28 12:44:16 +0000163extern void attr_show_all (struct vty *);
Paul Jakmacbdfbaa2006-03-30 13:20:48 +0000164extern unsigned long int attr_count (void);
165extern unsigned long int attr_unknown_count (void);
paul718e3742002-12-13 20:15:29 +0000166
167/* Cluster list prototypes. */
paul94f2b392005-06-28 12:44:16 +0000168extern int cluster_loop_check (struct cluster_list *, struct in_addr);
169extern void cluster_unintern (struct cluster_list *);
paul718e3742002-12-13 20:15:29 +0000170
171/* Transit attribute prototypes. */
172void transit_unintern (struct transit *);
paul00d252c2005-05-23 14:19:54 +0000173
Paul Jakma03292802008-06-07 20:37:10 +0000174/* Exported for unit-test purposes only */
Denis Ovsienkoefb2c332011-10-10 21:08:33 +0400175extern int bgp_mp_reach_parse (struct peer *, const bgp_size_t, struct attr *,
176 const u_char, u_char *, struct bgp_nlri *);
177extern int bgp_mp_unreach_parse (struct peer *, const bgp_size_t, const u_char,
178 u_char *, struct bgp_nlri *);
Paul Jakma03292802008-06-07 20:37:10 +0000179
paul00d252c2005-05-23 14:19:54 +0000180#endif /* _QUAGGA_BGP_ATTR_H */