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