/src/wireshark/epan/dissectors/packet-flip.c
Line | Count | Source |
1 | | /* packet-flip.c |
2 | | * Routines for FLIP packet dissection |
3 | | * |
4 | | * Copyright 2009, Juha Siltanen <juha.siltanen@nsn.com> |
5 | | * |
6 | | * Wireshark - Network traffic analyzer |
7 | | * By Gerald Combs <gerald@wireshark.org> |
8 | | * Copyright 1998 Gerald Combs |
9 | | * |
10 | | * SPDX-License-Identifier: GPL-2.0-or-later |
11 | | */ |
12 | | |
13 | | /* |
14 | | * FLIP (Flow Layer Internal Protocol) is a proprietary protocol |
15 | | * developed by Nokia Solutions and Networks (previous was 'Nokia Siemens Networks'). |
16 | | */ |
17 | | |
18 | | /* |
19 | | * Version information |
20 | | * |
21 | | * Version 0.0.1, November 23rd, 2009. |
22 | | * |
23 | | * Support for the basic and checksum headers. |
24 | | * |
25 | | * Version 0.0.2, August 26th, 2010. |
26 | | * |
27 | | * Support for payload dissecting. |
28 | | * |
29 | | * Version 0.0.3, September 14th, 2010. |
30 | | * |
31 | | * Bugfix: sorting by protocol didn't always fill in the protocol column. |
32 | | */ |
33 | | |
34 | | #include "config.h" |
35 | | |
36 | | #include <epan/packet.h> |
37 | | #include <epan/etypes.h> |
38 | | #include <epan/decode_as.h> |
39 | | #include <epan/in_cksum.h> |
40 | | #include <epan/tfs.h> |
41 | | #include <epan/prefs.h> |
42 | | |
43 | | void proto_register_flip(void); |
44 | | void proto_reg_handoff_flip(void); |
45 | | |
46 | | static dissector_handle_t flip_handle; |
47 | | |
48 | | static int proto_flip; |
49 | | |
50 | | /* BASIC */ |
51 | | static int hf_flip_basic_e; |
52 | | static int hf_flip_basic_reserved; |
53 | | static int hf_flip_basic_flowid; |
54 | | static int hf_flip_basic_seqnum; |
55 | | static int hf_flip_basic_len; |
56 | | |
57 | | /* CHECKSUM */ |
58 | | static int hf_flip_chksum_etype; |
59 | | static int hf_flip_chksum_spare; |
60 | | static int hf_flip_chksum_e; |
61 | | static int hf_flip_chksum_chksum; |
62 | | |
63 | | #define FLIP_BASIC (0) |
64 | 2 | #define FLIP_CHKSUM (1) |
65 | | |
66 | 160 | #define FLIP_BASIC_HDR_LEN (8) |
67 | 4 | #define FLIP_CHKSUM_HDR_LEN (4) |
68 | 7 | #define FLIP_EXTENSION_HDR_MIN_LEN (4) |
69 | | |
70 | | static const value_string flip_etype[] = { |
71 | | { FLIP_CHKSUM, "Checksum" }, |
72 | | { 0, NULL } |
73 | | }; |
74 | | |
75 | | static dissector_table_t subdissector_table; |
76 | | |
77 | | static int ett_flip; |
78 | | static int ett_flip_basic; |
79 | | static int ett_flip_chksum; |
80 | | static int ett_flip_payload; |
81 | | |
82 | | static void flip_prompt(packet_info *pinfo _U_, char* result) |
83 | 0 | { |
84 | 0 | snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Decode FLIP payload protocol as"); |
85 | 0 | } |
86 | | |
87 | | /* Dissect the checksum extension header. */ |
88 | | static int |
89 | | dissect_flip_chksum_hdr(tvbuff_t *tvb, |
90 | | packet_info *pinfo, |
91 | | proto_tree *tree, |
92 | | uint16_t computed_chksum, |
93 | | bool *ext_hdr_follows_ptr) |
94 | 2 | { |
95 | 2 | proto_tree *chksum_hdr_tree; |
96 | 2 | uint32_t dw; |
97 | 2 | uint8_t chksum_hdr_etype; |
98 | 2 | uint8_t chksum_hdr_ext; |
99 | 2 | uint16_t chksum_hdr_chksum; |
100 | | |
101 | 2 | int bytes_dissected; |
102 | 2 | int offset; |
103 | | |
104 | 2 | chksum_hdr_tree = NULL; |
105 | | |
106 | 2 | bytes_dissected = 0; |
107 | 2 | offset = 0; |
108 | | |
109 | 2 | dw = tvb_get_ntohl(tvb, offset); |
110 | 2 | chksum_hdr_etype = (uint8_t) ((dw & 0xFF000000) >> 24); |
111 | 2 | chksum_hdr_ext = (uint8_t) ((dw & 0x00010000) >> 16); |
112 | 2 | chksum_hdr_chksum = (uint16_t) (dw & 0x0000FFFF); |
113 | | |
114 | | /* The actually shouldn't be any headers after checksum. */ |
115 | 2 | if (chksum_hdr_ext == 1) { |
116 | 2 | *ext_hdr_follows_ptr = true; |
117 | 2 | } |
118 | 0 | else { |
119 | 0 | *ext_hdr_follows_ptr = false; |
120 | 0 | } |
121 | | |
122 | 2 | if (tree) { |
123 | 2 | chksum_hdr_tree = proto_tree_add_subtree(tree, tvb, offset + 0, 4, |
124 | 2 | ett_flip_chksum, NULL, "Checksum Header"); |
125 | | |
126 | | /* ETYPE: 8 bits */ |
127 | 2 | proto_tree_add_uint_format_value(chksum_hdr_tree, hf_flip_chksum_etype, |
128 | 2 | tvb, offset + 0, 1, dw, |
129 | 2 | "%s", val_to_str_const(chksum_hdr_etype, |
130 | 2 | flip_etype, |
131 | 2 | "Unknown")); |
132 | | /* SPARE: 7 bits */ |
133 | 2 | proto_tree_add_item(chksum_hdr_tree, hf_flip_chksum_spare, tvb, offset, 4, ENC_BIG_ENDIAN); |
134 | | |
135 | | /* EXT HDR: 1 bit */ |
136 | 2 | proto_tree_add_item(chksum_hdr_tree, hf_flip_chksum_e, |
137 | 2 | tvb, offset, 4, ENC_BIG_ENDIAN); |
138 | | /* CHKSUM: 16 bits. */ |
139 | 2 | proto_tree_add_uint_format_value( |
140 | 2 | chksum_hdr_tree, |
141 | 2 | hf_flip_chksum_chksum, |
142 | 2 | tvb, offset + 2, 2, |
143 | 2 | chksum_hdr_chksum, |
144 | 2 | "0x%04x [%s] (computed 0x%04x)", |
145 | 2 | chksum_hdr_chksum, |
146 | 2 | ((chksum_hdr_chksum == computed_chksum) ? "Correct" : "Incorrect"), |
147 | 2 | computed_chksum); |
148 | 2 | } |
149 | | |
150 | | /* Show faulty checksums. */ |
151 | 2 | if (computed_chksum != chksum_hdr_chksum) { |
152 | 2 | col_add_fstr(pinfo->cinfo, COL_INFO, |
153 | 2 | "Checksum 0x%04x [%s] (computed 0x%04x)", |
154 | 2 | chksum_hdr_chksum, |
155 | 2 | "Incorrect", |
156 | 2 | computed_chksum); |
157 | 2 | } |
158 | | |
159 | 2 | bytes_dissected += FLIP_CHKSUM_HDR_LEN; |
160 | | |
161 | 2 | return bytes_dissected; |
162 | | |
163 | 2 | } /* dissect_flip_chksum_hdr() */ |
164 | | |
165 | | /* Protocol dissection */ |
166 | | static int |
167 | | dissect_flip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) |
168 | 39 | { |
169 | 39 | proto_item *ti = NULL; |
170 | 39 | proto_tree *flip_tree = NULL; |
171 | 39 | proto_tree *basic_hdr_tree = NULL; |
172 | 39 | tvbuff_t *flip_tvb; |
173 | | |
174 | 39 | uint32_t dw1; |
175 | | |
176 | | /* Basic header fields. */ |
177 | 39 | uint8_t basic_hdr_ext; |
178 | 39 | uint32_t basic_hdr_flow_id; |
179 | 39 | uint16_t basic_hdr_len; |
180 | | |
181 | 39 | bool ext_hdr = false; |
182 | | |
183 | 39 | int bytes_dissected = 0; |
184 | 39 | int payload_len; |
185 | 39 | int frame_len; |
186 | 39 | int flip_len; |
187 | 39 | int offset = 0; |
188 | | |
189 | | /* Error handling for basic header. */ |
190 | 39 | bool is_faulty_frame = false; |
191 | | |
192 | | /* Show this protocol as FLIP. */ |
193 | 39 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "FLIP"); |
194 | | |
195 | | /* |
196 | | * The frame can be faulty in several ways: |
197 | | * - too short (even for the basic header) |
198 | | * - length inconsistent (header and frame info different) |
199 | | * - checksum doesn't check out |
200 | | * - extension header is indicated, but the frame is too short for it |
201 | | * - unknown extension header type |
202 | | */ |
203 | | |
204 | | /* Check that there's enough data at least for the basic header. */ |
205 | 39 | frame_len = tvb_captured_length(tvb); |
206 | 39 | if (frame_len < FLIP_BASIC_HDR_LEN) { |
207 | 5 | return 0; |
208 | 5 | } |
209 | | |
210 | 34 | bytes_dissected += FLIP_BASIC_HDR_LEN; |
211 | | |
212 | | /* Process the first 32 bits of the basic header. */ |
213 | 34 | dw1 = tvb_get_ntohl(tvb, offset + 0); |
214 | 34 | basic_hdr_ext = ((dw1 & 0x80000000) >> 31); |
215 | 34 | basic_hdr_flow_id = (dw1 & 0x0FFFFFFF); |
216 | | |
217 | | /* Process the second 32 bits of the basic header. */ |
218 | 34 | basic_hdr_len = (uint16_t) (tvb_get_ntohl(tvb, offset + 4) & 0x0000FFFF); |
219 | | |
220 | | |
221 | | /* Does the basic header indicate that an extension is next? */ |
222 | 34 | if (basic_hdr_ext == 1) { |
223 | 7 | ext_hdr = true; |
224 | 7 | } |
225 | | |
226 | 34 | flip_len = basic_hdr_len; |
227 | | |
228 | | /* |
229 | | * Check the length value. |
230 | | */ |
231 | 34 | if ((flip_len < FLIP_BASIC_HDR_LEN) || (flip_len > frame_len)) { |
232 | | /* Faulty frame. Show the basic header anyway for debugging. */ |
233 | 27 | is_faulty_frame = true; |
234 | 27 | } |
235 | | |
236 | | /* Fill in the info column. */ |
237 | 34 | col_add_fstr(pinfo->cinfo, COL_INFO, |
238 | 34 | "FlowID %s", val_to_str(pinfo->pool, basic_hdr_flow_id, NULL, "0x%08x")); |
239 | | |
240 | 34 | flip_tvb = tvb_new_subset_length(tvb, 0, frame_len); |
241 | | |
242 | | /* We are asked for details. */ |
243 | 34 | if (tree) { |
244 | 34 | ti = proto_tree_add_protocol_format( |
245 | 34 | tree, proto_flip, flip_tvb, 0, flip_len, |
246 | 34 | "NSN FLIP, FlowID %s", |
247 | 34 | val_to_str(pinfo->pool, basic_hdr_flow_id, NULL, "0x%08x")); |
248 | 34 | flip_tree = proto_item_add_subtree(ti, ett_flip); |
249 | | |
250 | | /* basic header */ |
251 | 34 | basic_hdr_tree = proto_tree_add_subtree(flip_tree, flip_tvb, offset, 8, ett_flip_basic, NULL, "Basic Header"); |
252 | | |
253 | | /* Extension header follows? 1 bit. */ |
254 | 34 | proto_tree_add_item(basic_hdr_tree, hf_flip_basic_e, flip_tvb, offset, 4, ENC_BIG_ENDIAN); |
255 | | |
256 | | /* Reserved: 3 bits. */ |
257 | 34 | proto_tree_add_item(basic_hdr_tree, hf_flip_basic_reserved, flip_tvb, offset, 4, ENC_BIG_ENDIAN); |
258 | | |
259 | | /* Flow ID: 28 bits. */ |
260 | 34 | proto_tree_add_item(basic_hdr_tree, hf_flip_basic_flowid, flip_tvb, offset, 4, ENC_BIG_ENDIAN); |
261 | | |
262 | | /* Sequence number: 16 bits. */ |
263 | 34 | proto_tree_add_item(basic_hdr_tree, hf_flip_basic_seqnum, flip_tvb, offset + 4, 2, ENC_BIG_ENDIAN); |
264 | | |
265 | | /* Packet length: 16 bits. */ |
266 | 34 | proto_tree_add_item(basic_hdr_tree, hf_flip_basic_len, flip_tvb, offset + 6, 2, ENC_BIG_ENDIAN); |
267 | 34 | } |
268 | | |
269 | 34 | offset += FLIP_BASIC_HDR_LEN; |
270 | | |
271 | | /* |
272 | | * Process faults found when parsing the basic header. |
273 | | */ |
274 | 34 | if (is_faulty_frame == true) { |
275 | 27 | if (flip_len > frame_len) { |
276 | 15 | col_add_fstr(pinfo->cinfo, COL_INFO, |
277 | 15 | "Length mismatch: frame %d bytes, hdr %d bytes", |
278 | 15 | frame_len, flip_len); |
279 | 15 | } |
280 | 12 | else if (flip_len < FLIP_BASIC_HDR_LEN) { |
281 | 12 | col_add_fstr(pinfo->cinfo, COL_INFO, |
282 | 12 | "Invalid length in basic header: %d bytes", flip_len); |
283 | 12 | } |
284 | | |
285 | 27 | goto DISSECT_FLIP_EXIT; |
286 | 27 | } |
287 | | |
288 | | /* |
289 | | * Now we know that the basic header is sensible. |
290 | | */ |
291 | 7 | payload_len = basic_hdr_len - FLIP_BASIC_HDR_LEN; |
292 | | |
293 | | /* |
294 | | * Dissect extension headers (if any). |
295 | | */ |
296 | 7 | if ((ext_hdr == true) && (payload_len < FLIP_EXTENSION_HDR_MIN_LEN)) { |
297 | 1 | col_set_str(pinfo->cinfo, COL_INFO, |
298 | 1 | "Extension header indicated, but not enough data"); |
299 | 1 | goto DISSECT_FLIP_EXIT; |
300 | 1 | } |
301 | | |
302 | 8 | while ((ext_hdr == true) && (payload_len >= FLIP_EXTENSION_HDR_MIN_LEN)) { |
303 | | /* Detect the next header type. */ |
304 | 4 | uint8_t ext_hdr_type; |
305 | 4 | int bytes_handled; |
306 | 4 | uint16_t computed_chksum; |
307 | | |
308 | 4 | tvbuff_t *chksum_tvb; |
309 | | |
310 | 4 | ext_hdr_type = tvb_get_uint8(flip_tvb, offset); |
311 | | |
312 | 4 | switch (ext_hdr_type) { |
313 | 2 | case FLIP_CHKSUM: |
314 | | /* Calculate checksum, let the chksum dissector verify it. */ |
315 | 2 | { |
316 | 2 | vec_t vec[2]; |
317 | | |
318 | 2 | SET_CKSUM_VEC_TVB(vec[0], flip_tvb, 0, bytes_dissected + 2); |
319 | 2 | SET_CKSUM_VEC_TVB(vec[1], flip_tvb, bytes_dissected + 4, |
320 | 2 | flip_len - (bytes_dissected + 4)); |
321 | 2 | computed_chksum = in_cksum(&vec[0], 2); |
322 | | |
323 | | /* Checksums handled in network order. */ |
324 | 2 | computed_chksum = g_htons(computed_chksum); |
325 | 2 | } |
326 | | |
327 | 2 | chksum_tvb = tvb_new_subset_length(flip_tvb, offset, |
328 | 2 | FLIP_CHKSUM_HDR_LEN); |
329 | | |
330 | | /* Note that flip_tree is NULL if no details are requested. */ |
331 | 2 | bytes_handled = dissect_flip_chksum_hdr(chksum_tvb, |
332 | 2 | pinfo, |
333 | 2 | flip_tree, |
334 | 2 | computed_chksum, |
335 | 2 | &ext_hdr); |
336 | 2 | bytes_dissected += bytes_handled; |
337 | 2 | payload_len -= bytes_handled; |
338 | 2 | offset += bytes_handled; |
339 | 2 | break; |
340 | | |
341 | 2 | default: |
342 | | /* Unknown header type. */ |
343 | 2 | col_add_fstr(pinfo->cinfo, COL_INFO, |
344 | 2 | "Invalid extension header type 0x%02x", ext_hdr_type); |
345 | 2 | goto DISSECT_FLIP_EXIT; |
346 | 0 | break; |
347 | 4 | } |
348 | 4 | } |
349 | | |
350 | | /* |
351 | | * Show payload (if any) as bytes. |
352 | | */ |
353 | 4 | if (payload_len > 0) { |
354 | | |
355 | 4 | tvbuff_t *payload_tvb; |
356 | 4 | int data_len; |
357 | | |
358 | 4 | payload_tvb = tvb_new_subset_length(flip_tvb, offset, payload_len); |
359 | | |
360 | 4 | data_len = dissector_try_payload_with_data(subdissector_table, payload_tvb, pinfo, tree, true, NULL); |
361 | 4 | if (data_len <= 0) |
362 | 4 | { |
363 | 4 | data_len = call_data_dissector(payload_tvb, pinfo, tree); |
364 | 4 | } |
365 | | |
366 | 4 | bytes_dissected += data_len; |
367 | | |
368 | 4 | } /* if (payload_len > 0) */ |
369 | | |
370 | 34 | DISSECT_FLIP_EXIT: |
371 | 34 | return bytes_dissected; |
372 | | |
373 | 4 | } /* dissect_flip() */ |
374 | | |
375 | | |
376 | | /* Protocol initialization */ |
377 | | void |
378 | | proto_register_flip(void) |
379 | 14 | { |
380 | 14 | static hf_register_info hf[] = { |
381 | | /* |
382 | | * Basic header. |
383 | | */ |
384 | 14 | {&hf_flip_basic_e, |
385 | 14 | {"Extension Header Follows", "flip.basic.e", FT_BOOLEAN, 32, |
386 | 14 | TFS(&tfs_yes_no), 0x80000000, NULL, HFILL} |
387 | 14 | }, |
388 | 14 | {&hf_flip_basic_reserved, |
389 | 14 | {"Reserved", "flip.basic.reserved", FT_UINT32, BASE_DEC, |
390 | 14 | NULL, 0x70000000, "Basic Header Reserved", HFILL} |
391 | 14 | }, |
392 | 14 | {&hf_flip_basic_flowid, |
393 | 14 | {"FlowID", "flip.basic.flowid", FT_UINT32, BASE_HEX, |
394 | 14 | NULL, 0x0FFFFFFF, "Basic Header Flow ID", HFILL} |
395 | 14 | }, |
396 | 14 | {&hf_flip_basic_seqnum, |
397 | 14 | {"Seqnum", "flip.basic.seqnum", FT_UINT16, BASE_DEC_HEX, |
398 | 14 | NULL, 0x0, "Basic Header Sequence Number", HFILL} |
399 | 14 | }, |
400 | 14 | {&hf_flip_basic_len, |
401 | 14 | {"Len", "flip.basic.len", FT_UINT16, BASE_DEC_HEX, |
402 | 14 | NULL, 0x0, "Basic Header Packet Length", HFILL} |
403 | 14 | }, |
404 | | /* |
405 | | * Checksum header. |
406 | | */ |
407 | 14 | {&hf_flip_chksum_etype, |
408 | 14 | {"Extension Type", "flip.chksum.etype", FT_UINT32, BASE_DEC, |
409 | 14 | VALS(flip_etype), 0xFF000000, "Checksum Header Extension Type", HFILL} |
410 | 14 | }, |
411 | 14 | {&hf_flip_chksum_spare, |
412 | 14 | {"Spare", "flip.chksum.spare", FT_UINT32, BASE_DEC_HEX, |
413 | 14 | NULL, 0x00FE0000, "Checksum Header Spare", HFILL} |
414 | 14 | }, |
415 | 14 | {&hf_flip_chksum_e, |
416 | 14 | {"Extension Header Follows", "flip.chksum.e", FT_BOOLEAN, 32, |
417 | 14 | TFS(&tfs_yes_no), 0x00010000, NULL, HFILL} |
418 | 14 | }, |
419 | 14 | {&hf_flip_chksum_chksum, |
420 | 14 | {"Checksum", "flip.chksum.chksum", FT_UINT32, BASE_HEX, |
421 | 14 | NULL, 0x0000FFFF, NULL, HFILL} |
422 | 14 | } |
423 | 14 | }; |
424 | | |
425 | 14 | static int *ett[] = { |
426 | 14 | &ett_flip, |
427 | 14 | &ett_flip_basic, |
428 | 14 | &ett_flip_chksum, |
429 | 14 | &ett_flip_payload |
430 | 14 | }; |
431 | | |
432 | 14 | module_t *flip_module; |
433 | | |
434 | 14 | proto_flip = proto_register_protocol("NSN FLIP", "FLIP", "flip"); |
435 | 14 | flip_handle = register_dissector("flip", dissect_flip, proto_flip); |
436 | | |
437 | 14 | proto_register_field_array(proto_flip, hf, array_length(hf)); |
438 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
439 | | |
440 | 14 | flip_module = prefs_register_protocol_obsolete(proto_flip); |
441 | | |
442 | | /* Register preferences - now obsolete because of Decode As*/ |
443 | 14 | prefs_register_obsolete_preference(flip_module, "decoding_mode"); |
444 | 14 | prefs_register_obsolete_preference(flip_module, "heur_enabled_protocols"); |
445 | 14 | prefs_register_obsolete_preference(flip_module, "heur_decode_rtp"); |
446 | 14 | prefs_register_obsolete_preference(flip_module, "heur_decode_rtcp"); |
447 | 14 | prefs_register_obsolete_preference(flip_module, "forced_protocol"); |
448 | 14 | prefs_register_obsolete_preference(flip_module, "forced_decode"); |
449 | | |
450 | 14 | subdissector_table = register_decode_as_next_proto(proto_flip, "flip.payload", "FLIP payload", flip_prompt); |
451 | | |
452 | 14 | } /* proto_register_flip() */ |
453 | | |
454 | | /* Protocol handoff */ |
455 | | void |
456 | | proto_reg_handoff_flip(void) |
457 | 14 | { |
458 | 14 | dissector_add_uint("ethertype", ETHERTYPE_FLIP, flip_handle); |
459 | 14 | } /* proto_reg_handoff_flip() */ |
460 | | |
461 | | /* |
462 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
463 | | * |
464 | | * Local variables: |
465 | | * c-basic-offset: 4 |
466 | | * tab-width: 8 |
467 | | * indent-tabs-mode: nil |
468 | | * End: |
469 | | * |
470 | | * vi: set shiftwidth=4 tabstop=8 expandtab: |
471 | | * :indentSize=4:tabSize=8:noTabs=true: |
472 | | */ |