-
Notifications
You must be signed in to change notification settings - Fork 11
/
bgpdump_formats.h
280 lines (240 loc) · 9.59 KB
/
bgpdump_formats.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
/*
Copyright (c) 2007 - 2010 RIPE NCC - All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted, provided
that the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation, and that the name of the author not be used in advertising or
publicity pertaining to distribution of the software without specific,
written prior permission.
THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS; IN NO EVENT SHALL
AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY
DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Parts of this code have been engineered after analiyzing GNU Zebra's
source code and therefore might contain declarations/code from GNU
Zebra, Copyright (C) 1999 Kunihiro Ishiguro. Zebra is a free routing
software, distributed under the GNU General Public License. A copy of
this license is included with libbgpdump.
Original Author: Dan Ardelean ([email protected])
*/
#ifndef _BGPDUMP_FORMATS_H
#define _BGPDUMP_FORMATS_H
#include "bgpdump_attr.h"
#include <stdio.h>
#include <sys/types.h>
#include <string.h>
#include <netinet/in.h>
/* type and subtypes values */
/* RFC6396 */
#define BGPDUMP_TYPE_MRTD_BGP 5
#define BGPDUMP_SUBTYPE_MRTD_BGP_NULL 0
#define BGPDUMP_SUBTYPE_MRTD_BGP_UPDATE 1
#define BGPDUMP_SUBTYPE_MRTD_BGP_PREFUPDATE 2
#define BGPDUMP_SUBTYPE_MRTD_BGP_STATE_CHANGE 3
#define BGPDUMP_SUBTYPE_MRTD_BGP_SYNC 4
#define BGPDUMP_SUBTYPE_MRTD_BGP_OPEN 5
#define BGPDUMP_SUBTYPE_MRTD_BGP_NOTIFICATION 6
#define BGPDUMP_SUBTYPE_MRTD_BGP_KEEPALIVE 7
#define BGPDUMP_SUBTYPE_MRTD_BGP_ROUT_REFRESH 133
#define BGPDUMP_TYPE_MRTD_TABLE_DUMP 12
#define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP 1
#define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6 2
#define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP_32BIT_AS 3
#define BGPDUMP_SUBTYPE_MRTD_TABLE_DUMP_AFI_IP6_32BIT_AS 4
#define BGPDUMP_TYPE_TABLE_DUMP_V2 13
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_PEER_INDEX_TABLE 1
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_UNICAST 2
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_MULTICAST 3
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_UNICAST 4
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_MULTICAST 5
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_GENERIC 6
#define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AFI_IP 0
#define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AFI_IP6 1
#define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AS2 0
#define BGPDUMP_PEERTYPE_TABLE_DUMP_V2_AS4 2
#define BGPDUMP_TYPE_TABLE_DUMP_V2_MAX_VIEWNAME_LEN 255
/* Zebra record types */
#define BGPDUMP_TYPE_ZEBRA_BGP 16 /* MSG_PROTOCOL_BGP4MP */
#define BGPDUMP_TYPE_ZEBRA_BGP_ET 17 /* MSG_PROTOCOL_BGP4MP_ET */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE 0 /* BGP4MP_STATE_CHANGE */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE 1 /* BGP4MP_MESSAGE */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_ENTRY 2 /* BGP4MP_ENTRY */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_SNAPSHOT 3 /* BGP4MP_SNAPSHOT */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4 4 /* BGP4MP_MESSAGE_AS4 */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_STATE_CHANGE_AS4 5 /* BGP4MP_STATE_CHANGE_AS4 */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL 6 /* BGP4MP_MESSAGE_LOCAL */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL 7 /* BGP4MP_MESSAGE_AS4_LOCAL */
/* RFC8050 add-path extensions */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_ADDPATH 8 /* BGP4MP_MESSAGE_ADDPATH */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_ADDPATH 9 /* BGP4MP_MESSAGE_AS4_ADDPATH */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_LOCAL_ADDPATH 10 /* BGP4MP_MESSAGE_LOCAL_ADDPATH */
#define BGPDUMP_SUBTYPE_ZEBRA_BGP_MESSAGE_AS4_LOCAL_ADDPATH 11 /* BGP4MP_MESSAGE_AS4_LOCAL */
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_UNICAST_ADDPATH 8 /* RIB_IPV4_UNICAST_ADDPATH */
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV4_MULTICAST_ADDPATH 9 /* RIB_IPV4_MULTICAST_ADDPATH */
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_UNICAST_ADDPATH 10 /* RIB_IPV6_UNICAST_ADDPATH */
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_IPV6_MULTICAST_ADDPATH 11 /* RIB_IPV6_MULTICAST_ADDPATH */
#define BGPDUMP_SUBTYPE_TABLE_DUMP_V2_RIB_GENERIC_ADDPATH 12 /* RIB_GENERIC_ADDPATH */
/* BGP state - defined in RFC1771 */
#define BGP_STATE_IDLE 1
#define BGP_STATE_CONNECT 2
#define BGP_STATE_ACTIVE 3
#define BGP_STATE_OPENSENT 4
#define BGP_STATE_OPENCONFIRM 5
#define BGP_STATE_ESTABLISHED 6
/* BGP message types */
#define BGP_MSG_OPEN 1
#define BGP_MSG_UPDATE 2
#define BGP_MSG_NOTIFY 3
#define BGP_MSG_KEEPALIVE 4
#define BGP_MSG_ROUTE_REFRESH_01 5
#define BGP_MSG_ROUTE_REFRESH 128
typedef struct struct_BGPDUMP_MRTD_TABLE_DUMP {
u_int16_t view;
u_int16_t sequence;
BGPDUMP_IP_ADDRESS prefix;
u_char mask;
u_char status;
time_t uptime;
BGPDUMP_IP_ADDRESS peer_ip;
as_t peer_as;
u_int16_t attr_len;
} BGPDUMP_MRTD_TABLE_DUMP;
typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY {
u_char afi;
BGPDUMP_IP_ADDRESS peer_ip;
struct in_addr peer_bgp_id;
as_t peer_as;
} BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY;
typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE {
struct in_addr local_bgp_id;
char view_name[BGPDUMP_TYPE_TABLE_DUMP_V2_MAX_VIEWNAME_LEN];
uint16_t peer_count;
BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY *entries;
} BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE;
typedef struct struct_BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY {
uint16_t peer_index;
uint32_t originated_time;
pathid_t path_id;
BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE_ENTRY *peer;
attributes_t *attr;
} BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY;
typedef struct struct_BGPDUMP_TABLE_DUMP_V2_PREFIX {
uint32_t seq;
uint16_t afi;
uint8_t safi;
u_char prefix_length;
BGPDUMP_IP_ADDRESS prefix;
uint16_t entry_count;
BGPDUMP_TABLE_DUMP_V2_ROUTE_ENTRY *entries;
} BGPDUMP_TABLE_DUMP_V2_PREFIX;
/* For Zebra BGP4MP_STATE_CHANGE */
typedef struct struct_BGPDUMP_ZEBRA_STATE_CHANGE {
as_t source_as;
as_t destination_as;
u_int16_t interface_index;
u_int16_t address_family;
BGPDUMP_IP_ADDRESS source_ip;
BGPDUMP_IP_ADDRESS destination_ip;
u_int16_t old_state;
u_int16_t new_state;
} BGPDUMP_ZEBRA_STATE_CHANGE;
struct zebra_incomplete {
u_int16_t afi;
u_int8_t orig_len;
struct prefix prefix;
};
/* For Zebra BGP4MP_MESSAGE */
typedef struct struct_BGPDUMP_ZEBRA_MESSAGE {
/* Zebra header */
as_t source_as;
as_t destination_as;
u_int16_t interface_index;
u_int16_t address_family;
BGPDUMP_IP_ADDRESS source_ip;
BGPDUMP_IP_ADDRESS destination_ip;
/* BGP packet header fields */
u_int16_t size;
u_char type;
/* For OPEN packets */
u_char version;
as_t my_as;
u_int16_t hold_time;
struct in_addr bgp_id;
u_char opt_len;
u_char *opt_data;
/* For UPDATE packets */
u_int16_t withdraw_count;
u_int16_t announce_count;
struct prefix *withdraw;
struct prefix *announce;
/* For corrupt update dumps */
u_int16_t cut_bytes;
struct zebra_incomplete incomplete;
/* For NOTIFY packets */
u_char error_code;
u_char sub_error_code;
u_int16_t notify_len;
u_char *notify_data;
} BGPDUMP_ZEBRA_MESSAGE;
/* For Zebra BGP4MP_ENTRY */
typedef struct struct_BGPDUMP_ZEBRA_ENTRY {
u_int16_t view;
u_int16_t status;
time_t time_last_change;
u_int16_t address_family;
u_char SAFI;
u_char next_hop_len;
u_char prefix_length;
u_char *address_prefix;
u_int16_t empty;
u_char *bgp_atribute;
} BGPDUMP_ZEBRA_ENTRY;
/* For Zebra BGP4MP_SNAPSHOT */
typedef struct struct_BGPDUMP_ZEBRA_SNAPSHOT {
u_int16_t view;
u_int16_t file;
} BGPDUMP_ZEBRA_SNAPSHOT;
typedef struct struct_BGPDUMP_MRTD_MESSAGE {
u_int16_t source_as;
struct in_addr source_ip;
u_int16_t destination_as;
struct in_addr destination_ip;
u_int16_t withdraw_count;
u_int16_t announce_count;
struct prefix *withdraw;
struct prefix *announce;
/* For corrupt update dumps */
struct zebra_incomplete incomplete;
} BGPDUMP_MRTD_MESSAGE;
typedef struct struct_BGPDUMP_MRTD_STATE_CHANGE {
u_int16_t destination_as;
struct in_addr destination_ip;
u_int16_t old_state;
u_int16_t new_state;
} BGPDUMP_MRTD_STATE_CHANGE;
typedef union union_BGPDUMP_BODY {
BGPDUMP_MRTD_MESSAGE mrtd_message;
BGPDUMP_MRTD_STATE_CHANGE mrtd_state_change;
BGPDUMP_MRTD_TABLE_DUMP mrtd_table_dump;
BGPDUMP_TABLE_DUMP_V2_PEER_INDEX_TABLE mrtd_table_dump_v2_peer_table;
BGPDUMP_TABLE_DUMP_V2_PREFIX mrtd_table_dump_v2_prefix;
BGPDUMP_ZEBRA_STATE_CHANGE zebra_state_change;
BGPDUMP_ZEBRA_MESSAGE zebra_message;
BGPDUMP_ZEBRA_ENTRY zebra_entry;
BGPDUMP_ZEBRA_SNAPSHOT zebra_snapshot;
} BGPDUMP_BODY;
/* The MRT header. Common to all records. */
typedef struct struct_BGPDUMP_ENTRY {
time_t time;
long ms;
u_int16_t type;
u_int16_t subtype;
u_int32_t length;
attributes_t *attr;
BGPDUMP_BODY body;
struct struct_BGPDUMP * dump;
} BGPDUMP_ENTRY;
#endif