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 | |
| 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 | |
paul | 3b42497 | 2003-10-13 09:47:32 +0000 | [diff] [blame^] | 30 | #define BGP_MED_MAX UINT32_MAX |
| 31 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 32 | /* 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. */ |
| 46 | struct 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. */ |
| 87 | struct cluster_list |
| 88 | { |
| 89 | unsigned long refcnt; |
| 90 | int length; |
| 91 | struct in_addr *list; |
| 92 | }; |
| 93 | |
| 94 | /* Unknown transit attribute. */ |
| 95 | struct 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. */ |
| 105 | void bgp_attr_init (); |
| 106 | int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t, |
| 107 | struct bgp_nlri *, struct bgp_nlri *); |
| 108 | int bgp_attr_check (struct peer *, struct attr *); |
| 109 | struct attr *bgp_attr_intern (struct attr *attr); |
| 110 | void bgp_attr_unintern (struct attr *); |
| 111 | void bgp_attr_flush (struct attr *); |
| 112 | struct attr *bgp_attr_default_set (struct attr *attr, u_char); |
| 113 | struct attr *bgp_attr_default_intern (u_char); |
| 114 | struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char, struct aspath *, struct community *, int as_set); |
| 115 | bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *, struct stream *, struct attr *, struct prefix *, afi_t, safi_t, struct peer *, struct prefix_rd *, u_char *); |
| 116 | bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s, struct prefix *p, afi_t, safi_t, struct prefix_rd *, u_char *); |
| 117 | void bgp_dump_routes_attr (struct stream *, struct attr *); |
| 118 | unsigned int attrhash_key_make (struct attr *); |
| 119 | int attrhash_cmp (struct attr *, struct attr *); |
| 120 | void attr_show_all (struct vty *); |
| 121 | |
| 122 | /* Cluster list prototypes. */ |
| 123 | int cluster_loop_check (struct cluster_list *, struct in_addr); |
| 124 | void cluster_unintern (struct cluster_list *); |
| 125 | |
| 126 | /* Transit attribute prototypes. */ |
| 127 | void transit_unintern (struct transit *); |