1
0

bgpdump_formats.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  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_FORMATS_H
  24. #define _BGPDUMP_FORMATS_H
  25. #include "bgpdump_attr.h"
  26. #include <stdio.h>
  27. #include <sys/types.h>
  28. #include <string.h>
  29. #include <netinet/in.h>
  30. /* type and subtypes values */
  31. /* RFC6396 */
  32. #define BGPDUMP_TYPE_MRTD_BGP 5
  33. #define BGPDUMP_SUBTYPE_MRTD_BGP_NULL 0
  34. #define BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE 1
  35. #define BGPDUMP_SUBTYPE_MRTD_BGP_PREFUPDATE 2
  36. #define BGPDUMP_SUBTYPE_MRTD_BGP_STATE_CHANGE 3
  37. #define BGPDUMP_SUBTYPE_MRTD_BGP_SYNC 4
  38. #define BGPDUMP_SUBTYPE_MRTD_BGP_OPEN 5
  39. #define BGPDUMP_SUBTYPE_MRTD_BGP_NOTIFICATION 6
  40. #define BGPDUMP_SUBTYPE_MRTD_BGP_KEEPALIVE 7
  41. #define BGPDUMP_SUBTYPE_MRTD_BGP_ROUT_REFRESH 133
  42. #define BGPDUMP_TYPE_MRTD_TABLE_DUMP 12
  43. #define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP 1
  44. #define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6 2
  45. #define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS 3
  46. #define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS 4
  47. #define BGPDUMP_TYPE_TABLE_DUMP_V2 13
  48. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_PEER_INDEX_TABLE 1
  49. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_UNICAST 2
  50. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_MULTICAST 3
  51. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_UNICAST 4
  52. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_MULTICAST 5
  53. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_GENERIC 6
  54. #define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AFI_IP 0
  55. #define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AFI_IP6 1
  56. #define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AS2 0
  57. #define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AS4 2
  58. #define BGPDUMP_TYPE_TABLE_DUMP_V2_MAX_VIEWNAME_LEN 255
  59. /* Zebra record types */
  60. #define BGPDUMP_TYPE_ZEBRA_BGP 16 /* MSG_PROTOCOL_BGP4MP */
  61. #define BGPDUMP_TYPE_ZEBRA_BGP_ET 17 /* MSG_PROTOCOL_BGP4MP_ET */
  62. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE 0 /* BGP4MP_STATE_CHANGE */
  63. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE 1 /* BGP4MP_MESSAGE */
  64. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_ENTRY 2 /* BGP4MP_ENTRY */
  65. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_SNAPSHOT 3 /* BGP4MP_SNAPSHOT */
  66. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4 4 /* BGP4MP_MESSAGE_AS4 */
  67. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE_AS4 5 /* BGP4MP_STATE_CHANGE_AS4 */
  68. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL 6 /* BGP4MP_MESSAGE_LOCAL */
  69. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL 7 /* BGP4MP_MESSAGE_AS4_LOCAL */
  70. /* RFC8050 add-path extensions */
  71. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_ADDPATH 8 /* BGP4MP_MESSAGE_ADDPATH */
  72. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_ADDPATH 9 /* BGP4MP_MESSAGE_AS4_ADDPATH */
  73. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL_ADDPATH 10 /* BGP4MP_MESSAGE_LOCAL_ADDPATH */
  74. #define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL_ADDPATH 11 /* BGP4MP_MESSAGE_AS4_LOCAL */
  75. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH 8 /* RIB_IPV4_UNICAST_ADDPATH */
  76. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH 9 /* RIB_IPV4_MULTICAST_ADDPATH */
  77. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH 10 /* RIB_IPV6_UNICAST_ADDPATH */
  78. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH 11 /* RIB_IPV6_MULTICAST_ADDPATH */
  79. #define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_GENERIC_ADDPATH 12 /* RIB_GENERIC_ADDPATH */
  80. /* BGP state - defined in RFC1771 */
  81. #define BGP_STATE_IDLE 1
  82. #define BGP_STATE_CONNECT 2
  83. #define BGP_STATE_ACTIVE 3
  84. #define BGP_STATE_OPENSENT 4
  85. #define BGP_STATE_OPENCONFIRM 5
  86. #define BGP_STATE_ESTABLISHED 6
  87. /* BGP message types */
  88. #define BGP_MSG_OPEN 1
  89. #define BGP_MSG_UPDATE 2
  90. #define BGP_MSG_NOTIFY 3
  91. #define BGP_MSG_KEEPALIVE 4
  92. #define BGP_MSG_ROUTE_REFRESH_01 5
  93. #define BGP_MSG_ROUTE_REFRESH 128
  94. typedef struct struct_BGPDUMP_MRTD_TABLE_DUMP {
  95. u_int16_t view;
  96. u_int16_t sequence;
  97. BGPDUMP_IP_ADDRESS prefix;
  98. u_char mask;
  99. u_char status;
  100. time_t uptime;
  101. BGPDUMP_IP_ADDRESS peer_ip;
  102. as_t peer_as;
  103. u_int16_t attr_len;
  104. } BGPDUMP_MRTD_TABLE_DUMP;
  105. typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY {
  106. u_char afi;
  107. BGPDUMP_IP_ADDRESS peer_ip;
  108. struct in_addr peer_bgp_id;
  109. as_t peer_as;
  110. } BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY;
  111. typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE {
  112. struct in_addr local_bgp_id;
  113. char view_name[BGPDUMP_TYPE_TABLE_DUMP_V2_MAX_VIEWNAME_LEN];
  114. uint16_t peer_count;
  115. BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY *entries;
  116. } BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE;
  117. typedef struct struct_BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY {
  118. uint16_t peer_index;
  119. uint32_t originated_time;
  120. pathid_t path_id;
  121. BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY *peer;
  122. attributes_t *attr;
  123. } BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY;
  124. typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PREFIX {
  125. uint32_t seq;
  126. uint16_t afi;
  127. uint8_t safi;
  128. u_char prefix_length;
  129. BGPDUMP_IP_ADDRESS prefix;
  130. uint16_t entry_count;
  131. BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY *entries;
  132. } BGPDUMP_TABLE_DUMP_V2_PREFIX;
  133. /* For Zebra BGP4MP_STATE_CHANGE */
  134. typedef struct struct_BGPDUMP_ZEBRA_STATE_CHANGE {
  135. as_t source_as;
  136. as_t destination_as;
  137. u_int16_t interface_index;
  138. u_int16_t address_family;
  139. BGPDUMP_IP_ADDRESS source_ip;
  140. BGPDUMP_IP_ADDRESS destination_ip;
  141. u_int16_t old_state;
  142. u_int16_t new_state;
  143. } BGPDUMP_ZEBRA_STATE_CHANGE;
  144. struct zebra_incomplete {
  145. u_int16_t afi;
  146. u_int8_t orig_len;
  147. struct prefix prefix;
  148. };
  149. /* For Zebra BGP4MP_MESSAGE */
  150. typedef struct struct_BGPDUMP_ZEBRA_MESSAGE {
  151. /* Zebra header */
  152. as_t source_as;
  153. as_t destination_as;
  154. u_int16_t interface_index;
  155. u_int16_t address_family;
  156. BGPDUMP_IP_ADDRESS source_ip;
  157. BGPDUMP_IP_ADDRESS destination_ip;
  158. /* BGP packet header fields */
  159. u_int16_t size;
  160. u_char type;
  161. /* For OPEN packets */
  162. u_char version;
  163. as_t my_as;
  164. u_int16_t hold_time;
  165. struct in_addr bgp_id;
  166. u_char opt_len;
  167. u_char *opt_data;
  168. /* For UPDATE packets */
  169. u_int16_t withdraw_count;
  170. u_int16_t announce_count;
  171. struct prefix withdraw[MAX_PREFIXES];
  172. struct prefix announce[MAX_PREFIXES];
  173. /* For corrupt update dumps */
  174. u_int16_t cut_bytes;
  175. struct zebra_incomplete incomplete;
  176. /* For NOTIFY packets */
  177. u_char error_code;
  178. u_char sub_error_code;
  179. u_int16_t notify_len;
  180. u_char *notify_data;
  181. } BGPDUMP_ZEBRA_MESSAGE;
  182. /* For Zebra BGP4MP_ENTRY */
  183. typedef struct struct_BGPDUMP_ZEBRA_ENTRY {
  184. u_int16_t view;
  185. u_int16_t status;
  186. time_t time_last_change;
  187. u_int16_t address_family;
  188. u_char SAFI;
  189. u_char next_hop_len;
  190. u_char prefix_length;
  191. u_char *address_prefix;
  192. u_int16_t empty;
  193. u_char *bgp_atribute;
  194. } BGPDUMP_ZEBRA_ENTRY;
  195. /* For Zebra BGP4MP_SNAPSHOT */
  196. typedef struct struct_BGPDUMP_ZEBRA_SNAPSHOT {
  197. u_int16_t view;
  198. u_int16_t file;
  199. } BGPDUMP_ZEBRA_SNAPSHOT;
  200. typedef struct struct_BGPDUMP_MRTD_MESSAGE {
  201. u_int16_t source_as;
  202. struct in_addr source_ip;
  203. u_int16_t destination_as;
  204. struct in_addr destination_ip;
  205. u_int16_t withdraw_count;
  206. u_int16_t announce_count;
  207. struct prefix withdraw[MAX_PREFIXES];
  208. struct prefix announce[MAX_PREFIXES];
  209. /* For corrupt update dumps */
  210. struct zebra_incomplete incomplete;
  211. } BGPDUMP_MRTD_MESSAGE;
  212. typedef struct struct_BGPDUMP_MRTD_STATE_CHANGE {
  213. u_int16_t destination_as;
  214. struct in_addr destination_ip;
  215. u_int16_t old_state;
  216. u_int16_t new_state;
  217. } BGPDUMP_MRTD_STATE_CHANGE;
  218. typedef union union_BGPDUMP_BODY {
  219. BGPDUMP_MRTD_MESSAGE mrtd_message;
  220. BGPDUMP_MRTD_STATE_CHANGE mrtd_state_change;
  221. BGPDUMP_MRTD_TABLE_DUMP mrtd_table_dump;
  222. BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE mrtd_table_dump_v2_peer_table;
  223. BGPDUMP_TABLE_DUMP_V2_PREFIX mrtd_table_dump_v2_prefix;
  224. BGPDUMP_ZEBRA_STATE_CHANGE zebra_state_change;
  225. BGPDUMP_ZEBRA_MESSAGE zebra_message;
  226. BGPDUMP_ZEBRA_ENTRY zebra_entry;
  227. BGPDUMP_ZEBRA_SNAPSHOT zebra_snapshot;
  228. } BGPDUMP_BODY;
  229. /* The MRT header. Common to all records. */
  230. typedef struct struct_BGPDUMP_ENTRY {
  231. time_t time;
  232. long ms;
  233. u_int16_t type;
  234. u_int16_t subtype;
  235. u_int32_t length;
  236. attributes_t *attr;
  237. BGPDUMP_BODY body;
  238. struct struct_BGPDUMP * dump;
  239. } BGPDUMP_ENTRY;
  240. #endif