bgpdump_attr.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /*
  2. Copyright (c) 2007 - 2010 RIPE NCC - All Rights Reserved
  3. Permission to use, copy, modify, and distribute this software and its
  4. documentation for any purpose and without fee is hereby granted, provided
  5. that the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation, and that the name of the author not be used in advertising or
  8. publicity pertaining to distribution of the software without specific,
  9. written prior permission.
  10. THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  11. ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
  12. AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
  13. DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  14. AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  15. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  16. Parts of this code have been engineered after analiyzing GNU Zebra's
  17. source code and therefore might contain declarations/code from GNU
  18. Zebra, Copyright (C) 1999 Kunihiro Ishiguro. Zebra is a free routing
  19. software, distributed under the GNU General Public License. A copy of
  20. this license is included with libbgpdump.
  21. Original Author: Dan Ardelean (dan@ripe.net)
  22. */
  23. #ifndef _BGPDUMP_ATTR_H
  24. #define _BGPDUMP_ATTR_H
  25. #include <sys/types.h>
  26. #include <netinet/in.h>
  27. /* BGP Attribute flags. */
  28. #define BGP_ATTR_FLAG_OPTIONAL 0x80 /* Attribute is optional. */
  29. #define BGP_ATTR_FLAG_TRANS 0x40 /* Attribute is transitive. */
  30. #define BGP_ATTR_FLAG_PARTIAL 0x20 /* Attribute is partial. */
  31. #define BGP_ATTR_FLAG_EXTLEN 0x10 /* Extended length flag. */
  32. /* BGP attribute type codes. */
  33. #define BGP_ATTR_ORIGIN 1
  34. #define BGP_ATTR_AS_PATH 2
  35. #define BGP_ATTR_NEXT_HOP 3
  36. #define BGP_ATTR_MULTI_EXIT_DISC 4
  37. #define BGP_ATTR_LOCAL_PREF 5
  38. #define BGP_ATTR_ATOMIC_AGGREGATE 6
  39. #define BGP_ATTR_AGGREGATOR 7
  40. #define BGP_ATTR_COMMUNITIES 8
  41. #define BGP_ATTR_ORIGINATOR_ID 9
  42. #define BGP_ATTR_CLUSTER_LIST 10
  43. #define BGP_ATTR_DPA 11
  44. #define BGP_ATTR_ADVERTISER 12
  45. #define BGP_ATTR_RCID_PATH 13
  46. #define BGP_ATTR_MP_REACH_NLRI 14
  47. #define BGP_ATTR_MP_UNREACH_NLRI 15
  48. #define BGP_ATTR_EXT_COMMUNITIES 16
  49. #define BGP_ATTR_NEW_AS_PATH 17
  50. #define BGP_ATTR_NEW_AGGREGATOR 18
  51. /* Flag macro */
  52. #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
  53. /* BGP ASPATH attribute defines */
  54. #define AS_HEADER_SIZE 2
  55. #define AS_SET 1
  56. #define AS_SEQUENCE 2
  57. #define AS_CONFED_SEQUENCE 3
  58. #define AS_CONFED_SET 4
  59. #define AS_SEG_START 0
  60. #define AS_SEG_END 1
  61. #define ASPATH_STR_DEFAULT_LEN 32
  62. #define ASPATH_STR_ERROR "! Error !"
  63. /* BGP COMMUNITY attribute defines */
  64. #define COMMUNITY_NO_EXPORT 0xFFFFFF01
  65. #define COMMUNITY_NO_ADVERTISE 0xFFFFFF02
  66. #define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03
  67. #define COMMUNITY_LOCAL_AS 0xFFFFFF03
  68. #define com_nthval(X,n) ((X)->val + (n))
  69. /* MP-BGP address families */
  70. #ifdef BGPDUMP_HAVE_IPV6
  71. #define AFI_IP 1
  72. #define AFI_IP6 2
  73. #define BGPDUMP_MAX_AFI AFI_IP6
  74. #else
  75. #define AFI_IP 1
  76. #define BGPDUMP_MAX_AFI AFI_IP
  77. #endif
  78. #define SAFI_UNICAST 1
  79. #define SAFI_MULTICAST 2
  80. #define SAFI_UNICAST_MULTICAST 3
  81. #define BGPDUMP_MAX_SAFI SAFI_UNICAST_MULTICAST
  82. struct unknown_attr
  83. {
  84. int flag;
  85. int type;
  86. int len;
  87. u_char *raw;
  88. };
  89. typedef u_int32_t as_t;
  90. typedef struct attr attributes_t;
  91. struct attr
  92. {
  93. /* Flag of attribute is set or not. */
  94. u_int32_t flag;
  95. /* Attributes. */
  96. int origin;
  97. struct in_addr nexthop;
  98. u_int32_t med;
  99. u_int32_t local_pref;
  100. as_t aggregator_as;
  101. struct in_addr aggregator_addr;
  102. u_int32_t weight;
  103. struct in_addr originator_id;
  104. struct cluster_list *cluster;
  105. struct aspath *aspath;
  106. struct community *community;
  107. struct ecommunity *ecommunity;
  108. struct transit *transit;
  109. /* libbgpdump additions */
  110. struct mp_info *mp_info;
  111. u_int16_t len;
  112. caddr_t data;
  113. u_int16_t unknown_num;
  114. struct unknown_attr *unknown;
  115. /* ASN32 support */
  116. struct aspath *new_aspath;
  117. struct aspath *old_aspath;
  118. as_t new_aggregator_as;
  119. as_t old_aggregator_as;
  120. struct in_addr new_aggregator_addr;
  121. struct in_addr old_aggregator_addr;
  122. };
  123. struct community
  124. {
  125. int size;
  126. u_int32_t *val;
  127. char *str;
  128. };
  129. struct cluster_list
  130. {
  131. int length;
  132. struct in_addr *list;
  133. };
  134. struct transit
  135. {
  136. int length;
  137. u_char *val;
  138. };
  139. struct aspath
  140. {
  141. u_int8_t asn_len;
  142. int length;
  143. int count;
  144. caddr_t data;
  145. char *str;
  146. };
  147. struct assegment
  148. {
  149. u_char type;
  150. u_char length;
  151. char data[0];
  152. };
  153. struct mp_info {
  154. /* AFI and SAFI start from 1, so the arrays must be 1-based */
  155. struct mp_nlri *withdraw[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  156. struct mp_nlri *announce[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  157. };
  158. #ifdef BGPDUMP_HAVE_IPV6
  159. #define MP_IPV6_ANNOUNCE(m) ((m)->announce[AFI_IP6][SAFI_UNICAST])
  160. #define MP_IPV6_WITHDRAW(m) ((m)->withdraw[AFI_IP6][SAFI_UNICAST])
  161. #endif
  162. typedef union union_BGPDUMP_IP_ADDRESS {
  163. struct in_addr v4_addr;
  164. struct in6_addr v6_addr;
  165. } BGPDUMP_IP_ADDRESS;
  166. #define BGPDUMP_ADDRSTRLEN 46
  167. #define ASN16_LEN sizeof(u_int16_t)
  168. #define ASN32_LEN sizeof(u_int32_t)
  169. #define AS_TRAN 23456
  170. struct prefix {
  171. BGPDUMP_IP_ADDRESS address;
  172. u_char len;
  173. };
  174. #define MAX_PREFIXES 2050
  175. struct mp_nlri {
  176. u_char nexthop_len;
  177. BGPDUMP_IP_ADDRESS nexthop;
  178. BGPDUMP_IP_ADDRESS nexthop_local;
  179. u_int16_t prefix_count;
  180. struct prefix nlri[MAX_PREFIXES];
  181. };
  182. #endif /* _BGPDUMP_ATTR_H */