Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-rtag.c
blobd559cae2cedf859dedfd11b644672f1c3f43382b
1 /* packet-rtag.c
2 * Dissector for IEEE 802.1CB R-TAG tags
3 * By Stephen Williams <steve.williams@getcruise.com>
4 * Copyright 2020-present, Cruise LLC
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
13 # include "config.h"
14 # include <epan/packet.h>
15 # include <epan/etypes.h>
17 static int proto_rtag;
19 static dissector_handle_t ethertype_handle;
20 static dissector_handle_t rtag_handle;
23 * These values and tables are a breakdown of the R-TAG parts.
25 static int hf_rtag_reserved;
26 static int hf_rtag_sequence;
27 static int hf_rtag_protocol;
28 static int hf_rtag_trailer;
29 static hf_register_info rtag_breakdown[] = {
30 { &hf_rtag_reserved,
31 { "<reserved>", "rtag.reserved",
32 FT_UINT16, BASE_HEX,
33 NULL, 0x0,
34 NULL, HFILL }
36 { &hf_rtag_sequence,
37 { "Sequence number", "rtag.seqno",
38 FT_UINT16, BASE_DEC,
39 NULL, 0x0,
40 NULL, HFILL }
42 { &hf_rtag_protocol,
43 { "Type", "rtag.protocol",
44 FT_UINT16, BASE_HEX,
45 VALS(etype_vals), 0x0,
46 "Ethertype", HFILL }
48 { &hf_rtag_trailer,
49 { "Trailer", "rtag.trailer",
50 FT_BYTES, BASE_NONE, NULL, 0x0,
51 "R-TAG Trailer", HFILL }
57 static int ett_rtag;
58 static int *ett[] = { &ett_rtag };
61 * Dissect the R-TAG portion of a given packet. This is called with
62 * the tvb pointing to where our payload starts (i.e. not including
63 * the 0xf1c1 tag that got us here.)
65 static int dissect_rtag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
67 proto_item*ti;
68 col_set_str(pinfo->cinfo, COL_PROTOCOL, "R-TAG");
69 /* Clear the info column */
70 col_clear(pinfo->cinfo, COL_INFO);
73 * The R-TAG is 6 octets: 2 reserved, 2 sequence number, and
74 * 2 encapsulated protocol.
76 ti = proto_tree_add_item(tree, proto_rtag, tvb, 0, 6, ENC_NA);
78 uint16_t seqno = tvb_get_ntohs(tvb, 2);
79 uint16_t rtag_protocol = tvb_get_ntohs(tvb, 4);
81 proto_tree *rtag_subtree = proto_item_add_subtree(ti, ett_rtag);
82 proto_tree_add_item(rtag_subtree, hf_rtag_reserved, tvb, 0, 2, ENC_BIG_ENDIAN);
83 proto_tree_add_item(rtag_subtree, hf_rtag_sequence, tvb, 2, 2, ENC_BIG_ENDIAN);
84 proto_tree_add_item(rtag_subtree, hf_rtag_protocol, tvb, 4, 2, ENC_BIG_ENDIAN);
86 /* Add a quick summary in the info column. */
87 col_add_fstr(pinfo->cinfo, COL_INFO, "R-TAG: %u", seqno);
90 * Process the encapsulated packet as an encapsulated Ethernet
91 * PDU. We have the encapsulated protocol type (and ethertype)
92 * as part of the R-TAG protocol
94 ethertype_data_t ethertype_data;
95 ethertype_data.etype = rtag_protocol;
96 ethertype_data.payload_offset = 6;
97 ethertype_data.fh_tree = tree;
98 ethertype_data.trailer_id = hf_rtag_trailer;
99 ethertype_data.fcs_len = 0;
100 call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, &ethertype_data);
102 return tvb_captured_length(tvb);
106 * This function is called to register a protocol description.
108 void proto_register_rtag(void)
110 proto_rtag = proto_register_protocol (
111 "802.1cb R-TAG", /* name */
112 "R-TAG", /* short name */
113 "rtag" /* filter_name */
116 proto_register_field_array(proto_rtag, rtag_breakdown,
117 array_length(rtag_breakdown));
118 proto_register_subtree_array(ett, array_length(ett));
122 * This function is called to register the actual dissector.
124 void proto_reg_handoff_rtag(void)
126 rtag_handle = create_dissector_handle(dissect_rtag, proto_rtag);
127 dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB, rtag_handle);
129 /* Get a handle for the ethertype dissector. */
130 ethertype_handle = find_dissector_add_dependency("ethertype", proto_rtag);