aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/pcapng.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-07wiretap, pcapng: Distinguish WTAP_ENCAP_UNKNOWN and _NONEJohn Thacker1-3/+7
WTAP_ENCAP_UNKNOWN is used for two different cases: 1. Encapsulation type values that are unsupported by libwiretap or bogus values (and thus "unknown" to libwiretap). 2. An initial state where the encapsulation type is "not yet" known for a file type like pcapng without a single encapsulation type in the header, before any packets or interfaces that set the encapsulation type have been read. (If the file has no packets, this may be the value after the file is entirely read in.) This can be the value when an output file is written out simultaneously with reading an input file, rather than reading the entire input file first, and, e.g., there is a custom block before any IDBs. The first case can never be handled when writing out a file, but the second case can possibly be handled, so long as (for pcapng) IDBs are available to write when they become necessary, or (for file types like pcap with a single link-layer type in the header) the writer waits until a link-layer type is seen to create the output header. (It is possible, of course, that writing would fail in the middle if an unsupported encapsulation type appears, or if the encapsulation becomes per-packet for file types that don't support that, but that is an unavoidable risk when writing without reading the entire input file(s).) Introduce WTAP_ENCAP_NONE for the second case, and use it for pcapng, where we guarantee that any necessary IDBs will be passed along. Continue to use WTAP_ENCAP_UNKNOWN for the first case. Allow pcapng files to open a file for writing with WTAP_ENCAP_NONE. There are some other file types that support per-packet link-types, and could also use WTAP_ENCAP_NONE, but they require more work to generate IDBs. (Note that all of them currently are impossible to write to pcapng when they have multiple encapsulations, even if the encapsulations are all supported by pcapng, because they don't properly generate IDBs.) Remove the workaround in ef43fd48b4f981392a0c61b5e9a804e8f9c85eb4 for tshark writing to pcapng when the source file is WTAP_ENCAP_UNKNOWN, since now such files will be WTAP_ENCAP_NONE and work properly (and also work in editcap, mergcap, etc.) Along with 8cddc32d35e36d9962495c3d4358842ea88aac41, fix #18449.
2023-02-06wiretap: Fix pcapng UTF-8 validationJoão Valverde1-4/+2
g_utf_8_make_valid() replaces embedded NULs with unicode replacement characters and this behaviour does not match the pcapng spec; the first NULL should terminate the string instead. Use ws_utf8_make_valid() which provides the correct behaviour.
2023-01-30wiretap: Preserve NRBs with editcap, mergecap, and tsharkJohn Thacker1-55/+109
Use a pointer to the growing array of NRBs from the source file, as with DSBs, so as to handle reading NRBs in the middle of a file in one-pass mode. Write NRBs when reading a file with editcap, or in tshark when not dissecting packets and writing our own NRB. Continue not to write the NRB if we're supplying our own list of address info instead. If we have already read the entire source file in (such as in two-pass tshark), move all the NRBs to the beginning of the file before packets, as done with DSBs. When merging files with mergecap, write both sets of NRBs. (There is no attempt to merge the NRBs by looking for common entries.) Check for name resolution data in the middle of dumping a file, not just at the end, and check for DSBs at the end of a file, after all the packets. This means that Wireshark no longer writes the NRB at the very end of the file after all the packets (which is worse for future one-pass reads), and DSBs after all packets are preserved. Ping #15502
2023-01-26wiretap, pcapng: process all initial internal blocks in pcapng_openJohn Thacker1-112/+201
pcapng allows multiple link-layer types, and allows new link-layer types in the middle of a file. Many (most) other capture types allow a single link-layer type, which must be specified in the initial header. When reading files and writing their contents to another file (which may be of a different type), many programs using the wiretap API want want to know the link-layer type upon initially opening the source file, so that they can check if that encapsulation can be written to the output file, and so that they can write the output file header. They should be able to wait until a link-layer type is seen before creating the output type, but don't. (Wireshark reads the entire file in intially, so this isn't a problem, but that isn't much of an option for some command line tools, particularly when operating on a pipe or FIFO.) Note that regardless, if a new link-layer type is encountered partway through a file, they would still have to fail in the middle of reading and writing. However, to make this a little bit easier for such file types, pcapng block types that are handled strictly internally and not passed back to the reader can be processed initially in pcapng_open(). (Note that for DSBs and NRBs, any blocks processed in pcapng_open() will automatically be sent to the callbacks when the callbacks are added later.) Previously we just processed all the IDBs immediately after the initial SHB, instead of all the internal block types. Fix #18581. Ping #15502.
2023-01-21wiretap: Reprocess Name Resolution Blocks during redissectJohn Thacker1-54/+61
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
2022-12-09wiretap: Validate UTF-8 encoding for pcapngJoão Valverde1-1/+11
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-11-22Fix some issues seen with cppcheckMartin Mathieson1-15/+15
2022-11-08pcapng: ws_debug - display option code in decimalChuck Craft1-1/+1
2022-10-31addr_resolv: add support for static hostname entriesChuck Craft1-2/+2
Ping #18075
2022-10-11wiretap: Make some pcapng logs noisy.Gerald Combs1-7/+7
Switch some pcapng log messages from debug to noisy.
2022-08-20pcapng: add support displaying hash from pcapngStephen Hemminger1-2/+61
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-07-10wiretap: Fix urls in commentsRoland Knall1-11/+11
The old ones are no longer valid and lead to 404
2022-04-22Provide the section number for blocks, and show it.Guy Harris1-0/+9
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-01-16tshark: improve robustness for PCAPNGs not starting with IDBsDr. Lars Völker1-0/+1
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.
2021-12-19Replace g_strdup_printf() with ws_strdup_printf()João Valverde1-46/+46
Use macros from inttypes.h.
2021-12-19Replace g_snprintf() with snprintf() (dissectors)João Valverde1-1/+1
Use macros from inttypes.h with format strings.
2021-12-19Replace g_snprintf() with snprintf()João Valverde1-5/+5
Use macros from inttypes.h with format strings.
2021-12-02wiretap: Fix an underflow in pcapng.Gerald Combs1-1/+1
Make sure account for our rounded option length when we process opt_endofopt. Fixes #17755.
2021-11-20BBLog: Fix the handling of skipped blocksMichael Tuexen1-2/+5
2021-10-29dissectors: support sysdig new block type BLOCK_TYPE_SYSDIG_EVENT_V2_LARGEFederico Di Pierro1-6/+15
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-09-30ws_getopt: Rename struct and macrosJoão Valverde1-3/+3
This is part of the API and should also be renamed to avoid conflicts.
2021-09-09pcapng: clean up block length checks.Guy Harris1-9/+26
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-07pcapng: Fix Branch condition evaluate to a garbage valueAlexis La Goutte1-0/+1
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-06pcapng(wiretap): Fix Dead Store found by Clang AnalyzerAlexis La Goutte1-1/+0
pcapng.c:2675:5: warning: Value stored to 'opt_cont_buf_len' is never read [deadcode.DeadStores]
2021-08-30pcapng: write packet and Netflix custom blocks the same as other blocks.Guy Harris1-152/+275
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-29pcapng: remove include of wtap_opttypes.h.Guy Harris1-1/+0
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-28pcapng: whitespace and other cleanups.Guy Harris1-12/+3
Remove some extra blank lines, add a blank line where it belongs, and get rid of a stray #-only line.
2021-08-28pcapng: fix handling of byte-swapped sysdig event blocks.Guy Harris1-0/+1
We weren't setting wblock->rec->rec_header.syscall_header.nparams for byte-swapped event blocks.
2021-08-27pcapng: fix output of comment and DNS server name options.Guy Harris1-1/+1
Copy to the buffer the string value, not the structure that contains it.
2021-08-27pcapng: process uint32 options like uint64 options.Guy Harris1-22/+53
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-27pcapng: remove some old code left behind by the previous change.Guy Harris1-2/+1
2021-08-27pcapng: export routines to do the option-section processing.Guy Harris1-57/+164
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-27Add initial support for BBLog filesMichael Tuexen1-43/+348
2021-07-19Carry drop count/packet ID/queue ID as options on packet blockDavid Perry1-83/+17
2021-07-14pcapng: shuffle functions that process various option types.Guy Harris1-48/+48
Define them in the order in which wiretap/wtap_opttypes.h defines the corresponding enum values for wtap_opttype_e.
2021-07-14wiretap: clean up option definitions a bit.Guy Harris1-4/+4
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-12pcapng: process OPT_COMMENT in pcapng_process_options().Guy Harris1-19/+4
That option applies to all pcapng blocks, so handle it in common code.
2021-07-12Carry EPB flags as an option on the packet blockDavid Perry1-25/+24
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-07Use wtap_blocks for packet commentsDavid Perry1-196/+232
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-06-29pcapng: centralize access to members of the wtap_optval_t union.Guy Harris1-41/+41
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-28pcapng: clean up some function names.Guy Harris1-134/+134
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-28pcapng: have more common code for writing options.Guy Harris1-296/+307
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-27wiretap: have the "for each option" routine return a success/fail indication.Guy Harris1-98/+58
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-27pcapng: have a common routine to write the "end of options" option.Guy Harris1-17/+17
2021-06-23pcapng: add support for custom optionsMichael Tuexen1-51/+337
2021-06-17pcapng: update a comment to reflect the name cleanups.Guy Harris1-1/+1
2021-06-17Just call the block type for custom blocks WTAP_BLOCK_CUSTOM.Guy Harris1-1/+1
No need to add a redundant "_BLOCK" at the end.
2021-06-17Make various names match the name of the systemd journal export block.Guy Harris1-15/+15
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-16pcapng: indentation cleanups.Guy Harris1-2/+2
2021-06-16pcapng: get rid of some now-redundant rounding up of the block length.Guy Harris1-35/+6
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.