Coverage Report

Created: 2025-08-04 07:15

/src/wireshark/epan/dissectors/packet-cisco-metadata.c
Line
Count
Source
1
/* packet-cisco-metadata.c
2
 * Routines for dissection of Cisco's MetaData protocol.
3
 * draft-smith-kandula-sxp
4
 * Copyright 2013 by Vaibhav Katkade (vkatkade[AT]cisco.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
#include "config.h"
14
15
#include <epan/packet.h>
16
#include <epan/etypes.h>
17
#if 0
18
#include "packet-ieee8023.h"
19
#endif
20
21
void proto_register_cmd(void);
22
void proto_reg_handoff_cmd(void);
23
24
static dissector_handle_t cmd_eth_handle;
25
static dissector_handle_t cmd_gre_handle;
26
27
static dissector_handle_t ethertype_handle;
28
29
static dissector_table_t gre_dissector_table;
30
31
static int proto_cmd;
32
33
static int hf_cmd_version;
34
static int hf_cmd_length;
35
static int hf_cmd_options;
36
static int hf_cmd_sgt;
37
38
static int hf_eth_type;
39
static int hf_cmd_trailer;
40
41
static int ett_cmd;
42
43
static int
44
dissect_cmd_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
45
2
{
46
2
    uint16_t encap_proto;
47
2
    ethertype_data_t ethertype_data;
48
49
2
    proto_tree *cmd_tree = NULL;
50
2
    int offset = 0;
51
52
2
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMD");
53
2
    col_clear(pinfo->cinfo, COL_INFO);
54
55
2
    if (tree) {
56
2
        proto_item *ti = proto_tree_add_item(tree, proto_cmd, tvb, 0, 8, ENC_NA);
57
58
2
        cmd_tree = proto_item_add_subtree(ti, ett_cmd);
59
2
        proto_tree_add_item(cmd_tree, hf_cmd_version, tvb, offset, 1, ENC_BIG_ENDIAN);
60
2
        offset += 1;
61
2
        proto_tree_add_item(cmd_tree, hf_cmd_length, tvb, offset, 1, ENC_BIG_ENDIAN);
62
2
        offset += 1;
63
2
        proto_tree_add_item(cmd_tree, hf_cmd_options, tvb, offset, 2, ENC_BIG_ENDIAN);
64
2
        offset += 2;
65
2
        proto_tree_add_item(cmd_tree, hf_cmd_sgt, tvb, offset, 2, ENC_BIG_ENDIAN);
66
        /*offset += 2;*/
67
2
    }
68
69
2
    encap_proto = tvb_get_ntohs(tvb, 6);
70
71
/* This Logic to identify and decode IEEE 802.3 frames is not working correctly. Carry over code from packet-vlan.c
72
 * Commenting it out for now will display as Unknown for L2 control frames instead of showing a wrong decode.
73
 */
74
#if 0
75
    if (encap_proto <= IEEE_802_3_MAX_LEN) {
76
        bool is_802_2 = true;
77
78
        /* Don't throw an exception for this check (even a BoundsError) */
79
        if (tvb_captured_length_remaining(tvb, 4) >= 2) {
80
            if (tvb_get_ntohs(tvb, 4) == 0xffff)
81
                is_802_2 = false;
82
        }
83
84
        dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, cmd_tree, hf_eth_type, hf_cmd_trailer, 0);
85
    } else {
86
#endif
87
88
2
    proto_tree_add_uint(cmd_tree, hf_eth_type, tvb, 6, 2, encap_proto);
89
90
2
    ethertype_data.etype = encap_proto;
91
2
    ethertype_data.payload_offset = 8;
92
2
    ethertype_data.fh_tree = cmd_tree;
93
2
    ethertype_data.trailer_id = hf_cmd_trailer;
94
2
    ethertype_data.fcs_len = 0;
95
96
2
    call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, &ethertype_data);
97
2
    return tvb_captured_length(tvb);
98
2
}
99
100
static int
101
dissect_cmd_gre(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
102
2
{
103
2
    proto_item *ti = NULL;
104
2
    proto_tree *cmd_tree = NULL;
105
2
    uint16_t encap_proto;
106
2
    tvbuff_t *next_tvb;
107
2
    int offset = 0;
108
109
2
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMD");
110
2
    col_clear(pinfo->cinfo, COL_INFO);
111
112
2
    if (tree) {
113
2
        ti = proto_tree_add_item(tree, proto_cmd, tvb, 0, 6, ENC_NA);
114
2
        cmd_tree = proto_item_add_subtree(ti, ett_cmd);
115
2
    }
116
2
    encap_proto = tvb_get_ntohs(tvb, 0);
117
2
    proto_tree_add_item(cmd_tree, hf_eth_type, tvb, offset, 2, ENC_BIG_ENDIAN);
118
2
    offset += 2;
119
120
2
    proto_tree_add_item(cmd_tree, hf_cmd_version, tvb, offset, 1, ENC_BIG_ENDIAN);
121
2
    offset += 1;
122
2
    proto_tree_add_item(cmd_tree, hf_cmd_length, tvb, offset, 1, ENC_BIG_ENDIAN);
123
2
    offset += 1;
124
2
    proto_tree_add_item(cmd_tree, hf_cmd_options, tvb, offset, 2, ENC_BIG_ENDIAN);
125
2
    offset += 2;
126
2
    proto_tree_add_item(cmd_tree, hf_cmd_sgt, tvb, offset, 2, ENC_BIG_ENDIAN);
127
2
    offset += 2;
128
129
2
    next_tvb = tvb_new_subset_remaining(tvb, offset);
130
2
    if (!dissector_try_uint(gre_dissector_table, encap_proto, next_tvb, pinfo, tree))
131
1
        call_data_dissector(next_tvb, pinfo, tree);
132
2
    return tvb_captured_length(tvb);
133
2
}
134
135
void
136
proto_register_cmd(void)
137
14
{
138
14
    static hf_register_info hf[] = {
139
14
        { &hf_cmd_version,
140
14
            { "Version", "cmd.version", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
141
14
        },
142
14
        { &hf_cmd_length,
143
14
            { "Length", "cmd.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
144
14
        },
145
14
        { &hf_cmd_options,
146
14
            { "Options", "cmd.options", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }
147
14
        },
148
14
        { &hf_cmd_sgt,
149
14
            { "SGT", "cmd.sgt", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
150
14
        },
151
14
        { &hf_eth_type,
152
14
            { "Type", "cmd.type", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0, NULL, HFILL }
153
14
        },
154
14
        { &hf_cmd_trailer,
155
14
            { "Trailer", "cmd.trailer", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
156
14
        },
157
14
    };
158
159
14
    static int *ett[] = {
160
14
        &ett_cmd
161
14
    };
162
163
14
    proto_cmd = proto_register_protocol("Cisco MetaData", "Cisco MetaData", "cmd");
164
14
    proto_register_field_array(proto_cmd, hf, array_length(hf));
165
14
    proto_register_subtree_array(ett, array_length(ett));
166
167
14
    cmd_eth_handle = register_dissector("cmd.eth", dissect_cmd_eth, proto_cmd);
168
14
    cmd_gre_handle = register_dissector("cmd.gre", dissect_cmd_gre, proto_cmd);
169
14
}
170
171
void
172
proto_reg_handoff_cmd(void)
173
14
{
174
14
    ethertype_handle = find_dissector_add_dependency("ethertype", proto_cmd);
175
176
14
    gre_dissector_table = find_dissector_table("gre.proto");
177
178
14
    dissector_add_uint("ethertype", ETHERTYPE_CMD, cmd_eth_handle);
179
14
    dissector_add_uint("gre.proto", ETHERTYPE_CMD, cmd_gre_handle);
180
14
}
181
182
/*
183
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
184
 *
185
 * Local variables:
186
 * c-basic-offset: 4
187
 * tab-width: 8
188
 * indent-tabs-mode: nil
189
 * End:
190
 *
191
 * vi: set shiftwidth=4 tabstop=8 expandtab:
192
 * :indentSize=4:tabSize=8:noTabs=true:
193
 */