blob: 70e27aed98a6ba6e042fff7dad16a7c3f442b8ee [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
paul718e3742002-12-13 20:15:29 +000035/* BGP Attribute type range. */
36#define BGP_ATTR_TYPE_RANGE 256
37#define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
38
39/* BGP Attribute flags. */
40#define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */
41#define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */
42#define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */
43#define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */
44
45/* BGP attribute header must bigger than 2. */
46#define BGP_ATTR_MIN_LEN 2 /* Attribute flag and type. */
47
48/* BGP attribute structure. */
49struct attr
50{
51 /* Reference count of this attribute. */
52 unsigned long refcnt;
53
54 /* Flag of attribute is set or not. */
55 u_int32_t flag;
56
57 /* Attributes. */
58 u_char origin;
59 struct in_addr nexthop;
60 u_int32_t med;
61 u_int32_t local_pref;
62 as_t aggregator_as;
63 struct in_addr aggregator_addr;
64 u_int32_t weight;
65 struct in_addr originator_id;
66 struct cluster_list *cluster;
67
68 u_char mp_nexthop_len;
69#ifdef HAVE_IPV6
70 struct in6_addr mp_nexthop_global;
71 struct in6_addr mp_nexthop_local;
72#endif /* HAVE_IPV6 */
73 struct in_addr mp_nexthop_global_in;
74 struct in_addr mp_nexthop_local_in;
75
76 /* AS Path structure */
77 struct aspath *aspath;
78
79 /* Community structure */
80 struct community *community;
81
82 /* Extended Communities attribute. */
83 struct ecommunity *ecommunity;
84
85 /* Unknown transitive attribute. */
86 struct transit *transit;
87};
88
89/* Router Reflector related structure. */
90struct cluster_list
91{
92 unsigned long refcnt;
93 int length;
94 struct in_addr *list;
95};
96
97/* Unknown transit attribute. */
98struct transit
99{
100 unsigned long refcnt;
101 int length;
102 u_char *val;
103};
104
105#define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
106
107/* Prototypes. */
108void bgp_attr_init ();
109int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
110 struct bgp_nlri *, struct bgp_nlri *);
111int bgp_attr_check (struct peer *, struct attr *);
112struct attr *bgp_attr_intern (struct attr *attr);
113void bgp_attr_unintern (struct attr *);
114void bgp_attr_flush (struct attr *);
115struct attr *bgp_attr_default_set (struct attr *attr, u_char);
116struct attr *bgp_attr_default_intern (u_char);
paul5228ad22004-06-04 17:58:18 +0000117struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
118 struct aspath *,
119 struct community *, int as_set);
120bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
121 struct stream *, struct attr *,
122 struct prefix *, afi_t, safi_t,
123 struct peer *, struct prefix_rd *, char *);
124bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
125 struct prefix *p, afi_t, safi_t,
126 struct prefix_rd *, char *);
paula3845922003-10-18 01:30:50 +0000127void bgp_dump_routes_attr (struct stream *, struct attr *, struct prefix *);
paul718e3742002-12-13 20:15:29 +0000128unsigned int attrhash_key_make (struct attr *);
129int attrhash_cmp (struct attr *, struct attr *);
130void attr_show_all (struct vty *);
131
132/* Cluster list prototypes. */
133int cluster_loop_check (struct cluster_list *, struct in_addr);
134void cluster_unintern (struct cluster_list *);
135
136/* Transit attribute prototypes. */
137void transit_unintern (struct transit *);
paul00d252c2005-05-23 14:19:54 +0000138
139#endif /* _QUAGGA_BGP_ATTR_H */