2 * Routines for VLAN 802.1Q ethernet header disassembly
4 * $Id: packet-vlan.c,v 1.42 2003/01/31 03:17:47 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@ethereal.com>
8 * Copyright 1998 Gerald Combs
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.
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.
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.
30 #include <epan/packet.h>
31 #include "packet-ieee8023.h"
32 #include "packet-ipx.h"
33 #include "packet-llc.h"
34 #include "packet-vlan.h"
37 static int proto_vlan = -1;
38 static int hf_vlan_priority = -1;
39 static int hf_vlan_cfi = -1;
40 static int hf_vlan_id = -1;
41 static int hf_vlan_etype = -1;
42 static int hf_vlan_len = -1;
43 static int hf_vlan_trailer = -1;
45 static gint ett_vlan = -1;
48 capture_vlan(const guchar *pd, int offset, int len, packet_counts *ld ) {
50 if ( !BYTES_ARE_IN_FRAME(offset,len,5) ) {
54 encap_proto = pntohs( &pd[offset+2] );
55 if ( encap_proto <= IEEE_802_3_MAX_LEN) {
56 if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) {
59 capture_llc(pd,offset+4,len,ld);
62 capture_ethertype(encap_proto, pd, offset+4, len, ld);
67 dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
70 guint16 tci,encap_proto;
71 volatile gboolean is_802_2;
72 proto_tree *volatile vlan_tree;
74 if (check_col(pinfo->cinfo, COL_PROTOCOL))
75 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VLAN");
76 if (check_col(pinfo->cinfo, COL_INFO))
77 col_clear(pinfo->cinfo, COL_INFO);
79 tci = tvb_get_ntohs( tvb, 0 );
81 if (check_col(pinfo->cinfo, COL_INFO)) {
82 col_add_fstr(pinfo->cinfo, COL_INFO, "PRI: %d CFI: %d ID: %d",
83 (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
89 ti = proto_tree_add_item(tree, proto_vlan, tvb, 0, 4, FALSE);
90 vlan_tree = proto_item_add_subtree(ti, ett_vlan);
92 proto_tree_add_uint(vlan_tree, hf_vlan_priority, tvb, 0, 2, tci);
93 proto_tree_add_uint(vlan_tree, hf_vlan_cfi, tvb, 0, 2, tci);
94 proto_tree_add_uint(vlan_tree, hf_vlan_id, tvb, 0, 2, tci);
97 encap_proto = tvb_get_ntohs(tvb, 2);
98 if (encap_proto <= IEEE_802_3_MAX_LEN) {
99 /* Is there an 802.2 layer? I can tell by looking at the first 2
100 bytes after the VLAN header. If they are 0xffff, then what
101 follows the VLAN header is an IPX payload, meaning no 802.2.
102 (IPX/SPX is they only thing that can be contained inside a
103 straight 802.3 packet, so presumably the same applies for
104 Ethernet VLAN packets). A non-0xffff value means that there's an
105 802.2 layer inside the VLAN layer */
108 if (tvb_get_ntohs(tvb, 4) == 0xffff) {
112 CATCH2(BoundsError, ReportedBoundsError) {
118 dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, vlan_tree,
119 hf_vlan_len, hf_vlan_trailer);
121 ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree,
122 hf_vlan_etype, hf_vlan_trailer);
127 proto_register_vlan(void)
129 static hf_register_info hf[] = {
130 { &hf_vlan_priority, {
131 "Priority", "vlan.priority", FT_UINT16, BASE_DEC,
132 0, 0xE000, "Priority", HFILL }},
134 "CFI", "vlan.cfi", FT_UINT16, BASE_DEC,
135 0, 0x1000, "CFI", HFILL }}, /* XXX - Boolean? */
137 "ID", "vlan.id", FT_UINT16, BASE_DEC,
138 0, 0x0FFF, "ID", HFILL }},
140 "Type", "vlan.etype", FT_UINT16, BASE_HEX,
141 VALS(etype_vals), 0x0, "Type", HFILL }},
143 "Length", "vlan.len", FT_UINT16, BASE_DEC,
144 NULL, 0x0, "Length", HFILL }},
145 { &hf_vlan_trailer, {
146 "Trailer", "vlan.trailer", FT_BYTES, BASE_NONE,
147 NULL, 0x0, "VLAN Trailer", HFILL }}
149 static gint *ett[] = {
153 proto_vlan = proto_register_protocol("802.1q Virtual LAN", "VLAN", "vlan");
154 proto_register_field_array(proto_vlan, hf, array_length(hf));
155 proto_register_subtree_array(ett, array_length(ett));
159 proto_reg_handoff_vlan(void)
161 dissector_handle_t vlan_handle;
163 vlan_handle = create_dissector_handle(dissect_vlan, proto_vlan);
164 dissector_add("ethertype", ETHERTYPE_VLAN, vlan_handle);