Get rid of unused variable.
[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 #include <epan/prefs.h>
53
54 void proto_reg_handoff_vmlab(void);
55
56 static int proto_vmlab = -1;
57
58 static int hf_vmlab_flags_part1 = -1;           /* Unknown so far */
59 static int hf_vmlab_flags_fragment = -1;
60 static int hf_vmlab_flags_part2 = -1;           /* Unknown so far */
61
62 static int hf_vmlab_portgroup = -1;
63 static int hf_vmlab_eth_src = -1;
64 static int hf_vmlab_eth_dst = -1;
65 static int hf_vmlab_eth_addr = -1;
66 static int hf_vmlab_etype = -1;
67 static int hf_vmlab_trailer = -1;
68
69 static gint ett_vmlab = -1;
70
71 static const value_string fragment_vals[] = {
72         { 0, "Not set" },
73         { 1, "Set" },
74         { 0, NULL }
75 };
76
77 static void
78 dissect_vmlab(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
79 {
80
81     proto_tree*     volatile vmlab_tree;
82     proto_item*     ti;
83     
84     guint32         offset=0;
85
86     const guint8*   src_addr;
87     const guint8*   dst_addr;
88     const guint8*   eth_addr;
89     guint8          attributes;
90     guint8          portgroup;
91
92     volatile guint16 encap_proto;
93
94     col_set_str(pinfo->cinfo, COL_PROTOCOL, "VMLAB");
95     col_clear(pinfo->cinfo, COL_INFO);
96
97     vmlab_tree = NULL;
98
99     if (tree) {
100         ti = proto_tree_add_item(tree, proto_vmlab, tvb, 0, 24, FALSE);
101         vmlab_tree = proto_item_add_subtree(ti, ett_vmlab);
102    
103         /* Flags*/
104         attributes = tvb_get_guint8(tvb, offset);
105         proto_tree_add_item(vmlab_tree, hf_vmlab_flags_part1,    tvb, offset, 1, FALSE);
106         proto_tree_add_item(vmlab_tree, hf_vmlab_flags_fragment, tvb, offset, 1, FALSE);
107         proto_tree_add_item(vmlab_tree, hf_vmlab_flags_part2,    tvb, offset, 1, FALSE);
108         if (attributes & 0x04) {
109             proto_item_append_text(ti, ", Fragment");
110         }
111         offset += 1;
112         
113         /* Portgroup*/
114         portgroup = tvb_get_guint8(tvb, offset);
115         proto_tree_add_uint(vmlab_tree, hf_vmlab_portgroup, tvb, offset, 1, portgroup);
116         proto_item_append_text(ti, ", Portgroup: %d", portgroup);
117         offset += 1;
118
119         /* The next two bytes were always 0x0000 as far as I could tell*/
120         offset += 2;
121
122         /* Not really clear, what the difference between this and the next MAC address is
123          Both are usually equal*/
124         eth_addr=tvb_get_ptr(tvb, offset, 6);
125         proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_addr, tvb, offset, 6, eth_addr);
126         offset += 6;
127
128         dst_addr=tvb_get_ptr(tvb, offset, 6);
129         proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_dst, tvb, offset, 6, dst_addr);
130         offset += 6;
131
132         /* Source MAC*/
133         src_addr=tvb_get_ptr(tvb, offset, 6);
134         proto_tree_add_ether(vmlab_tree, hf_vmlab_eth_src, tvb, offset, 6, src_addr);
135         offset += 6;
136
137         proto_item_append_text(ti, ", Src: %s (%s), Dst: %s (%s)", 
138             get_ether_name(src_addr), ether_to_str(src_addr), get_ether_name(dst_addr), ether_to_str(dst_addr));
139         
140         /*Encapsulated Ethertype is also part of the block*/
141         encap_proto = tvb_get_ntohs(tvb, offset);
142         offset += 2;
143     }
144
145     /* Now call whatever was encapsulated*/
146     ethertype(encap_proto, tvb, offset, pinfo, tree, vmlab_tree, hf_vmlab_etype, hf_vmlab_trailer, 0);
147
148 }
149
150 void
151 proto_register_vmlab(void)
152 {
153     static hf_register_info hf[] = {
154
155         { &hf_vmlab_flags_part1,        { "Unknown       ", "vmlab.unknown1", 
156             FT_UINT8, FT_BOOLEAN, NULL, 0xF8, NULL, HFILL }},
157         { &hf_vmlab_flags_fragment,     { "More Fragments", "vmlab.fragment", 
158             FT_UINT8, BASE_NONE, VALS(fragment_vals), 0x04, NULL, HFILL }},
159         { &hf_vmlab_flags_part2,        { "Unknown       ", "vmlab.unknown2", 
160             FT_UINT8, FT_BOOLEAN, NULL, 0x03, NULL, HFILL }},
161
162         { &hf_vmlab_portgroup,  { "Portgroup        ", "vmlab.pgrp", 
163             FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
164         { &hf_vmlab_eth_src,    { "Source           ", "vmlab.src", 
165             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
166         { &hf_vmlab_eth_dst,    { "Destination      ", "vmlab.dst", 
167             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
168         { &hf_vmlab_eth_addr,   { "Address          ", "vmlab.addr", 
169             FT_ETHER, BASE_NONE, NULL, 0x0, NULL, HFILL }},
170         { &hf_vmlab_etype,      { "Encapsulated Type", "vmlab.subtype", 
171             FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0, NULL, HFILL }},
172         { &hf_vmlab_trailer,    { "Trailer", "vmlab.trailer", 
173             FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }}
174     };
175     static gint *ett[] = {
176         &ett_vmlab
177     };
178
179     module_t *vmlab_module;
180
181     proto_vmlab = proto_register_protocol("VMware Lab Manager", "VMLAB", "vmlab");
182     proto_register_field_array(proto_vmlab, hf, array_length(hf));
183     proto_register_subtree_array(ett, array_length(ett));
184
185     vmlab_module = prefs_register_protocol(proto_vmlab, proto_reg_handoff_vmlab);
186
187 }
188
189 void
190 proto_reg_handoff_vmlab(void)
191 {
192     static dissector_handle_t vmlab_handle;
193
194     vmlab_handle = create_dissector_handle(dissect_vmlab, proto_vmlab);
195
196     dissector_add("ethertype", ETHERTYPE_VMLAB, vmlab_handle);
197 }