Wireshark  4.3.0
The Wireshark network protocol analyzer
tap-sctp-analysis.h
Go to the documentation of this file.
1 
12 #ifndef __TAP_SCTP_ANALYSIS_H__
13 #define __TAP_SCTP_ANALYSIS_H__
14 
15 #include <stdbool.h>
16 #include <epan/dissectors/packet-sctp.h>
17 #include <epan/address.h>
18 #ifdef _WIN32
19 #include <winsock2.h>
20 #else
21 #include <sys/types.h>
22 #include <sys/socket.h>
23 #include <netinet/in.h>
24 #endif
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif /* __cplusplus */
29 
30 #define CHUNK_TYPE_LENGTH 1
31 #define CHUNK_FLAGS_LENGTH 1
32 #define CHUNK_LENGTH_LENGTH 2
33 
34 #define CHUNK_HEADER_OFFSET 0
35 #define CHUNK_TYPE_OFFSET CHUNK_HEADER_OFFSET
36 #define CHUNK_FLAGS_OFFSET (CHUNK_TYPE_OFFSET + CHUNK_TYPE_LENGTH)
37 #define CHUNK_LENGTH_OFFSET (CHUNK_FLAGS_OFFSET + CHUNK_FLAGS_LENGTH)
38 #define CHUNK_VALUE_OFFSET (CHUNK_LENGTH_OFFSET + CHUNK_LENGTH_LENGTH)
39 
40 #define INIT_CHUNK_INITIATE_TAG_LENGTH 4
41 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH 4
42 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH 2
43 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH 2
44 
45 
46 #define INIT_CHUNK_INITIATE_TAG_OFFSET CHUNK_VALUE_OFFSET
47 #define INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET (INIT_CHUNK_INITIATE_TAG_OFFSET + \
48  INIT_CHUNK_INITIATE_TAG_LENGTH )
49 #define INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET (INIT_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET + \
50  INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH )
51 #define INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET (INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_OFFSET + \
52  INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH )
53 #define INIT_CHUNK_INITIAL_TSN_OFFSET (INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_OFFSET + \
54  INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH )
55 
56 #define DATA_CHUNK_TSN_LENGTH 4
57 #define DATA_CHUNK_TSN_OFFSET (CHUNK_VALUE_OFFSET + 0)
58 #define DATA_CHUNK_STREAM_ID_OFFSET (DATA_CHUNK_TSN_OFFSET + DATA_CHUNK_TSN_LENGTH)
59 #define DATA_CHUNK_STREAM_ID_LENGTH 2
60 #define DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH 2
61 #define DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH 4
62 #define I_DATA_CHUNK_RESERVED_LENGTH 2
63 #define I_DATA_CHUNK_MID_LENGTH 4
64 #define I_DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH 4
65 #define I_DATA_CHUNK_FSN_LENGTH 4
66 #define I_DATA_CHUNK_RESERVED_OFFSET (DATA_CHUNK_STREAM_ID_OFFSET + \
67  DATA_CHUNK_STREAM_ID_LENGTH)
68 #define I_DATA_CHUNK_MID_OFFSET (I_DATA_CHUNK_RESERVED_OFFSET + \
69  I_DATA_CHUNK_RESERVED_LENGTH)
70 #define I_DATA_CHUNK_PAYLOAD_PROTOCOL_ID_OFFSET (I_DATA_CHUNK_MID_OFFSET + \
71  I_DATA_CHUNK_MID_LENGTH)
72 #define I_DATA_CHUNK_FSN_OFFSET (I_DATA_CHUNK_MID_OFFSET + \
73  I_DATA_CHUNK_MID_LENGTH)
74 #define I_DATA_CHUNK_PAYLOAD_OFFSET (I_DATA_CHUNK_PAYLOAD_PROTOCOL_ID_OFFSET + \
75  I_DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
76 #define DATA_CHUNK_HEADER_LENGTH (CHUNK_HEADER_LENGTH + \
77  DATA_CHUNK_TSN_LENGTH + \
78  DATA_CHUNK_STREAM_ID_LENGTH + \
79  DATA_CHUNK_STREAM_SEQ_NUMBER_LENGTH + \
80  DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
81 #define I_DATA_CHUNK_HEADER_LENGTH (CHUNK_HEADER_LENGTH + \
82  DATA_CHUNK_TSN_LENGTH + \
83  DATA_CHUNK_STREAM_ID_LENGTH + \
84  I_DATA_CHUNK_RESERVED_LENGTH + \
85  I_DATA_CHUNK_MID_LENGTH +\
86  I_DATA_CHUNK_PAYLOAD_PROTOCOL_ID_LENGTH)
87 #define MAX_ADDRESS_LEN 47
88 
89 #define SCTP_ABORT_CHUNK_T_BIT 0x01
90 
91 #define PARAMETER_TYPE_LENGTH 2
92 #define PARAMETER_LENGTH_LENGTH 2
93 #define PARAMETER_HEADER_LENGTH (PARAMETER_TYPE_LENGTH + PARAMETER_LENGTH_LENGTH)
94 
95 #define PARAMETER_HEADER_OFFSET 0
96 #define PARAMETER_TYPE_OFFSET PARAMETER_HEADER_OFFSET
97 #define PARAMETER_LENGTH_OFFSET (PARAMETER_TYPE_OFFSET + PARAMETER_TYPE_LENGTH)
98 #define PARAMETER_VALUE_OFFSET (PARAMETER_LENGTH_OFFSET + PARAMETER_LENGTH_LENGTH)
99 
100 #define IPV6_ADDRESS_LENGTH 16
101 #define IPV6_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
102 #define IPV4_ADDRESS_LENGTH 4
103 #define IPV4_ADDRESS_OFFSET PARAMETER_VALUE_OFFSET
104 #define IPV4ADDRESS_PARAMETER_ID 0x0005
105 #define IPV6ADDRESS_PARAMETER_ID 0x0006
106 
107 #define SACK_CHUNK_CUMULATIVE_TSN_ACK_LENGTH 4
108 #define SACK_CHUNK_CUMULATIVE_TSN_ACK_OFFSET (CHUNK_VALUE_OFFSET + 0)
109 #define SACK_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH 4
110 #define SACK_CHUNK_ADV_REC_WINDOW_CREDIT_OFFSET (SACK_CHUNK_CUMULATIVE_TSN_ACK_OFFSET + \
111  SACK_CHUNK_CUMULATIVE_TSN_ACK_LENGTH)
112 
113 #define INIT_CHUNK_INITIAL_TSN_LENGTH 4
114 #define INIT_CHUNK_FIXED_PARAMETERS_LENGTH (INIT_CHUNK_INITIATE_TAG_LENGTH + \
115  INIT_CHUNK_ADV_REC_WINDOW_CREDIT_LENGTH + \
116  INIT_CHUNK_NUMBER_OF_OUTBOUND_STREAMS_LENGTH + \
117  INIT_CHUNK_NUMBER_OF_INBOUND_STREAMS_LENGTH + \
118  INIT_CHUNK_INITIAL_TSN_LENGTH)
119 #define CHUNK_HEADER_LENGTH (CHUNK_TYPE_LENGTH + \
120  CHUNK_FLAGS_LENGTH + \
121  CHUNK_LENGTH_LENGTH)
122 #define INIT_CHUNK_VARIABLE_LENGTH_PARAMETER_OFFSET (INIT_CHUNK_INITIAL_TSN_OFFSET + \
123  INIT_CHUNK_INITIAL_TSN_LENGTH )
124 
125 /* The below value is 255 */
126 #define NUM_CHUNKS 0x100
127 
128 /* This variable is used as an index into arrays
129  * which store the cumulative information corresponding
130  * all chunks with Chunk Type greater > 16
131  * The value for the below variable is 17
132  */
133 #define OTHER_CHUNKS_INDEX 0xfe
134 
135 /* VNB */
136 /* This variable stores the maximum chunk type value
137  * that can be associated with a sctp chunk.
138  */
139 #define MAX_SCTP_CHUNK_TYPE 256
140 
141 typedef struct _tsn {
142  uint32_t frame_number;
143  uint32_t secs; /* Absolute seconds */
144  uint32_t usecs;
145  address src;
146  address dst;
147  uint32_t first_tsn;
148  GList *tsns;
149 } tsn_t;
150 
151 typedef struct _sctp_tmp_info {
152  uint16_t assoc_id;
153  uint16_t direction;
154  address src;
155  address dst;
156  uint16_t port1;
157  uint16_t port2;
158  uint32_t verification_tag1;
159  uint32_t verification_tag2;
160  uint32_t initiate_tag;
161  uint32_t n_tvbs;
163 
164 typedef struct _sctp_init_collision {
165  uint32_t init_vtag; /* initiate tag of the INIT chunk */
166  uint32_t initack_vtag; /* initiate tag of the INIT-ACK chunk */
167  uint32_t init_min_tsn; /* initial tsn of the INIT chunk */
168  uint32_t initack_min_tsn; /* initial tsn of the INIT-ACK chunk */
169  bool init:1;
170  bool initack:1;
172 
173 struct tsn_sort{
174  uint32_t tsnumber;
175  uint32_t secs;
176  uint32_t usecs;
177  uint32_t offset;
178  uint32_t length;
179  uint32_t framenumber;
180 };
181 
182 typedef struct _sctp_addr_chunk {
183  uint32_t direction;
184  address addr;
185  /* The array is initialized to MAX_SCTP_CHUNK_TYPE
186  * so that there is no memory overwrite
187  * when accessed using sctp chunk type as index.
188  */
189  uint32_t addr_count[MAX_SCTP_CHUNK_TYPE];
191 
192 typedef struct _sctp_assoc_info {
193  uint16_t assoc_id;
194  address src;
195  address dst;
196  uint16_t port1;
197  uint16_t port2;
198  uint32_t verification_tag1;
199  uint32_t verification_tag2;
200  uint32_t initiate_tag;
201  uint32_t n_tvbs;
202  GList *addr1;
203  GList *addr2;
204  uint16_t instream1;
205  uint16_t outstream1;
206  uint16_t instream2;
207  uint16_t outstream2;
208  uint32_t n_adler32_calculated;
209  uint32_t n_adler32_correct;
210  uint32_t n_crc32c_calculated;
211  uint32_t n_crc32c_correct;
212  char checksum_type[8];
213  uint32_t n_checksum_errors;
214  uint32_t n_bundling_errors;
215  uint32_t n_padding_errors;
216  uint32_t n_length_errors;
217  uint32_t n_value_errors;
218  uint32_t n_data_chunks;
219  uint32_t n_forward_chunks;
220  uint32_t n_forward_chunks_ep1;
221  uint32_t n_forward_chunks_ep2;
222  uint32_t n_data_bytes;
223  uint32_t n_packets;
224  uint32_t n_data_chunks_ep1;
225  uint32_t n_data_bytes_ep1;
226  uint32_t n_data_chunks_ep2;
227  uint32_t n_data_bytes_ep2;
228  uint32_t n_sack_chunks_ep1;
229  uint32_t n_sack_chunks_ep2;
230  uint32_t n_array_tsn1;
231  uint32_t n_array_tsn2;
232  uint32_t max_window1;
233  uint32_t max_window2;
234  uint32_t arwnd1;
235  uint32_t arwnd2;
236  bool init:1;
237  bool initack:1;
238  bool firstdata:1;
239  bool init_collision:1;
240  uint16_t initack_dir;
241  uint16_t direction;
242  uint32_t min_secs;
243  uint32_t min_usecs;
244  uint32_t max_secs;
245  uint32_t max_usecs;
246  uint32_t min_tsn1;
247  uint32_t min_tsn2;
248  uint32_t max_tsn1;
249  uint32_t max_tsn2;
250  uint32_t max_bytes1;
251  uint32_t max_bytes2;
252  sctp_init_collision_t *dir1;
253  sctp_init_collision_t *dir2;
254  GSList *min_max;
255  GList *frame_numbers;
256  GList *tsn1;
257  GPtrArray *sort_tsn1;
258  GPtrArray *sort_sack1;
259  GList *sack1;
260  GList *tsn2;
261  GPtrArray *sort_tsn2;
262  GPtrArray *sort_sack2;
263  GList *sack2;
264  bool check_address;
265  GList* error_info_list;
266  /* The array is initialized to MAX_SCTP_CHUNK_TYPE
267  * so that there is no memory overwrite
268  * when accessed using sctp chunk type as index.
269  */
270  uint32_t chunk_count[MAX_SCTP_CHUNK_TYPE];
271  uint32_t ep1_chunk_count[MAX_SCTP_CHUNK_TYPE];
272  uint32_t ep2_chunk_count[MAX_SCTP_CHUNK_TYPE];
273  GList *addr_chunk_count;
275 
276 typedef struct _sctp_error_info {
277  uint32_t frame_number;
278  char chunk_info[200];
279  const char *info_text;
281 
282 
283 typedef struct _sctp_allassocs_info {
284  uint32_t sum_tvbs;
285  GList *assoc_info_list;
286  bool is_registered;
287  GList *children;
289 
290 
291 
292 void register_tap_listener_sctp_stat(void);
293 
294 const sctp_allassocs_info_t* sctp_stat_get_info(void);
295 
296 void sctp_stat_scan(void);
297 
298 void remove_tap_listener_sctp_stat(void);
299 
300 const sctp_assoc_info_t* get_sctp_assoc_info(uint16_t assoc_id);
301 const sctp_assoc_info_t* get_selected_assoc(void);
302 
303 #ifdef __cplusplus
304 }
305 #endif /* __cplusplus */
306 
307 #endif /* __TAP_SCTP_ANALYSIS_H__ */
Definition: address.h:56
Definition: tap-sctp-analysis.h:182
Definition: tap-sctp-analysis.h:283
Definition: tap-sctp-analysis.h:192
Definition: tap-sctp-analysis.h:276
Definition: tap-sctp-analysis.h:164
Definition: tap-sctp-analysis.h:151
Definition: tap-sctp-analysis.h:141
Definition: tap-sctp-analysis.h:173