bgpdump_attr.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. #define BGP_ATTR_LARGE_COMMUNITIES 32
  52. /* Flag macro */
  53. #define ATTR_FLAG_BIT(X) (1 << ((X) - 1))
  54. /* BGP ASPATH attribute defines */
  55. #define AS_HEADER_SIZE 2
  56. #define AS_SET 1
  57. #define AS_SEQUENCE 2
  58. #define AS_CONFED_SEQUENCE 3
  59. #define AS_CONFED_SET 4
  60. #define AS_SEG_START 0
  61. #define AS_SEG_END 1
  62. #define ASPATH_STR_DEFAULT_LEN 32
  63. #define ASPATH_STR_ERROR "! Error !"
  64. /* BGP COMMUNITY attribute defines */
  65. #define COMMUNITY_NO_EXPORT 0xFFFFFF01
  66. #define COMMUNITY_NO_ADVERTISE 0xFFFFFF02
  67. #define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03
  68. #define COMMUNITY_LOCAL_AS 0xFFFFFF03
  69. #define com_nthval(X,n) ((X)->val + (n))
  70. /* MP-BGP address families */
  71. #ifdef BGPDUMP_HAVE_IPV6
  72. #define AFI_IP 1
  73. #define AFI_IP6 2
  74. #define BGPDUMP_MAX_AFI AFI_IP6
  75. #else
  76. #define AFI_IP 1
  77. #define BGPDUMP_MAX_AFI AFI_IP
  78. #endif
  79. #define SAFI_UNICAST 1
  80. #define SAFI_MULTICAST 2
  81. #define SAFI_UNICAST_MULTICAST 3
  82. #define BGPDUMP_MAX_SAFI SAFI_UNICAST_MULTICAST
  83. struct unknown_attr
  84. {
  85. int flag;
  86. int type;
  87. int len;
  88. u_char *raw;
  89. };
  90. typedef u_int32_t as_t;
  91. typedef u_int32_t pathid_t;
  92. typedef struct attr attributes_t;
  93. struct attr
  94. {
  95. /* Flag of attribute is set or not. */
  96. u_int32_t flag;
  97. /* Attributes. */
  98. int origin;
  99. struct in_addr nexthop;
  100. u_int32_t med;
  101. u_int32_t local_pref;
  102. as_t aggregator_as;
  103. struct in_addr aggregator_addr;
  104. u_int32_t weight;
  105. struct in_addr originator_id;
  106. struct cluster_list *cluster;
  107. struct aspath *aspath;
  108. struct community *community;
  109. struct ecommunity *ecommunity;
  110. struct lcommunity *lcommunity;
  111. struct transit *transit;
  112. /* libbgpdump additions */
  113. struct mp_info *mp_info;
  114. u_int16_t len;
  115. caddr_t data;
  116. u_int16_t unknown_num;
  117. struct unknown_attr *unknown;
  118. /* ASN32 support */
  119. struct aspath *new_aspath;
  120. struct aspath *old_aspath;
  121. as_t new_aggregator_as;
  122. as_t old_aggregator_as;
  123. struct in_addr new_aggregator_addr;
  124. struct in_addr old_aggregator_addr;
  125. };
  126. struct community
  127. {
  128. int size;
  129. u_int32_t *val;
  130. char *str;
  131. };
  132. struct lcommunity
  133. {
  134. int size;
  135. u_int32_t *val;
  136. char *str;
  137. };
  138. struct cluster_list
  139. {
  140. int length;
  141. struct in_addr *list;
  142. };
  143. struct transit
  144. {
  145. int length;
  146. u_char *val;
  147. };
  148. struct aspath
  149. {
  150. u_int8_t asn_len;
  151. int length;
  152. int count;
  153. caddr_t data;
  154. char *str;
  155. };
  156. struct assegment
  157. {
  158. u_char type;
  159. u_char length;
  160. char data[0];
  161. };
  162. struct mp_info {
  163. /* AFI and SAFI start from 1, so the arrays must be 1-based */
  164. struct mp_nlri *withdraw[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  165. struct mp_nlri *announce[BGPDUMP_MAX_AFI+1][BGPDUMP_MAX_SAFI+1];
  166. };
  167. #ifdef BGPDUMP_HAVE_IPV6
  168. #define MP_IPV6_ANNOUNCE(m) ((m)->announce[AFI_IP6][SAFI_UNICAST])
  169. #define MP_IPV6_WITHDRAW(m) ((m)->withdraw[AFI_IP6][SAFI_UNICAST])
  170. #endif
  171. typedef union union_BGPDUMP_IP_ADDRESS {
  172. struct in_addr v4_addr;
  173. struct in6_addr v6_addr;
  174. } BGPDUMP_IP_ADDRESS;
  175. #define BGPDUMP_ADDRSTRLEN 46
  176. #define ASN16_LEN sizeof(u_int16_t)
  177. #define ASN32_LEN sizeof(u_int32_t)
  178. #define AS_TRAN 23456
  179. struct prefix {
  180. BGPDUMP_IP_ADDRESS address;
  181. u_char len;
  182. pathid_t path_id;
  183. };
  184. #define MAX_PREFIXES 2050
  185. struct mp_nlri {
  186. u_char nexthop_len;
  187. BGPDUMP_IP_ADDRESS nexthop;
  188. BGPDUMP_IP_ADDRESS nexthop_local;
  189. u_int16_t prefix_count;
  190. struct prefix nlri[MAX_PREFIXES];
  191. };
  192. #endif /* _BGPDUMP_ATTR_H */