bgp_attr.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 3 /* Attribute flag, type length. */
  35. #define BGP_ATTR_DEFAULT_WEIGHT 32768
  36. /* Additional/uncommon BGP attributes.
  37. * lazily allocated as and when a struct attr
  38. * requires it.
  39. */
  40. struct attr_extra
  41. {
  42. /* Multi-Protocol Nexthop, AFI IPv6 */
  43. #ifdef HAVE_IPV6
  44. struct in6_addr mp_nexthop_global;
  45. struct in6_addr mp_nexthop_local;
  46. #endif /* HAVE_IPV6 */
  47. /* Extended Communities attribute. */
  48. struct ecommunity *ecommunity;
  49. /* Route-Reflector Cluster attribute */
  50. struct cluster_list *cluster;
  51. /* Unknown transitive attribute. */
  52. struct transit *transit;
  53. struct in_addr mp_nexthop_global_in;
  54. struct in_addr mp_nexthop_local_in;
  55. /* Aggregator Router ID attribute */
  56. struct in_addr aggregator_addr;
  57. /* Route Reflector Originator attribute */
  58. struct in_addr originator_id;
  59. /* Local weight, not actually an attribute */
  60. u_int32_t weight;
  61. /* Aggregator ASN */
  62. as_t aggregator_as;
  63. /* MP Nexthop length */
  64. u_char mp_nexthop_len;
  65. };
  66. /* BGP core attribute structure. */
  67. struct attr
  68. {
  69. /* AS Path structure */
  70. struct aspath *aspath;
  71. /* Community structure */
  72. struct community *community;
  73. /* Lazily allocated pointer to extra attributes */
  74. struct attr_extra *extra;
  75. /* Reference count of this attribute. */
  76. unsigned long refcnt;
  77. /* Flag of attribute is set or not. */
  78. u_int32_t flag;
  79. /* Apart from in6_addr, the remaining static attributes */
  80. struct in_addr nexthop;
  81. u_int32_t med;
  82. u_int32_t local_pref;
  83. /* AS-Pathlimit */
  84. struct {
  85. u_int32_t as;
  86. u_char ttl;
  87. } pathlimit;
  88. /* Path origin attribute */
  89. u_char origin;
  90. };
  91. /* Router Reflector related structure. */
  92. struct cluster_list
  93. {
  94. unsigned long refcnt;
  95. int length;
  96. struct in_addr *list;
  97. };
  98. /* Unknown transit attribute. */
  99. struct transit
  100. {
  101. unsigned long refcnt;
  102. int length;
  103. u_char *val;
  104. };
  105. #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
  106. /* Prototypes. */
  107. extern void bgp_attr_init (void);
  108. extern int bgp_attr_parse (struct peer *, struct attr *, bgp_size_t,
  109. struct bgp_nlri *, struct bgp_nlri *);
  110. extern int bgp_attr_check (struct peer *, struct attr *);
  111. extern struct attr_extra *bgp_attr_extra_get (struct attr *);
  112. extern void bgp_attr_extra_free (struct attr *);
  113. extern void bgp_attr_dup (struct attr *, struct attr *);
  114. extern struct attr *bgp_attr_intern (struct attr *attr);
  115. extern void bgp_attr_unintern (struct attr *);
  116. extern void bgp_attr_flush (struct attr *);
  117. extern struct attr *bgp_attr_default_set (struct attr *attr, u_char);
  118. extern struct attr *bgp_attr_default_intern (u_char);
  119. extern struct attr *bgp_attr_aggregate_intern (struct bgp *, u_char,
  120. struct aspath *,
  121. struct community *, int as_set);
  122. extern bgp_size_t bgp_packet_attribute (struct bgp *bgp, struct peer *,
  123. struct stream *, struct attr *,
  124. struct prefix *, afi_t, safi_t,
  125. struct peer *, struct prefix_rd *, u_char *);
  126. extern bgp_size_t bgp_packet_withdraw (struct peer *peer, struct stream *s,
  127. struct prefix *p, afi_t, safi_t,
  128. struct prefix_rd *, u_char *);
  129. extern void bgp_dump_routes_attr (struct stream *, struct attr *,
  130. struct prefix *);
  131. extern int attrhash_cmp (void *, void *);
  132. extern unsigned int attrhash_key_make (void *);
  133. extern void attr_show_all (struct vty *);
  134. extern unsigned long int attr_count (void);
  135. extern unsigned long int attr_unknown_count (void);
  136. /* Cluster list prototypes. */
  137. extern int cluster_loop_check (struct cluster_list *, struct in_addr);
  138. extern void cluster_unintern (struct cluster_list *);
  139. /* Transit attribute prototypes. */
  140. void transit_unintern (struct transit *);
  141. #endif /* _QUAGGA_BGP_ATTR_H */