Commit Graph

458 Commits

Author SHA1 Message Date
Tomasz Moń e7d5c49fe1
epan: Use hash table for dependent frames
Dependent frames list order does not matter and thus significantly
faster data structure can be used. Replace the list with hash table to
avoid excessive CPU usage when opening files containing reassembled
packets consisting of large number of fragments.
2023-01-28 15:17:42 +01:00
John Thacker b230aa1df0 epan: Do not add dependent packets more than once
Do not add a dependent frame if it's already been added to a
frame's list. Do not mark a frame as a dependent of a displayed
frame if we've already marked it as such in this pass.

Clear the list of dependent frames if we reset the frame data,
because the list of dependent frames depends on the dissection
and may not be valid if redissecting (because, for example,
a reassembly preference may have changed.)

Move the pointer to the list of dependent frames away from the
bitfields to a location that minimizes the struct size.

Fixup f870c6085d
Fix #18809
2023-01-20 16:16:47 +00:00
Joris Peeraer b782c599ae Provide create_dissector_handle_with_data
Provide function create_dissector_handle_with_data that creates an
anonymous handle that uses a dissector with callback argument.
2023-01-13 08:57:58 +00:00
Sake Blok f870c6085d epan: Allow nested dependent packets
Save all dependent frames when there are multiple levels
of reassembly.

This is a retry of !6329, combined with the fix in !6509 which
were reverted in !6545.

epan: fix a segfault, introduced in !6329
2023-01-06 23:15:48 +00:00
AndersBroman d4cd1d9d1d packet.c: Wrong pointer conversion in get_data_source_tvb_by_name()
Closes #18517
Solution by Zhao Ziqing
2023-01-04 12:30:16 +00:00
John Thacker 80e287f82c Reset the "current conversation elements" after each dissector call
packet_info has items that correspond to the single "most recent"
conversation set via conversation_set_conv_addr_port_endpoints or
conversation_set_elements_by_id. These should be reset after each
call of a dissector, because they are only relevant for the
dissector and any additional higher level dissectors it calls.

Lower level protocols and protocols at the same level (i.e., in
different PDUs of a shared lower level protocol) don't want to
automatically use those conversation elements to find the current
conversation.

Separately, there should be an array or linked list of all conversation
elements set in a packet, so that it can be used by the conversation table,
conversation filters, etc., instead of just accessing the most recent
conversation / conversation based on the last set address and ports.

Fix #18278
2022-11-01 17:26:14 +00:00
Brian Sipos 80c95b26d0 COSE: Cleanup custom dissector keys with new API 2022-10-07 06:36:21 +00:00
Guy Harris c9342873e5 Clarify dissector description, protocol short name, and protocol ong name.
Rename dissector_handle_get_long_name() and
dissector_handle_get_short_name() to
dissector_handle_get_protocol_long_name() and
dissector_handle_get_protocol_short_name(), to clarify that they fetch
names for the protocol that the dissector dissects, not for the
dissector *itself*.  Leave a deprecated
dissector_handle_get_short_name() wrapper, and export
dissector_handle_get_protocol_long_name(), as it's now used in some
dissectors.

Change some calls to dissector_handle_get_description() back to
dissector_handle_get_protocol_short_name(), as they appear to be made in
order to display a *protocol* name.

Rename some methods, variables, enums, and table column names to reflect
cases where the dissector description is being used.
2022-09-13 00:47:24 -07:00
Guy Harris d4394de669 Give dissectors a descriptive string.
It defaults to the short name of the protocol dissected by the
descriptor, but it's now possible to register a dissector with an
explicit description.

This is mainly for use in the Decode As UI.  It handles the case where
the same protocol might have different "Decode As..."-specifiable
dissectors for different situations.
2022-09-12 21:05:14 +00:00
Guy Harris a6ee179427 conversation: speak of the "conversation key" as just address/port endpoints.
It's not a general key for looking up arbitrary conversations - that's
what an array of conversation elements is for - it's just a pair of
address/port endpoints.  (It's not even hijacked for conversations
identified by a circuit ID any more.)
2022-08-29 19:19:59 -07:00
Guy Harris 8195bdd340 Rename a bunch of things with "conversation".
A conversation in Wireshark might have two endpoints or might have no
endpoints; few if any have one endpoint.  Distinguish between
conversations and endpoints.
2022-08-25 20:02:20 -07:00
John Thacker c7a136a5c0 epan: Rearrange column includes
Move all the declarations of routines that are internal and
not for use by dissectors from column-utils.h column-info.h
Move the column max length defines into column-utils.h because
dissectors might need that

Since packet.h already includes column-utils.h, dissectors don't
need to include column-utils.h anymore.
Remove or downgrade a few other column header includes that are
unnecessary.
2022-08-13 19:37:28 +00:00
John Thacker 8604d03a98 prefs: Make all auto port preferences ranges
When a single port is added to a dissector along with an auto
preference, make it create a range preference (defaulting to
that single value.) This converts the rest of the auto port
preferences to ranges.

Ping #14319. Still to do are converting other non-auto port
preferences to auto preferences (e.g., sctp ports), and maybe
some minor cleanups.
2022-08-04 05:43:47 +00:00
John Thacker 13bffe4630 prefs: Add default range to description of auto pref 2022-08-03 19:19:18 -04:00
John Thacker ab6f902216 prefs: Make add_for_decode_as_with_preference add ranges
Make add_for_decode_as_with_preference create a range preference,
instead of a single uint preference. Decode As allows multiple
ports to be set for a dissector, so a range preference is correct.
This prevents an odd situation where the quasi preference only
holds the last value set in the Decode As table, and changing it
only changes that one value, not all the other values. Moving
the preference to a range also means that the empty string clears
the result instead of doing nothing. (With uint preferences
inputing 0 is required to not dissect.)

This moves a lot of the automatic port preferences over to ranges.

Ping #14319. Fix #15554.
2022-08-03 00:00:24 +00:00
John Thacker 0749873c70 decode as: Add data dissector to all tables that support Decode As
Register the data dissector to all dissector tables that support
Decode As. This provides a way to disable decoding for table
entries that have a default dissector registered to a value.
It is particularly useful when a dissector is registered by default
to several values (e.g. HTTP), to be able to disable decoding
for one port without disabling the dissector in general.

It is also useful to prevent payloads from being handed off
to heuristic dissectors, and is thus distinguished from the
fallback to data when no dissector is set.  N.B.: that this has no
effect on dissectors that have a "Try heuristic sub-dissectors first"
preference set to TRUE.

It does not solve a second issue for table entries with a default
dissector - setting the dissector to "none" in order to force
payloads to be sent to heuristic dissectors without setting a
preference as above. (Note that in some cases one will wish to
send dissection on some ports to heuristics without enabling
heuristics first for _all_ ports.)

Fix #17518. Fix #15717. Related to #12098, which also needs the
last issue mentioned above addressed.
2022-07-16 16:02:36 -04:00
Chuck Craft e12954a637 epan: ws_debug log for heuristic that claims frame (len != 0)
It's possible for a dissector to claim a frame without adding to
the tree or being added to frame.protocols (see !6669)
Log a debug message showing the pinfo layers and the dissector that
claimed the tvb (frame/packet).
2022-07-12 14:15:33 +00:00
Gerald Combs 5cd591129f epan: Convert remaining conversation code to elements.
Convert the address+port conversation code to element lists. Make our
conversation keys element lists. Document more of the conversation API.

Update the Conversation Hash Table dialog to use the new API.

Describe an alternative key type and data structure at the top of
conversation.c.
2022-06-05 19:05:33 +00:00
Gerald Combs be929e162d epan: Allow conversations based on arbitrary element lists.
Add conversation_new_full and find_conversation_full, which take
arbitrary element lists instead of fixed addresses and ports.

Update the comments in conversation.h to be more Doxygen-conformant.
Update README.dissector.

Use the new functionality to add initial conversation support to the
Falco Bridge dissector.
2022-05-23 18:12:26 +00:00
João Valverde d517feee74 epan: Add more bookkeeping for layers
Packet info already contains the notion of layer depth for the
current protocol, among all the protocols in the frame. This
adds an extra layer number for the protocols that are the same
as the current one. Obviously this will only go above one if
the protocol is repeated in the stack, such as with IP tunneling.

Adds extra logic to track numbers for each protocol in the frame
and update them when calling a dissector.

The total layer number and protocol layer number are store in
the field info structure so they can be used after dissection,
namely by display filters.
2022-04-26 16:50:59 +00:00
João Valverde 842f53c329 Revert "epan: Allow nested dependent packets"
This reverts commit 2d8607e7e0.

This reverts commit be915d7374.

Introduces a segmentation fault, needs more work.
2022-03-28 12:40:21 +00:00
Sake Blok be915d7374 epan: Allow nested dependent packets
Save all dependent frames when there are multiple levels
of reassembly.
2022-03-06 23:43:03 +00:00
Michael Tuexen d11c069786 BBLog: Fix support of TCP window scaling
Rcv.Wind.Shift and Snd.Wind.Shift were not displayed correctly by
the BBLog dissector and the TCP dissector was not using the
information about the shift values available in the BBLog file.
2021-11-08 23:05:20 +00:00
João Valverde 01f234571f epan: Optimize heuristic name validity check
Do the name check in one pass only, instead of two passes, one
for all letters and a second one to exclude upper case letters.
2021-11-04 14:03:37 +00:00
John Thacker f58ccfc068 TCP, UDP, SCTP: Try user specified ports first
When the user has manually registered to a port a dissector other than
the default subdissector (through Decode As, or the preferences
registered via dissector_add_uint_[range_]with_preference), try
those ports with a custom dissector first.

There's a few dissectors (e.g., GTP) that have port preferences
that haven't been migrated to use the DECODE_AS_ preferences for
various reasons; this won't change anything when their preferences
are changed from the default, though it can still work via Decode As.

Fixes #6223 and #12168.
2021-10-21 06:48:52 +00:00
Stig Bjørlykke e9ac4d3900 proto: Delay deleting heur_dtbl_entry_t in heur_dissector_delete
Add the heur_dtbl_entry_t entry as deregistered when deleting a
heuristics dissector. The UDP dissector is storing a pointer to
this in proto_data and may access the entry during reload Lua
plugins until all packets are redissected.
2021-09-29 07:08:52 +00:00
Guy Harris 3cb6403a4c wiretap: always allocate a block for a record.
Without that, you could add a comment to a record in a file format the
reading code for which doesn't allocate blocks, but the comment doesn't
get saved, as there's no block in which to save the comment option.

This simplifies some code paths, as we're either using the record's
modified block or we're using the block as read from the file, there's
no third possibility.

If we attempt to read a record, and we get an error, and a block was
allocated for the record, unreference it, so the individual file readers
don't have to worry about it.
2021-08-29 19:12:13 -07:00
Michael Tuexen b17f354304 Add initial support for BBLog files 2021-08-27 04:48:21 +02:00
João Valverde 133b0c583f Move epan/wmem/wmem_scopes.h to epan/
This header was installed incorrectly to epan/wmem_scopes.h.

Instead of creating additional installation rules for a single
header in a subfolder (kept for backward compatibility) just
rename the standard "epan/wmem/wmem.h" include to
"epan/wmem_scopes.h" and fix the documentation.

Now the header is installed *correctly* to epan/wmem_scopes.h.
2021-07-26 14:56:11 +00:00
Guy Harris dd5907d2a3 Consistently refer to blocks that have been modified as "modified".
"User" sounds as if the blocks belong to the user; at most, the current
user might have modified them directly, but they might also have, for
example, run a Lua script that, unknown to them, modified comments.
Also, a file might have "user comments" added by a previous user, who
them wrote the file and and provided it to the current user.

"Modified" seems a bit clearer than "changed".
2021-07-08 00:05:35 -07:00
David Perry 73087d6fb4 Use wtap_blocks for packet comments
Mostly functioning proof of concept for #14329. This work is intended to
allow Wireshark to support multiple packet comments per packet.

Uses and expands upon the `wtap_block` API in `wiretap/wtap_opttypes.h`.
It attaches a `wtap_block` structure to `wtap_rec` in place of its
current `opt_comment` and `packet_verdict` members to hold OPT_COMMENT
and OPT_PKT_VERDICT option values.
2021-07-07 18:40:24 +00:00
João Valverde 0e50979b3f Replace g_assert() with ws_assert() 2021-06-19 01:23:31 +00:00
Guy Harris 6eb3703379 Make various names match the name of the systemd journal export block.
The name of the block, in the pcapng specification is the systemd
Journal Export Block; add "export" after "journal" in various
variable/enum/define names.
2021-06-17 13:52:45 -07:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Michael Tuexen 4ddae68508 pcapng: add support for custom blocks 2021-06-06 21:15:35 +00:00
João Valverde 9ba97d12d6 Add ws_debug() and use it
Replace most instances of ws_debug_printf() except in
epan/dissectors and dissector plugins.

Some replacements use printf(), some use ws_debug(), and
some were removed because they were dead or judged to be
temporary.
2021-05-24 01:13:19 +00:00
Moshe Kaplan e16166a74c Detect and replace bad allocation patterns
Adds a pre-commit hook for detecting and replacing
occurrences of `g_malloc()` and `wmem_alloc()` with
`g_new()` and `wmem_new()`, to improve the
readability of Wireshark's code, and
occurrences of
`g_malloc(sizeof(struct myobj) * foo)`
with
`g_new(struct myobj, foo)`
to prevent integer overflows

Also fixes all existing occurrences across
the codebase.
2020-12-22 14:56:38 +00:00
Martin Mathieson 580de09849 Fix a few spelling mistakes. 2020-11-12 09:52:52 +00:00
Guy Harris 889e0d5cb6 Add a new record type REC_TYPE_SYSTEMD_JOURNAL.
Systemd journal entries aren't file-type-specific; they're found in both
systemd journal entry blocks in pcapng files and in systemd journal
export files.  Give it a record type, for use with both file types.

This fixes #16955.

It also means that you can open a systemd journal export file and save
it as a pcapng file.
2020-10-27 20:06:26 -07:00
John Thacker 524a28c4b1 QT/CLI: Move max tree items and depth to prefs
Move the maximum number of tree items and maximum tree depth to
preferences instead of hardcoded values. Refer to issue #12584 for
an example VNC capture where real data exceeds the current limit.
2020-10-23 04:18:36 +00:00
Guy Harris 272502790b Add FT_STRINGZTRUNC.
FT_STRINGZPAD is for null-*padded* strings, where the field is in an
area of specified length, and, if the string is shorter than that
length, all bytes past the end of the string are NULs.

FT_STRINGZTRUNC is for null-*truncated* strings, where the field is in
an area of specified length and, if the string is shorter than that
length, there's a null character (which might be more than one byte, for
UCS-2, UTF-16, or UTF-32), and anything after that is not guaranteed to
have any particular value.

Use IS_FT_STRING() in some places rather than enumerating all the string
types, so that those places get automatically changed if the set of
string types changes.
2020-09-12 14:16:12 -07:00
Dario Lombardo 584569932b packet: don't mess up the subdissectors list during optimization.
Bug: 16690
Change-Id: Ie8340dca7bb56d58425985c16a07d0ed6887d03f
Reviewed-on: https://code.wireshark.org/review/37820
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Dario Lombardo <lomato@gmail.com>
2020-07-10 21:24:42 +00:00
Phan Duc Nhat Minh 5654dfd982 Optimize heuristic search by bubbling the matched element
The matched entry is bubbled to the head of the list for
faster future search.

Change-Id: I47375515f43387adbe0652556c03f0979a8dbe85
Reviewed-on: https://code.wireshark.org/review/37395
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-06-25 17:17:20 +00:00
Guy Harris 43b945d116 Note why we're getting the time stamp from the frame data structure.
Change-Id: I5b92ea027e1182e4b0d3248d338780fad810fd2b
Reviewed-on: https://code.wireshark.org/review/37015
Reviewed-by: Guy Harris <gharris@sonic.net>
2020-05-01 22:32:20 +00:00
Michael Mann e06969455b Restrict allowed characters in "short name" of heuristic_protos
This is done to limit parsing errors.
Update documentation of function parameters to remove confusion with dissectors.

Bug: 16106
Change-Id: I6b2cd0badaaf6217fb80bdc411a86cad5e6b07ca
Reviewed-on: https://code.wireshark.org/review/35267
Petri-Dish: Michael Mann <mmann78@netscape.net>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
2019-12-01 17:07:42 +00:00
Anders Broman 98cda1bf46 Load environment vars to globals for efficency.
These environment variables are read very frequently, read them once to
globals for performance improvment.

Change-Id: I4f05a5edca85b370674cc5f85fce40bd1af695cb
Reviewed-on: https://code.wireshark.org/review/34449
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-09-04 12:31:53 +00:00
Guy Harris 20800366dd HTTPS (almost) everywhere.
Change all wireshark.org URLs to use https.

Fix some broken links while we're at it.

Change-Id: I161bf8eeca43b8027605acea666032da86f5ea1c
Reviewed-on: https://code.wireshark.org/review/34089
Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-07-26 18:44:40 +00:00
Martin Kaiser cc15201436 helper function to get a payload dissector table's current handle
Add a simple helper function to get the dissector handle that's
currently selected in a given payload dissector table.

We have similar functions already for string and uint dissector tables.

Change-Id: Ia1092fe2b8d038bae2b26db99fd08cd9d6979fcd
Reviewed-on: https://code.wireshark.org/review/33933
Petri-Dish: Martin Kaiser <wireshark@kaiser.cx>
Tested-by: Petri Dish Buildbot
Reviewed-by: Peter Wu <peter@lekensteyn.nl>
Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
2019-07-22 15:44:08 +00:00
Anders Broman f7cf0b7ec7 Doxygen: Try to fix reported warnings.
Change-Id: Ia2e08265681c6700328a5782a70c3108eeb443bf
Reviewed-on: https://code.wireshark.org/review/33887
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-07-10 12:48:21 +00:00
XuNiu e66ded5efe packet: make sure handle and dissector table exist
Some patches have done one same thing, that is checking the
existence of both handle and dissector before further operating.
Based on this, one missed spot was found.

Bug: 15852
Change-Id: I11ef51aa1aa3fab305203df931882a19cd6670f8
Reviewed-on: https://code.wireshark.org/review/33706
Reviewed-by: Jaap Keuter <jaap.keuter@xs4all.nl>
Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-06-24 08:49:36 +00:00