paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 21 | #ifndef _QUAGGA_BGP_ATTR_H |
| 22 | #define _QUAGGA_BGP_ATTR_H |
| 23 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 | |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame] | 33 | #define BGP_MED_MAX UINT32_MAX |
| 34 | |
Paul Jakma | 03e214c | 2007-04-29 18:31:07 +0000 | [diff] [blame] | 35 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 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 2 /* Attribute flag and type. */ |
Paul Jakma | 03e214c | 2007-04-29 18:31:07 +0000 | [diff] [blame] | 48 | #define BGP_ATTR_DEFAULT_WEIGHT 32768 |
| 49 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 50 | /* Additional/uncommon BGP attributes. |
| 51 | * lazily allocated as and when a struct attr |
| 52 | * requires it. |
| 53 | */ |
| 54 | struct attr_extra |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 55 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 56 | /* Multi-Protocol Nexthop, AFI IPv6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | #ifdef HAVE_IPV6 |
| 58 | struct in6_addr mp_nexthop_global; |
| 59 | struct in6_addr mp_nexthop_local; |
| 60 | #endif /* HAVE_IPV6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 61 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 62 | /* Extended Communities attribute. */ |
| 63 | struct ecommunity *ecommunity; |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 64 | |
| 65 | /* Route-Reflector Cluster attribute */ |
| 66 | struct cluster_list *cluster; |
| 67 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | /* Unknown transitive attribute. */ |
| 69 | struct transit *transit; |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 70 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 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 | |
| 90 | /* BGP core attribute structure. */ |
| 91 | struct 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 Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 102 | /* 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 Jakma | 4136717 | 2007-08-06 15:24:51 +0000 | [diff] [blame] | 112 | |
| 113 | /* AS-Pathlimit */ |
| 114 | struct { |
| 115 | u_int32_t as; |
| 116 | u_char ttl; |
| 117 | } pathlimit; |
| 118 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 119 | /* Path origin attribute */ |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 120 | u_char origin; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | /* Router Reflector related structure. */ |
| 124 | struct cluster_list |
| 125 | { |
| 126 | unsigned long refcnt; |
| 127 | int length; |
| 128 | struct in_addr *list; |
| 129 | }; |
| 130 | |
| 131 | /* Unknown transit attribute. */ |
| 132 | struct transit |
| 133 | { |
| 134 | unsigned long refcnt; |
| 135 | int length; |
| 136 | u_char *val; |
| 137 | }; |
| 138 | |
| 139 | #define ATTR_FLAG_BIT(X) (1 << ((X) - 1)) |
| 140 | |
| 141 | /* Prototypes. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 142 | extern void bgp_attr_init (void); |
| 143 | extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 144 | struct bgp_nlri *, struct bgp_nlri *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 145 | extern int bgp_attr_check (struct peer *, struct attr *); |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 146 | extern struct attr_extra *bgp_attr_extra_get (struct attr *); |
| 147 | extern void bgp_attr_extra_free (struct attr *); |
| 148 | extern void bgp_attr_dup (struct attr *, struct attr *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 149 | extern struct attr *bgp_attr_intern (struct attr *attr); |
| 150 | extern void bgp_attr_unintern (struct attr *); |
| 151 | extern void bgp_attr_flush (struct attr *); |
| 152 | extern struct attr *bgp_attr_default_set (struct attr *attr, u_char); |
| 153 | extern struct attr *bgp_attr_default_intern (u_char); |
| 154 | extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 155 | struct aspath *, |
| 156 | struct community *, int as_set); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 157 | extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 158 | struct stream *, struct attr *, |
| 159 | struct prefix *, afi_t, safi_t, |
Paul Jakma | a3b6ea5 | 2006-05-04 07:52:12 +0000 | [diff] [blame] | 160 | struct peer *, struct prefix_rd *, u_char *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 161 | extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 162 | struct prefix *p, afi_t, safi_t, |
Paul Jakma | a3b6ea5 | 2006-05-04 07:52:12 +0000 | [diff] [blame] | 163 | struct prefix_rd *, u_char *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 164 | extern void bgp_dump_routes_attr (struct stream *, struct attr *, |
| 165 | struct prefix *); |
Paul Jakma | 923de65 | 2007-04-29 18:25:17 +0000 | [diff] [blame] | 166 | extern int attrhash_cmp (void *, void *); |
| 167 | extern unsigned int attrhash_key_make (void *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 168 | extern void attr_show_all (struct vty *); |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 169 | extern unsigned long int attr_count (void); |
| 170 | extern unsigned long int attr_unknown_count (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 171 | |
| 172 | /* Cluster list prototypes. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 173 | extern int cluster_loop_check (struct cluster_list *, struct in_addr); |
| 174 | extern void cluster_unintern (struct cluster_list *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 175 | |
| 176 | /* Transit attribute prototypes. */ |
| 177 | void transit_unintern (struct transit *); |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 178 | |
| 179 | #endif /* _QUAGGA_BGP_ATTR_H */ |