2 * Copyright 2004-2013, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #ifndef __TAP_SCTP_ANALYSIS_H__
24 #define __TAP_SCTP_ANALYSIS_H__
28 #endif /* __cplusplus */
30 #include <epan/dissectors/packet-sctp.h>
31 #include <epan/address.h>
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
37 #ifdef HAVE_WINSOCK2_H
42 #define SCTP_DATA_CHUNK_ID 0
43 #define SCTP_INIT_CHUNK_ID 1
44 #define SCTP_INIT_ACK_CHUNK_ID 2
45 #define SCTP_SACK_CHUNK_ID 3
46 #define SCTP_HEARTBEAT_CHUNK_ID 4
47 #define SCTP_HEARTBEAT_ACK_CHUNK_ID 5
48 #define SCTP_ABORT_CHUNK_ID 6
49 #define SCTP_SHUTDOWN_CHUNK_ID 7
50 #define SCTP_SHUTDOWN_ACK_CHUNK_ID 8
51 #define SCTP_ERROR_CHUNK_ID 9
52 #define SCTP_COOKIE_ECHO_CHUNK_ID 10
53 #define SCTP_COOKIE_ACK_CHUNK_ID 11
54 #define SCTP_ECNE_CHUNK_ID 12
55 #define SCTP_CWR_CHUNK_ID 13
56 #define SCTP_SHUTDOWN_COMPLETE_CHUNK_ID 14
57 #define SCTP_AUTH_CHUNK_ID 15
58 #define SCTP_NR_SACK_CHUNK_ID 16
59 #define SCTP_ASCONF_ACK_CHUNK_ID 0x80
60 #define SCTP_PKTDROP_CHUNK_ID 0x81
61 #define SCTP_RE_CONFIG_CHUNK_ID 0x82
62 #define SCTP_PAD_CHUNK_ID 0x84
63 #define SCTP_FORWARD_TSN_CHUNK_ID 0xC0
64 #define SCTP_ASCONF_CHUNK_ID 0xC1
65 #define SCTP_IETF_EXT 0xFF
67 #define IS_SCTP_CHUNK_TYPE(t) \
68 (((t) <= 16) || ((t) == 0xC0) || ((t) == 0xC1) || ((t) == 0x80) || ((t) == 0x81))
70 #define CHUNK_TYPE_LENGTH 1
71 #define CHUNK_FLAGS_LENGTH 1
72 #define CHUNK_LENGTH_LENGTH 2
74 #define CHUNK_HEADER_OFFSET 0
75 #define CHUNK_TYPE_OFFSET CHUNK_HEADER_OFFSET
76 #define CHUNK_FLAGS_OFFSET (CHUNK_TYPE_OFFSET + CHUNK_TYPE_LENGTH)
77 #define CHUNK_LENGTH_OFFSET (CHUNK_FLAGS_OFFSET + CHUNK_FLAGS_LENGTH)
78 #define CHUNK_VALUE_OFFSET (CHUNK_LENGTH_OFFSET + CHUNK_LENGTH_LENGTH)
80 #define INIT_CHUNK_INITIATE_TAG_LENGTH 4
81 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH 4
82 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH 2
83 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH 2
86 #define INIT_CHUNK_INITIATE_TAG_OFFSET CHUNK_VALUE_OFFSET
87 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET (INIT_CHUNK_INITIATE_TAG_OFFSET + \
88 INIT_CHUNK_INITIATE_TAG_LENGTH )
89 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET (INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET + \
90 INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH )
91 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET (INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET + \
92 INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH )
93 #define INIT_CHUNK_INITIAL_TSN_OFFSET (INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET + \
94 INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH )
96 #define DATA_CHUNK_TSN_LENGTH 4
97 #define DATA_CHUNK_TSN_OFFSET (CHUNK_VALUE_OFFSET + 0)
98 #define DATA_CHUNK_STREAM_ID_OFFSET (DATA_CHUNK_TSN_OFFSET + DATA_CHUNK_TSN_LENGTH)
99 #define DATA_CHUNK_STREAM_ID_LENGTH 2
100 #define DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH 2
101 #define DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH 4
102 #define DATA_CHUNK_HEADER_LENGTH (CHUNK_HEADER_LENGTH + \
103 DATA_CHUNK_TSN_LENGTH + \
104 DATA_CHUNK_STREAM_ID_LENGTH + \
105 DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH + \
106 DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
107 #define MAX_ADDRESS_LEN 47
109 #define SCTP_ABORT_CHUNK_T_BIT 0x01
111 #define PARAMETER_TYPE_LENGTH 2
112 #define PARAMETER_LENGTH_LENGTH 2
113 #define PARAMETER_HEADER_LENGTH (PARAMETER_TYPE_LENGTH + PARAMETER_LENGTH_LENGTH)
115 #define PARAMETER_HEADER_OFFSET 0
116 #define PARAMETER_TYPE_OFFSET PARAMETER_HEADER_OFFSET
117 #define PARAMETER_LENGTH_OFFSET (PARAMETER_TYPE_OFFSET + PARAMETER_TYPE_LENGTH)
118 #define PARAMETER_VALUE_OFFSET (PARAMETER_LENGTH_OFFSET + PARAMETER_LENGTH_LENGTH)
120 #define IPV6_ADDRESS_LENGTH 16
121 #define IPV6_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
122 #define IPV4_ADDRESS_LENGTH 4
123 #define IPV4_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
124 #define IPV4ADDRESS_PARAMETER_ID 0x0005
125 #define IPV6ADDRESS_PARAMETER_ID 0x0006
127 #define SACK_CHUNK_CUMULATIVE_TSN_ACK_LENGTH 4
128 #define SACK_CHUNK_CUMULATIVE_TSN_ACK_OFFSET (CHUNK_VALUE_OFFSET + 0)
129 #define SACK_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH 4
130 #define SACK_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET (SACK_CHUNK_CUMULATIVE_TSN_ACK_OFFSET + \
131 SACK_CHUNK_CUMULATIVE_TSN_ACK_LENGTH)
133 #define INIT_CHUNK_INITIAL_TSN_LENGTH 4
134 #define INIT_CHUNK_FIXED_PARAMTERS_LENGTH (INIT_CHUNK_INITIATE_TAG_LENGTH + \
135 INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH + \
136 INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH + \
137 INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH + \
138 INIT_CHUNK_INITIAL_TSN_LENGTH)
139 #define CHUNK_HEADER_LENGTH (CHUNK_TYPE_LENGTH + \
140 CHUNK_FLAGS_LENGTH + \
142 #define INIT_CHUNK_VARIABLE_LENGTH_PARAMETER_OFFSET (INIT_CHUNK_INITIAL_TSN_OFFSET + \
143 INIT_CHUNK_INITIAL_TSN_LENGTH )
145 static const value_string chunk_type_values[] = {
146 { SCTP_DATA_CHUNK_ID, "DATA" },
147 { SCTP_INIT_CHUNK_ID, "INIT" },
148 { SCTP_INIT_ACK_CHUNK_ID, "INIT_ACK" },
149 { SCTP_SACK_CHUNK_ID, "SACK" },
150 { SCTP_HEARTBEAT_CHUNK_ID, "HEARTBEAT" },
151 { SCTP_HEARTBEAT_ACK_CHUNK_ID, "HEARTBEAT_ACK" },
152 { SCTP_ABORT_CHUNK_ID, "ABORT" },
153 { SCTP_SHUTDOWN_CHUNK_ID, "SHUTDOWN" },
154 { SCTP_SHUTDOWN_ACK_CHUNK_ID, "SHUTDOWN_ACK" },
155 { SCTP_ERROR_CHUNK_ID, "ERROR" },
156 { SCTP_COOKIE_ECHO_CHUNK_ID, "COOKIE_ECHO" },
157 { SCTP_COOKIE_ACK_CHUNK_ID, "COOKIE_ACK" },
158 { SCTP_ECNE_CHUNK_ID, "ECNE" },
159 { SCTP_CWR_CHUNK_ID, "CWR" },
160 { SCTP_SHUTDOWN_COMPLETE_CHUNK_ID, "SHUTDOWN_COMPLETE" },
161 { SCTP_AUTH_CHUNK_ID, "AUTH" },
162 { SCTP_NR_SACK_CHUNK_ID, "NR-SACK" },
163 { SCTP_ASCONF_ACK_CHUNK_ID, "ASCONF_ACK" },
164 { SCTP_PKTDROP_CHUNK_ID, "PKTDROP" },
165 { SCTP_RE_CONFIG_CHUNK_ID, "RE_CONFIG" },
166 { SCTP_PAD_CHUNK_ID, "PAD" },
167 { SCTP_FORWARD_TSN_CHUNK_ID, "FORWARD_TSN" },
168 { SCTP_ASCONF_CHUNK_ID, "ASCONF" },
169 { SCTP_IETF_EXT, "IETF_EXTENSION" },
172 /* The below value is 255 */
173 #define NUM_CHUNKS 0x100
175 /* This variable is used as an index into arrays
176 * which store the cumulative information corresponding
177 * all chunks with Chunk Type greater > 16
178 * The value for the below variable is 17
180 #define OTHER_CHUNKS_INDEX 0xfe
183 /* This variable stores the maximum chunk type value
184 * that can be associated with a sctp chunk.
186 #define MAX_SCTP_CHUNK_TYPE 256
188 typedef struct _tsn {
189 guint32 frame_number;
190 guint32 secs; /* Absolute seconds */
198 typedef struct _sctp_tmp_info {
205 guint32 verification_tag1;
206 guint32 verification_tag2;
207 guint32 initiate_tag;
211 typedef struct _sctp_min_max {
212 guint32 tmp_min_secs;
213 guint32 tmp_min_usecs;
214 guint32 tmp_max_secs;
215 guint32 tmp_max_usecs;
216 guint32 tmp_min_tsn1;
217 guint32 tmp_min_tsn2;
218 guint32 tmp_max_tsn1;
219 guint32 tmp_max_tsn2;
232 typedef struct _sctp_addr_chunk {
235 /* The array is initialized to MAX_SCTP_CHUNK_TYPE
236 * so that there is no memory overwrite
237 * when accessed using sctp chunk type as index.
239 guint32 addr_count[MAX_SCTP_CHUNK_TYPE];
242 typedef struct _sctp_assoc_info {
248 guint32 verification_tag1;
249 guint32 verification_tag2;
250 guint32 initiate_tag;
258 guint32 n_adler32_calculated;
259 guint32 n_adler32_correct;
260 guint32 n_crc32c_calculated;
261 guint32 n_crc32c_correct;
262 gchar checksum_type[8];
263 guint32 n_checksum_errors;
264 guint32 n_bundling_errors;
265 guint32 n_padding_errors;
266 guint32 n_length_errors;
267 guint32 n_value_errors;
268 guint32 n_data_chunks;
269 guint32 n_forward_chunks;
270 guint32 n_forward_chunks_ep1;
271 guint32 n_forward_chunks_ep2;
272 guint32 n_data_bytes;
274 guint32 n_data_chunks_ep1;
275 guint32 n_data_bytes_ep1;
276 guint32 n_data_chunks_ep2;
277 guint32 n_data_bytes_ep2;
278 guint32 n_sack_chunks_ep1;
279 guint32 n_sack_chunks_ep2;
280 guint32 n_array_tsn1;
281 guint32 n_array_tsn2;
301 GList *frame_numbers;
303 GPtrArray *sort_tsn1;
304 GPtrArray *sort_sack1;
307 GPtrArray *sort_tsn2;
308 GPtrArray *sort_sack2;
310 gboolean check_address;
311 GList* error_info_list;
312 /* The array is initialized to MAX_SCTP_CHUNK_TYPE
313 * so that there is no memory overwrite
314 * when accessed using sctp chunk type as index.
316 guint32 chunk_count[MAX_SCTP_CHUNK_TYPE];
317 guint32 ep1_chunk_count[MAX_SCTP_CHUNK_TYPE];
318 guint32 ep2_chunk_count[MAX_SCTP_CHUNK_TYPE];
319 GList *addr_chunk_count;
322 typedef struct _sctp_error_info {
323 guint32 frame_number;
324 gchar chunk_info[200];
325 const gchar *info_text;
329 typedef struct _sctp_allassocs_info {
331 GList *assoc_info_list;
332 gboolean is_registered;
334 } sctp_allassocs_info_t;
338 void register_tap_listener_sctp_stat(void);
340 const sctp_allassocs_info_t* sctp_stat_get_info(void);
342 void sctp_stat_scan(void);
344 void remove_tap_listener_sctp_stat(void);
347 const sctp_assoc_info_t* get_selected_assoc(void);
351 #endif /* __cplusplus */
353 #endif /* __TAP_SCTP_ANALYSIS_H__ */
356 * Editor modelines - http://www.wireshark.org/tools/modelines.html
361 * indent-tabs-mode: t
364 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
365 * :indentSize=8:tabSize=8:noTabs=false: