aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2001-01-18 07:44:41 +0000
committerGuy Harris <guy@alum.mit.edu>2001-01-18 07:44:41 +0000
commit18bfc670eccbc7b9acacd7121e415b3d335b7ff9 (patch)
tree479f963eaed0ad216b7059a8ce374cb81805e8b8
parentf655d094b544e0c2dc4cf20b46de5d178b4ccc4d (diff)
Pull the handling of trailers in Ethernet (as opposed to 802.3) frames
into "ethertype()". svn path=/trunk/; revision=2915
-rw-r--r--epan/packet.h10
-rw-r--r--packet-eth.c161
-rw-r--r--packet-ethertype.c54
-rw-r--r--packet-llc.c4
-rw-r--r--packet-null.c4
-rw-r--r--packet-sll.c47
-rw-r--r--packet-vlan.c47
7 files changed, 142 insertions, 185 deletions
diff --git a/epan/packet.h b/epan/packet.h
index 6b5f55e130..f472ea9d39 100644
--- a/epan/packet.h
+++ b/epan/packet.h
@@ -1,7 +1,7 @@
/* packet.h
* Definitions for packet disassembly structures and routines
*
- * $Id: packet.h,v 1.19 2001/01/13 06:34:33 guy Exp $
+ * $Id: packet.h,v 1.20 2001/01/18 07:44:41 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -363,12 +363,12 @@ void old_dissect_data(const u_char *, int, frame_data *, proto_tree *);
void dissect_data(tvbuff_t *tvb, int, packet_info *pinfo, proto_tree *tree);
-/* These functions are in ethertype.c */
+/* These functions are in packet-ethertype.c */
void capture_ethertype(guint16 etype, int offset,
const u_char *pd, packet_counts *ld);
-guint ethertype(guint16 etype, tvbuff_t*, int offset_after_ethertype,
- packet_info *pinfo, proto_tree *tree,
- proto_tree *fh_tree, int item_id);
+void ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_ethertype,
+ packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
+ int etype_id, int trailer_id);
extern const value_string etype_vals[];
/* ipproto.c */
diff --git a/packet-eth.c b/packet-eth.c
index 0370982d27..8051248e6d 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.55 2001/01/09 09:59:28 guy Exp $
+ * $Id: packet-eth.c,v 1.56 2001/01/18 07:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -150,14 +150,13 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint8 *dst, *src;
const guint8 *pd;
- volatile guint16 etype;
+ guint16 etype;
volatile int ethhdr_type; /* the type of Ethernet frame */
- volatile int eth_offset;
+ int eth_offset;
volatile guint16 length;
tvbuff_t *volatile next_tvb;
tvbuff_t *volatile trailer_tvb;
proto_tree *volatile fh_tree;
- guint length_before;
CHECK_DISPLAY_AS_DATA(proto_eth, tvb, pinfo, tree);
@@ -218,20 +217,19 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
(ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
}
if (tree) {
-
- ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
+ ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
"IEEE 802.3 %s", (ethhdr_type == ETHERNET_802_3 ? "Raw " : ""));
- fh_tree = proto_item_add_subtree(ti, ett_ieee8023);
+ fh_tree = proto_item_add_subtree(ti, ett_ieee8023);
- proto_tree_add_ether(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
- proto_tree_add_ether(fh_tree, hf_eth_src, tvb, 6, 6, src);
+ proto_tree_add_ether(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
+ proto_tree_add_ether(fh_tree, hf_eth_src, tvb, 6, 6, src);
/* 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_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);
+ 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
@@ -247,99 +245,78 @@ dissect_eth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
pinfo->len = length;
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);
+ }
+ }
} else {
ethhdr_type = ETHERNET_II;
if (check_col(pinfo->fd, COL_INFO))
col_set_str(pinfo->fd, COL_INFO, "Ethernet II");
if (tree) {
-
- ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
+ ti = proto_tree_add_protocol_format(tree, proto_eth, tvb, 0, ETH_HEADER_SIZE,
"Ethernet II");
- fh_tree = proto_item_add_subtree(ti, ett_ether2);
+ fh_tree = proto_item_add_subtree(ti, ett_ether2);
- proto_tree_add_ether(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
- proto_tree_add_ether(fh_tree, hf_eth_src, tvb, 6, 6, src);
+ proto_tree_add_ether(fh_tree, hf_eth_dst, tvb, 0, 6, dst);
+ proto_tree_add_ether(fh_tree, hf_eth_src, tvb, 6, 6, src);
/* 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_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);
}
- }
- eth_offset += ETH_HEADER_SIZE;
-
- if (etype <= IEEE_802_3_MAX_LEN) {
- /* 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;
- }
- else {
- next_tvb = NULL; /* "ethertype()" will create the next tvb for us */
- trailer_tvb = NULL; /* we don't know how big the trailer is */
- }
-
- 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;
- case ETHERNET_II:
- length_before = tvb_reported_length(tvb);
- length = ethertype(etype, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree,
- hf_eth_type) + ETH_HEADER_SIZE;
- if (length < length_before) {
- /*
- * Create a tvbuff for the padding.
- */
- TRY {
- trailer_tvb = tvb_new_subset(tvb, length, -1, -1);
- }
- CATCH2(BoundsError, ReportedBoundsError) {
- /* The packet doesn't have "length" bytes worth of captured
- data left in it. No trailer to display. */
- trailer_tvb = NULL;
- }
- ENDTRY;
- }
- break;
- }
- /* If there's some bytes left over, mark them. */
- if (trailer_tvb && tree) {
- guint trailer_length;
+ next_tvb = NULL; /* "ethertype()" will create the next tvb for us */
+ trailer_tvb = NULL; /* we don't know how big the trailer is */
- 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);
- }
+ ethertype(etype, tvb, ETH_HEADER_SIZE, pinfo, tree, fh_tree, hf_eth_type,
+ hf_eth_trailer);
}
-
}
void
diff --git a/packet-ethertype.c b/packet-ethertype.c
index 454c58fbfa..ffe3682fb3 100644
--- a/packet-ethertype.c
+++ b/packet-ethertype.c
@@ -1,7 +1,7 @@
/* ethertype.c
* Routines for calling the right protocol for the ethertype.
*
- * $Id: packet-ethertype.c,v 1.9 2000/11/18 10:38:24 guy Exp $
+ * $Id: packet-ethertype.c,v 1.10 2001/01/18 07:44:39 guy Exp $
*
* Gilbert Ramirez <gram@xiexie.org>
*
@@ -95,21 +95,28 @@ capture_ethertype(guint16 etype, int offset,
}
}
-guint
-ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype, packet_info *pinfo,
- proto_tree *tree, proto_tree *fh_tree, int item_id)
+void
+ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype,
+ packet_info *pinfo, proto_tree *tree, proto_tree *fh_tree,
+ int etype_id, int trailer_id)
{
char *description;
tvbuff_t *next_tvb;
+ guint length_before, length;
+ tvbuff_t *volatile trailer_tvb;
/* Add to proto_tree */
if (tree) {
- proto_tree_add_uint(fh_tree, item_id, tvb, offset_after_etype - 2, 2, etype);
+ proto_tree_add_uint(fh_tree, etype_id, tvb,
+ offset_after_etype - 2, 2, etype);
}
/* Tvbuff for the payload after the Ethernet type. */
next_tvb = tvb_new_subset(tvb, offset_after_etype, -1, -1);
+ /* Remember how much data there is in it. */
+ length_before = tvb_reported_length(next_tvb);
+
/* Look for sub-dissector */
if (!dissector_try_port(ethertype_dissector_table, etype,
next_tvb, pinfo, tree)) {
@@ -139,10 +146,39 @@ ethertype(guint16 etype, tvbuff_t *tvb, int offset_after_etype, packet_info *pin
}
}
- /* Return the length of that tvbuff; the subdissector may have
- reduced the length to a value specified by a length field
- in its header, meaning what remains is padding. */
- return tvb_reported_length(next_tvb);
+ /* OK, how much is there in that tvbuff now? */
+ length = tvb_reported_length(next_tvb);
+
+ /* If there's less than there was before, what's left is
+ a trailer. */
+ if (length < length_before) {
+ /*
+ * Create a tvbuff for the padding.
+ */
+ TRY {
+ trailer_tvb = tvb_new_subset(tvb,
+ offset_after_etype + length, -1, -1);
+ }
+ CATCH2(BoundsError, ReportedBoundsError) {
+ /* The packet doesn't have "length" bytes worth of
+ captured data left in it. No trailer to display. */
+ trailer_tvb = NULL;
+ }
+ ENDTRY;
+ } else
+ trailer_tvb = NULL; /* no trailer */
+
+ /* If there's some bytes left over, and we were given an item ID
+ for a trailer, mark those bytes as a trailer. */
+ if (trailer_tvb && tree && trailer_id != -1) {
+ 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);
+ }
+ }
}
diff --git a/packet-llc.c b/packet-llc.c
index f6b6a5cbf0..c517b19f74 100644
--- a/packet-llc.c
+++ b/packet-llc.c
@@ -2,7 +2,7 @@
* Routines for IEEE 802.2 LLC layer
* Gilbert Ramirez <gram@xiexie.org>
*
- * $Id: packet-llc.c,v 1.80 2001/01/11 07:24:17 guy Exp $
+ * $Id: packet-llc.c,v 1.81 2001/01/18 07:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -398,7 +398,7 @@ dissect_snap(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree,
packet type for AARP packets. */
if (XDLC_IS_INFORMATION(control)) {
ethertype(etype, tvb, offset+5,
- pinfo, tree, snap_tree, hf_type);
+ pinfo, tree, snap_tree, hf_type, -1);
} else {
next_tvb = tvb_new_subset(tvb, offset+5, -1, -1);
dissect_data(next_tvb, 0, pinfo, tree);
diff --git a/packet-null.c b/packet-null.c
index 7d334aad81..b2559a6524 100644
--- a/packet-null.c
+++ b/packet-null.c
@@ -1,7 +1,7 @@
/* packet-null.c
* Routines for null packet disassembly
*
- * $Id: packet-null.c,v 1.38 2001/01/09 06:31:39 guy Exp $
+ * $Id: packet-null.c,v 1.39 2001/01/18 07:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -269,7 +269,7 @@ dissect_null(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
fh_tree = proto_item_add_subtree(ti, ett_null);
} else
fh_tree = NULL;
- ethertype(null_header, tvb, 4, pinfo, tree, fh_tree, hf_null_etype);
+ ethertype(null_header, tvb, 4, pinfo, tree, fh_tree, hf_null_etype, -1);
} else {
/* populate a tree in the second pane with the status of the link
layer (ie none) */
diff --git a/packet-sll.c b/packet-sll.c
index 2e82af1d62..78bec6f64c 100644
--- a/packet-sll.c
+++ b/packet-sll.c
@@ -1,7 +1,7 @@
/* packet-sll.c
* Routines for disassembly of packets from Linux "cooked mode" captures
*
- * $Id: packet-sll.c,v 1.5 2001/01/09 09:59:28 guy Exp $
+ * $Id: packet-sll.c,v 1.6 2001/01/18 07:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -138,11 +138,8 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint16 hatype, halen;
guint8 *src;
proto_item *ti;
- volatile guint16 length;
- tvbuff_t *volatile next_tvb;
- tvbuff_t *volatile trailer_tvb;
- proto_tree *volatile fh_tree = NULL;
- guint length_before;
+ tvbuff_t *next_tvb;
+ proto_tree *fh_tree = NULL;
CHECK_DISPLAY_AS_DATA(proto_sll, tvb, pinfo, tree);
@@ -201,7 +198,6 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
protocol);
next_tvb = tvb_new_subset(tvb, SLL_HEADER_SIZE, -1, -1);
- trailer_tvb = NULL;
switch (protocol) {
case LINUX_SLL_P_802_2:
@@ -224,41 +220,8 @@ dissect_sll(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
break;
}
} else {
- length_before = tvb_reported_length(tvb);
- length = ethertype(protocol, tvb, SLL_HEADER_SIZE, pinfo, tree,
- fh_tree, hf_sll_etype) + SLL_HEADER_SIZE;
- if (length < length_before) {
- /*
- * Create a tvbuff for the padding.
- */
- TRY {
- trailer_tvb = tvb_new_subset(tvb, length, -1,
- -1);
- }
- CATCH2(BoundsError, ReportedBoundsError) {
- /* The packet doesn't have "length" bytes
- worth of captured data left in it. No
- trailer to display. */
- trailer_tvb = NULL;
- }
- ENDTRY;
- } else {
- /*
- * There is no padding.
- */
- trailer_tvb = NULL;
- }
- }
-
- /* 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_sll_trailer,
- trailer_tvb, 0, trailer_length, FALSE);
- }
+ ethertype(protocol, tvb, SLL_HEADER_SIZE, pinfo, tree,
+ fh_tree, hf_sll_etype, hf_sll_trailer);
}
}
diff --git a/packet-vlan.c b/packet-vlan.c
index 173f14bfd4..595ec8f8e9 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.29 2001/01/09 09:59:28 guy Exp $
+ * $Id: packet-vlan.c,v 1.30 2001/01/18 07:44:39 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -82,7 +82,6 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
tvbuff_t *volatile next_tvb;
tvbuff_t *volatile trailer_tvb;
proto_tree *volatile vlan_tree;
- guint length_before, length;
CHECK_DISPLAY_AS_DATA(proto_vlan, tvb, pinfo, tree);
@@ -164,40 +163,22 @@ dissect_vlan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
} else {
call_dissector(ipx_handle, next_tvb, pinfo, tree);
}
- } else {
- length_before = tvb_reported_length(tvb);
- length = ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree,
- hf_vlan_etype) + 4;
- if (length < length_before) {
- /*
- * Create a tvbuff for the padding.
- */
- TRY {
- trailer_tvb = tvb_new_subset(tvb, length, -1, -1);
- }
- CATCH2(BoundsError, ReportedBoundsError) {
- /* The packet doesn't have "length" bytes worth of captured
- data left in it. No trailer to display. */
- trailer_tvb = NULL;
- }
- ENDTRY;
- } else {
- /* No padding. */
- trailer_tvb = NULL;
- }
- }
- /* If there's some bytes left over, mark them. */
- if (trailer_tvb && tree) {
- int trailer_length;
- const guint8 *ptr;
+ /* 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);
+ 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);
+ }
}
+ } else {
+ ethertype(encap_proto, tvb, 4, pinfo, tree, vlan_tree,
+ hf_vlan_etype, hf_vlan_trailer);
}
}