Commit Graph

54 Commits

Author SHA1 Message Date
Tomasz Moń 2fcc819366
USBLL: Correctly handle last fragment retransmissions
Add fragment_add_check_with_fallback() and use it in USBLL dissector
instead of fragment_add_check() to avoid last fragment retransmissions
from being treated as separate transfers. With this change, the last
fragment retransmissions are correctly grouped together with the rest
of the transfer.

Only skip single fragment reassembly if retransmission is not possible
at the protocol level, i.e. for SETUP DATA0 (when it is not merged with
OUT data) and for isochronous transfers. The reassembly must not be
skipped for other transfers (especially for full-speed bulk) because
otherwise it wouldn't be possible to group retransmissions together with
the first data packet.

Do not use DATA0/DATA1 tracking for isochronous transfers. Isochronous
data cannot be retransmitted because there are no handshakes (there is
no ACK nor NAK after isochronous data packets).
2022-12-06 07:26:02 +01:00
Tomasz Moń 5853886d50
reassembly: Store pointer to first gap
Store pointer to first gap to reduce number of full list traversals
needed when linking new fragments. When all captured fragments are in
order, the first gap is effectively pointing to list tail. The best case
scenario, where the list traversals are completely eliminated, happens
every time for protocols that always have the fragments ordered (most
notably USBLL Full-Speed capture containing Bulk OUT transfers with
a lot of retransmissions).

The memory usage is increased by a single pointer and 32-bit contiguous
length counter per fragment head. The additional CPU usage is constant
per insertion, i.e. does not increase with the number of fragments in
the list.

Fixes #17311
2022-12-01 20:14:40 +01:00
John Thacker 4f3b028d94 epan: Separate fragment_head and fragment_item
Separate fragment_head and fragment_item into two
different types of structs.

Remove "offset" from fragment_head, which was unused,
making fragment heads 4 bytes smaller.

Remove fragment_nr_offset, datalen, reassembled_in,
reas_in_layer_num, and error from fragment_item,
making them 24 bytes smaller.

Change a few dissectors which were using fragment_head
and fragment_item indistinguishably.

Ping #17311
2022-11-14 01:18:11 +00:00
John Thacker f1cbc6b662 epan: Remove fragment_get_reassembled()
Because completed reassemblies are hashed in the reassembled_table for
all the frame numbers that contributed fragments,
fragment_get_reassembled_id() works wherever fragment_get_reassembled()
does, and also works where the fragment id is not the frame number.

However, since the reassembled_table hash key only depends on the
fragment id and the frame number, it only allows a frame to have
one reassembly with a given fragment id. Some protocols can have
more than one reassembly with a given fragment id (that differ on
addresses or other keys), such as GSM SMS, and the wrong reassembly
is retrieved on the second pass in those cases.

For this reason, we might want to add additional key elements to
reassembled_table, such as layer number. fragment_get_reassembled_id
already takes packet_info as a parameter and can accommodate that
without further changes, but fragment_get_reassembled cannot, so
remove the latter in favor of the former.
2022-06-14 00:59:34 +00:00
John Thacker 7ab343e7d6 tcp: Split MSPs in out of order processing
When processing segments out of order in TCP, it is possible to
get new segments that fill a sequence gap and be able to dissect
at least one PDU but need more data for additional PDUs (that have
data from the contiguous stream bytes.) We can only determine this
after passing the reassembled segments to the subdissector first.

To keep dissection and layer numbers consistent between passes,
split the multisegment PDU, keeping the already dissect PDU(s) in
the current reassembly and creating a new MSP for the parts not yet
dissected.

Update the dissection test to enable the currently skipped test that
require MSP splitting and remove test_tcp_out_of_order_twopass_with_bug
2022-05-26 00:49:16 +00:00
John Thacker 444e3f230c tcp reassembly: Add fragment_add_out_of_order 2022-04-06 07:53:02 -04:00
Moshe Kaplan 69d54d6f8e Corrects repeated words throughout the code.
Repeated words were found with:
egrep "(\b[a-zA-Z]+) +\1\b" . -Ir
and then manually reviewed.
Non-displayed strings (e.g., in comments)
were also corrected, to ease future review.
2021-12-22 11:01:11 +00:00
Moshe Kaplan 1c3a9af869 Add files with WS_DLL_PUBLIC to Doxygen
Add @file markers for most files that
contain functions exported with
WS_DLL_PUBLIC so that Doxygen will
generate documentation for them.
2021-11-29 21:27:45 +00:00
Uli Heilmeier 75a4be6cf2 Reassemble: Fix typo
Change-Id: I63472001a825febed6b2fe88bca61bc2ea896ed3
Reviewed-on: https://code.wireshark.org/review/35069
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-11-12 13:43:16 +00:00
Peter Wu ca42331437 tcp: add support for reassembling out-of-order segments
Currently out-of-order segments will result in cutting a stream into
two pieces while the out-of-order segment itself is ignored. For
example, a stream of segments "ABDCE" is interpreted as "AB", "DE" with
"C" ignored. This behavior breaks TLS decryption or prevent application
layer PDUs (such as HTTP requests/responses) from being reconstructed.
To fix this, buffer segments when a gap is detected.

The proposed approach extends the "multi-segment PDU" (MSP) mechanism
which is normally used for linking multiple, sequential TCP segments
into a single PDU. When a gap is detected between segments, it is
assumed that the segments within this gap are out-of-order and will be
received (or retransmitted) later.

The current implementation has a limitation though, if multiple gaps
exist, then the subdissector will only be called when all gaps are
filled (the subdissector will receive segments later than necessary).
For example with "ACEBD", "ABC" can already be processed after "B" is
received (with "E" still buffered), but due to how MSP are extended, it
must receive "D" too before it reassembles "ABCDE". In practice this
could mean that the request/response times between HTTP requests and
responses are slightly off, but at least the stream is correct now.
(These limitations are documented in the User's Guide.)

As the feature fails at least the 802.11 decryption test where packets
are missing (instead of OoO), hide this feature behind a preference.

Tested with captures containing out-of-order TCP segments from the
linked bug reports, comparing the effect of toggling the preference on
the summary output of tshark, the verbose output (-V) and the two-pass
output (-2 or -2V). Captures marked with "ok" just needed "simple"
out-of-order handling. Captures marked with "ok2" additionally required
the reassembly API change to set the correct reassembled length.

This change does "regress" on bug 10289 though when the preference is
enabled as retransmitted single-segment PDUs are now passed to
subdissectors. I added a TODO comment for this unrelated cosmetic issue.

Bug: 3389   # capture 2907 (HTTP) ok
Bug: 4727   # capture 4590 (HTTP) ok
Bug: 9461   # capture 12130 (TLS/HTTP/RPC-over-HTTP +key 12131) ok
Bug: 12006  # capture 14236 (HTTP) ok2; capture 15261 (HTTP) ok
Bug: 13517  # capture 15370 (HTTP) ok; capture 16059 (MQ) ok
Bug: 13754  # capture 15593 (MySQL) ok2
Bug: 14649  # capture 16305 (WebSocket) ok
Change-Id: If3938c5c1c96db8f7f50e39ea779f623ce657d56
Reviewed-on: https://code.wireshark.org/review/27943
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-06-28 06:10:35 +00:00
Dario Lombardo 55c68ee69c epan: use SPDX indentifiers.
Skipping dissectors dir for now.

Change-Id: I717b66bfbc7cc81b83f8c2cbc011fcad643796aa
Reviewed-on: https://code.wireshark.org/review/25694
Petri-Dish: Dario Lombardo <lomato@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08 19:29:45 +00:00
Guy Harris 984d78da13 Clean up indentation.
Change-Id: I0815bf008ed056e3cd400a24fb10abb4ca88c3ce
Reviewed-on: https://code.wireshark.org/review/19854
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-01-30 01:17:21 +00:00
Michael Mann af54b292e6 Register reassembly tables
Register all reassembly tables with a central unit, allowing the
central unit to have the callback that initializes and destroys
the reassembly tables, rather than have dissectors do it individually.

Change-Id: Ic92619c06fb5ba6f1c3012f613cae14982e101d4
Reviewed-on: https://code.wireshark.org/review/19834
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-29 13:29:04 +00:00
Dario Lombardo 317649f949 reassemble: add cleanup routine.
Change-Id: I948d342a29aacc2212076359e5b073113c50c5de
Reviewed-on: https://code.wireshark.org/review/19697
Reviewed-by: Michael Mann <mmann78@netscape.net>
2017-01-21 00:28:28 +00:00
John A. Thacker da7354a636 Fragmentation reassembly as in PPP MP (RFC 1990/2686)
Add support for defragmentation of fragments that use the defragmentation
scheme of PPP MP (RFC 1990). Instead of getting "sequence_number,
fragment_number, last" as in other protocols, PPP MP provides a single
sequence number that is effectively "seqnum + fragnum", though it provides
flags for both the first and last fragment of a reassembly.

See Appendix A of RFC 4623 (PWE3 Fragmentation and Reassembly) for a list
of protocols that use this style, including PPP MP (RFC 1990), PWE3 MPLS
(RFC 4385), L2TPv2 (RFC 2661), L2TPv3 (RFC 3931), ATM, and Frame Relay.

Also add support for the Multi-class Extension to Multilink PPP (RFC 2686),
which uses some of the previously reserved bits as classes that distinguish
otherwise identical sequence numbers.

Bug: 12548
Change-Id: Ic2ce3c50e61ab2eb50e4d92fd353ca4d2a48fe18
Reviewed-on: https://code.wireshark.org/review/16327
Reviewed-by: Michael Mann <mmann78@netscape.net>
Petri-Dish: Michael Mann <mmann78@netscape.net>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-11-03 05:08:07 +00:00
Peter Wu c5b2c1e8f4 reassemble: remove special treatment for truncated data
Do not try to recover from truncated tvbs for fragment_add_seq-like
functions:

 - If it is the first block and the dissector requested frag_data_len
   number of bytes, we should not lie and pretend that we are fully
   reassembled.
 - For other blocks, returning NULL as no reassembly was possible makes
   sense. But other fragments in the list should not be cleared as there
   may be partial fragments which were returned before.

It seems that this special behavior was introduced in
b2c11b5e13 (freeing fragments and
returning NULL as an optimization when fragments are deemed not needed
anymore) and faeb2c2ee1 (for returning
fd_head for the first fragment, "so the first fragment gets dissected as
fragmented packet").

Now in theory unused fragments could stick around, but that also
possible with the normal fragment_add functions.

Bug: 11799
Change-Id: I20829c54e1b2eee25a91fe4de51b19b1458c7789
Reviewed-on: https://code.wireshark.org/review/14082
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-04-03 16:22:46 +00:00
Peter Wu c2f85b6925 Extend reassembly documentation
Documentation changes only (comments and docbook).

Update WSDG with the fragment_add_seq_check API that was introduced in
Wireshark 1.10.

Fix typos and clarify the many functions we have for adding reassembling
fragments.

Change-Id: I38715a8f58e9cf1fe3e34ee4b1a4ae339630282b
Reviewed-on: https://code.wireshark.org/review/14066
Petri-Dish: Peter Wu <peter@lekensteyn.nl>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-02-24 06:18:47 +00:00
AndersBroman 98b7f21370 [Reassembly] Fix a reassembly case where the two fragments are in the same
frame
but in different SCTP DATA chunks, whitout the patch the message is
reassembled in both chunks leading to duplicated upper layer PDU:s in the
frame.

Change-Id: Ie31142c38c728018178947544b571622447d8e8f
Reviewed-on: https://code.wireshark.org/review/7716
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2015-03-18 05:32:06 +00:00
Alexis La Goutte 296591399f Remove all $Id$ from top of file
(Using sed : sed -i '/^ \* \$Id\$/,+1 d')

Fix manually some typo (in export_object_dicom.c and crc16-plain.c)

Change-Id: I4c1ae68d1c4afeace8cb195b53c715cf9e1227a8
Reviewed-on: https://code.wireshark.org/review/497
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2014-03-04 14:27:33 +00:00
Bill Meier 11b5c15fdb Remove trailing whitespace
Change-Id: I8116f63ff88687c8db3fd6e8e23b22ab2f759af0
Reviewed-on: https://code.wireshark.org/review/385
Reviewed-by: Bill Meier <wmeier@newsguy.com>
Tested-by: Bill Meier <wmeier@newsguy.com>
2014-02-25 20:46:49 +00:00
Pascal Quantin f2f95a49c5 Update a comment
svn path=/trunk/; revision=52481
2013-10-09 21:59:41 +00:00
Jakub Zawadzki a18172147f Remove fragment_data, add fragment_head, fragment_item - for now alias it to the same structure.
This is begin of work to split fragment head and fragments items.

svn path=/trunk/; revision=50708
2013-07-17 21:12:24 +00:00
Jakub Zawadzki c766e78cfa Rewrite reassemble API to use TVBs instead of raw data.
(it seems to be working for TCP ^^)

svn path=/trunk/; revision=50580
2013-07-14 14:42:05 +00:00
Guy Harris c2087da0ab When we throw a reassembly error, remember the error, so that, if we
revisit this reassembly (in a multi-pass program such as Wireshark, or
TShark with -2), we'll throw the same error.

In fragment_set_tot_len(), allow the length to be set to a value that's
before the offset of existing fragments; we'll catch that later when the
reassembly completes.  This lets us handle some problems with DTLS less
confusingly.

When adding frames to an already-completed reassembly, check for
fragments that overlap existing fragments or go past the end of the
reassembly, and report errors.

When completing a reassembly, make the buffer for the reassembled data
big enough to contain the specified data length for the reassembly, even
if that's less than the offset + length of the last fragment.  Flag all
fragments that go past that length as "too long", and only copy out what
part of them fits, if any.  That lets us flag the correct fragment or
fragments as being "too long".

When adding fragments, do some additional checks, even if we're not
doing the first pass through the packets, so errors that show up in the
first pass also show up on subsequent passes.

svn path=/trunk/; revision=48909
2013-04-18 02:31:45 +00:00
Evan Huus 0314bd1c1b From Roland Knall via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=8502
Allow reassembly of sequences when the sequence numbers do not count from 0.

svn path=/trunk/; revision=48548
2013-03-25 12:53:26 +00:00
Guy Harris a2414d8909 Don't wire into the reassembly code the notion that reassemblies should
be done on flows from one address to another; reassembly for protocols
running atop TCP should be done on flows from one TCP endpoint to
another.

We do this by:

	adding "reassembly table" as a data structure;

	associating hash tables for both in-progress reassemblies and
	completed reassemblies with that data structure (currently, not
	all reassemblies use the latter; they might keep completed
	reassemblies in the first table);

	having functions to create and destroy keys in that table;

	offering standard routines for doing address-based and
	address-and-port-based flow processing, so that dissectors not
	needing their own specialized flow processing can just use them.

This fixes some mis-reassemblies of NIS YPSERV YPALL responses (where
the second YPALL response is processed as if it were a continuation of
a previous response between different endpoints, even though said
response is already reassembled), and also allows the DCE RPC-specific
stuff to be moved out of epan/reassembly.c into the DCE RPC dissector.

svn path=/trunk/; revision=48491
2013-03-22 23:59:54 +00:00
Balint Reczey 1ebdb2e521 Export libwireshark symbols using WS_DLL_PUBLIC define
Also remove old WS_VAR_IMPORT define and related Makefile magic
everywhere in the project.

svn path=/trunk/; revision=47992
2013-03-01 23:53:11 +00:00
Jeff Morriss aa5d9d78dd From Robert Bullen via https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=7683 :
The reassembled fragments tree in the Packet Details view is awesome, but it
lacks one thing: a field that exposes the reassembled data.

tcp.data already exists for exposing a single TCP segment's payload as a byte
array. It would be handy to have something similar for a single application
layer PDU when TCP segment reassembly is involved. I propose
tcp.reassembled.data, named and placed after the already existing field
tcp.reassembled.length.

My primary use case for this feature is outputting tcp.reassembled.data with
tshark for further processing with a script.

The attached patch implements this very feature. Because the reassembled
fragment tree code is general purpose, i.e. not specific to just TCP, any
dissector that relies upon it can add a similar field very cheaply. In that
vein I've also implemented ip.reassembled.data and ipv6.reassembled.data, which
expose reassembled fragment data as a single byte stream for IPv4 and IPv6,
respectively. All other protocols that use the reassembly code have been left
alone, other than inserting NULL into their initializer lists for the newly
introduced struct field reassemble.h:fragment_items.hf_reassembled_data.

svn path=/trunk/; revision=44802
2012-09-07 02:09:59 +00:00
Bill Meier 38b39b6b77 Add 'fragment_table_destroy()'
svn path=/trunk/; revision=44459
2012-08-12 20:53:17 +00:00
Jakub Zawadzki bf81b42e1e Update Free Software Foundation address.
(COPYING will be updated in next commit)

svn path=/trunk/; revision=43536
2012-06-28 22:56:06 +00:00
Balint Reczey 26503be7dc fix compile errors found by dumpabi target
svn path=/trunk/; revision=40595
2012-01-19 22:55:37 +00:00
Gerald Combs 49b92440de More GLIB_CHECK_VERSION cleanups. Update the minimum GLib/GTK+ versions
in README.devloper. Remove g_gnuc.h since it's no longer needed. Remove
tvbuff_init(), tvbuff_cleanup(), reassemble_init(), and
reassemble_cleanup() since they were only used for older GLib versions
which didn't support GSlices. Assume we always support the "matches"
operator.

svn path=/trunk/; revision=37978
2011-07-11 20:32:19 +00:00
Stig Bjørlykke 84bc28bd6a Introduce "Fragment count" filter element for all protocols doing reassembly.
svn path=/trunk/; revision=35705
2011-01-30 21:01:07 +00:00
Jeff Morriss 64f5d56bba Fix reassemble_test's (copy of the) proto_tree_add_item() prototype to get it
compiling again.

fragment_add_seq_check(), fragment_add_seq_802_11(), and fragment_add_seq_next()
all call fragment_add_seq_check_work() so make their prototypes match each other
in const-ness.  This fixes a warning when compiling reassemble_test.

svn path=/trunk/; revision=32933
2010-05-24 15:13:02 +00:00
Bill Meier 6812b68eb1 From Yaniv Kaul: constify parameters
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4422

 From me: Fix a number of instances where the function prototype or
  the function definition wasn't changed so there was a mismatch 
  thus causing Windows (but not gcc) compilation errors.

svn path=/trunk/; revision=32365
2010-04-03 18:18:50 +00:00
Bill Meier d32b4c0758 Revert SVN #32360 until Windows compilation errors corrected.
svn path=/trunk/; revision=32361
2010-04-02 15:18:03 +00:00
Bill Meier 049f9eac85 From Yaniv Kaul: constify parameters
https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=4422

svn path=/trunk/; revision=32360
2010-04-02 14:37:49 +00:00
Stig Bjørlykke 88b72356ad Introduce "Reassembled length" filter element for all protocols doing
reassembly.

svn path=/trunk/; revision=31767
2010-02-02 16:01:52 +00:00
Bill Meier f670e428d0 (Trivial) Fix some typos in a comment.
svn path=/trunk/; revision=30562
2009-10-15 19:26:00 +00:00
Kovarththanan Rajaratnam 0e5cef61be Split a bunch of init routines into init() and cleanup(). This allows us to free memory properly on shutdown.
This is an initial step. There's still some work to do.

svn path=/trunk/; revision=29754
2009-09-06 18:25:23 +00:00
Bill Meier 5aef94e6eb reassemble.h: update two comments; reassemble.c: correct a typo.
svn path=/trunk/; revision=29205
2009-07-27 13:59:53 +00:00
Guy Harris 320c1117f6 Add a comment.
svn path=/trunk/; revision=24642
2008-03-15 20:14:29 +00:00
Stig Bjørlykke c6ba6d714d Added fragment_start_seq_check to start a reassembly without adding any data.
svn path=/trunk/; revision=22513
2007-08-15 22:24:05 +00:00
Anders Broman c9e31101a1 Export fragment_end_seq_next to get the Windows buildbot going again.
svn path=/trunk/; revision=22177
2007-06-24 08:13:11 +00:00
Anders Broman e2cab6caa9 From Richard van der Hoff:
01_reassemble_test.patch
------------------------
I didn't want to do anything without some unit tests, so here they are. 
This allows a standalone binary, epan/reassemble_test, to be built; this can be run from the commandline and should end up printing out "success" 
if all goes well.
NOTE the changes to makefile.am NOT checked in currently.

Incidentally: is it possible to get the buildbot to run things like this, exntest and tvbtest?

02_reassemble_refactor.patch
----------------------------
fragment_add_seq, fragment_add_dcerpc_dg and fragment_add_seq_check_work were all pretty much carbon-copies of each other. This patch factors out the common parts of the routines into a new routine, fragment_add_seq_key().

03_reassemble_partial_reassembly.patch
---------------------------------------
This makes fragment_set_partial_reassembly() work for datagrams assembled with fragment_add_seq(). The patch itself is actually quite small, but it adds another unit test which is reasonably lengthy.

svn path=/trunk/; revision=20888
2007-02-21 06:19:03 +00:00
Jeff Morriss 1a9420702e Fix the SCCP dissector so it doesn't show non-segmented DT1 messages as
having been reassembled.

Fix the comments in reassembly.c and reassembly.h regarding what the reassembly
routines actually return in the 802.11 and no-sequence-number cases when they
are given the first and last packet (that is, a non-segmented packet): in
particular the routines return a pointer to a list containing just the one
fragment.

svn path=/trunk/; revision=20505
2007-01-19 23:27:24 +00:00
Ronnie Sahlberg 89f022b12b name change
svn path=/trunk/; revision=18197
2006-05-21 05:12:17 +00:00
Ulf Lamping 4843257596 add fragment_get_reassembled_id so the handed id doesn't need to be a packet number (experimental)
add a check to fragment_add_common() if the given tvb parameters are ok, otherwise throw a DissectorError

add some more symbols to libethereal.def

svn path=/trunk/; revision=17073
2006-01-22 16:47:16 +00:00
Ulf Lamping 55c3e85a95 fix reassembling problem I've introduced yesterday, by using fragment_add_seq_next() function instead of fragment_add()
in addition, I had to implement fragment_get_reassembled() in addition to fragment_get(), which works with reassembled_table

svn path=/trunk/; revision=15762
2005-09-12 00:16:57 +00:00
Ulf Lamping 0bb7a6e003 rename fragment_add_dcerpc -> fragment_add_dcerpc_dg to avoid confusion a bit,
as connection oriented (cn) and connectionless (dg) DCE/RPC uses different ways to handle defragmentation and this function is only used for dg

svn path=/trunk/; revision=15757
2005-09-11 21:10:26 +00:00