bgpdump_attr.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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 u_int32_t pathid_t;
  91. typedef struct attr attributes_t;
  92. struct attr
  93. {
  94. /* Flag of attribute is set or not. */
  95. u_int32_t flag;
  96. /* Attributes. */
  97. int origin;
  98. struct in_addr nexthop;
  99. u_int32_t med;
  100. u_int32_t local_pref;
  101. as_t aggregator_as;
  102. struct in_addr aggregator_addr;
  103. u_int32_t weight;
  104. struct in_addr originator_id;
  105. struct cluster_list *cluster;
  106. struct aspath *aspath;
  107. struct community *community;
  108. struct ecommunity *ecommunity;
  109. struct transit *transit;
  110. /* libbgpdump additions */
  111. struct mp_info *mp_info;
  112. u_int16_t len;
  113. caddr_t data;
  114. u_int16_t unknown_num;
  115. struct unknown_attr *unknown;
  116. /* ASN32 support */
  117. struct aspath *new_aspath;
  118. struct aspath *old_aspath;
  119. as_t new_aggregator_as;
  120. as_t old_aggregator_as;
  121. struct in_addr new_aggregator_addr;
  122. struct in_addr old_aggregator_addr;
  123. };
  124. struct community
  125. {
  126. int size;
  127. u_int32_t *val;
  128. char *str;
  129. };
  130. struct cluster_list
  131. {
  132. int length;
  133. struct in_addr *list;
  134. };
  135. struct transit
  136. {
  137. int length;
  138. u_char *val;
  139. };
  140. struct aspath
  141. {
  142. u_int8_t asn_len;
  143. int length;
  144. int count;
  145. caddr_t data;
  146. char *str;
  147. };
  148. struct assegment
  149. {
  150. u_char type;
  151. u_char length;
  152. char data[0];
  153. };
  154. struct mp_info {
  155. /* AFI and SAFI start from 1, so the arrays must be 1-based */
  156. struct mp_nlri *withdraw[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  157. struct mp_nlri *announce[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  158. };
  159. #ifdef BGPDUMP_HAVE_IPV6
  160. #define MP_IPV6_ANNOUNCE(m) ((m)->announce[AFI_IP6][SAFI_UNICAST])
  161. #define MP_IPV6_WITHDRAW(m) ((m)->withdraw[AFI_IP6][SAFI_UNICAST])
  162. #endif
  163. typedef union union_BGPDUMP_IP_ADDRESS {
  164. struct in_addr v4_addr;
  165. struct in6_addr v6_addr;
  166. } BGPDUMP_IP_ADDRESS;
  167. #define BGPDUMP_ADDRSTRLEN 46
  168. #define ASN16_LEN sizeof(u_int16_t)
  169. #define ASN32_LEN sizeof(u_int32_t)
  170. #define AS_TRAN 23456
  171. struct prefix {
  172. BGPDUMP_IP_ADDRESS address;
  173. u_char len;
  174. pathid_t path_id;
  175. };
  176. #define MAX_PREFIXES 2050
  177. struct mp_nlri {
  178. u_char nexthop_len;
  179. BGPDUMP_IP_ADDRESS nexthop;
  180. BGPDUMP_IP_ADDRESS nexthop_local;
  181. u_int16_t prefix_count;
  182. struct prefix nlri[MAX_PREFIXES];
  183. };
  184. #endif /* _BGPDUMP_ATTR_H */