blob: 0734bc270314d6999f9ed9ad803748b8d1ad944f [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. */
47#define BGP_ATTR_MIN_LEN 2 /* Attribute flag and type. */
48
Paul Jakma03e214c2007-04-29 18:31:07 +000049#define BGP_ATTR_DEFAULT_WEIGHT 32768
50
paul718e3742002-12-13 20:15:29 +000051/* BGP attribute structure. */
52struct attr
53{
paul718e3742002-12-13 20:15:29 +000054 /* Attributes. */
paul718e3742002-12-13 20:15:29 +000055#ifdef HAVE_IPV6
56 struct in6_addr mp_nexthop_global;
57 struct in6_addr mp_nexthop_local;
58#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +000059
60 /* AS Path structure */
61 struct aspath *aspath;
62
63 /* Community structure */
64 struct community *community;
65
66 /* Extended Communities attribute. */
67 struct ecommunity *ecommunity;
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000068
69 /* Route-Reflector Cluster attribute */
70 struct cluster_list *cluster;
71
paul718e3742002-12-13 20:15:29 +000072 /* Unknown transitive attribute. */
73 struct transit *transit;
Paul Jakmacbdfbaa2006-03-30 13:20:48 +000074
75 /* Reference count of this attribute. */
76 unsigned long refcnt;
77
78 /* Flag of attribute is set or not. */
79 u_int32_t flag;
80
81 /* Apart from in6_addr, the remaining static attributes */
82 struct in_addr nexthop;
83 u_int32_t med;
84 u_int32_t local_pref;
85 struct in_addr aggregator_addr;
86 struct in_addr originator_id;
87 struct in_addr mp_nexthop_global_in;
88 struct in_addr mp_nexthop_local_in;
89 u_int32_t weight;
90 as_t aggregator_as;
91 u_char origin;
92 u_char mp_nexthop_len;
paul718e3742002-12-13 20:15:29 +000093};
94
95/* Router Reflector related structure. */
96struct cluster_list
97{
98 unsigned long refcnt;
99 int length;
100 struct in_addr *list;
101};
102
103/* Unknown transit attribute. */
104struct transit
105{
106 unsigned long refcnt;
107 int length;
108 u_char *val;
109};
110
111#define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
112
113/* Prototypes. */
paul94f2b392005-06-28 12:44:16 +0000114extern void bgp_attr_init (void);
115extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
paul718e3742002-12-13 20:15:29 +0000116 struct bgp_nlri *, struct bgp_nlri *);
paul94f2b392005-06-28 12:44:16 +0000117extern int bgp_attr_check (struct peer *, struct attr *);
118extern struct attr *bgp_attr_intern (struct attr *attr);
119extern void bgp_attr_unintern (struct attr *);
120extern void bgp_attr_flush (struct attr *);
121extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
122extern struct attr *bgp_attr_default_intern (u_char);
123extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
paul5228ad22004-06-04 17:58:18 +0000124 struct aspath *,
125 struct community *, int as_set);
paul94f2b392005-06-28 12:44:16 +0000126extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
paul5228ad22004-06-04 17:58:18 +0000127 struct stream *, struct attr *,
128 struct prefix *, afi_t, safi_t,
Paul Jakmaa3b6ea52006-05-04 07:52:12 +0000129 struct peer *, struct prefix_rd *, u_char *);
paul94f2b392005-06-28 12:44:16 +0000130extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
paul5228ad22004-06-04 17:58:18 +0000131 struct prefix *p, afi_t, safi_t,
Paul Jakmaa3b6ea52006-05-04 07:52:12 +0000132 struct prefix_rd *, u_char *);
paul94f2b392005-06-28 12:44:16 +0000133extern void bgp_dump_routes_attr (struct stream *, struct attr *,
134 struct prefix *);
Paul Jakma923de652007-04-29 18:25:17 +0000135extern int attrhash_cmp (void *, void *);
136extern unsigned int attrhash_key_make (void *);
paul94f2b392005-06-28 12:44:16 +0000137extern void attr_show_all (struct vty *);
Paul Jakmacbdfbaa2006-03-30 13:20:48 +0000138extern unsigned long int attr_count (void);
139extern unsigned long int attr_unknown_count (void);
paul718e3742002-12-13 20:15:29 +0000140
141/* Cluster list prototypes. */
paul94f2b392005-06-28 12:44:16 +0000142extern int cluster_loop_check (struct cluster_list *, struct in_addr);
143extern void cluster_unintern (struct cluster_list *);
paul718e3742002-12-13 20:15:29 +0000144
145/* Transit attribute prototypes. */
146void transit_unintern (struct transit *);
paul00d252c2005-05-23 14:19:54 +0000147
148#endif /* _QUAGGA_BGP_ATTR_H */