Always put editor-modelines at the end of the file ...
[metze/wireshark/wip.git] / ui / tap-sctp-analysis.h
1 /*
2  * Copyright 2004-2013, Irene Ruengeler <i.ruengeler [AT] fh-muenster.de>
3  *
4  * Wireshark - Network traffic analyzer
5  * By Gerald Combs <gerald@wireshark.org>
6  * Copyright 1998 Gerald Combs
7  *
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.
12  *
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.
17  *
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.
21  */
22
23 #ifndef __TAP_SCTP_ANALYSIS_H__
24 #define __TAP_SCTP_ANALYSIS_H__
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29
30 #include <epan/dissectors/packet-sctp.h>
31 #include <epan/address.h>
32 #ifndef _WIN32
33 #include <sys/types.h>
34 #include <sys/socket.h>
35 #include <netinet/in.h>
36 #else
37 #ifdef HAVE_WINSOCK2_H
38 #include <winsock2.h>
39 #endif
40 #endif
41
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
66
67 #define IS_SCTP_CHUNK_TYPE(t) \
68         (((t) <= 16) || ((t) == 0xC0) || ((t) == 0xC1) || ((t) == 0x80) || ((t) == 0x81))
69
70 #define CHUNK_TYPE_LENGTH             1
71 #define CHUNK_FLAGS_LENGTH            1
72 #define CHUNK_LENGTH_LENGTH           2
73
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)
79
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
84
85
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 )
95
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
108
109 #define SCTP_ABORT_CHUNK_T_BIT        0x01
110
111 #define PARAMETER_TYPE_LENGTH            2
112 #define PARAMETER_LENGTH_LENGTH          2
113 #define PARAMETER_HEADER_LENGTH          (PARAMETER_TYPE_LENGTH + PARAMETER_LENGTH_LENGTH)
114
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)
119
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
126
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)
132
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 + \
141                                        CHUNK_LENGTH_LENGTH)
142 #define INIT_CHUNK_VARIABLE_LENGTH_PARAMETER_OFFSET  (INIT_CHUNK_INITIAL_TSN_OFFSET + \
143                                                       INIT_CHUNK_INITIAL_TSN_LENGTH )
144
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" },
170         { 0,                               NULL } };
171
172 /* The below value is 255 */
173 #define NUM_CHUNKS  0x100
174
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
179  */
180 #define OTHER_CHUNKS_INDEX      0xfe
181
182 /* VNB */
183 /* This variable stores the maximum chunk type value
184  * that can be associated with a sctp chunk.
185  */
186 #define MAX_SCTP_CHUNK_TYPE 256
187
188 typedef struct _tsn {
189         guint32  frame_number;
190         guint32  secs;          /* Absolute seconds */
191         guint32  usecs;
192         address  src;
193         address  dst;
194         guint32  first_tsn;
195         GList   *tsns;
196 } tsn_t;
197
198 typedef struct _sctp_tmp_info {
199         guint16 assoc_id;
200         guint16 direction;
201         address src;
202         address dst;
203         guint16 port1;
204         guint16 port2;
205         guint32 verification_tag1;
206         guint32 verification_tag2;
207         guint32 initiate_tag;
208         guint32 n_tvbs;
209 } sctp_tmp_info_t;
210
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;
220         gint    tmp_secs;
221 } sctp_min_max_t;
222
223 struct tsn_sort{
224         guint32 tsnumber;
225         guint32 secs;
226         guint32 usecs;
227         guint32 offset;
228         guint32 length;
229         guint32 framenumber;
230 };
231
232 typedef struct _sctp_addr_chunk {
233         guint32  direction;
234         address *addr;
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.
238          */
239         guint32  addr_count[MAX_SCTP_CHUNK_TYPE];
240 } sctp_addr_chunk;
241
242 typedef struct _sctp_assoc_info {
243         guint16    assoc_id;
244         address    src;
245         address    dst;
246         guint16    port1;
247         guint16    port2;
248         guint32    verification_tag1;
249         guint32    verification_tag2;
250         guint32    initiate_tag;
251         guint32    n_tvbs;
252         GList     *addr1;
253         GList     *addr2;
254         guint16    instream1;
255         guint16    outstream1;
256         guint16    instream2;
257         guint16    outstream2;
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;
273         guint32    n_packets;
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;
282         guint32    max_window1;
283         guint32    max_window2;
284         guint32    arwnd1;
285         guint32    arwnd2;
286         gboolean   init;
287         gboolean   initack;
288         guint16    initack_dir;
289         guint16    direction;
290         guint32    min_secs;
291         guint32    min_usecs;
292         guint32    max_secs;
293         guint32    max_usecs;
294         guint32    min_tsn1;
295         guint32    min_tsn2;
296         guint32    max_tsn1;
297         guint32    max_tsn2;
298         guint32    max_bytes1;
299         guint32    max_bytes2;
300         GSList    *min_max;
301         GList     *frame_numbers;
302         GList     *tsn1;
303         GPtrArray *sort_tsn1;
304         GPtrArray *sort_sack1;
305         GList     *sack1;
306         GList     *tsn2;
307         GPtrArray *sort_tsn2;
308         GPtrArray *sort_sack2;
309         GList     *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.
315          */
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;
320 } sctp_assoc_info_t;
321
322 typedef struct _sctp_error_info {
323         guint32      frame_number;
324         gchar        chunk_info[200];
325         const gchar *info_text;
326 } sctp_error_info_t;
327
328
329 typedef struct _sctp_allassocs_info {
330         guint32   sum_tvbs;
331         GList    *assoc_info_list;
332         gboolean  is_registered;
333         GList    *children;
334 } sctp_allassocs_info_t;
335
336
337
338 void register_tap_listener_sctp_stat(void);
339
340 const sctp_allassocs_info_t* sctp_stat_get_info(void);
341
342 void sctp_stat_scan(void);
343
344 void remove_tap_listener_sctp_stat(void);
345
346
347 const sctp_assoc_info_t* get_selected_assoc(void);
348
349 #ifdef __cplusplus
350 }
351 #endif /* __cplusplus */
352
353 #endif /* __TAP_SCTP_ANALYSIS_H__ */
354
355 /*
356  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
357  *
358  * Local variables:
359  * c-basic-offset: 8
360  * tab-width: 8
361  * indent-tabs-mode: t
362  * End:
363  *
364  * vi: set shiftwidth=8 tabstop=8 noexpandtab:
365  * :indentSize=8:tabSize=8:noTabs=false:
366  */