epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-vntag.c
blob1ac12fafb8adbe703a04ff21f1c62509fb5c2e5a
1 /* packet-vntag.c
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
10 #include "config.h"
12 #include <epan/packet.h>
13 #include <epan/etypes.h>
14 #include <epan/expert.h>
15 #include <epan/tfs.h>
16 #include "packet-ieee8023.h"
18 void proto_register_vntag(void);
19 void proto_reg_handoff_vntag(void);
21 static dissector_handle_t vntag_handle;
22 static dissector_handle_t ethertype_handle;
24 static int proto_vntag;
26 static int hf_vntag_etype;
27 static int hf_vntag_dir;
28 static int hf_vntag_ptr;
29 static int hf_vntag_dst;
30 static int hf_vntag_looped;
31 static int hf_vntag_r;
32 static int hf_vntag_version;
33 static int hf_vntag_src;
34 static int hf_vntag_len;
35 static int hf_vntag_trailer;
37 static int ett_vntag;
39 static expert_field ei_vntag_len;
41 static const true_false_string vntag_dir_tfs = {
42 "From Bridge",
43 "To Bridge"
45 static const true_false_string vntag_ptr_tfs = {
46 "vif_list_id",
47 "vif_id"
50 static int
51 dissect_vntag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
53 uint16_t encap_proto;
54 proto_tree *vntag_tree = NULL;
55 ethertype_data_t ethertype_data;
57 /* Documentation:
58 https://d2zmdbbm9feqrf.cloudfront.net/2012/usa/pdf/BRKDCT-2340.pdf p.61
59 http://www.definethecloud.net/access-layer-network-virtualization-vn-tag-and-vepa
61 static int * const fields[] = {
62 &hf_vntag_dir,
63 &hf_vntag_ptr,
64 &hf_vntag_dst,
65 &hf_vntag_looped,
66 &hf_vntag_r,
67 &hf_vntag_version,
68 &hf_vntag_src,
69 NULL
72 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VNTAG");
73 col_clear(pinfo->cinfo, COL_INFO);
75 if (tree) {
76 proto_item *ti = proto_tree_add_item(tree, proto_vntag, tvb, 0, 4, ENC_NA);
77 vntag_tree = proto_item_add_subtree(ti, ett_vntag);
79 proto_tree_add_bitmask_list(vntag_tree, tvb, 0, 4, fields, ENC_BIG_ENDIAN);
82 encap_proto = tvb_get_ntohs(tvb, 4);
84 /* VNTAG may also carry 802.2 encapsulated data */
85 if (encap_proto <= IEEE_802_3_MAX_LEN) {
86 bool is_802_2;
88 /* Is there an 802.2 layer? I can tell by looking at the first 2
89 bytes after the VLAN header. If they are 0xffff, then what
90 follows the VLAN header is an IPX payload, meaning no 802.2.
91 (IPX/SPX is they only thing that can be contained inside a
92 straight 802.3 packet, so presumably the same applies for
93 Ethernet VLAN packets). A non-0xffff value means that there's an
94 802.2 layer inside the VLAN layer */
95 is_802_2 = true;
97 /* Don't throw an exception for this check (even a BoundsError) */
98 if (tvb_captured_length_remaining(tvb, 6) >= 2) {
99 if (tvb_get_ntohs(tvb, 6) == 0xffff)
100 is_802_2 = false;
103 dissect_802_3(encap_proto, is_802_2, tvb, 6, pinfo, tree, vntag_tree, hf_vntag_len, hf_vntag_trailer, &ei_vntag_len, 0);
104 } else {
105 proto_tree_add_uint(vntag_tree, hf_vntag_etype, tvb, 4, 2,
106 encap_proto);
108 ethertype_data.etype = encap_proto;
109 ethertype_data.payload_offset = 6;
110 ethertype_data.fh_tree = vntag_tree;
111 ethertype_data.trailer_id = hf_vntag_trailer;
112 ethertype_data.fcs_len = 0;
114 call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, &ethertype_data);
116 return tvb_captured_length(tvb);
119 void
120 proto_register_vntag(void)
122 static hf_register_info hf[] = {
123 { &hf_vntag_etype,
124 { "Type", "vntag.etype", FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0, NULL, HFILL }
126 { &hf_vntag_dir,
127 { "Direction", "vntag.dir", FT_BOOLEAN, 32, TFS(&vntag_dir_tfs), 0x80000000, NULL, HFILL }
129 { &hf_vntag_ptr,
130 { "Pointer", "vntag.ptr", FT_BOOLEAN, 32, TFS(&vntag_ptr_tfs), 0x40000000, NULL, HFILL }
132 { &hf_vntag_dst,
133 { "Destination", "vntag.dst", FT_UINT32, BASE_DEC, NULL, 0x3FFF0000, NULL, HFILL }
135 { &hf_vntag_looped,
136 { "Looped", "vntag.looped", FT_BOOLEAN, 32, TFS(&tfs_yes_no), 0x00008000, NULL, HFILL }
138 { &hf_vntag_r,
139 { "Reserved", "vntag.r", FT_UINT32, BASE_DEC, NULL, 0x00004000, NULL, HFILL }
141 { &hf_vntag_version,
142 { "Version", "vntag.version", FT_UINT32, BASE_DEC, NULL, 0x00003000, NULL, HFILL }
144 { &hf_vntag_src,
145 { "Source", "vntag.src", FT_UINT32, BASE_DEC, NULL, 0x00000FFF, NULL, HFILL }
147 { &hf_vntag_len,
148 { "Length", "vntag.len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }
150 { &hf_vntag_trailer,
151 { "Trailer", "vntag.trailer", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
155 static int *ett[] = {
156 &ett_vntag
159 static ei_register_info ei[] = {
160 { &ei_vntag_len, { "vntag.len.past_end", PI_MALFORMED, PI_ERROR, "Length field value goes past the end of the payload", EXPFILL }},
162 expert_module_t* expert_vntag;
164 proto_vntag = proto_register_protocol("VN-Tag", "VNTAG", "vntag");
165 proto_register_field_array(proto_vntag, hf, array_length(hf));
166 proto_register_subtree_array(ett, array_length(ett));
167 expert_vntag = expert_register_protocol(proto_vntag);
168 expert_register_field_array(expert_vntag, ei, array_length(ei));
169 vntag_handle = register_dissector("vntag", dissect_vntag, proto_vntag);
172 void
173 proto_reg_handoff_vntag(void)
175 dissector_add_uint("ethertype", ETHERTYPE_VNTAG, vntag_handle);
177 ethertype_handle = find_dissector_add_dependency("ethertype", proto_vntag);
181 * Editor modelines - https://www.wireshark.org/tools/modelines.html
183 * Local variables:
184 * c-basic-offset: 8
185 * tab-width: 8
186 * indent-tabs-mode: t
187 * End:
189 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
190 * :indentSize=8:tabSize=8:noTabs=false: