summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2003-01-20 05:42:37 +0000
committerGuy Harris <guy@alum.mit.edu>2003-01-20 05:42:37 +0000
commit6c4a845613b90fc008ce96a6da214fbb0046a856 (patch)
tree0c50e4b74147f8ee520a0cdc7cdaf0a7d2745ded
parentfa62e3b4d4bb3ede669620b9df62bec65575f12f (diff)
downloadwireshark-6c4a845613b90fc008ce96a6da214fbb0046a856.tar.gz
Move into "call_dissector_work()" the stuff to handle dissecting, in
error packets, the copy of the packet that got the error, rather than doing it in the CLNP dissector and the ICMP dissector and the ICMPv6 dissector and the PPP dissector for various control protocols; have it do that work iff "pinfo->in_error_pkt" is set. svn path=/trunk/; revision=6942
-rw-r--r--epan/packet.c122
-rw-r--r--packet-clnp.c59
-rw-r--r--packet-icmpv6.c72
-rw-r--r--packet-ip.c78
-rw-r--r--packet-ppp.c56
5 files changed, 142 insertions, 245 deletions
diff --git a/epan/packet.c b/epan/packet.c
index ab50d0a614..7969171aae 100644
--- a/epan/packet.c
+++ b/epan/packet.c
@@ -1,7 +1,7 @@
/* packet.c
* Routines for packet disassembly
*
- * $Id: packet.c,v 1.84 2002/12/08 02:32:36 gerald Exp $
+ * $Id: packet.c,v 1.85 2003/01/20 05:42:37 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -335,6 +335,29 @@ struct dissector_handle {
int proto_index;
};
+static int
+call_dissector_through_handle(dissector_handle_t handle, tvbuff_t *tvb,
+ packet_info *pinfo, proto_tree *tree)
+{
+ int ret;
+
+ if (handle->is_new)
+ ret = (*handle->dissector.new)(tvb, pinfo, tree);
+ else {
+ (*handle->dissector.old)(tvb, pinfo, tree);
+ ret = tvb_length(tvb);
+ if (ret == 0) {
+ /*
+ * XXX - a tvbuff can have 0 bytes of data in
+ * it, so we have to make sure we don't return
+ * 0.
+ */
+ ret = 1;
+ }
+ }
+ return ret;
+}
+
/*
* Call a dissector through a handle.
* If the protocol for that handle isn't enabled, return 0 without
@@ -349,7 +372,14 @@ call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb,
{
const char *saved_proto;
guint16 saved_can_desegment;
- int ret;
+ volatile int ret;
+ gboolean save_writable;
+ volatile address save_dl_src;
+ volatile address save_dl_dst;
+ volatile address save_net_src;
+ volatile address save_net_dst;
+ volatile address save_src;
+ volatile address save_dst;
if (handle->proto_index != -1 &&
!proto_is_protocol_enabled(handle->proto_index)) {
@@ -375,19 +405,87 @@ call_dissector_work(dissector_handle_t handle, tvbuff_t *tvb,
pinfo->current_proto =
proto_get_protocol_short_name(handle->proto_index);
}
- if (handle->is_new)
- ret = (*handle->dissector.new)(tvb, pinfo, tree);
- else {
- (*handle->dissector.old)(tvb, pinfo, tree);
- ret = tvb_length(tvb);
- if (ret == 0) {
+
+ if (pinfo->in_error_pkt) {
+ /*
+ * This isn't a packet being transported inside
+ * the protocol whose dissector is calling us,
+ * it's a copy of a packet that caused an error
+ * in some protocol included in a packet that
+ * reports the error (e.g., an ICMP Unreachable
+ * packet).
+ */
+
+ /*
+ * Save the current state of the writability of
+ * the columns, and restore them after the
+ * dissector returns, so that the columns
+ * don't reflect the packet that got the error,
+ * they reflect the packet that reported the
+ * error.
+ */
+ save_writable = col_get_writable(pinfo->cinfo);
+ col_set_writable(pinfo->cinfo, FALSE);
+ save_dl_src = pinfo->dl_src;
+ save_dl_dst = pinfo->dl_dst;
+ save_net_src = pinfo->net_src;
+ save_net_dst = pinfo->net_dst;
+ save_src = pinfo->src;
+ save_dst = pinfo->dst;
+
+ /* Dissect the contained packet. */
+ TRY {
+ ret = call_dissector_through_handle(handle, tvb,
+ pinfo, tree);
+ }
+ CATCH(BoundsError) {
/*
- * XXX - a tvbuff can have 0 bytes of data in
- * it, so we have to make sure we don't return
- * 0.
+ * Restore the column writability and addresses.
*/
- ret = 1;
+ col_set_writable(pinfo->cinfo, save_writable);
+ pinfo->dl_src = save_dl_src;
+ pinfo->dl_dst = save_dl_dst;
+ pinfo->net_src = save_net_src;
+ pinfo->net_dst = save_net_dst;
+ pinfo->src = save_src;
+ pinfo->dst = save_dst;
+
+ /*
+ * Restore the current protocol, so any
+ * "Short Frame" indication reflects that
+ * protocol, not the protocol for the
+ * packet that got the error.
+ */
+ pinfo->current_proto = saved_proto;
+
+ /*
+ * Restore the desegmentability state.
+ */
+ pinfo->can_desegment = saved_can_desegment;
+
+ /*
+ * Rethrow the exception, so this will be
+ * reported as a short frame.
+ */
+ RETHROW;
+ }
+ CATCH(ReportedBoundsError) {
+ ; /* do nothing */
}
+ ENDTRY;
+
+ col_set_writable(pinfo->cinfo, save_writable);
+ pinfo->dl_src = save_dl_src;
+ pinfo->dl_dst = save_dl_dst;
+ pinfo->net_src = save_net_src;
+ pinfo->net_dst = save_net_dst;
+ pinfo->src = save_src;
+ pinfo->dst = save_dst;
+ } else {
+ /*
+ * Just call the subdissector.
+ */
+ ret = call_dissector_through_handle(handle, tvb, pinfo, tree);
}
pinfo->current_proto = saved_proto;
pinfo->can_desegment = saved_can_desegment;
diff --git a/packet-clnp.c b/packet-clnp.c
index b06b5893a0..ca32671549 100644
--- a/packet-clnp.c
+++ b/packet-clnp.c
@@ -1,7 +1,7 @@
/* packet-clnp.c
* Routines for ISO/OSI network and transport protocol packet disassembly
*
- * $Id: packet-clnp.c,v 1.63 2003/01/05 02:50:23 guy Exp $
+ * $Id: packet-clnp.c,v 1.64 2003/01/20 05:42:30 guy Exp $
* Laurent Deniel <deniel@worldnet.fr>
* Ralf Schneider <Ralf.Schneider@t-online.de>
*
@@ -86,6 +86,7 @@ static const fragment_items clnp_frag_items = {
"segments"
};
+static dissector_handle_t clnp_handle;
static dissector_handle_t data_handle;
/*
@@ -1617,15 +1618,9 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
gint len;
guint next_length;
proto_tree *discpdu_tree;
- volatile address save_dl_src;
- volatile address save_dl_dst;
- volatile address save_net_src;
- volatile address save_net_dst;
- volatile address save_src;
- volatile address save_dst;
gboolean save_in_error_pkt;
fragment_data *fd_head;
- tvbuff_t *volatile next_tvb;
+ tvbuff_t *next_tvb;
gboolean update_col_info = TRUE;
gboolean save_fragmented;
@@ -1942,22 +1937,10 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
if (tree) {
next_length = tvb_length_remaining(tvb, offset);
if (next_length != 0) {
- /* We have payload; dissect it.
- Make the columns non-writable, so the packet isn't shown
- in the summary based on what the discarded PDU's contents
- are. */
- col_set_writable(pinfo->cinfo, FALSE);
-
- /* Also, save the current values of the addresses, and restore
- them when we're finished dissecting the contained packet, so
- that the address columns in the summary don't reflect the
- contained packet, but reflect this packet instead. */
- save_dl_src = pinfo->dl_src;
- save_dl_dst = pinfo->dl_dst;
- save_net_src = pinfo->net_src;
- save_net_dst = pinfo->net_dst;
- save_src = pinfo->src;
- save_dst = pinfo->dst;
+ /* We have payload; dissect it. */
+ ti = proto_tree_add_text(clnp_tree, tvb, offset, next_length,
+ "Discarded PDU");
+ discpdu_tree = proto_item_add_subtree(ti, ett_clnp_disc_pdu);
/* Save the current value of the "we're inside an error packet"
flag, and set that flag; subdissectors may treat packets
@@ -1966,34 +1949,10 @@ static void dissect_clnp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
save_in_error_pkt = pinfo->in_error_pkt;
pinfo->in_error_pkt = TRUE;
- /* Dissect the contained packet.
- Catch ReportedBoundsError, and do nothing if we see it,
- because it's not an error if the contained packet is short;
- there's no guarantee that all of it was included.
-
- XXX - should catch BoundsError, and re-throw it after cleaning
- up. */
- ti = proto_tree_add_text(clnp_tree, tvb, offset, next_length,
- "Discarded PDU");
- discpdu_tree = proto_item_add_subtree(ti, ett_clnp_disc_pdu);
- TRY {
- dissect_clnp(next_tvb, pinfo, discpdu_tree);
- }
- CATCH(ReportedBoundsError) {
- ; /* do nothing */
- }
- ENDTRY;
+ call_dissector(clnp_handle, next_tvb, pinfo, discpdu_tree);
/* Restore the "we're inside an error packet" flag. */
pinfo->in_error_pkt = save_in_error_pkt;
-
- /* Restore the addresses. */
- pinfo->dl_src = save_dl_src;
- pinfo->dl_dst = save_dl_dst;
- pinfo->net_src = save_net_src;
- pinfo->net_dst = save_net_dst;
- pinfo->src = save_src;
- pinfo->dst = save_dst;
}
}
pinfo->fragmented = save_fragmented;
@@ -2152,8 +2111,6 @@ void proto_register_cltp(void)
void
proto_reg_handoff_clnp(void)
{
- dissector_handle_t clnp_handle;
-
data_handle = find_dissector("data");
clnp_handle = create_dissector_handle(dissect_clnp, proto_clnp);
diff --git a/packet-icmpv6.c b/packet-icmpv6.c
index 3b311f0f6c..2fa4fd8615 100644
--- a/packet-icmpv6.c
+++ b/packet-icmpv6.c
@@ -1,7 +1,7 @@
/* packet-icmpv6.c
* Routines for ICMPv6 packet disassembly
*
- * $Id: packet-icmpv6.c,v 1.68 2002/12/02 23:43:26 guy Exp $
+ * $Id: packet-icmpv6.c,v 1.69 2003/01/20 05:42:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -116,71 +116,27 @@ static const value_string names_router_pref[] = {
static void
dissect_contained_icmpv6(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
{
- tvbuff_t *next_tvb;
- volatile address save_dl_src;
- volatile address save_dl_dst;
- volatile address save_net_src;
- volatile address save_net_dst;
- volatile address save_src;
- volatile address save_dst;
gboolean save_in_error_pkt;
+ tvbuff_t *next_tvb;
+
+ /* Save the current value of the "we're inside an error packet"
+ flag, and set that flag; subdissectors may treat packets
+ that are the payload of error packets differently from
+ "real" packets. */
+ save_in_error_pkt = pinfo->in_error_pkt;
+ pinfo->in_error_pkt = TRUE;
next_tvb = tvb_new_subset(tvb, offset, -1, -1);
/* tiny sanity check */
if ((tvb_get_guint8(tvb, offset) & 0xf0) == 0x60) {
- /* The contained packet is an IPv6 datagram; dissect it.
-
- Set the columns non-writable, so that the packet list
- shows this as an ICMPv6 packet, not as the type of packet
- for which the ICMPv6 packet was generated. */
- col_set_writable(pinfo->cinfo, FALSE);
-
- /* Also, save the current values of the addresses, and restore
- them when we're finished dissecting the contained packet, so
- that the address columns in the summary don't reflect the
- contained packet, but reflect this packet instead. */
- save_dl_src = pinfo->dl_src;
- save_dl_dst = pinfo->dl_dst;
- save_net_src = pinfo->net_src;
- save_net_dst = pinfo->net_dst;
- save_src = pinfo->src;
- save_dst = pinfo->dst;
-
- /* Save the current value of the "we're inside an error packet"
- flag, and set that flag; subdissectors may treat packets
- that are the payload of error packets differently from
- "real" packets. */
- save_in_error_pkt = pinfo->in_error_pkt;
- pinfo->in_error_pkt = TRUE;
-
- /* Dissect the contained packet.
- Catch ReportedBoundsError, and do nothing if we see it,
- because it's not an error if the contained packet is short;
- there's no guarantee that all of it was included.
-
- XXX - should catch BoundsError, and re-throw it after cleaning
- up. */
- TRY {
- call_dissector(ipv6_handle, next_tvb, pinfo, tree);
- }
- CATCH(ReportedBoundsError) {
- ; /* do nothing */
- }
- ENDTRY;
-
- /* Restore the "we're inside an error packet" flag. */
- pinfo->in_error_pkt = save_in_error_pkt;
-
- /* Restore the addresses. */
- pinfo->dl_src = save_dl_src;
- pinfo->dl_dst = save_dl_dst;
- pinfo->net_src = save_net_src;
- pinfo->net_dst = save_net_dst;
- pinfo->src = save_src;
- pinfo->dst = save_dst;
+ /* The contained packet is an IPv6 datagram; dissect it. */
+ call_dissector(ipv6_handle, next_tvb, pinfo, tree);
} else
call_dissector(data_handle,next_tvb, pinfo, tree);
+
+ /* Restore the "we're inside an error packet" flag. */
+ pinfo->in_error_pkt = save_in_error_pkt;
}
static void
diff --git a/packet-ip.c b/packet-ip.c
index 65403c6cfe..bef1c05e3a 100644
--- a/packet-ip.c
+++ b/packet-ip.c
@@ -1,7 +1,7 @@
/* packet-ip.c
* Routines for IP and miscellaneous IP protocol packet disassembly
*
- * $Id: packet-ip.c,v 1.179 2003/01/19 22:21:01 guy Exp $
+ * $Id: packet-ip.c,v 1.180 2003/01/20 05:42:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -1304,14 +1304,6 @@ dissect_icmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
guint8 num_addrs = 0;
guint8 addr_entry_size = 0;
int i;
- gboolean save_writable;
- const char *save_current_proto;
- volatile address save_dl_src;
- volatile address save_dl_dst;
- volatile address save_net_src;
- volatile address save_net_dst;
- volatile address save_src;
- volatile address save_dst;
gboolean save_in_error_pkt;
tvbuff_t *next_tvb;
@@ -1496,31 +1488,6 @@ dissect_icmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
case ICMP_PARAMPROB:
case ICMP_SOURCEQUENCH:
case ICMP_REDIRECT:
- /* Decode the IP header and first 64 bits of data from the
- original datagram.
-
- Set the columns non-writable, so that the packet list
- shows this as an ICMP packet, not as the type of packet
- for which the ICMP packet was generated. Save the current
- setting, so we can restore it after we're done. */
- save_writable = col_get_writable(pinfo->cinfo);
- col_set_writable(pinfo->cinfo, FALSE);
-
- /* Save the current protocol string as well, and restore it
- after we're done. */
- save_current_proto = pinfo->current_proto;
-
- /* Also, save the current values of the addresses, and restore
- them when we're finished dissecting the contained packet, so
- that the address columns in the summary don't reflect the
- contained packet, but reflect this packet instead. */
- save_dl_src = pinfo->dl_src;
- save_dl_dst = pinfo->dl_dst;
- save_net_src = pinfo->net_src;
- save_net_dst = pinfo->net_dst;
- save_src = pinfo->src;
- save_dst = pinfo->dst;
-
/* Save the current value of the "we're inside an error packet"
flag, and set that flag; subdissectors may treat packets
that are the payload of error packets differently from
@@ -1528,50 +1495,13 @@ dissect_icmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
save_in_error_pkt = pinfo->in_error_pkt;
pinfo->in_error_pkt = TRUE;
- /* Dissect the contained packet.
- Catch ReportedBoundsError, and do nothing if we see it,
- because it's not an error if the contained packet is short;
- there's no guarantee that all of it was included. */
+ /* Decode the IP header and first 64 bits of data from the
+ original datagram. */
next_tvb = tvb_new_subset(tvb, 8, -1, -1);
- TRY {
- call_dissector(ip_handle, next_tvb, pinfo, icmp_tree);
- }
- CATCH(BoundsError) {
- /* Restore the writability of the columns. */
- col_set_writable(pinfo->cinfo, save_writable);
-
- /* Restore the current protocol string. */
- pinfo->current_proto = save_current_proto;
-
- /* Restore the "we're inside an error packet" flag. */
- pinfo->in_error_pkt = save_in_error_pkt;
-
- /* Restore the addresses. */
- pinfo->dl_src = save_dl_src;
- pinfo->dl_dst = save_dl_dst;
- pinfo->net_src = save_net_src;
- pinfo->net_dst = save_net_dst;
- pinfo->src = save_src;
- pinfo->dst = save_dst;
-
- /* Rethrow the exception, so this will be reported as a short frame */
- RETHROW;
- }
- CATCH(ReportedBoundsError) {
- ; /* do nothing */
- }
- ENDTRY;
+ call_dissector(ip_handle, next_tvb, pinfo, icmp_tree);
/* Restore the "we're inside an error packet" flag. */
pinfo->in_error_pkt = save_in_error_pkt;
-
- /* Restore the addresses. */
- pinfo->dl_src = save_dl_src;
- pinfo->dl_dst = save_dl_dst;
- pinfo->net_src = save_net_src;
- pinfo->net_dst = save_net_dst;
- pinfo->src = save_src;
- pinfo->dst = save_dst;
break;
case ICMP_ECHOREPLY:
diff --git a/packet-ppp.c b/packet-ppp.c
index 72eaeea55d..268ca868a6 100644
--- a/packet-ppp.c
+++ b/packet-ppp.c
@@ -1,7 +1,7 @@
/* packet-ppp.c
* Routines for ppp packet disassembly
*
- * $Id: packet-ppp.c,v 1.105 2003/01/06 22:33:57 guy Exp $
+ * $Id: packet-ppp.c,v 1.106 2003/01/20 05:42:30 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -2276,7 +2276,7 @@ dissect_cp( tvbuff_t *tvb, int proto_id, int proto_subtree_index,
proto_tree *tree )
{
proto_item *ti;
- proto_tree *volatile fh_tree = NULL;
+ proto_tree *fh_tree = NULL;
proto_item *tf;
proto_tree *field_tree;
@@ -2360,12 +2360,6 @@ dissect_cp( tvbuff_t *tvb, int proto_id, int proto_subtree_index,
case PROTREJ:
if(tree) {
- volatile address save_dl_src;
- volatile address save_dl_dst;
- volatile address save_net_src;
- volatile address save_net_dst;
- volatile address save_src;
- volatile address save_dst;
gboolean save_in_error_pkt;
tvbuff_t *next_tvb;
@@ -2381,24 +2375,6 @@ dissect_cp( tvbuff_t *tvb, int proto_id, int proto_subtree_index,
"Rejected packet (%d byte%s)",
length, plurality(length, "", "s"));
- /* Decode the rejected packet.
-
- Set the columns non-writable, so that the packet list
- shows this as an LCP packet, not as the type of packet
- for which the LCP packet was generated. */
- col_set_writable(pinfo->cinfo, FALSE);
-
- /* Also, save the current values of the addresses, and restore
- them when we're finished dissecting the contained packet, so
- that the address columns in the summary don't reflect the
- contained packet, but reflect this packet instead. */
- save_dl_src = pinfo->dl_src;
- save_dl_dst = pinfo->dl_dst;
- save_net_src = pinfo->net_src;
- save_net_dst = pinfo->net_dst;
- save_src = pinfo->src;
- save_dst = pinfo->dst;
-
/* Save the current value of the "we're inside an error packet"
flag, and set that flag; subdissectors may treat packets
that are the payload of error packets differently from
@@ -2406,35 +2382,15 @@ dissect_cp( tvbuff_t *tvb, int proto_id, int proto_subtree_index,
save_in_error_pkt = pinfo->in_error_pkt;
pinfo->in_error_pkt = TRUE;
- /* Dissect the contained packet.
- Catch ReportedBoundsError, and do nothing if we see it,
- because it's not an error if the contained packet is short;
- there's no guarantee that all of it was included.
-
- XXX - should catch BoundsError, and re-throw it after cleaning
- up. */
+ /* Decode the rejected packet. */
next_tvb = tvb_new_subset(tvb, offset, length, length);
- TRY {
- if (!dissector_try_port(ppp_subdissector_table, protocol,
- next_tvb, pinfo, fh_tree)) {
- call_dissector(data_handle, next_tvb, pinfo, fh_tree);
- }
+ if (!dissector_try_port(ppp_subdissector_table, protocol,
+ next_tvb, pinfo, fh_tree)) {
+ call_dissector(data_handle, next_tvb, pinfo, fh_tree);
}
- CATCH(ReportedBoundsError) {
- ; /* do nothing */
- }
- ENDTRY;
/* Restore the "we're inside an error packet" flag. */
pinfo->in_error_pkt = save_in_error_pkt;
-
- /* Restore the addresses. */
- pinfo->dl_src = save_dl_src;
- pinfo->dl_dst = save_dl_dst;
- pinfo->net_src = save_net_src;
- pinfo->net_dst = save_net_dst;
- pinfo->src = save_src;
- pinfo->dst = save_dst;
}
}
break;