Coverage Report

Created: 2026-06-30 07:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
0
#define FLIP_CHKSUM           (1)
65
66
111
#define FLIP_BASIC_HDR_LEN         (8)
67
0
#define FLIP_CHKSUM_HDR_LEN        (4)
68
2
#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
0
{
95
0
    proto_tree *chksum_hdr_tree;
96
0
    uint32_t dw;
97
0
    uint8_t  chksum_hdr_etype;
98
0
    uint8_t  chksum_hdr_ext;
99
0
    uint16_t chksum_hdr_chksum;
100
101
0
    int bytes_dissected;
102
0
    int offset;
103
104
0
    chksum_hdr_tree = NULL;
105
106
0
    bytes_dissected = 0;
107
0
    offset          = 0;
108
109
0
    dw = tvb_get_ntohl(tvb, offset);
110
0
    chksum_hdr_etype  = (uint8_t) ((dw & 0xFF000000) >> 24);
111
0
    chksum_hdr_ext    = (uint8_t) ((dw & 0x00010000) >> 16);
112
0
    chksum_hdr_chksum = (uint16_t) (dw & 0x0000FFFF);
113
114
    /* The actually shouldn't be any headers after checksum. */
115
0
    if (chksum_hdr_ext == 1) {
116
0
        *ext_hdr_follows_ptr = true;
117
0
    }
118
0
    else {
119
0
        *ext_hdr_follows_ptr = false;
120
0
    }
121
122
0
    if (tree) {
123
0
        chksum_hdr_tree = proto_tree_add_subtree(tree, tvb, offset + 0, 4,
124
0
                            ett_flip_chksum, NULL, "Checksum Header");
125
126
        /* ETYPE: 8 bits */
127
0
        proto_tree_add_uint_format_value(chksum_hdr_tree, hf_flip_chksum_etype,
128
0
                                         tvb, offset + 0, 1, dw,
129
0
                                         "%s", val_to_str_const(chksum_hdr_etype,
130
0
                                                                flip_etype,
131
0
                                                                "Unknown"));
132
        /* SPARE: 7 bits */
133
0
        proto_tree_add_item(chksum_hdr_tree, hf_flip_chksum_spare, tvb, offset, 4, ENC_BIG_ENDIAN);
134
135
        /* EXT HDR: 1 bit */
136
0
        proto_tree_add_item(chksum_hdr_tree, hf_flip_chksum_e,
137
0
                                         tvb, offset, 4, ENC_BIG_ENDIAN);
138
        /* CHKSUM: 16 bits. */
139
0
        proto_tree_add_uint_format_value(
140
0
            chksum_hdr_tree,
141
0
            hf_flip_chksum_chksum,
142
0
            tvb, offset + 2, 2,
143
0
            chksum_hdr_chksum,
144
0
            "0x%04x [%s] (computed 0x%04x)",
145
0
            chksum_hdr_chksum,
146
0
            ((chksum_hdr_chksum == computed_chksum) ? "Correct" : "Incorrect"),
147
0
            computed_chksum);
148
0
    }
149
150
    /* Show faulty checksums. */
151
0
    if (computed_chksum != chksum_hdr_chksum) {
152
0
        col_add_fstr(pinfo->cinfo, COL_INFO,
153
0
                     "Checksum 0x%04x [%s] (computed 0x%04x)",
154
0
                     chksum_hdr_chksum,
155
0
                     "Incorrect",
156
0
                     computed_chksum);
157
0
    }
158
159
0
    bytes_dissected += FLIP_CHKSUM_HDR_LEN;
160
161
0
    return bytes_dissected;
162
163
0
} /* 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
26
{
169
26
    proto_item *ti = NULL;
170
26
    proto_tree *flip_tree = NULL;
171
26
    proto_tree *basic_hdr_tree = NULL;
172
26
    tvbuff_t   *flip_tvb;
173
174
26
    uint32_t dw1;
175
176
    /* Basic header fields. */
177
26
    uint8_t  basic_hdr_ext;
178
26
    uint32_t basic_hdr_flow_id;
179
26
    uint16_t basic_hdr_len;
180
181
26
    bool ext_hdr = false;
182
183
26
    int bytes_dissected = 0;
184
26
    int payload_len;
185
26
    int frame_len;
186
26
    int flip_len;
187
26
    unsigned offset = 0;
188
189
    /* Error handling for basic header. */
190
26
    bool is_faulty_frame = false;
191
192
    /* Show this protocol as FLIP. */
193
26
    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
26
    frame_len = tvb_captured_length(tvb);
206
26
    if (frame_len < FLIP_BASIC_HDR_LEN) {
207
2
        return 0;
208
2
    }
209
210
24
    bytes_dissected += FLIP_BASIC_HDR_LEN;
211
212
    /* Process the first 32 bits of the basic header. */
213
24
    dw1 = tvb_get_ntohl(tvb, offset + 0);
214
24
    basic_hdr_ext      = ((dw1 & 0x80000000) >> 31);
215
24
    basic_hdr_flow_id  = (dw1 & 0x0FFFFFFF);
216
217
    /* Process the second 32 bits of the basic header. */
218
24
    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
24
    if (basic_hdr_ext == 1) {
223
5
        ext_hdr = true;
224
5
    }
225
226
24
    flip_len = basic_hdr_len;
227
228
    /*
229
     * Check the length value.
230
     */
231
24
    if ((flip_len < FLIP_BASIC_HDR_LEN) || (flip_len > frame_len)) {
232
        /* Faulty frame. Show the basic header anyway for debugging. */
233
22
        is_faulty_frame = true;
234
22
    }
235
236
    /* Fill in the info column. */
237
24
    col_add_fstr(pinfo->cinfo, COL_INFO,
238
24
                 "FlowID %s", val_to_str(pinfo->pool, basic_hdr_flow_id, NULL, "0x%08x"));
239
240
24
    flip_tvb = tvb_new_subset_length(tvb, 0, frame_len);
241
242
    /* We are asked for details. */
243
24
    if (tree) {
244
24
        ti = proto_tree_add_protocol_format(
245
24
                tree, proto_flip, flip_tvb, 0, flip_len,
246
24
                "NSN FLIP, FlowID %s",
247
24
                val_to_str(pinfo->pool, basic_hdr_flow_id, NULL, "0x%08x"));
248
24
        flip_tree = proto_item_add_subtree(ti, ett_flip);
249
250
        /* basic header */
251
24
        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
24
        proto_tree_add_item(basic_hdr_tree, hf_flip_basic_e, flip_tvb, offset, 4, ENC_BIG_ENDIAN);
255
256
        /* Reserved: 3 bits. */
257
24
        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
24
        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
24
        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
24
        proto_tree_add_item(basic_hdr_tree, hf_flip_basic_len, flip_tvb, offset + 6, 2, ENC_BIG_ENDIAN);
267
24
    }
268
269
24
    offset += FLIP_BASIC_HDR_LEN;
270
271
    /*
272
     * Process faults found when parsing the basic header.
273
     */
274
24
    if (is_faulty_frame == true) {
275
22
        if (flip_len > frame_len) {
276
11
            col_add_fstr(pinfo->cinfo, COL_INFO,
277
11
                         "Length mismatch: frame %d bytes, hdr %d bytes",
278
11
                         frame_len, flip_len);
279
11
        }
280
11
        else if (flip_len < FLIP_BASIC_HDR_LEN) {
281
11
            col_add_fstr(pinfo->cinfo, COL_INFO,
282
11
                         "Invalid length in basic header: %d bytes", flip_len);
283
11
        }
284
285
22
        goto DISSECT_FLIP_EXIT;
286
22
    }
287
288
    /*
289
     * Now we know that the basic header is sensible.
290
     */
291
2
    payload_len  = basic_hdr_len - FLIP_BASIC_HDR_LEN;
292
293
    /*
294
     * Dissect extension headers (if any).
295
     */
296
2
    if ((ext_hdr == true) && (payload_len < FLIP_EXTENSION_HDR_MIN_LEN)) {
297
0
        col_set_str(pinfo->cinfo, COL_INFO,
298
0
                    "Extension header indicated, but not enough data");
299
0
        goto DISSECT_FLIP_EXIT;
300
0
    }
301
302
2
    while ((ext_hdr == true) && (payload_len >= FLIP_EXTENSION_HDR_MIN_LEN)) {
303
        /* Detect the next header type. */
304
1
        uint8_t ext_hdr_type;
305
1
        int     bytes_handled;
306
1
        uint16_t computed_chksum;
307
308
1
        tvbuff_t *chksum_tvb;
309
310
1
        ext_hdr_type = tvb_get_uint8(flip_tvb, offset);
311
312
1
        switch (ext_hdr_type) {
313
0
        case FLIP_CHKSUM:
314
            /* Calculate checksum, let the chksum dissector verify it. */
315
0
            {
316
0
                vec_t   vec[2];
317
318
0
                SET_CKSUM_VEC_TVB(vec[0], flip_tvb, 0, bytes_dissected + 2);
319
0
                SET_CKSUM_VEC_TVB(vec[1], flip_tvb, bytes_dissected + 4,
320
0
                                  flip_len - (bytes_dissected + 4));
321
0
                computed_chksum = in_cksum(&vec[0], 2);
322
323
                /* Checksums handled in network order. */
324
0
                computed_chksum = g_htons(computed_chksum);
325
0
            }
326
327
0
            chksum_tvb = tvb_new_subset_length(flip_tvb, offset,
328
0
                                        FLIP_CHKSUM_HDR_LEN);
329
330
            /* Note that flip_tree is NULL if no details are requested. */
331
0
            bytes_handled = dissect_flip_chksum_hdr(chksum_tvb,
332
0
                                                    pinfo,
333
0
                                                    flip_tree,
334
0
                                                    computed_chksum,
335
0
                                                    &ext_hdr);
336
0
            bytes_dissected += bytes_handled;
337
0
            payload_len     -= bytes_handled;
338
0
            offset          += bytes_handled;
339
0
            break;
340
341
1
        default:
342
            /* Unknown header type. */
343
1
            col_add_fstr(pinfo->cinfo, COL_INFO,
344
1
                         "Invalid extension header type 0x%02x", ext_hdr_type);
345
1
            goto DISSECT_FLIP_EXIT;
346
0
            break;
347
1
        }
348
1
    }
349
350
    /*
351
     * Show payload (if any) as bytes.
352
     */
353
1
    if (payload_len > 0) {
354
355
0
        tvbuff_t           *payload_tvb;
356
0
        int                data_len;
357
358
0
        payload_tvb = tvb_new_subset_length(flip_tvb, offset, payload_len);
359
360
0
        data_len = dissector_try_payload_with_data(subdissector_table, payload_tvb, pinfo, tree, true, NULL);
361
0
        if (data_len <= 0)
362
0
        {
363
0
            data_len = call_data_dissector(payload_tvb, pinfo, tree);
364
0
        }
365
366
0
        bytes_dissected += data_len;
367
368
0
    } /* if (payload_len > 0) */
369
370
24
DISSECT_FLIP_EXIT:
371
24
    return bytes_dissected;
372
373
1
} /* 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
 */