2 * Routines for calling the right protocol for the ethertype.
6 * Gilbert Ramirez <gram@alumni.rice.edu>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
32 #include <epan/packet.h>
33 #include "packet-eth.h"
34 #include "packet-frame.h"
35 #include "packet-ip.h"
36 #include "packet-ipv6.h"
37 #include "packet-ipx.h"
38 #include "packet-vlan.h"
39 #include "packet-vines.h"
40 #include <epan/etypes.h>
41 #include <epan/ppptypes.h>
43 static dissector_table_t ethertype_dissector_table;
45 static dissector_handle_t data_handle;
47 const value_string etype_vals[] = {
48 {ETHERTYPE_IP, "IP" },
49 {ETHERTYPE_IPv6, "IPv6" },
50 {ETHERTYPE_WLCCP, "Cisco Wireless Lan Context Control Protocol" },
51 {ETHERTYPE_CENTRINO_PROMISC, "IEEE 802.11 (Centrino promiscuous)" },
52 {ETHERTYPE_XNS_IDP, "XNS Internet Datagram Protocol" },
53 {ETHERTYPE_X25L3, "X.25 Layer 3" },
54 {ETHERTYPE_ARP, "ARP" },
55 {ETHERTYPE_EPL_V1, "EPL_V1" },
56 {ETHERTYPE_REVARP, "RARP" },
57 {ETHERTYPE_DEC_LB, "DEC LanBridge" },
58 {ETHERTYPE_ATALK, "Appletalk" },
59 {ETHERTYPE_SNA, "SNA-over-Ethernet" },
60 {ETHERTYPE_AARP, "AARP" },
61 {ETHERTYPE_IPX, "Netware IPX/SPX" },
62 {ETHERTYPE_VINES_IP, "Vines IP" },
63 {ETHERTYPE_VINES_ECHO, "Vines Echo" },
64 {ETHERTYPE_TRAIN, "Netmon Train" },
65 {ETHERTYPE_LOOP, "Loopback" }, /* Ethernet Loopback */
66 {ETHERTYPE_FOUNDRY, "Foundry proprietary" },
67 {ETHERTYPE_WCP, "Wellfleet Compression Protocol" },
68 {ETHERTYPE_STP, "Spanning Tree Protocol" },
69 {ETHERTYPE_ISMP, "Cabletron Interswitch Message Protocol" },
70 {ETHERTYPE_ISMP_TBFLOOD, "Cabletron SFVLAN 1.8 Tag-Based Flood" },
71 /* for ISMP, see RFC 2641, RFC 2642, RFC 2643 */
72 {ETHERTYPE_PPPOED, "PPPoE Discovery" },
73 {ETHERTYPE_PPPOES, "PPPoE Session" },
74 {ETHERTYPE_INTEL_ANS, "Intel ANS probe" },
75 {ETHERTYPE_MS_NLB_HEARTBEAT, "MS NLB heartbeat" },
76 {ETHERTYPE_HOMEPLUG, "Homeplug" },
77 {ETHERTYPE_VLAN, "802.1Q Virtual LAN" },
78 {ETHERTYPE_EAPOL, "802.1X Authentication" },
79 {ETHERTYPE_RSN_PREAUTH, "802.11i Pre-Authentication" },
80 {ETHERTYPE_MPLS, "MPLS label switched packet" },
81 {ETHERTYPE_MPLS_MULTI, "MPLS multicast label switched packet" },
82 {ETHERTYPE_3C_NBP_DGRAM, "3Com NBP Datagram" },
83 {ETHERTYPE_DEC, "DEC proto" },
84 {ETHERTYPE_DNA_DL, "DEC DNA Dump/Load" },
85 {ETHERTYPE_DNA_RC, "DEC DNA Remote Console" },
86 {ETHERTYPE_DNA_RT, "DEC DNA Routing" },
87 {ETHERTYPE_LAT, "DEC LAT" },
88 {ETHERTYPE_DEC_DIAG, "DEC Diagnostics" },
89 {ETHERTYPE_DEC_CUST, "DEC Customer use" },
90 {ETHERTYPE_DEC_SCA, "DEC LAVC/SCA" },
91 {ETHERTYPE_DEC_LAST, "DEC LAST" },
92 {ETHERTYPE_ETHBRIDGE, "Transparent Ethernet bridging" },
93 {ETHERTYPE_CGMP, "Cisco Group Management Protocol" },
94 {ETHERTYPE_MAC_CONTROL, "MAC Control" },
95 {ETHERTYPE_SLOW_PROTOCOLS, "Slow Protocols" },
96 {ETHERTYPE_RTMAC, "Real-Time Media Access Control" },
97 {ETHERTYPE_RTCFG, "Real-Time Configuration Protocol" },
98 {ETHERTYPE_CDMA2000_A10_UBS, "CDMA2000 A10 Unstructured byte stream" },
99 {ETHERTYPE_PROFINET, "PROFINET" },
100 {ETHERTYPE_AOE, "ATA over Ethernet" },
101 {ETHERTYPE_TELKONET, "Telkonet powerline" },
102 {ETHERTYPE_EPL_V2, "ETHERNET Powerlink v2" },
103 {ETHERTYPE_CSM_ENCAPS, "CSM_ENCAPS Protocol" },
104 {ETHERTYPE_IEEE802_OUI_EXTENDED, "IEEE 802a OUI Extended Ethertype" },
105 {ETHERTYPE_IEC61850_GOOSE, "IEC 61850/GOOSE" },
106 {ETHERTYPE_IEC61850_GSE, "IEC 61850/GSE management services" },
107 {ETHERTYPE_IEC61850_SV, "IEC 61850/SV (Sampled Value Transmission" },
108 {ETHERTYPE_TIPC, "Transparent Inter Process Communication" },
109 {ETHERTYPE_LLDP, "802.1 Link Layer Discovery Protocol (LLDP)" },
110 {ETHERTYPE_3GPP2, "CDMA2000 A10 3GPP2 Packet" },
111 {ETHERTYPE_LLTD, "Link Layer Topology Discovery (LLTD)" },
112 {ETHERTYPE_COBRANET, "Cirrus Cobranet Packet" },
114 * NDISWAN on Windows translates Ethernet frames from higher-level
115 * protocols into PPP frames to hand to the PPP driver, and translates
116 * PPP frames from the PPP driver to hand to the higher-level protocols.
118 * Apparently the PPP driver, on at least some versions of Windows,
119 * passes frames for internal-to-PPP protocols up through NDISWAN;
120 * the protocol type field appears to be passed through unchanged
121 * (unlike what's done with, for example, the protocol type field
122 * for IP, which is mapped from its PPP value to its Ethernet value).
124 * This means that we may see, on Ethernet captures, frames for
125 * protocols internal to PPP, so we list as "Ethernet" protocol
126 * types the PPP protocol types we've seen.
128 {PPP_IPCP, "PPP IP Control Protocol" },
129 {PPP_LCP, "PPP Link Control Protocol" },
130 {PPP_PAP, "PPP Password Authentication Protocol" },
131 {PPP_CCP, "PPP Compression Control Protocol" },
132 {ETHERTYPE_LLT, "Veritas Low Latency Transport (not officially registered)"},
135 static void add_dix_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb,
136 tvbuff_t *next_tvb, int offset_after_etype, guint length_before,
140 capture_ethertype(guint16 etype, const guchar *pd, int offset, int len,
148 capture_ip(pd, offset, len, ld);
151 capture_ipv6(pd, offset, len, ld);
157 capture_vlan(pd, offset, len, ld);
159 case ETHERTYPE_VINES_IP:
160 case ETHERTYPE_VINES_ECHO:
170 ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype,
171 packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
172 int etype_id, int trailer_id, int fcs_len)
174 const char *description;
177 volatile gboolean dissector_found = FALSE;
178 const char *saved_proto;
180 /* Add the Ethernet type to the protocol tree */
182 proto_tree_add_uint(fh_tree, etype_id, tvb,
183 offset_after_etype - 2, 2, etype);
186 /* Tvbuff for the payload after the Ethernet type. */
187 next_tvb = tvb_new_subset(tvb, offset_after_etype, -1, -1);
189 pinfo->ethertype = etype;
191 /* Remember how much data there is in it. */
192 length_before = tvb_reported_length(next_tvb);
194 /* Look for sub-dissector, and call it if found.
195 Catch exceptions, so that if the reported length of "next_tvb"
196 was reduced by some dissector before an exception was thrown,
197 we can still put in an item for the trailer. */
198 saved_proto = pinfo->current_proto;
200 dissector_found = dissector_try_port(ethertype_dissector_table,
201 etype, next_tvb, pinfo, tree);
204 /* Somebody threw BoundsError, which means that:
206 1) a dissector was found, so we don't need to
207 dissect the payload as data or update the
208 protocol or info columns;
210 2) dissecting the payload found that the packet was
211 cut off by a snapshot length before the end of
212 the payload. The trailer comes after the payload,
213 so *all* of the trailer is cut off, and we'll
214 just get another BoundsError if we add the trailer.
216 Therefore, we just rethrow the exception so it gets
217 reported; we don't dissect the trailer or do anything
221 CATCH(OutOfMemoryError) {
225 /* Somebody threw an exception other than BoundsError, which
226 means that a dissector was found, so we don't need to
227 dissect the payload as data or update the protocol or info
228 columns. We just show the exception and then drive on
229 to show the trailer, after noting that a dissector was
230 found and restoring the protocol value that was in effect
231 before we called the subdissector. */
232 show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
233 dissector_found = TRUE;
234 pinfo->current_proto = saved_proto;
238 if (!dissector_found) {
239 /* No sub-dissector found.
240 Label rest of packet as "Data" */
241 call_dissector(data_handle,next_tvb, pinfo, tree);
244 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
245 col_add_fstr(pinfo->cinfo, COL_PROTOCOL, "0x%04x",
248 if (check_col(pinfo->cinfo, COL_INFO)) {
249 description = match_strval(etype, etype_vals);
251 col_add_fstr(pinfo->cinfo, COL_INFO, "%s",
257 add_dix_trailer(fh_tree, trailer_id, tvb, next_tvb, offset_after_etype,
258 length_before, fcs_len);
262 add_dix_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *tvb,
263 tvbuff_t *next_tvb, int offset_after_etype, guint length_before,
267 tvbuff_t *volatile trailer_tvb;
270 return; /* we're not building a protocol tree */
272 if (trailer_id == -1)
273 return; /* our caller doesn't care about trailers */
275 /* OK, how much is there in that tvbuff now? */
276 length = tvb_reported_length(next_tvb);
278 /* If there's less than there was before, what's left is
280 if (length < length_before) {
282 * Is any of the padding present in the tvbuff?
284 if (tvb_offset_exists(tvb, offset_after_etype + length)) {
286 * Yes - create a tvbuff for the padding.
288 trailer_tvb = tvb_new_subset(tvb,
289 offset_after_etype + length, -1, -1);
292 * No - don't bother showing the trailer.
293 * XXX - show a Short Frame indication?
298 trailer_tvb = NULL; /* no trailer */
300 add_ethernet_trailer(fh_tree, trailer_id, tvb, trailer_tvb, fcs_len);
304 proto_register_ethertype(void)
306 /* subdissector code */
307 ethertype_dissector_table = register_dissector_table("ethertype",
308 "Ethertype", FT_UINT16, BASE_HEX);
312 proto_reg_handoff_ethertype(void)
314 data_handle = find_dissector("data");