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-ieee8021cb.c
Line
Count
Source
1
/* packet-ieee8021cb.c
2
 * Routines for 802.1CB R-tag ethernet header disassembly
3
 *
4
 * Copyright 2020, Rene Nielsen <rene.nielsen@microchip.com>
5
 * In association with Microchip Technology Inc.
6
 *
7
 * Wireshark - Network traffic analyzer
8
 * By Gerald Combs <gerald@wireshark.org>
9
 * Copyright 1998 Gerald Combs
10
 *
11
 * SPDX-License-Identifier: GPL-2.0-or-later
12
 */
13
14
#include "config.h"
15
16
#include <epan/packet.h>
17
#include <epan/capture_dissectors.h>
18
#include <wsutil/pint.h>
19
#include <epan/addr_resolv.h>
20
21
#include "packet-ipx.h"
22
#include "packet-llc.h"
23
#include <epan/etypes.h>
24
#include <epan/prefs.h>
25
26
void proto_register_ieee8021cb(void);
27
void proto_reg_handoff_ieee8021cb(void);
28
29
static dissector_handle_t ieee8021cb_handle;
30
static dissector_handle_t ethertype_handle;
31
32
static capture_dissector_handle_t ieee8021cb_cap_handle;
33
static capture_dissector_handle_t ipx_cap_handle;
34
static capture_dissector_handle_t llc_cap_handle;
35
36
/* GLOBALS ************************************************************/
37
38
static int proto_ieee8021cb;
39
40
/* dot1cb R-tag fields */
41
static int hf_ieee8021cb_res;
42
static int hf_ieee8021cb_seq;
43
44
/* Encapsulated protocol */
45
static int hf_ieee8021cb_etype;
46
47
static int ett_ieee8021cb;
48
49
0
#define IEEE8021CB_LEN 6
50
51
static bool
52
capture_ieee8021cb(const unsigned char *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header)
53
0
{
54
0
    uint16_t encap_proto;
55
56
0
    if (!BYTES_ARE_IN_FRAME(offset, len, IEEE8021CB_LEN + 1))
57
0
        return false;
58
59
0
    encap_proto = pntohu16( &pd[offset + IEEE8021CB_LEN - 2] );
60
0
    if (encap_proto <= IEEE_802_3_MAX_LEN) {
61
0
        if ( pd[offset + IEEE8021CB_LEN] == 0xff
62
0
             && pd[offset + IEEE8021CB_LEN + 1] == 0xff ) {
63
0
            return call_capture_dissector(ipx_cap_handle, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header);
64
0
        }
65
0
        else {
66
0
            return call_capture_dissector(llc_cap_handle, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header);
67
0
        }
68
0
    }
69
70
0
    return try_capture_dissector("ethertype", encap_proto, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header);
71
0
}
72
73
/* Dissector *************************************************************/
74
static
75
int dissect_ieee8021cb(tvbuff_t *tvb, packet_info *pinfo,
76
                   proto_tree *tree, void* data _U_)
77
0
{
78
0
    proto_tree       *ptree   = NULL;
79
0
    uint16_t          seq, pro;
80
0
    ethertype_data_t  ethertype_data;
81
0
    proto_tree       *ieee8021cb_tree;
82
83
    /* add info to column display */
84
0
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "802.1CB R-Tag");
85
0
    col_clear(pinfo->cinfo, COL_INFO);
86
87
0
    seq = tvb_get_ntohs(tvb, 2);
88
0
    pro = tvb_get_ntohs(tvb, 4);
89
90
0
    col_add_fstr(pinfo->cinfo, COL_INFO, "SEQ: %u", seq);
91
92
    /* create the protocol tree */
93
0
    ptree = proto_tree_add_item(tree, proto_ieee8021cb, tvb, 0, IEEE8021CB_LEN, ENC_NA);
94
0
    ieee8021cb_tree = proto_item_add_subtree(ptree, ett_ieee8021cb);
95
96
    /* add fields */
97
0
    proto_tree_add_uint(ieee8021cb_tree, hf_ieee8021cb_seq,   tvb, 2, 2, seq);
98
0
    proto_tree_add_uint(ieee8021cb_tree, hf_ieee8021cb_etype, tvb, 4, 2, pro);
99
100
0
    proto_item_append_text(ptree, ", SEQ: %u", seq);
101
102
0
    ethertype_data.fh_tree        = ieee8021cb_tree;
103
0
    ethertype_data.fcs_len        = 0;
104
0
    ethertype_data.etype          = pro;
105
0
    ethertype_data.payload_offset = IEEE8021CB_LEN;
106
107
    /* 802.1CB tags are always followed by an ethertype; call next dissector
108
       based on ethertype */
109
0
    call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, &ethertype_data);
110
111
0
    return tvb_captured_length(tvb);
112
0
}
113
114
void
115
proto_register_ieee8021cb(void)
116
14
{
117
14
    static hf_register_info hf_1cb[] = {
118
14
        { &hf_ieee8021cb_res, {
119
14
                "Reserved", "ieee8021cb.reserved", FT_UINT16, BASE_HEX,
120
14
                NULL, 0x0, NULL, HFILL }},
121
14
        { &hf_ieee8021cb_seq, {
122
14
                "SEQ", "ieee8021cb.seq", FT_UINT16, BASE_HEX_DEC,
123
14
                NULL, 0x0, NULL, HFILL }},
124
14
        { &hf_ieee8021cb_etype, {
125
14
                "Type", "ieee8021cb.etype", FT_UINT16, BASE_HEX,
126
14
                VALS(etype_vals), 0x0, "Ethertype", HFILL }}
127
14
    };
128
129
14
    static int *ett[] = {
130
14
        &ett_ieee8021cb
131
14
    };
132
133
    /* registration */
134
14
    proto_ieee8021cb = proto_register_protocol("802.1CB Redundancy Tag", "R-Tag", "ieee8021cb");
135
14
    proto_register_field_array(proto_ieee8021cb, hf_1cb, array_length(hf_1cb));
136
14
    proto_register_subtree_array(ett, array_length(ett));
137
138
14
    ieee8021cb_handle = register_dissector("ieee8021cb", dissect_ieee8021cb, proto_ieee8021cb);
139
14
    ieee8021cb_cap_handle = register_capture_dissector("ieee8021cb", capture_ieee8021cb, proto_ieee8021cb);
140
14
}
141
142
void
143
proto_reg_handoff_ieee8021cb(void)
144
14
{
145
146
14
    dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB, ieee8021cb_handle);
147
14
    ethertype_handle = find_dissector_add_dependency("ethertype", proto_ieee8021cb);
148
14
    capture_dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB, ieee8021cb_cap_handle);
149
150
14
    ipx_cap_handle = find_capture_dissector("ipx");
151
14
    llc_cap_handle = find_capture_dissector("llc");
152
14
}
153
154
/*
155
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
156
 *
157
 * Local Variables:
158
 * c-basic-offset: 4
159
 * tab-width: 8
160
 * indent-tabs-mode: nil
161
 * End:
162
 *
163
 * ex: set shiftwidth=4 tabstop=8 expandtab:
164
 * :indentSize=4:tabSize=8:noTabs=true:
165
 */