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 | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 35 | /* 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. */ |
| 49 | struct attr |
| 50 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | /* Attributes. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 52 | #ifdef HAVE_IPV6 |
| 53 | struct in6_addr mp_nexthop_global; |
| 54 | struct in6_addr mp_nexthop_local; |
| 55 | #endif /* HAVE_IPV6 */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | |
| 57 | /* AS Path structure */ |
| 58 | struct aspath *aspath; |
| 59 | |
| 60 | /* Community structure */ |
| 61 | struct community *community; |
| 62 | |
| 63 | /* Extended Communities attribute. */ |
| 64 | struct ecommunity *ecommunity; |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 65 | |
| 66 | /* Route-Reflector Cluster attribute */ |
| 67 | struct cluster_list *cluster; |
| 68 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 69 | /* Unknown transitive attribute. */ |
| 70 | struct transit *transit; |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 71 | |
| 72 | /* Reference count of this attribute. */ |
| 73 | unsigned long refcnt; |
| 74 | |
| 75 | /* Flag of attribute is set or not. */ |
| 76 | u_int32_t flag; |
| 77 | |
| 78 | /* Apart from in6_addr, the remaining static attributes */ |
| 79 | struct in_addr nexthop; |
| 80 | u_int32_t med; |
| 81 | u_int32_t local_pref; |
| 82 | struct in_addr aggregator_addr; |
| 83 | struct in_addr originator_id; |
| 84 | struct in_addr mp_nexthop_global_in; |
| 85 | struct in_addr mp_nexthop_local_in; |
| 86 | u_int32_t weight; |
| 87 | as_t aggregator_as; |
| 88 | u_char origin; |
| 89 | u_char mp_nexthop_len; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
| 92 | /* Router Reflector related structure. */ |
| 93 | struct cluster_list |
| 94 | { |
| 95 | unsigned long refcnt; |
| 96 | int length; |
| 97 | struct in_addr *list; |
| 98 | }; |
| 99 | |
| 100 | /* Unknown transit attribute. */ |
| 101 | struct transit |
| 102 | { |
| 103 | unsigned long refcnt; |
| 104 | int length; |
| 105 | u_char *val; |
| 106 | }; |
| 107 | |
| 108 | #define ATTR_FLAG_BIT(X) (1 << ((X) - 1)) |
| 109 | |
| 110 | /* Prototypes. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 111 | extern void bgp_attr_init (void); |
| 112 | extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | struct bgp_nlri *, struct bgp_nlri *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 114 | extern int bgp_attr_check (struct peer *, struct attr *); |
| 115 | extern struct attr *bgp_attr_intern (struct attr *attr); |
| 116 | extern void bgp_attr_unintern (struct attr *); |
| 117 | extern void bgp_attr_flush (struct attr *); |
| 118 | extern struct attr *bgp_attr_default_set (struct attr *attr, u_char); |
| 119 | extern struct attr *bgp_attr_default_intern (u_char); |
| 120 | extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 121 | struct aspath *, |
| 122 | struct community *, int as_set); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 123 | extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 124 | struct stream *, struct attr *, |
| 125 | struct prefix *, afi_t, safi_t, |
Paul Jakma | a3b6ea5 | 2006-05-04 07:52:12 +0000 | [diff] [blame^] | 126 | struct peer *, struct prefix_rd *, u_char *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 127 | extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s, |
paul | 5228ad2 | 2004-06-04 17:58:18 +0000 | [diff] [blame] | 128 | struct prefix *p, afi_t, safi_t, |
Paul Jakma | a3b6ea5 | 2006-05-04 07:52:12 +0000 | [diff] [blame^] | 129 | struct prefix_rd *, u_char *); |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 130 | extern void bgp_dump_routes_attr (struct stream *, struct attr *, |
| 131 | struct prefix *); |
| 132 | extern unsigned int attrhash_key_make (struct attr *); |
| 133 | extern int attrhash_cmp (struct attr *, struct attr *); |
| 134 | extern void attr_show_all (struct vty *); |
Paul Jakma | cbdfbaa | 2006-03-30 13:20:48 +0000 | [diff] [blame] | 135 | extern unsigned long int attr_count (void); |
| 136 | extern unsigned long int attr_unknown_count (void); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 137 | |
| 138 | /* Cluster list prototypes. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 139 | extern int cluster_loop_check (struct cluster_list *, struct in_addr); |
| 140 | extern void cluster_unintern (struct cluster_list *); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 141 | |
| 142 | /* Transit attribute prototypes. */ |
| 143 | void transit_unintern (struct transit *); |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 144 | |
| 145 | #endif /* _QUAGGA_BGP_ATTR_H */ |