2 * Routines for calling the right protocol for the ethertype.
4 * $Id: packet-ethertype.c,v 1.28 2002/04/24 06:03:33 guy Exp $
6 * Gilbert Ramirez <gram@alumni.rice.edu>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
36 #include <epan/packet.h>
37 #include "packet-ip.h"
38 #include "packet-ipx.h"
39 #include "packet-vlan.h"
40 #include "packet-vines.h"
44 static dissector_table_t ethertype_dissector_table;
46 static dissector_handle_t data_handle;
48 const value_string etype_vals[] = {
49 {ETHERTYPE_IP, "IP" },
50 {ETHERTYPE_IPv6, "IPv6" },
51 {ETHERTYPE_X25L3, "X.25 Layer 3" },
52 {ETHERTYPE_ARP, "ARP" },
53 {ETHERTYPE_REVARP, "RARP" },
54 {ETHERTYPE_DEC_LB, "DEC LanBridge" },
55 {ETHERTYPE_ATALK, "Appletalk" },
56 {ETHERTYPE_SNA, "SNA-over-Ethernet" },
57 {ETHERTYPE_AARP, "AARP" },
58 {ETHERTYPE_IPX, "Netware IPX/SPX" },
59 {ETHERTYPE_VINES, "Vines" },
60 {ETHERTYPE_TRAIN, "Netmon Train" },
61 {ETHERTYPE_LOOP, "Loopback" }, /* Ethernet Loopback */
62 {ETHERTYPE_WCP, "Wellfleet Compression Protocol" },
63 {ETHERTYPE_PPPOED, "PPPoE Discovery" },
64 {ETHERTYPE_PPPOES, "PPPoE Session" },
65 {ETHERTYPE_VLAN, "802.1Q Virtual LAN" },
66 {ETHERTYPE_EAPOL, "802.1X Authentication" },
67 {ETHERTYPE_MPLS, "MPLS label switched packet" },
68 {ETHERTYPE_MPLS_MULTI, "MPLS multicast label switched packet" },
69 {ETHERTYPE_3C_NBP_DGRAM, "3Com NBP Datagram" },
70 {ETHERTYPE_DEC, "DEC proto" },
71 {ETHERTYPE_DNA_DL, "DEC DNA Dump/Load" },
72 {ETHERTYPE_DNA_RC, "DEC DNA Remote Console" },
73 {ETHERTYPE_DNA_RT, "DEC DNA Routing" },
74 {ETHERTYPE_LAT, "DEC LAT" },
75 {ETHERTYPE_DEC_DIAG, "DEC Diagnostics" },
76 {ETHERTYPE_DEC_CUST, "DEC Customer use" },
77 {ETHERTYPE_DEC_SCA, "DEC LAVC/SCA" },
78 {ETHERTYPE_ETHBRIDGE, "Transparent Ethernet bridging" },
79 {ETHERTYPE_CGMP, "Cisco Group Management Protocol" },
82 * NDISWAN on Windows translates Ethernet frames from higher-level
83 * protocols into PPP frames to hand to the PPP driver, and translates
84 * PPP frames from the PPP driver to hand to the higher-level protocols.
86 * Apparently the PPP driver, on at least some versions of Windows,
87 * passes frames for internal-to-PPP protocols up through NDISWAN;
88 * the protocol type field appears to be passed through unchanged
89 * (unlike what's done with, for example, the protocol type field
90 * for IP, which is mapped from its PPP value to its Ethernet value).
92 * This means that we may see, on Ethernet captures, frames for
93 * protocols internal to PPP, so we list as "Ethernet" protocol
94 * types the PPP protocol types we've seen.
96 {PPP_IPCP, "PPP IP Control Protocol" },
97 {PPP_LCP, "PPP Link Control Protocol" },
98 {PPP_PAP, "PPP Password Authentication Protocol" },
99 {PPP_CCP, "PPP Compression Control Protocol" },
102 static void add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb,
103 tvbuff_t *next_tvb, int offset_after_etype, guint length_before);
106 capture_ethertype(guint16 etype, const u_char *pd, int offset, int len,
111 capture_ip(pd, offset, len, ld);
117 capture_vlan(pd, offset, len, ld);
119 case ETHERTYPE_VINES:
129 ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype,
130 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
131 int etype_id, int trailer_id)
136 volatile gboolean dissector_found;
138 /* Add to proto_tree */
140 proto_tree_add_uint(fh_tree, etype_id, tvb,
141 offset_after_etype - 2, 2, etype);
144 /* Tvbuff for the payload after the Ethernet type. */
145 next_tvb = tvb_new_subset(tvb, offset_after_etype, -1, -1);
147 pinfo->ethertype = etype;
149 /* Remember how much data there is in it. */
150 length_before = tvb_reported_length(next_tvb);
152 /* Look for sub-dissector, and call it if found.
153 Catch BoundsError and ReportedBoundsError, so that if the
154 reported length of "next_tvb" was reduced by some dissector
155 before an exception was thrown, we can still put in an item
158 dissector_found = dissector_try_port(ethertype_dissector_table,
159 etype, next_tvb, pinfo, tree);
161 CATCH2(BoundsError, ReportedBoundsError) {
162 /* Well, somebody threw an exception; that means that a
163 dissector was found, so we don't need to dissect
164 the payload as data or update the protocol or info
166 dissector_found = TRUE;
168 /* Add the trailer, if appropriate. */
169 add_trailer(fh_tree, trailer_id, tvb, next_tvb,
170 offset_after_etype, length_before);
172 /* Rrethrow the exception, so the "Short Frame" or "Mangled
173 Frame" indication can be put into the tree. */
176 /* XXX - RETHROW shouldn't return. */
177 g_assert_not_reached();
181 if (!dissector_found) {
182 /* No sub-dissector found.
183 Label rest of packet as "Data" */
184 call_dissector(data_handle,next_tvb, pinfo, tree);
190 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
191 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "LOOP");
196 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
197 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "0x%04x",
202 if (check_col(pinfo->cinfo, COL_INFO)) {
203 description = match_strval(etype, etype_vals);
205 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
211 add_trailer(fh_tree, trailer_id, tvb, next_tvb, offset_after_etype,
216 add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb,
217 tvbuff_t *next_tvb, int offset_after_etype, guint length_before)
220 tvbuff_t *volatile trailer_tvb;
223 return; /* we're not building a protocol tree */
225 if (trailer_id == -1)
226 return; /* our caller doesn't care about trailers */
228 /* OK, how much is there in that tvbuff now? */
229 length = tvb_reported_length(next_tvb);
231 /* If there's less than there was before, what's left is
233 if (length < length_before) {
235 * Create a tvbuff for the padding.
238 trailer_tvb = tvb_new_subset(tvb,
239 offset_after_etype + length, -1, -1);
241 CATCH2(BoundsError, ReportedBoundsError) {
242 /* The packet doesn't have "length" bytes worth of
243 captured data left in it. No trailer to display. */
248 trailer_tvb = NULL; /* no trailer */
250 /* If there's some bytes left over, and we were given an item ID
251 for a trailer, mark those bytes as a trailer. */
253 guint trailer_length;
255 trailer_length = tvb_length(trailer_tvb);
256 if (trailer_length != 0) {
257 proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0,
258 trailer_length, FALSE);
265 proto_register_ethertype(void)
267 /* subdissector code */
268 ethertype_dissector_table = register_dissector_table("ethertype",
269 "Ethertype", FT_UINT16, BASE_HEX);
273 proto_reg_handoff_ethertype(void){
274 data_handle = find_dissector("data");