2 * Routines for VLAN 802.1Q ethernet header disassembly
4 * $Id: packet-vlan.c,v 1.38 2002/01/21 07:36:44 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.
29 #ifdef HAVE_SYS_TYPES_H
30 # include <sys/types.h>
33 #ifdef HAVE_NETINET_IN_H
34 # include <netinet/in.h>
38 #include <epan/packet.h>
39 #include "packet-ieee8023.h"
40 #include "packet-ipx.h"
41 #include "packet-llc.h"
42 #include "packet-vlan.h"
45 static int proto_vlan = -1;
46 static int hf_vlan_priority = -1;
47 static int hf_vlan_cfi = -1;
48 static int hf_vlan_id = -1;
49 static int hf_vlan_etype = -1;
50 static int hf_vlan_len = -1;
51 static int hf_vlan_trailer = -1;
53 static gint ett_vlan = -1;
56 capture_vlan(const u_char *pd, int offset, int len, packet_counts *ld ) {
58 if ( !BYTES_ARE_IN_FRAME(offset,len,5) ) {
62 encap_proto = pntohs( &pd[offset+2] );
63 if ( encap_proto <= IEEE_802_3_MAX_LEN) {
64 if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) {
65 capture_ipx(pd,offset+4,len,ld);
67 capture_llc(pd,offset+4,len,ld);
70 capture_ethertype(encap_proto, pd, offset+4, len, ld);
75 dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
78 guint16 tci,encap_proto;
79 volatile gboolean is_802_2;
80 proto_tree *volatile vlan_tree;
82 if (check_col(pinfo->cinfo, COL_PROTOCOL))
83 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VLAN");
84 if (check_col(pinfo->cinfo, COL_INFO))
85 col_clear(pinfo->cinfo, COL_INFO);
87 tci = tvb_get_ntohs( tvb, 0 );
89 if (check_col(pinfo->cinfo, COL_INFO)) {
90 col_add_fstr(pinfo->cinfo, COL_INFO, "PRI: %d CFI: %d ID: %d",
91 (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
97 ti = proto_tree_add_item(tree, proto_vlan, tvb, 0, 4, FALSE);
98 vlan_tree = proto_item_add_subtree(ti, ett_vlan);
100 proto_tree_add_uint(vlan_tree, hf_vlan_priority, tvb, 0, 2, tci);
101 proto_tree_add_uint(vlan_tree, hf_vlan_cfi, tvb, 0, 2, tci);
102 proto_tree_add_uint(vlan_tree, hf_vlan_id, tvb, 0, 2, tci);
105 encap_proto = tvb_get_ntohs(tvb, 2);
106 if (encap_proto <= IEEE_802_3_MAX_LEN) {
107 /* Is there an 802.2 layer? I can tell by looking at the first 2
108 bytes after the VLAN header. If they are 0xffff, then what
109 follows the VLAN header is an IPX payload, meaning no 802.2.
110 (IPX/SPX is they only thing that can be contained inside a
111 straight 802.3 packet, so presumably the same applies for
112 Ethernet VLAN packets). A non-0xffff value means that there's an
113 802.2 layer inside the VLAN layer */
116 if (tvb_get_ntohs(tvb, 4) == 0xffff) {
120 CATCH2(BoundsError, ReportedBoundsError) {
126 dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, vlan_tree,
127 hf_vlan_len, hf_vlan_trailer);
129 ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree,
130 hf_vlan_etype, hf_vlan_trailer);
135 proto_register_vlan(void)
137 static hf_register_info hf[] = {
138 { &hf_vlan_priority, {
139 "Priority", "vlan.priority", FT_UINT16, BASE_BIN,
140 0, 0xE000, "Priority", HFILL }},
142 "CFI", "vlan.cfi", FT_UINT16, BASE_BIN,
143 0, 0x1000, "CFI", HFILL }}, /* XXX - Boolean? */
145 "ID", "vlan.id", FT_UINT16, BASE_BIN,
146 0, 0x0FFF, "ID", HFILL }},
148 "Type", "vlan.etype", FT_UINT16, BASE_HEX,
149 VALS(etype_vals), 0x0, "Type", HFILL }},
151 "Length", "vlan.len", FT_UINT16, BASE_DEC,
152 NULL, 0x0, "Length", HFILL }},
153 { &hf_vlan_trailer, {
154 "Trailer", "vlan.trailer", FT_BYTES, BASE_NONE,
155 NULL, 0x0, "VLAN Trailer", HFILL }}
157 static gint *ett[] = {
161 proto_vlan = proto_register_protocol("802.1q Virtual LAN", "VLAN", "vlan");
162 proto_register_field_array(proto_vlan, hf, array_length(hf));
163 proto_register_subtree_array(ett, array_length(ett));
167 proto_reg_handoff_vlan(void)
169 dissector_handle_t vlan_handle;
171 vlan_handle = create_dissector_handle(dissect_vlan, proto_vlan);
172 dissector_add("ethertype", ETHERTYPE_VLAN, vlan_handle);