2001-02-08 07:08:05 +00:00
|
|
|
/* packet-ieee8023.c
|
|
|
|
* Routine for dissecting 802.3 (as opposed to D/I/X Ethernet) packets.
|
|
|
|
*
|
2006-05-21 04:49:01 +00:00
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
2001-02-08 07:08:05 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-02-08 07:08:05 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-02-08 07:08:05 +00:00
|
|
|
* 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.
|
2002-08-28 21:04:11 +00:00
|
|
|
*
|
2001-02-08 07:08:05 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2012-06-28 22:56:06 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2001-02-08 07:08:05 +00:00
|
|
|
*/
|
|
|
|
|
2012-09-20 02:03:38 +00:00
|
|
|
#include "config.h"
|
2001-02-08 07:08:05 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
2002-01-21 07:37:49 +00:00
|
|
|
#include <epan/packet.h>
|
2013-11-10 15:59:37 +00:00
|
|
|
#include <epan/exceptions.h>
|
2008-07-13 18:56:54 +00:00
|
|
|
#include <epan/expert.h>
|
Move show_exception() and show_reported_bounds_error() to
epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c. Update their callers to include
<epan/show_exception.h> to get their declaration.
Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff. Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).
Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).
Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.
Use show_exception() to report non-fatal errors, rather than doing it
yourself.
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.
Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.
Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.
svn path=/trunk/; revision=47924
2013-02-27 22:43:54 +00:00
|
|
|
#include <epan/show_exception.h>
|
2001-02-08 07:08:05 +00:00
|
|
|
#include "packet-ieee8023.h"
|
2003-08-21 21:05:30 +00:00
|
|
|
#include "packet-eth.h"
|
2001-02-08 07:08:05 +00:00
|
|
|
|
2013-12-15 23:44:12 +00:00
|
|
|
void proto_reg_handoff_ieee802_3(void);
|
|
|
|
|
2001-02-08 07:08:05 +00:00
|
|
|
static dissector_handle_t ipx_handle;
|
|
|
|
static dissector_handle_t llc_handle;
|
2009-01-18 12:08:56 +00:00
|
|
|
static dissector_handle_t ccsds_handle;
|
2001-02-08 07:08:05 +00:00
|
|
|
|
|
|
|
void
|
2008-07-13 18:56:54 +00:00
|
|
|
dissect_802_3(volatile int length, gboolean is_802_2, tvbuff_t *tvb,
|
2001-02-08 07:08:05 +00:00
|
|
|
int offset_after_length, packet_info *pinfo, proto_tree *tree,
|
2013-09-05 01:39:35 +00:00
|
|
|
proto_tree *fh_tree, int length_id, int trailer_id, expert_field* ei_len,
|
2003-10-01 07:11:49 +00:00
|
|
|
int fcs_len)
|
2001-02-08 07:08:05 +00:00
|
|
|
{
|
2008-07-13 18:56:54 +00:00
|
|
|
proto_item *length_it;
|
2005-05-30 21:00:05 +00:00
|
|
|
tvbuff_t *volatile next_tvb = NULL;
|
Move show_exception() and show_reported_bounds_error() to
epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c. Update their callers to include
<epan/show_exception.h> to get their declaration.
Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff. Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).
Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).
Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.
Use show_exception() to report non-fatal errors, rather than doing it
yourself.
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.
Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.
Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.
svn path=/trunk/; revision=47924
2013-02-27 22:43:54 +00:00
|
|
|
tvbuff_t *trailer_tvb = NULL;
|
2004-02-21 05:12:45 +00:00
|
|
|
const char *saved_proto;
|
2008-07-13 18:56:54 +00:00
|
|
|
gint captured_length, reported_length;
|
2010-10-08 17:48:22 +00:00
|
|
|
void *pd_save;
|
2001-02-08 07:08:05 +00:00
|
|
|
|
2008-07-13 18:56:54 +00:00
|
|
|
length_it = proto_tree_add_uint(fh_tree, length_id, tvb,
|
|
|
|
offset_after_length - 2, 2, length);
|
2001-02-08 07:08:05 +00:00
|
|
|
|
2008-07-13 18:56:54 +00:00
|
|
|
/* Get the length of the payload.
|
|
|
|
If the FCS length is positive, remove the FCS.
|
|
|
|
(If it's zero, there's no FCS; if it's negative, we don't know whether
|
|
|
|
there's an FCS, so we'll guess based on the length of the trailer.) */
|
|
|
|
reported_length = tvb_reported_length_remaining(tvb, offset_after_length);
|
|
|
|
if (fcs_len > 0) {
|
|
|
|
if (reported_length >= fcs_len)
|
|
|
|
reported_length -= fcs_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the length in the 802.3 header doesn't go past the end of
|
|
|
|
the payload. */
|
|
|
|
if (length > reported_length) {
|
|
|
|
length = reported_length;
|
2013-09-05 01:39:35 +00:00
|
|
|
expert_add_info(pinfo, length_it, ei_len);
|
2008-07-13 18:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Give the next dissector only 'length' number of bytes. */
|
2005-08-13 22:34:44 +00:00
|
|
|
captured_length = tvb_length_remaining(tvb, offset_after_length);
|
|
|
|
if (captured_length > length)
|
|
|
|
captured_length = length;
|
|
|
|
next_tvb = tvb_new_subset(tvb, offset_after_length, captured_length, length);
|
2001-02-08 07:08:05 +00:00
|
|
|
|
|
|
|
/* Dissect the payload either as IPX or as an LLC frame.
|
2013-02-28 18:13:41 +00:00
|
|
|
Catch non-fatal exceptions, 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. */
|
2004-02-21 05:12:45 +00:00
|
|
|
saved_proto = pinfo->current_proto;
|
2010-10-08 17:48:22 +00:00
|
|
|
pd_save = pinfo->private_data;
|
2001-02-08 07:08:05 +00:00
|
|
|
TRY {
|
|
|
|
if (is_802_2)
|
|
|
|
call_dissector(llc_handle, next_tvb, pinfo, tree);
|
2009-01-18 12:08:56 +00:00
|
|
|
else {
|
|
|
|
/* Check if first three bits of payload are 0x7.
|
|
|
|
If so, then payload is IPX. If not, then it's CCSDS.
|
|
|
|
Refer to packet-eth.c for setting of is_802_2 variable. */
|
|
|
|
if (tvb_get_bits8(next_tvb, 0, 3) == 7)
|
|
|
|
call_dissector(ipx_handle, next_tvb, pinfo, tree);
|
|
|
|
else
|
|
|
|
call_dissector(ccsds_handle, next_tvb, pinfo, tree);
|
|
|
|
}
|
2001-02-08 07:08:05 +00:00
|
|
|
}
|
Move show_exception() and show_reported_bounds_error() to
epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c. Update their callers to include
<epan/show_exception.h> to get their declaration.
Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff. Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).
Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).
Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.
Use show_exception() to report non-fatal errors, rather than doing it
yourself.
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.
Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.
Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.
svn path=/trunk/; revision=47924
2013-02-27 22:43:54 +00:00
|
|
|
CATCH_NONFATAL_ERRORS {
|
|
|
|
/* Somebody threw an exception that means that there was a problem
|
|
|
|
dissecting the payload; that means that a dissector was found,
|
|
|
|
so we don't need to dissect the payload as data or update the
|
|
|
|
protocol or info columns.
|
2010-10-08 17:48:22 +00:00
|
|
|
|
Move show_exception() and show_reported_bounds_error() to
epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c. Update their callers to include
<epan/show_exception.h> to get their declaration.
Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff. Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).
Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).
Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.
Use show_exception() to report non-fatal errors, rather than doing it
yourself.
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.
Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.
Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.
svn path=/trunk/; revision=47924
2013-02-27 22:43:54 +00:00
|
|
|
Just show the exception and then drive on to show the trailer,
|
|
|
|
after noting that a dissector was found and restoring the
|
|
|
|
protocol value that was in effect before we called the subdissector. */
|
2010-10-08 17:48:22 +00:00
|
|
|
pinfo->private_data = pd_save;
|
|
|
|
|
2005-01-16 16:06:15 +00:00
|
|
|
show_exception(next_tvb, pinfo, tree, EXCEPT_CODE, GET_MESSAGE);
|
2001-02-08 07:08:05 +00:00
|
|
|
}
|
|
|
|
ENDTRY;
|
|
|
|
|
Move show_exception() and show_reported_bounds_error() to
epan/show_exception.c, as it's used outside
epan/dissectors/packet-frame.c. Update their callers to include
<epan/show_exception.h> to get their declaration.
Add a CATCH_NONFATAL_ERRORS macro that catches all exceptions that, if
there's more stuff in the packet to dissect after the dissector call
that threw the exception, doesn't mean you shouldn't go ahead and
dissect that stuff. Use it in all those cases, including ones where
BoundsError was inappropriately being caught (you want those passed up
to the top level, so that the packet is reported as having been cut
short in the capture process).
Add a CATCH_BOUNDS_ERRORS macro that catches all exceptions that
correspond to running past the end of the data for a tvbuff; use it
rather than explicitly catching those exceptions individually, and
rather than just catching all exceptions (the only place that
DissectorError should be caught, for example, is at the top level, so
dissector bugs show up in the protocol tree).
Don't catch and then immediately rethrow exceptions without doing
anything else; just let the exceptions go up to the final catcher.
Use show_exception() to report non-fatal errors, rather than doing it
yourself.
If a dissector is called from Lua, catch all non-fatal errors and use
show_exception() to report them rather than catching only
ReportedBoundsError and adding a proto_malformed item.
Don't catch exceptions when constructing a trailer tvbuff in
packet-ieee8023.c - just construct it after the payload has been
dissected, and let whatever exceptions that throws be handled at the top
level.
Avoid some TRY/CATCH/ENDTRY cases by using checks such as
tvb_bytes_exist() before even looking in the tvbuff.
svn path=/trunk/; revision=47924
2013-02-27 22:43:54 +00:00
|
|
|
/* Restore the protocol value, so that any exception thrown by
|
|
|
|
tvb_new_subset_remaining() refers to the protocol for which
|
|
|
|
this is a trailer, and restore the private_data structure in
|
|
|
|
case one of the called dissectors modified it. */
|
|
|
|
pinfo->private_data = pd_save;
|
|
|
|
pinfo->current_proto = saved_proto;
|
|
|
|
|
|
|
|
/* Construct a tvbuff for the trailer; if the trailer is past the
|
|
|
|
end of the captured data, this will throw a BoundsError, which
|
|
|
|
is what we want, as it'll report that the packet was cut short. */
|
|
|
|
trailer_tvb = tvb_new_subset_remaining(tvb, offset_after_length + length);
|
|
|
|
|
2010-06-19 01:16:29 +00:00
|
|
|
add_ethernet_trailer(pinfo, tree, fh_tree, trailer_id, tvb, trailer_tvb, fcs_len);
|
2001-02-08 07:08:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_ieee802_3(void)
|
|
|
|
{
|
2003-08-21 21:05:30 +00:00
|
|
|
/*
|
2009-01-18 12:08:56 +00:00
|
|
|
* Get handles for the subdissectors.
|
2003-08-21 21:05:30 +00:00
|
|
|
*/
|
|
|
|
ipx_handle = find_dissector("ipx");
|
|
|
|
llc_handle = find_dissector("llc");
|
2009-01-18 12:08:56 +00:00
|
|
|
ccsds_handle = find_dissector("ccsds");
|
2001-02-08 07:08:05 +00:00
|
|
|
}
|