Commit Graph

438 Commits

Author SHA1 Message Date
John Thacker c65d5a0a80 wiretap: Reprocess Name Resolution Blocks during redissect
Keep name resolution information as mandatory elements for
NRBs, and when the ipv4 or ipv6 callback is set, have name
resolution entries from already read NRBs sent to the callback.
rescan_packets can use this when redissecting to reobtain the
name resolution entries from the NRB, similar to what is done
with Decryption Secrets Blocks. (This can also later be used
if we read NRBs and DSBs in pcapng_open before the first packet,
and before the callbacks are set.)

This doesn't yet make the changes to wtap_dumper to write them out,
but is a step towards that too. (It's not clear in cases where we
dissect packets whether we want to copy the entire NRB, or only
write out actually used addresses as done now. For copying without
reading a file, like with editcap, we presumably do want to copy them.)

Fix #13425. Ping #15502
2023-01-21 22:25:03 +00:00
João Valverde a74027ad00 wiretap: Validate UTF-8 encoding for pcapng
Validate UTF-8 encoding for pcapng string options. To
avoid two unnecessary memory allocations for invalid strings and
make the code cleaner a new wtap_block_add_string_option_owned()
function is used.

Add UTF-8 debug check for wiretap API.

Fixes #18703.
2022-12-09 19:17:05 +00:00
Martin Mathieson 793365d0e0 Fix some issues seen with cppcheck 2022-11-22 20:55:24 +00:00
Chuck Craft 085cbd27e1 pcapng: ws_debug - display option code in decimal 2022-11-08 22:15:44 -06:00
Chuck Craft 8de2b2e860 addr_resolv: add support for static hostname entries
Ping #18075
2022-10-31 14:45:56 +00:00
Gerald Combs 8700e9c407 wiretap: Make some pcapng logs noisy.
Switch some pcapng log messages from debug to noisy.
2022-10-11 07:10:16 +00:00
Stephen Hemminger 005169491e pcapng: add support displaying hash from pcapng
Add support for displaying one or more packet hashes that
have been recorded in EPB options.

A patch to add support for EPB hash option is pending for next
DPDK release.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
2022-08-20 06:12:28 +00:00
Roland Knall 885d6b7f73 wiretap: Fix urls in comments
The old ones are no longer valid and lead to 404
2022-07-10 16:05:30 +00:00
Guy Harris 1ee8ead845 Provide the section number for blocks, and show it.
Add a "section number" field to wtap_rec, with a presence flag, and
provide the section number (0-based) for pcapng files.

Display it (1-based) if present.
2022-04-22 18:14:29 -07:00
Dr. Lars Völker ef43fd48b4 tshark: improve robustness for PCAPNGs not starting with IDBs
The PCAPNG code assumes that PCAPNGs start with IDBs, which might not be
true. This patch adds a workaround for Tshark to process such files.
2022-01-16 08:55:24 +00:00
João Valverde 0ccd69e530 Replace g_strdup_printf() with ws_strdup_printf()
Use macros from inttypes.h.
2021-12-19 21:21:58 +00:00
João Valverde 22ee2764a7 Replace g_snprintf() with snprintf() (dissectors)
Use macros from inttypes.h with format strings.
2021-12-19 20:25:11 +00:00
João Valverde fe5248717f Replace g_snprintf() with snprintf()
Use macros from inttypes.h with format strings.
2021-12-19 20:06:13 +00:00
Gerald Combs fcf945f747 wiretap: Fix an underflow in pcapng.
Make sure account for our rounded option length when we process
opt_endofopt. Fixes #17755.
2021-12-02 04:06:59 +00:00
Michael Tuexen 2b52d14d62 BBLog: Fix the handling of skipped blocks 2021-11-20 00:10:28 +01:00
Federico Di Pierro d95935d969 dissectors: support sysdig new block type BLOCK_TYPE_SYSDIG_EVENT_V2_LARGE
The new block type enlarge payload lens up to 4B,
to support larger payload sizes.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
2021-10-29 08:04:21 +00:00
João Valverde 5362d0c31b ws_getopt: Rename struct and macros
This is part of the API and should also be renamed to avoid conflicts.
2021-09-30 13:59:28 +00:00
Guy Harris 58d053923e pcapng: clean up block length checks.
Use the same style of message for too-short block errors ("pcapng: total
block length XXX of {a,an} XXX is too small...").

Add an additional check for the "skip" Netflix cutom block, to make sure
it has enough room for the 4-byte "skipped" value.
2021-09-09 00:19:36 -07:00
Alexis La Goutte 5fc6549178 pcapng: Fix Branch condition evaluate to a garbage value
wblock->internal is not initialized on pcapng_read_custom_block function
pcapng.c:3747:9: warning: Branch condition evaluates to a garbage value [core.uninitialized.Branch]
2021-09-07 05:56:36 +00:00
Alexis La Goutte 7740e9ae27 pcapng(wiretap): Fix Dead Store found by Clang Analyzer
pcapng.c:2675:5: warning: Value stored to 'opt_cont_buf_len' is never read [deadcode.DeadStores]
2021-09-06 04:21:14 +00:00
Guy Harris 030b06ba3c pcapng: write packet and Netflix custom blocks the same as other blocks.
Use compute_options_size() to get the total size of all the options, and
use write_options() to write out the options for those blocks, as we do
for other blocks.

Get rid of wtap_block_option_get_value_size() and
wtap_block_get_options_size_padded(); they're no longer needed, and
their notion of an option's "size" is "size in a pcapng file", so that
doesn't belong in code that's intended to support all file types.
2021-08-30 16:29:04 -07:00
Guy Harris dd8c23c83d pcapng: remove include of wtap_opttypes.h.
It's already included by wtap/wtap.h, which this file includes, and it
doesn't need to be included that early, so that #include isn't
necessary.
2021-08-29 01:00:02 -07:00
Guy Harris 266d707dff pcapng: whitespace and other cleanups.
Remove some extra blank lines, add a blank line where it belongs, and
get rid of a stray #-only line.
2021-08-28 22:29:21 -07:00
Guy Harris 10be4d1611 pcapng: fix handling of byte-swapped sysdig event blocks.
We weren't setting wblock->rec->rec_header.syscall_header.nparams for
byte-swapped event blocks.
2021-08-28 16:00:41 -07:00
Guy Harris 9b132c2353 pcapng: fix output of comment and DNS server name options.
Copy to the buffer the string value, not the structure that contains it.
2021-08-27 18:14:02 -07:00
Guy Harris 4b7bfe35c5 pcapng: process uint32 options like uint64 options.
Move the extraction of the option value from the option content from the
callers of pcapng_process_uint32_option() to
pcapng_process_uint32_option() itself.
2021-08-27 08:58:13 +00:00
Guy Harris a21972d6b9 pcapng: remove some old code left behind by the previous change. 2021-08-27 00:33:09 -07:00
Guy Harris 8acd0d1151 pcapng: export routines to do the option-section processing.
That way, add-on modules to handle block types not handled by the core
pcapng code can use pcap_process_options() to process a block's options
and can use the routines to handle the "standard" option value types to
handle particular options.

Also, allow both everything-is-little-endian and
everything-is-big-endian Custom Block types in pcap_process_options().
2021-08-27 06:48:47 +00:00
Michael Tuexen b17f354304 Add initial support for BBLog files 2021-08-27 04:48:21 +02:00
David Perry dc7089e831 Carry drop count/packet ID/queue ID as options on packet block 2021-07-19 21:25:40 +00:00
Guy Harris cc36b74139 pcapng: shuffle functions that process various option types.
Define them in the order in which wiretap/wtap_opttypes.h defines the
corresponding enum values for wtap_opttype_e.
2021-07-14 01:01:27 -07:00
Guy Harris 7b0c4950a5 wiretap: clean up option definitions a bit.
Spell out "DESCRIPTION" for the IDB description option, as it's spelled
out in the pcapng spec.

Put the #defines for various options in the same order as the block
types for them are in the pcapng spec.
2021-07-14 06:55:12 +00:00
Guy Harris fa9ee0f37a pcapng: process OPT_COMMENT in pcapng_process_options().
That option applies to all pcapng blocks, so handle it in common code.
2021-07-12 18:06:38 -07:00
David Perry 06ed6930dc Carry EPB flags as an option on the packet block
As requested by [this comment][1] on !2859, move `pack_flags` from a
dedicated field in `wtap_rec` to a block option on the packet block in
`wtap_rec.block`.

[1]: https://gitlab.com/wireshark/wireshark/-/merge_requests/2859#note_615984624
2021-07-12 12:41:57 -04: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
Guy Harris 689ff5a3ad pcapng: centralize access to members of the wtap_optval_t union.
Have the "compute option size" and "write option" routines take a
wtap_optval_t * as an argument and choose the appropriate member of the
union.
2021-06-29 14:54:48 -07:00
Guy Harris c0dc9106dd pcapng: clean up some function names.
Consistently use pcapng_compute_XXX_option_size() for routines to
compute the size of an option of type XXX and pcapng_write_XXX_option()
for routins to write out an option of type XXX.

Sort the routines by the order in which their option type values are
defined.
2021-06-28 17:20:26 -07:00
Guy Harris 73e058032f pcapng: have more common code for writing options.
Have common routines that iterate over all the options, processing
comment and custom options in common code (as they're defined
independently of particular block types), with callbacks to handle the
options for particular block types.
2021-06-28 15:14:36 -07:00
Guy Harris c1082bd99e wiretap: have the "for each option" routine return a success/fail indication.
Have the routine it calls return a Boolean value, with "true" meaning
"keep going" and "false" meaning "stop iterating and return a failure
indication".  If the callback routine never returns "false", the routine
returns "true" as a success indication.
2021-06-27 13:25:16 -07:00
Guy Harris 9e6aa424f1 pcapng: have a common routine to write the "end of options" option. 2021-06-27 03:14:14 -07:00
Michael Tuexen 1f0a16e472 pcapng: add support for custom options 2021-06-23 04:38:27 +00:00
Guy Harris 5eda4c0128 pcapng: update a comment to reflect the name cleanups. 2021-06-17 15:55:18 -07:00
Guy Harris 9773b5a4a7 Just call the block type for custom blocks WTAP_BLOCK_CUSTOM.
No need to add a redundant "_BLOCK" at the end.
2021-06-17 15:04:44 -07: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
Guy Harris 2c9d262ed1 pcapng: indentation cleanups. 2021-06-16 20:03:00 -07:00
Guy Harris 8aceee774a pcapng: get rid of some now-redundant rounding up of the block length.
Now that it's being done in common code, we don't need to do it in the
routines to read sysdig event blocks, systemd journal export blocks, or
unknown blocks.

Add in a comment to match other comments while we're at it.
2021-06-16 18:59:34 -07:00
Guy Harris a16f65ab20 pcapng: have more common code for processing options.
Have a common loop for processing options, with a callback to process
options for a particular block type.
2021-06-16 16:50:22 -07:00
Guy Harris ea38a1d419 pcapng: round up block lengths to a multiple of 4 in common code.
Do it earlier in the reading process, rather than in the packet block
code.
2021-06-16 13:15:24 -07:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00:00
Guy Harris 8176a16798 pcapng: fix indentation. 2021-06-16 03:31:27 -07:00