As suggested by Kovarththanan Rajaratnam in https://bugs.wireshark.org/bugzilla/show_...
[obnox/wireshark/wip.git] / epan / dissectors / packet-vmlab.c
1 /* packet-vmlab.c
2  * Routines for VMware Lab Manager Frame Dis-assembly
3  *
4  * $Id$
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25
26 /* History
27  *
28  * Apr 4, 2010 - David Aggeler
29  *
30  * - Initial version based on packet-vlan.c
31  *
32  *   VMware Lab Manager is using this encapsulation directly as Ethernet Frames
33  *   or inside VLANs. The Ethernet type was originally registered to Akimbi, but VMware
34  *   acquired this company in 2006. No public information found, so the decoding here
35  *   is an educated guess. Since one of the features of Lab Manager is to separate
36  *   VMs with equal host name, IP and MAC Address, I expect the upper layer dissectors
37  *   (namely ARP, ICMP, IP, TCP) to create false alerts, since identical configurations
38  *   may communicate at the same time. The main goal of this dissector is to be able
39  *   to troubleshoot connectivity, preferably pings. It's also a little to understand
40  *   as to how host spanning fenced configurations actually talk.
41  *
42  */
43
44 #ifdef HAVE_CONFIG_H
45 # include "config.h"
46 #endif
47
48 #include <glib.h>
49 #include <epan/addr_resolv.h>
50 #include <epan/packet.h>
51 #include <epan/etypes.h>
52
53 static int proto_vmlab = -1;
54
55 static int hf_vmlab_flags_part1 = -1;           /* Unknown so far */
56 static int hf_vmlab_flags_fragment = -1;
57 static int hf_vmlab_flags_part2 = -1;           /* Unknown so far */
58
59 static int hf_vmlab_portgroup = -1;
60 static int hf_vmlab_eth_src = -1;
61 static int hf_vmlab_eth_dst = -1;
62 static int hf_vmlab_eth_addr = -1;
63 static int hf_vmlab_etype = -1;
64 static int hf_vmlab_trailer = -1;
65
66 static gint ett_vmlab = -1;
67
68 static const value_string fragment_vals[] = {
69     { 0, "Not set" },
70     { 1, "Set" },
71     { 0, NULL }
72 };
73
74 static void
75 dissect_vmlab(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
76 {
77
78     proto_tree*     volatile vmlab_tree;
79     proto_item*     ti;
80
81     guint32         offset=0;
82
83     const guint8*   src_addr;
84     const guint8*   dst_addr;
85     const guint8*   eth_addr;
86     guint8          attributes;
87     guint8          portgroup;
88
89     volatile guint16 encap_proto;
90
91     col_set_str(pinfo->cinfo, COL_PROTOCOL, "VMLAB");
92     col_clear(pinfo->cinfo, COL_INFO);
93
94     ti = proto_tree_add_item(tree, proto_vmlab, tvb, 0, 24, FALSE);
95     vmlab_tree = proto_item_add_subtree(ti, ett_vmlab);
96
97     /* Flags*/
98     attributes = tvb_get_guint8(tvb, offset);
99     proto_tree_add_item(vmlab_tree, hf_vmlab_flags_part1,    tvb, offset, 1, FALSE);
100     proto_tree_add_item(vmlab_tree, hf_vmlab_flags_fragment, tvb, offset, 1, FALSE);
101     proto_tree_add_item(vmlab_tree, hf_vmlab_flags_part2,    tvb, offset, 1, FALSE);
102     if (attributes & 0x04) {
103         proto_item_append_text(ti, ", Fragment");
104     }
105     offset += 1;
106
107     /* Portgroup*/
108     portgroup = tvb_get_guint8(tvb, offset);
109     proto_tree_add_uint(vmlab_tree, hf_vmlab_portgroup, tvb, offset, 1, portgroup);
110     proto_item_append_text(ti, ", Portgroup: %d", portgroup);
111     offset += 1;
112
113     /* The next two bytes were always 0x0000 as far as I could tell*/
114     offset += 2;
115
116     /* Not really clear, what the difference between this and the next MAC address is
117        Both are usually equal*/
118     eth_addr=tvb_get_ptr(tvb, offset, 6);
119     proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_addr, tvb, offset, 6, eth_addr);
120     offset += 6;
121
122     dst_addr=tvb_get_ptr(tvb, offset, 6);
123     proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_dst, tvb, offset, 6, dst_addr);
124     offset += 6;
125
126     /* Source MAC*/
127     src_addr=tvb_get_ptr(tvb, offset, 6);
128     proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_src, tvb, offset, 6, src_addr);
129     offset += 6;
130
131     proto_item_append_text(ti, ", Src: %s (%s), Dst: %s (%s)",
132                            get_ether_name(src_addr), ether_to_str(src_addr), get_ether_name(dst_addr), ether_to_str(dst_addr));
133
134     /* Encapsulated Ethertype is also part of the block*/
135     encap_proto = tvb_get_ntohs(tvb, offset);
136     offset += 2;
137
138     /* Now call whatever was encapsulated*/
139     ethertype(encap_proto, tvb, offset, pinfo, tree, vmlab_tree, hf_vmlab_etype, hf_vmlab_trailer, 0);
140
141 }
142
143 void
144 proto_register_vmlab(void)
145 {
146     static hf_register_info hf[] = {
147
148         { &hf_vmlab_flags_part1,    { "Unknown", "vmlab.unknown1",
149             FT_UINT8, BASE_HEX,  NULL, 0xF8, NULL, HFILL }},
150         { &hf_vmlab_flags_fragment, { "More Fragments", "vmlab.fragment",
151             FT_UINT8, BASE_NONE, VALS(fragment_vals), 0x04, NULL, HFILL }},
152         { &hf_vmlab_flags_part2,    { "Unknown", "vmlab.unknown2",
153             FT_UINT8, BASE_HEX,  NULL, 0x03, NULL, HFILL }},
154
155         { &hf_vmlab_portgroup,      { "Portgroup", "vmlab.pgrp",
156             FT_UINT8, BASE_DEC,  NULL, 0, NULL, HFILL }},
157         { &hf_vmlab_eth_src,        { "Source", "vmlab.src",
158             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
159         { &hf_vmlab_eth_dst,        { "Destination", "vmlab.dst",
160             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
161         { &hf_vmlab_eth_addr,       { "Address", "vmlab.addr",
162             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
163         { &hf_vmlab_etype,          { "Encapsulated Type", "vmlab.subtype",
164             FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0, NULL, HFILL }},
165         { &hf_vmlab_trailer,        { "Trailer", "vmlab.trailer",
166             FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
167     };
168     static gint *ett[] = {
169         &ett_vmlab
170     };
171
172     proto_vmlab = proto_register_protocol("VMware Lab Manager", "VMLAB", "vmlab");
173     proto_register_field_array(proto_vmlab, hf, array_length(hf));
174     proto_register_subtree_array(ett, array_length(ett));
175 }
176
177 void
178 proto_reg_handoff_vmlab(void)
179 {
180     dissector_handle_t vmlab_handle;
181
182     vmlab_handle = create_dissector_handle(dissect_vmlab, proto_vmlab);
183
184     dissector_add("ethertype", ETHERTYPE_VMLAB, vmlab_handle);
185 }