diff options
author | Guy Harris <guy@alum.mit.edu> | 2001-02-08 07:08:05 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2001-02-08 07:08:05 +0000 |
commit | 7f4a71ab8be5d403c49e28d901a85a8f764b521b (patch) | |
tree | ddee328985310f2ee437bfff15d19c9cf4040773 | |
parent | b1eb3635c2806bcadeb02fea81b9874d30f79c99 (diff) | |
download | wireshark-7f4a71ab8be5d403c49e28d901a85a8f764b521b.tar.gz wireshark-7f4a71ab8be5d403c49e28d901a85a8f764b521b.tar.bz2 wireshark-7f4a71ab8be5d403c49e28d901a85a8f764b521b.zip |
Pull a lot of common code for handling 802.3 frames (i.e., frames with a
length field rather than an Ethernet type field) into a
"dissect_802_3()" routine.
In that routine, catch exceptions thrown by the IPX or LLC dissector or
dissectors under them, so that the trailer information is added to the
tree even if an exception is thrown (similar to what "ethertype()"
does).
svn path=/trunk/; revision=3002
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | Makefile.nmake | 3 | ||||
-rw-r--r-- | packet-eth.c | 103 | ||||
-rw-r--r-- | packet-ieee8023.c | 134 | ||||
-rw-r--r-- | packet-ieee8023.h | 34 | ||||
-rw-r--r-- | packet-vlan.c | 69 |
6 files changed, 203 insertions, 144 deletions
diff --git a/Makefile.am b/Makefile.am index 0b01838d98..1d9734a5f7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,7 +1,7 @@ # Makefile.am # Automake file for Ethereal # -# $Id: Makefile.am,v 1.281 2001/02/01 20:21:13 gram Exp $ +# $Id: Makefile.am,v 1.282 2001/02/08 07:08:04 guy Exp $ # # Ethereal - Network traffic analyzer # By Gerald Combs <gerald@zing.org> @@ -121,6 +121,7 @@ DISSECTOR_SOURCES = \ packet-ipx.c \ packet-irc.c \ packet-ieee80211.c \ + packet-ieee8023.c \ packet-isakmp.c\ packet-isis.c \ packet-isis-clv.c \ @@ -249,6 +250,7 @@ noinst_HEADERS = \ packet-hclnfsd.h \ packet-http.h \ packet-ieee80211.h \ + packet-ieee8023.h \ packet-ip.h \ packet-ipsec.h \ packet-ipv6.h \ diff --git a/Makefile.nmake b/Makefile.nmake index 9d11b75f6e..0e83fdc855 100644 --- a/Makefile.nmake +++ b/Makefile.nmake @@ -1,7 +1,7 @@ ## Makefile for building ethereal.exe with Microsoft C and nmake ## Use: nmake -f makefile.nmake # -# $Id: Makefile.nmake,v 1.78 2001/02/02 04:03:37 gram Exp $ +# $Id: Makefile.nmake,v 1.79 2001/02/08 07:08:05 guy Exp $ include config.nmake @@ -71,6 +71,7 @@ DISSECTOR_SOURCES = \ packet-ipx.c \ packet-irc.c \ packet-ieee80211.c \ + packet-ieee8023.c \ packet-isakmp.c\ packet-isis.c \ packet-isis-clv.c \ diff --git a/packet-eth.c b/packet-eth.c index 4fab51b777..5e1e34e064 100644 --- a/packet-eth.c +++ b/packet-eth.c @@ -1,7 +1,7 @@ /* packet-eth.c * Routines for ethernet packet disassembly * - * $Id: packet-eth.c,v 1.59 2001/01/21 22:10:22 guy Exp $ + * $Id: packet-eth.c,v 1.60 2001/02/08 07:08:05 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -36,6 +36,7 @@ #include "etypes.h" #include "resolv.h" #include "packet-eth.h" +#include "packet-ieee8023.h" #include "packet-ipx.h" #include "packet-isl.h" #include "packet-llc.h" @@ -55,8 +56,6 @@ static gint ett_ieee8023 = -1; static gint ett_ether2 = -1; static dissector_handle_t isl_handle; -static dissector_handle_t ipx_handle; -static dissector_handle_t llc_handle; #define ETH_HEADER_SIZE 14 @@ -151,11 +150,9 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) const guint8 *pd; guint16 etype; - volatile int ethhdr_type; /* the type of Ethernet frame */ + volatile gboolean is_802_2; int eth_offset; volatile guint16 length; - tvbuff_t *volatile next_tvb; - tvbuff_t *volatile trailer_tvb; proto_tree *volatile fh_tree = NULL; tvb_compat(tvb, &pd, (int*)ð_offset); @@ -178,16 +175,29 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (etype <= IEEE_802_3_MAX_LEN) { length = etype; + /* Oh, yuck. Cisco ISL frames require special interpretation of the + destination address field; fortunately, they can be recognized by + checking the first 5 octets of the destination address, which are + 01-00-0C-00-00 for ISL frames. */ + if ( tvb_get_guint8(tvb, 0) == 0x01 && + tvb_get_guint8(tvb, 1) == 0x00 && + tvb_get_guint8(tvb, 2) == 0x0C && + tvb_get_guint8(tvb, 3) == 0x00 && + tvb_get_guint8(tvb, 4) == 0x00 ) { + call_dissector(isl_handle, tvb, pinfo, tree); + return; + } + /* Is there an 802.2 layer? I can tell by looking at the first 2 bytes after the 802.3 header. If they are 0xffff, then what follows the 802.3 header is an IPX payload, meaning no 802.2. (IPX/SPX is they only thing that can be contained inside a straight 802.3 packet). A non-0xffff value means that there's an 802.2 layer inside the 802.3 layer */ - ethhdr_type = ETHERNET_802_2; + is_802_2 = TRUE; TRY { if (tvb_get_ntohs(tvb, 14) == 0xffff) { - ethhdr_type = ETHERNET_802_3; + is_802_2 = FALSE; } } CATCH2(BoundsError, ReportedBoundsError) { @@ -196,26 +206,13 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } ENDTRY; - /* Oh, yuck. Cisco ISL frames require special interpretation of the - destination address field; fortunately, they can be recognized by - checking the first 5 octets of the destination address, which are - 01-00-0C-00-00 for ISL frames. */ - if ( tvb_get_guint8(tvb, 0) == 0x01 && - tvb_get_guint8(tvb, 1) == 0x00 && - tvb_get_guint8(tvb, 2) == 0x0C && - tvb_get_guint8(tvb, 3) == 0x00 && - tvb_get_guint8(tvb, 4) == 0x00 ) { - call_dissector(isl_handle, tvb, pinfo, tree); - return; - } - if (check_col(pinfo->fd, COL_INFO)) { col_add_fstr(pinfo->fd, COL_INFO, "IEEE 802.3 %s", - (ethhdr_type == ETHERNET_802_3 ? "Raw " : "")); + (is_802_2 ? "" : "Raw ")); } if (tree) { ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE, - "IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : "")); + "IEEE 802.3 %s", (is_802_2 ? "" : "Raw ")); fh_tree = proto_item_add_subtree(ti, ett_ieee8023); @@ -225,8 +222,6 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) /* add items for eth.addr filter */ proto_tree_add_ether_hidden(fh_tree, hf_eth_addr, tvb, 0, 6, dst); proto_tree_add_ether_hidden(fh_tree, hf_eth_addr, tvb, 6, 6, src); - - proto_tree_add_uint(fh_tree, hf_eth_len, tvb, 12, 2, length); } /* Convert the LLC length from the 802.3 header to a total @@ -243,56 +238,9 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) if (pinfo->captured_len > length) pinfo->captured_len = length; - /* Give the next dissector only 'length' number of bytes */ - TRY { - next_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE, etype, etype); - trailer_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE + etype, -1, -1); - } - CATCH2(BoundsError, ReportedBoundsError) { - /* Either: - - the packet doesn't have "etype" bytes worth of - captured data left in it - or it may not even have - "etype" bytes worth of data in it, period - - so the "tvb_new_subset()" creating "next_tvb" - threw an exception - - or - - the packet has exactly "etype" bytes worth of - captured data left in it, so the "tvb_new_subset()" - creating "trailer_tvb" threw an exception. - - In either case, this means that all the data in the frame - is within the length value, so we give all the data to the - next protocol and have no trailer. */ - next_tvb = tvb_new_subset(tvb, ETH_HEADER_SIZE, -1, etype); - trailer_tvb = NULL; - } - ENDTRY; - - /* Dissect the payload either as IPX or as an LLC frame. */ - switch (ethhdr_type) { - case ETHERNET_802_3: - call_dissector(ipx_handle, next_tvb, pinfo, tree); - break; - case ETHERNET_802_2: - call_dissector(llc_handle, next_tvb, pinfo, tree); - break; - } - - /* If there's some bytes left over, mark them. */ - if (trailer_tvb && tree) { - guint trailer_length; - - trailer_length = tvb_length(trailer_tvb); - if (trailer_length != 0) { - proto_tree_add_item(fh_tree, hf_eth_trailer, trailer_tvb, 0, - trailer_length, FALSE); - } - } + dissect_802_3(etype, is_802_2, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree, + hf_eth_len, hf_eth_trailer); } else { - ethhdr_type = ETHERNET_II; if (check_col(pinfo->fd, COL_INFO)) col_set_str(pinfo->fd, COL_INFO, "Ethernet II"); if (tree) { @@ -308,9 +256,6 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_ether_hidden(fh_tree, hf_eth_addr, tvb, 6, 6, src); } - next_tvb = NULL; /* "ethertype()" will create the next tvb for us */ - trailer_tvb = NULL; /* we don't know how big the trailer is */ - ethertype(etype, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree, hf_eth_type, hf_eth_trailer); } @@ -362,11 +307,9 @@ void proto_reg_handoff_eth(void) { /* - * Get handles for the ISL, IPX, and LLC dissectors. + * Get a handle for the ISL dissector. */ isl_handle = find_dissector("isl"); - ipx_handle = find_dissector("ipx"); - llc_handle = find_dissector("llc"); dissector_add("wtap_encap", WTAP_ENCAP_ETHERNET, dissect_eth, proto_eth); diff --git a/packet-ieee8023.c b/packet-ieee8023.c new file mode 100644 index 0000000000..2a671860c4 --- /dev/null +++ b/packet-ieee8023.c @@ -0,0 +1,134 @@ +/* packet-ieee8023.c + * Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets. + * + * $Id: packet-ieee8023.c,v 1.1 2001/02/08 07:08:05 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#ifdef HAVE_SYS_TYPES_H +# include <sys/types.h> +#endif + +#include <glib.h> +#include "packet.h" +#include "packet-ieee8023.h" + +static dissector_handle_t ipx_handle; +static dissector_handle_t llc_handle; + +static void add_trailer(proto_tree *fh_tree, int trailer_id, + tvbuff_t *trailer_tvb); + +void +dissect_802_3(int length, gboolean is_802_2, tvbuff_t *tvb, + int offset_after_length, packet_info *pinfo, proto_tree *tree, + proto_tree *fh_tree, int length_id, int trailer_id) +{ + tvbuff_t *volatile next_tvb; + tvbuff_t *volatile trailer_tvb; + + if (fh_tree) + proto_tree_add_uint(fh_tree, length_id, tvb, offset_after_length - 2, 2, + length); + + /* Give the next dissector only 'length' number of bytes */ + TRY { + next_tvb = tvb_new_subset(tvb, offset_after_length, length, length); + trailer_tvb = tvb_new_subset(tvb, offset_after_length + length, -1, -1); + } + CATCH2(BoundsError, ReportedBoundsError) { + /* Either: + + the packet doesn't have "length" bytes worth of + captured data left in it - or it may not even have + "length" bytes worth of data in it, period - + so the "tvb_new_subset()" creating "next_tvb" + threw an exception + + or + + the packet has exactly "length" bytes worth of + captured data left in it, so the "tvb_new_subset()" + creating "trailer_tvb" threw an exception. + + In either case, this means that all the data in the frame + is within the length value, so we give all the data to the + next protocol and have no trailer. */ + next_tvb = tvb_new_subset(tvb, offset_after_length, -1, length); + trailer_tvb = NULL; + } + ENDTRY; + + /* Dissect the payload either as IPX or as an LLC frame. + Catch BoundsError and ReportedBoundsError, so that if the + reported length of "next_tvb" was reduced by some dissector + before an exception was thrown, we can still put in an item + for the trailer. */ + TRY { + if (is_802_2) + call_dissector(llc_handle, next_tvb, pinfo, tree); + else + call_dissector(ipx_handle, next_tvb, pinfo, tree); + } + CATCH2(BoundsError, ReportedBoundsError) { + /* Well, somebody threw an exception. Add the trailer, if appropriate. */ + add_trailer(fh_tree, trailer_id, trailer_tvb); + + /* Rethrow the exception, so the "Short Frame" or "Mangled Frame" + indication can be put into the tree. */ + RETHROW; + + /* XXX - RETHROW shouldn't return. */ + g_assert_not_reached(); + } + ENDTRY; + + add_trailer(fh_tree, trailer_id, trailer_tvb); +} + +static void +add_trailer(proto_tree *fh_tree, int trailer_id, tvbuff_t *trailer_tvb) +{ + /* If there's some bytes left over, mark them. */ + if (trailer_tvb && fh_tree) { + guint trailer_length; + + trailer_length = tvb_length(trailer_tvb); + if (trailer_length != 0) { + proto_tree_add_item(fh_tree, trailer_id, trailer_tvb, 0, + trailer_length, FALSE); + } + } +} + +void +proto_reg_handoff_ieee802_3(void) +{ + /* + * Get handles for the IPX and LLC dissectors. + */ + ipx_handle = find_dissector("ipx"); + llc_handle = find_dissector("llc"); +} diff --git a/packet-ieee8023.h b/packet-ieee8023.h new file mode 100644 index 0000000000..615647511c --- /dev/null +++ b/packet-ieee8023.h @@ -0,0 +1,34 @@ +/* packet-ieee8023.h + * Declaration of routine for dissecting 802.3 (as opposed to D/I/X Ethernet) + * packets. + * + * $Id: packet-ieee8023.h,v 1.1 2001/02/08 07:08:05 guy Exp $ + * + * Ethereal - Network traffic analyzer + * By Gerald Combs <gerald@zing.org> + * Copyright 1998 Gerald Combs + * + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +#ifndef __PACKET_IEEE8023_H__ +#define __PACKET_IEEE8023_H__ + +void dissect_802_3(int length, gboolean is_802_2, tvbuff_t *tvb, + int offset_after_length, packet_info *pinfo, proto_tree *tree, + proto_tree *fh_tree, int length_id, int trailer_id); + +#endif diff --git a/packet-vlan.c b/packet-vlan.c index cf072f79e0..d0430b0a20 100644 --- a/packet-vlan.c +++ b/packet-vlan.c @@ -1,7 +1,7 @@ /* packet-vlan.c * Routines for VLAN 802.1Q ethernet header disassembly * - * $Id: packet-vlan.c,v 1.32 2001/02/05 02:47:31 guy Exp $ + * $Id: packet-vlan.c,v 1.33 2001/02/08 07:08:05 guy Exp $ * * Ethereal - Network traffic analyzer * By Gerald Combs <gerald@zing.org> @@ -37,6 +37,7 @@ #include <glib.h> #include "packet.h" +#include "packet-ieee8023.h" #include "packet-ipx.h" #include "packet-llc.h" #include "etypes.h" @@ -51,9 +52,6 @@ static int hf_vlan_trailer = -1; static gint ett_vlan = -1; -static dissector_handle_t ipx_handle; -static dissector_handle_t llc_handle; - void capture_vlan(const u_char *pd, int offset, packet_counts *ld ) { guint16 encap_proto; @@ -79,8 +77,6 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree *ti; guint16 tci,encap_proto; volatile gboolean is_802_2; - tvbuff_t *volatile next_tvb; - tvbuff_t *volatile trailer_tvb; proto_tree *volatile vlan_tree; if (check_col(pinfo->fd, COL_PROTOCOL)) @@ -106,37 +102,8 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) proto_tree_add_uint(vlan_tree, hf_vlan_id, tvb, 0, 2, tci); } - encap_proto = tvb_get_ntohs( tvb, 2 ); - if ( encap_proto <= IEEE_802_3_MAX_LEN) { - /* Give the next dissector only 'encap_proto' number of bytes */ - proto_tree_add_uint(vlan_tree, hf_vlan_len, tvb, 2, 2, encap_proto); - TRY { - next_tvb = tvb_new_subset(tvb, 4, encap_proto, encap_proto); - trailer_tvb = tvb_new_subset(tvb, 4 + encap_proto, -1, -1); - } - CATCH2(BoundsError, ReportedBoundsError) { - /* Either: - - the packet doesn't have "encap_proto" bytes worth of - captured data left in it - or it may not even have - "encap_proto" bytes worth of data in it, period - - so the "tvb_new_subset()" creating "next_tvb" - threw an exception - - or - - the packet has exactly "encap_proto" bytes worth of - captured data left in it, so the "tvb_new_subset()" - creating "trailer_tvb" threw an exception. - - In either case, this means that all the data in the frame - is within the length value, so we give all the data to the - next protocol and have no trailer. */ - next_tvb = tvb_new_subset(tvb, 4, -1, encap_proto); - trailer_tvb = NULL; - } - ENDTRY; - + encap_proto = tvb_get_ntohs(tvb, 2); + if (encap_proto <= IEEE_802_3_MAX_LEN) { /* Is there an 802.2 layer? I can tell by looking at the first 2 bytes after the VLAN header. If they are 0xffff, then what follows the VLAN header is an IPX payload, meaning no 802.2. @@ -146,7 +113,7 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) 802.2 layer inside the VLAN layer */ is_802_2 = TRUE; TRY { - if (tvb_get_ntohs(next_tvb, 2) == 0xffff) { + if (tvb_get_ntohs(tvb, 4) == 0xffff) { is_802_2 = FALSE; } } @@ -155,25 +122,9 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) } ENDTRY; - if (is_802_2 ) { - /* 802.2 LLC */ - call_dissector(llc_handle, next_tvb, pinfo, tree); - } else { - call_dissector(ipx_handle, next_tvb, pinfo, tree); - } - /* If there's some bytes left over, mark them. */ - if (trailer_tvb && tree) { - int trailer_length; - const guint8 *ptr; - - trailer_length = tvb_length(trailer_tvb); - if (trailer_length > 0) { - ptr = tvb_get_ptr(trailer_tvb, 0, trailer_length); - proto_tree_add_bytes(vlan_tree, hf_vlan_trailer, trailer_tvb, 0, - trailer_length, ptr); - } - } + dissect_802_3(encap_proto, is_802_2, tvb, 4, pinfo, tree, vlan_tree, + hf_vlan_len, hf_vlan_trailer); } else { ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree, hf_vlan_etype, hf_vlan_trailer); @@ -215,11 +166,5 @@ proto_register_vlan(void) void proto_reg_handoff_vlan(void) { - /* - * Get handles for the IPX and LLC dissectors. - */ - llc_handle = find_dissector("llc"); - ipx_handle = find_dissector("ipx"); - dissector_add("ethertype", ETHERTYPE_VLAN, dissect_vlan, proto_vlan); } |