bgp_attr.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /* BGP attributes.
  2. Copyright (C) 1996, 97, 98 Kunihiro Ishiguro
  3. This file is part of GNU Zebra.
  4. GNU Zebra is free software; you can redistribute it and/or modify it
  5. under the terms of the GNU General Public License as published by the
  6. Free Software Foundation; either version 2, or (at your option) any
  7. later version.
  8. GNU Zebra is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Zebra; see the file COPYING. If not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  15. 02111-1307, USA. */
  16. #ifndef _QUAGGA_BGP_ATTR_H
  17. #define _QUAGGA_BGP_ATTR_H
  18. /* Simple bit mapping. */
  19. #define BITMAP_NBBY 8
  20. #define SET_BITMAP(MAP, NUM) \
  21. SET_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
  22. #define CHECK_BITMAP(MAP, NUM) \
  23. CHECK_FLAG (MAP[(NUM) / BITMAP_NBBY], 1 << ((NUM) % BITMAP_NBBY))
  24. #define BGP_MED_MAX UINT32_MAX
  25. /* BGP Attribute type range. */
  26. #define BGP_ATTR_TYPE_RANGE 256
  27. #define BGP_ATTR_BITMAP_SIZE (BGP_ATTR_TYPE_RANGE / BITMAP_NBBY)
  28. /* BGP Attribute flags. */
  29. #define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */
  30. #define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */
  31. #define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */
  32. #define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */
  33. /* BGP attribute header must bigger than 2. */
  34. #define BGP_ATTR_MIN_LEN 2 /* Attribute flag and type. */
  35. /* BGP attribute structure. */
  36. struct attr
  37. {
  38. /* Reference count of this attribute. */
  39. unsigned long refcnt;
  40. /* Flag of attribute is set or not. */
  41. u_int32_t flag;
  42. /* Attributes. */
  43. u_char origin;
  44. struct in_addr nexthop;
  45. u_int32_t med;
  46. u_int32_t local_pref;
  47. as_t aggregator_as;
  48. struct in_addr aggregator_addr;
  49. u_int32_t weight;
  50. struct in_addr originator_id;
  51. struct cluster_list *cluster;
  52. u_char mp_nexthop_len;
  53. #ifdef HAVE_IPV6
  54. struct in6_addr mp_nexthop_global;
  55. struct in6_addr mp_nexthop_local;
  56. #endif /* HAVE_IPV6 */
  57. struct in_addr mp_nexthop_global_in;
  58. struct in_addr mp_nexthop_local_in;
  59. /* AS Path structure */
  60. struct aspath *aspath;
  61. /* Community structure */
  62. struct community *community;
  63. /* Extended Communities attribute. */
  64. struct ecommunity *ecommunity;
  65. /* Unknown transitive attribute. */
  66. struct transit *transit;
  67. };
  68. /* Router Reflector related structure. */
  69. struct cluster_list
  70. {
  71. unsigned long refcnt;
  72. int length;
  73. struct in_addr *list;
  74. };
  75. /* Unknown transit attribute. */
  76. struct transit
  77. {
  78. unsigned long refcnt;
  79. int length;
  80. u_char *val;
  81. };
  82. #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
  83. /* Prototypes. */
  84. extern void bgp_attr_init (void);
  85. extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
  86. struct bgp_nlri *, struct bgp_nlri *);
  87. extern int bgp_attr_check (struct peer *, struct attr *);
  88. extern struct attr *bgp_attr_intern (struct attr *attr);
  89. extern void bgp_attr_unintern (struct attr *);
  90. extern void bgp_attr_flush (struct attr *);
  91. extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
  92. extern struct attr *bgp_attr_default_intern (u_char);
  93. extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
  94. struct aspath *,
  95. struct community *, int as_set);
  96. extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
  97. struct stream *, struct attr *,
  98. struct prefix *, afi_t, safi_t,
  99. struct peer *, struct prefix_rd *, char *);
  100. extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
  101. struct prefix *p, afi_t, safi_t,
  102. struct prefix_rd *, char *);
  103. extern void bgp_dump_routes_attr (struct stream *, struct attr *,
  104. struct prefix *);
  105. extern unsigned int attrhash_key_make (struct attr *);
  106. extern int attrhash_cmp (struct attr *, struct attr *);
  107. extern void attr_show_all (struct vty *);
  108. /* Cluster list prototypes. */
  109. extern int cluster_loop_check (struct cluster_list *, struct in_addr);
  110. extern void cluster_unintern (struct cluster_list *);
  111. /* Transit attribute prototypes. */
  112. void transit_unintern (struct transit *);
  113. #endif /* _QUAGGA_BGP_ATTR_H */