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)
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/etypes.h>
18 #include "packet-ieee8023.h"
21 void proto_register_cmd(void);
22 void proto_reg_handoff_cmd(void);
24 static dissector_handle_t cmd_eth_handle
;
25 static dissector_handle_t cmd_gre_handle
;
27 static dissector_handle_t ethertype_handle
;
29 static dissector_table_t gre_dissector_table
;
33 static int hf_cmd_version
;
34 static int hf_cmd_length
;
35 static int hf_cmd_options
;
36 static int hf_cmd_sgt
;
38 static int hf_eth_type
;
39 static int hf_cmd_trailer
;
44 dissect_cmd_eth(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
47 ethertype_data_t ethertype_data
;
49 proto_tree
*cmd_tree
= NULL
;
52 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "CMD");
53 col_clear(pinfo
->cinfo
, COL_INFO
);
56 proto_item
*ti
= proto_tree_add_item(tree
, proto_cmd
, tvb
, 0, 8, ENC_NA
);
58 cmd_tree
= proto_item_add_subtree(ti
, ett_cmd
);
59 proto_tree_add_item(cmd_tree
, hf_cmd_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
61 proto_tree_add_item(cmd_tree
, hf_cmd_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
63 proto_tree_add_item(cmd_tree
, hf_cmd_options
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
65 proto_tree_add_item(cmd_tree
, hf_cmd_sgt
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
69 encap_proto
= tvb_get_ntohs(tvb
, 6);
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.
75 if (encap_proto
<= IEEE_802_3_MAX_LEN
) {
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)
84 dissect_802_3(encap_proto
, is_802_2
, tvb
, 4, pinfo
, tree
, cmd_tree
, hf_eth_type
, hf_cmd_trailer
, 0);
88 proto_tree_add_uint(cmd_tree
, hf_eth_type
, tvb
, 6, 2, encap_proto
);
90 ethertype_data
.etype
= encap_proto
;
91 ethertype_data
.payload_offset
= 8;
92 ethertype_data
.fh_tree
= cmd_tree
;
93 ethertype_data
.trailer_id
= hf_cmd_trailer
;
94 ethertype_data
.fcs_len
= 0;
96 call_dissector_with_data(ethertype_handle
, tvb
, pinfo
, tree
, ðertype_data
);
97 return tvb_captured_length(tvb
);
101 dissect_cmd_gre(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
103 proto_item
*ti
= NULL
;
104 proto_tree
*cmd_tree
= NULL
;
105 uint16_t encap_proto
;
109 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "CMD");
110 col_clear(pinfo
->cinfo
, COL_INFO
);
113 ti
= proto_tree_add_item(tree
, proto_cmd
, tvb
, 0, 6, ENC_NA
);
114 cmd_tree
= proto_item_add_subtree(ti
, ett_cmd
);
116 encap_proto
= tvb_get_ntohs(tvb
, 0);
117 proto_tree_add_item(cmd_tree
, hf_eth_type
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
120 proto_tree_add_item(cmd_tree
, hf_cmd_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
122 proto_tree_add_item(cmd_tree
, hf_cmd_length
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
124 proto_tree_add_item(cmd_tree
, hf_cmd_options
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
126 proto_tree_add_item(cmd_tree
, hf_cmd_sgt
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
129 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
130 if (!dissector_try_uint(gre_dissector_table
, encap_proto
, next_tvb
, pinfo
, tree
))
131 call_data_dissector(next_tvb
, pinfo
, tree
);
132 return tvb_captured_length(tvb
);
136 proto_register_cmd(void)
138 static hf_register_info hf
[] = {
140 { "Version", "cmd.version", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
143 { "Length", "cmd.length", FT_UINT8
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
146 { "Options", "cmd.options", FT_UINT16
, BASE_HEX
, NULL
, 0x0, NULL
, HFILL
}
149 { "SGT", "cmd.sgt", FT_UINT16
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
}
152 { "Type", "cmd.type", FT_UINT16
, BASE_HEX
, VALS(etype_vals
), 0x0, NULL
, HFILL
}
155 { "Trailer", "cmd.trailer", FT_BYTES
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
}
159 static int *ett
[] = {
163 proto_cmd
= proto_register_protocol("Cisco MetaData", "Cisco MetaData", "cmd");
164 proto_register_field_array(proto_cmd
, hf
, array_length(hf
));
165 proto_register_subtree_array(ett
, array_length(ett
));
167 cmd_eth_handle
= register_dissector("cmd.eth", dissect_cmd_eth
, proto_cmd
);
168 cmd_gre_handle
= register_dissector("cmd.gre", dissect_cmd_gre
, proto_cmd
);
172 proto_reg_handoff_cmd(void)
174 ethertype_handle
= find_dissector_add_dependency("ethertype", proto_cmd
);
176 gre_dissector_table
= find_dissector_table("gre.proto");
178 dissector_add_uint("ethertype", ETHERTYPE_CMD
, cmd_eth_handle
);
179 dissector_add_uint("gre.proto", ETHERTYPE_CMD
, cmd_gre_handle
);
183 * Editor modelines - https://www.wireshark.org/tools/modelines.html
188 * indent-tabs-mode: nil
191 * vi: set shiftwidth=4 tabstop=8 expandtab:
192 * :indentSize=4:tabSize=8:noTabs=true: