2 * Routines for VLAN 802.1Q ethernet header disassembly
4 * $Id: packet-vlan.c,v 1.20 2000/11/12 05:43:26 guy Exp $
6 * Ethereal - Network traffic analyzer
7 * By Gerald Combs <gerald@zing.org>
8 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifdef HAVE_SYS_TYPES_H
31 # include <sys/types.h>
34 #ifdef HAVE_NETINET_IN_H
35 # include <netinet/in.h>
40 #include "packet-ipx.h"
41 #include "packet-llc.h"
44 static int proto_vlan = -1;
45 static int hf_vlan_etype = -1;
46 static int hf_vlan_priority = -1;
47 static int hf_vlan_id = -1;
48 static int hf_vlan_cfi = -1;
50 static gint ett_vlan = -1;
53 capture_vlan(const u_char *pd, int offset, packet_counts *ld ) {
55 if ( !BYTES_ARE_IN_FRAME(offset,5) ) {
59 encap_proto = pntohs( &pd[offset+2] );
60 if ( encap_proto <= IEEE_802_3_MAX_LEN) {
61 if ( pd[offset+4] == 0xff && pd[offset+5] == 0xff ) {
62 capture_ipx(pd,offset+4,ld);
64 capture_llc(pd,offset+4,ld);
67 capture_ethertype(encap_proto, offset+4, pd, ld);
72 dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
73 proto_tree *ti, *vlan_tree = NULL;
74 guint16 tci,encap_proto;
77 CHECK_DISPLAY_AS_DATA(proto_vlan, tvb, pinfo, tree);
79 pinfo->current_proto = "VLAN";
81 if (check_col(pinfo->fd, COL_PROTOCOL))
82 col_add_str(pinfo->fd, COL_PROTOCOL, "VLAN");
84 tci = tvb_get_ntohs( tvb, 0 );
85 encap_proto = tvb_get_ntohs( tvb, 2 );
87 if (check_col(pinfo->fd, COL_INFO)) {
88 col_add_fstr(pinfo->fd, COL_INFO, "PRI: %d CFI: %d ID: %d",
89 (tci >> 13), ((tci >> 12) & 1), (tci & 0xFFF));
93 ti = proto_tree_add_item(tree, proto_vlan, tvb, 0, 4, FALSE);
94 vlan_tree = proto_item_add_subtree(ti, ett_vlan);
96 proto_tree_add_uint(vlan_tree, hf_vlan_priority, tvb, 0, 2, tci);
97 proto_tree_add_uint(vlan_tree, hf_vlan_cfi, tvb, 0, 2, tci);
98 proto_tree_add_uint(vlan_tree, hf_vlan_id, tvb, 0, 2, tci);
101 if ( encap_proto <= IEEE_802_3_MAX_LEN) {
102 next_tvb = tvb_new_subset(tvb, 4, -1, -1); /* XXX - should TRY() like dissect_eth() */
103 if ( tvb_get_ntohs(next_tvb, 2) == 0xffff ) {
104 dissect_ipx(next_tvb, pinfo, tree);
106 dissect_llc(next_tvb, pinfo, tree);
109 ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree, hf_vlan_etype);
114 proto_register_vlan(void)
116 static hf_register_info hf[] = {
118 "Type", "vlan.etype", FT_UINT16, BASE_HEX,
119 VALS(etype_vals), 0x0, "Type" }},
120 { &hf_vlan_priority, {
121 "Priority", "vlan.priority", FT_UINT16, BASE_BIN,
122 0, 0xE000, "Priority" }},
124 "CFI", "vlan.cfi", FT_UINT16, BASE_BIN,
127 "ID", "vlan.id", FT_UINT16, BASE_BIN,
130 static gint *ett[] = {
134 proto_vlan = proto_register_protocol("802.1q Virtual LAN", "vlan");
135 proto_register_field_array(proto_vlan, hf, array_length(hf));
136 proto_register_subtree_array(ett, array_length(ett));
140 proto_reg_handoff_vlan(void)
142 dissector_add("ethertype", ETHERTYPE_VLAN, dissect_vlan);