aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/merge.c
AgeCommit message (Collapse)AuthorFilesLines
2023-02-04cli: Process IDBs after the final packet recordJohn Thacker1-1/+9
Process IDBs that are read after the final packet record returned by wtap_read() in tshark, editcap, and mergecap. Ping #18449
2023-02-04merge: Check if each encapsulation type is supportedJohn Thacker1-8/+12
Just because a file type supports per packet encapsulation does not mean it can write every encapsulation type. When determining what file-level encapsulation to write the merged file, check each file's encapsulation to see if it is writable by the output file type. If any are not, report _UNKNOWN so that the merge will fail early with an appropriate error message, instead of always reporting WTAP_ENCAP_PER_PACKET. This prevents confusing errors when trying to merge, e.g., a JSON file and a normal packet file into a pcapng.
2023-01-30wiretap: Preserve NRBs with editcap, mergecap, and tsharkJohn Thacker1-3/+53
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
2022-06-02wiretap: merge support for IDBs in the middle of a fileJohn Thacker1-40/+128
Support merging files with IDBs in the middle of the file. Use wtap_get_next_interface_description when doing the initial list of interfaces so that we can correctly get IDBs later. Note that while IDB merge modes "any" and "none" work as expected, the default "all" mode can't really work for IDBs in the middle of the file without adding a two-pass mode. In "all" mode, if there are any such IDBs, merge them with duplicates iff the interfaces at the beginning of the files were merged. Related to #15502 and #16542.
2022-05-13merge: Don't write to stdout if tempdir is not setJohn Thacker1-5/+6
If merge_files_common() is called with a non NULL value for out_filenamep, that always indicates tempfile mode, even if the tempdir is not set. A NULL value for the tempdir is handled by wtap_dump_open_tempfile, which writes to the OS default temp directory. Only write to stdout if both out_filename and out_filenamep are NULL. Fixes a crash introduced by commit 1e0d117eb7ab1ce7f4ff8a4f when selecting Merge from the GUI and the new temp_dir option is not set.
2022-03-14wiretap: have wtap_dump_close() provide a "needs to be reloaded" indication.Guy Harris1-2/+2
This allows the "needs to be reloaded" indication to be set in the close process, as is the case for ERF; having a routine that returns the value of that indication is not useful if it gets seet in the close process, as the handle for the wtap_dumper is no longer valid after wtap_dump_close() finishes. We also get rid of wtap_dump_get_needs_reload(), as callers should get that information via the added argument to wtap_dump_close(). Fixes #17989.
2022-02-09Specify directory for temporary capturesDavid Perry1-5/+5
2021-08-10[#17478] free blocks in more placesDavid Perry1-0/+1
Bug 17478 was caused by `wtap_rec.block` being allocated for each packet, but not freed when it was done being used -- typically at the end of a loop. Rather than requiring each caller of `wtap_read()` to know to free a member of `rec`, I added a new function `wtap_rec_reset()` for a slightly cleaner API. Added calls to it everywhere that seemed to make sense. Fixes #17478
2021-07-14wiretap: clean up option definitions a bit.Guy Harris1-2/+2
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-06-11Refactor our logging and extend the wslog APIJoão Valverde1-1/+1
Experience has shown that: 1. The current logging methods are not very reliable or practical. A logging bitmask makes little sense as the user-facing interface (who would want debug but not crtical messages for example?); it's computer-friendly and user-unfriendly. More importantly the console log level preference is initialized too late in the startup process to be used for the logging subsystem and that fact raises a number of annoying and hard-to-fix usability issues. 2. Coding around G_MESSAGES_DEBUG to comply with our log level mask and not clobber the user's settings or not create unexpected log misses is unworkable and generally follows the principle of most surprise. The fact that G_MESSAGES_DEBUG="all" can leak to other programs using GLib is also annoying. 3. The non-structured GLib logging API is very opinionated and lacks configurability beyond replacing the log handler. 4. Windows GUI has some special code to attach to a console, but it would be nice to abstract away the rest under a single interface. 5. Using this logger seems to be noticeably faster. Deprecate the console log level preference and extend our API to implement a log handler in wsutil/wslog.h to provide easy-to-use, flexible and dependable logging during all execution phases. Log levels have a hierarchy, from most verbose to least verbose (debug to error). When a given level is set everything above that is also enabled. The log level can be set with an environment variable or a command line option (parsed as soon as possible but still later than the environment). The default log level is "message". Dissector logging is not included because it is not clear what log domain they should use. An explosion to thousands of domains is not desirable and putting everything in a single domain is probably too coarse and noisy. For now I think it makes sense to let them do their own thing using g_log_default_handler() and continue using the G_MESSAGES_DEBUG mechanism with specific domains for each individual dissector. In the future a mechanism may be added to selectively enable these domains at runtime while trying to avoid the problems introduced by G_MESSAGES_DEBUG.
2021-06-06Replace g_assert() with ws_assert() in placesJoão Valverde1-28/+29
2021-06-06wiretap: Remove some redundant debug informationJoão Valverde1-24/+24
It is not necessary to include the function name and/or locations, ws_debug() includes that information,
2021-05-24wiretap: change wtapng_mandatory_section_t to wtapng_section_mandatory_t.Guy Harris1-2/+2
This is consistent with other names for block mandatory data structures.
2021-05-24Add ws_debug() and use itJoão Valverde1-44/+41
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-03-15Remove unnecessary inclues of wiretap/pcapng.h.Guy Harris1-1/+0
2021-02-21wiretap: have file handlers advertise blocks and options supported.Guy Harris1-3/+19
Instead of a "supports name resolution" Boolean and bitflags for types of comments supported, provide a list of block types that the file type/subtype supports, with each block type having a list of options supported. Indicate whether "supported" means "one instance" or "multiple instances". "Supports" doesn't just mean "can be written", it also means "could be read". Rename WTAP_BLOCK_IF_DESCRIPTION to WTAP_BLOCK_IF_ID_AND_INFO, to indicate that it provides, in addition to information about the interface, an ID (implicitly, in pcapng files, by its ordinal number) that is associated with every packet in the file. Emphasize that in comments - just because your capture file format can list the interfaces on which a capture was done, that doesn't mean it supports this; it doesn't do so if the file doesn't indicate, for every packet, on which of those interfaces it was captured (I'm looking at *you*, Microsoft Network Monitor...). Use APIs to query that information to do what the "does this file type/subtype support name resolution information", "does this file type/subtype support all of these comment types", and "does this file type/subtype support - and require - interface IDs" APIs did. Provide backwards compatibility for Lua. This allows us to eliminate the WTAP_FILE_TYPE_SUBTYPE_ values for IBM's iptrace; do so.
2021-02-09wiretap: clean up WTAP_BLOCK_ names.Guy Harris1-1/+1
Remove NG from the names - it adds nothing. Don't use the abbreviations for pcapng block names, spell out what the block does (e.g. "WTAP_BLOCK_DECRYPTION_SECRETS" rather than "WTAP_BLOCK_DSB"), to make it more obvious what the block does. Spell out some other abbreviations. Add WTAP_BLOCK_PACKET for future use for packet blocks; there's no need to distinguish between the Enhanced Packet Block, the Simple Packet Block, and the deprecated Packet Block here.
2020-10-22Use wtap_uses_interface_ids() to check if IDBs are necessary.Guy Harris1-1/+1
Use that, rather than specifically checking for pcapng.
2020-10-20Add an API to determine whether a file type uses interface IDs.Guy Harris1-1/+1
Currently, the only file types that use them are pcapng and IBM's iptrace; we don't support writing the latter, so this is mainly of interest for pcapng. This makes it a bit more obvious what some "is this pcapng?" tests are really trying to determine, and allows them to automatically support any new file types that use them. (With regard to interface descriptions, tere are three types of file: 1) files that contain no interface information; 2) files that contain "just FYI" interface information but that don't tie packets or other records to particular interfaces; 3) files that contain interface information and tie all packets (and possibly other records) to an interface. This tests for files of type 3.)
2020-10-14Have WTAP_ERR_INTERNAL include an err_info string giving details.Guy Harris1-5/+10
That way, users won't just see "You got an internal error", the details will be given, so they can report them in a bug.
2020-10-11Fix many spelling errorsРоман Донченко1-1/+1
2020-08-04wiretap: fix an internal routine's name.Guy Harris1-5/+5
generate_merged_idb() can generate multiple IDBs, so rename it to generate_merged_idbs(). Change-Id: I4c54326f69ff0de16f0a716b7c82beefdda99cbd Reviewed-on: https://code.wireshark.org/review/38040 Reviewed-by: Guy Harris <gharris@sonic.net>
2019-07-26HTTPS (almost) everywhere.Guy Harris1-1/+1
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-04-061514 is a better initial Buffer size than 1500.Guy Harris1-1/+1
Ethernet packets without the CRC are 1514 bytes long, not 1500 bytes long; using 1514 bytes will avoid a reallocation for a full-sized Ethernet packet. Change-Id: Ie8da3f13bf3df07e23e4478b7dcf84f06dec6a9d Reviewed-on: https://code.wireshark.org/review/32761 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2019-04-05Have wtap_read() fill in a wtap_rec and Buffer.Guy Harris1-5/+15
That makes it - and the routines that implement it - work more like the seek-read routine. Change-Id: I0cace2d0e4c9ebfc21ac98fd1af1ec70f60a240d Reviewed-on: https://code.wireshark.org/review/32727 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-20wiretap: add read/write support for Decryption Secrets Block (DSB)Peter Wu1-3/+30
Support reading and writing pcapng files with DSBs. A DSB may occur multiple times but should appear before packets that need those decryption secrets (so it cannot be moved to the end like NRB). The TLS dissector will be updated in the future to make use of these secrets. pcapng spec update: https://github.com/pcapng/pcapng/pull/54 As DSBs may be interleaved with packets, do not even try to read it in pcapng_open (as is done for IDBs). Instead process them during the sequential read, appending them to the 'wtap::dsbs' array. Writing is more complicated, secrets may initially not be available when 'wtap_dumper' is created. As they may become available in 'wtap::dsbs' as more packets are read, allow 'wtap_dumper::dsbs_growing' to reference this array. This saves every user from checking/dumping DSBs. If the wtap user needs to insert extra DSBs (while preserving existing DSBs), they can set the 'wtap_dumper::dsbs_initial' field. The test file was creating using a patched editcap (future patch) and combined using mergecap (which required a change to preserve the DSBs). Change-Id: I74e4ee3171bd852a89ea0f6fbae9e0f65ed6eda9 Ping-Bug: 15252 Reviewed-on: https://code.wireshark.org/review/30692 Reviewed-by: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-17wiretap/merge.c: consolidate three similar merge_files routinesPeter Wu1-179/+46
The three merge_files routines (filename, tempfile, stdout) have exactly the same code except for a single wtap_dump_open routine. Reduce code duplication to ease further improvements to this file. Change-Id: I4fa890730d54c11b3614e56cf4d3d3da1ae9f5fd Reviewed-on: https://code.wireshark.org/review/30678 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-11-16Use an enum for compression types in various interfaces.Guy Harris1-4/+4
This: 1) means that we don't have to flag the compression argument with a comment to indicate what it means (FALSE doesn't obviously say "not compressed", WTAP_UNCOMPRESSED does); 2) leaves space in the interfaces in question for additional compression types. (No, this is not part 1 of an implementation of additional compression types, it's just an API cleanup. Implementing additional compression types involves significant work in libwiretap, as well as UI changes to replace "compress the file" checkboxes with something to indicate *how* to compress the file, or to always use some other form of compression). Change-Id: I1d23dc720be10158e6b34f97baa247ba8a537abf Reviewed-on: https://code.wireshark.org/review/30660 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-16Use the dump parameters structure for non-pcapng-specific stuff.Guy Harris1-36/+20
Use it for all the per-file information, including the per-file link-layer type and the per-file snapshot length. Change-Id: Id75687c7faa6418a2bfcf7f8198206a9f95db629 Reviewed-on: https://code.wireshark.org/review/30616 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-11-13Don't have _ng versions of the dumper open routines.Guy Harris1-11/+12
Have the routines always take a parameters pointer; pass either null or a pointer to an initialized-to-nothing structure in cases where we were calling the non-_ng versions. Change-Id: I23b779d87f3fbd29306ebe1df568852be113d3b2 Reviewed-on: https://code.wireshark.org/review/30590 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-11-12wiretap: refactor common parameters for pcapng dump routinesPeter Wu1-5/+18
Four variants of wtap_dump_open_ng exists, each of them take the same three parameters for the SHB, IDB and NRB blocks that has to be written before packets are even written. Similarly, a lot of tools always create these arguments based on an existing capture file session (wth). Address the former duplication by creating a new data structure to hold the arguments. Address the second issue by creating new helper functions to initialize the parameters based on a wth. This refactoring should make it easier to add the new Decryption Secrets Block (DSB). No functional change intended. Change-Id: I42c019dc1d48a476773459212ca213de91a55684 Reviewed-on: https://code.wireshark.org/review/30578 Petri-Dish: Peter Wu <peter@lekensteyn.nl> Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu> Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2018-08-11Add support for reading and writing the new if_hardware IDB option.Guy Harris1-2/+17
Support for writing it in live captures will come later; this change, but not that one, will be backported so older versions of Wireshark won't remove it when writing a file out. Change-Id: I9fd4067991acfd2d18c03d0a373ce8337a9f3a76 Reviewed-on: https://code.wireshark.org/review/29064 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-06-28Add macros to initialize nstime_t values and use them.Guy Harris1-1/+1
This allows code to initialize them without having to know the details of the structure; the initializes should, and will, be changed if the members of the structure are changed. Change-Id: I93e6ebfcde9ceca17df696fcba4e8410c5afb175 Reviewed-on: https://code.wireshark.org/review/28501 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-18Fix some source headers, reformat SPDX license lines in comment block.Jaap Keuter1-1/+2
Change-Id: Ibae6a64a9915003435a3fb17763535a3844143be Reviewed-on: https://code.wireshark.org/review/25891 Petri-Dish: Jaap Keuter <jaap.keuter@xs4all.nl> Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann <mmann78@netscape.net>
2018-02-09Generalize wtap_pkthdr into a structure for packet and non-packet records.Guy Harris1-30/+36
Separate the stuff that any record could have from the stuff that only particular record types have; put the latter into a union, and put all that into a wtap_rec structure. Add some record-type checks as necessary. Change-Id: Id6b3486858f826fce4b096c59231f463e44bfaa2 Reviewed-on: https://code.wireshark.org/review/25696 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-08replace SPDX identifier GPL-2.0+ with GPL-2.0-or-later.Dario Lombardo1-1/+1
The first is deprecated, as per https://spdx.org/licenses/. Change-Id: I8e21e1d32d09b8b94b93a2dc9fbdde5ffeba6bed Reviewed-on: https://code.wireshark.org/review/25661 Petri-Dish: Anders Broman <a.broman58@gmail.com> Petri-Dish: Dario Lombardo <lomato@gmail.com> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-02-08Fix white space.Guy Harris1-1/+1
Change-Id: I90047f070f42991a67da5215b6eda60f70d7945f Reviewed-on: https://code.wireshark.org/review/25678 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-08Get rid of unused structure member.Guy Harris1-3/+5
Change-Id: I86c32f18f8168d776fc5eb2116bc600a87ab57e0 Reviewed-on: https://code.wireshark.org/review/25677 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-05Don't assume records all have time stamps and captured lengths.Guy Harris1-14/+30
Not all do, so test the preference bits for them. Change-Id: I62976f5d17de3611c4d2f9eb64a0763c0b698c8d Reviewed-on: https://code.wireshark.org/review/25618 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-02-05Speak of records, not packets.Guy Harris1-6/+6
Not everything wtap_read() returns is a packet. Change-Id: I3784bbfa308da52f4c55db2a90f9b55f8bfbb2ef Reviewed-on: https://code.wireshark.org/review/25617 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2018-01-30wiretap/merge.c: Fix memory leak, fix description.Jakub Zawadzki1-4/+7
If merge_open_in_files() is going to fail, free files array to avoid memleak. Found by clang. Change-Id: I156c5f1c041cd7779ff0a0095bc2810f50768ab6 Reviewed-on: https://code.wireshark.org/review/25421 Petri-Dish: Jakub Zawadzki <darkjames-ws@darkjames.pl> Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman <a.broman58@gmail.com>
2018-01-20wiretap: more SPDX license convertions.Dario Lombardo1-14/+1
Change-Id: I12695d0713b1d7fe58f09b2037303fab523085e9 Reviewed-on: https://code.wireshark.org/review/25394 Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Gerald Combs <gerald@wireshark.org>
2017-12-26Fix some comments.Guy Harris1-3/+5
Change-Id: I8f22a38a944573e43f6232e0fab6188967deefd6 Reviewed-on: https://code.wireshark.org/review/24999 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-12-26wiretap: remove unneeded check (CID: 1396988).Dario Lombardo1-1/+1
Existence of in_file has been checked in line 908. Change-Id: Ida6c06362a1f88caec40701be7f3e42133ce404a Reviewed-on: https://code.wireshark.org/review/24994 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2017-06-05Allow bigger snapshot lengths for D-Bus captures.Guy Harris1-3/+3
Use WTAP_MAX_PACKET_SIZE_STANDARD, set to 256KB, for everything except for D-Bus captures. Use WTAP_MAX_PACKET_SIZE_DBUS, set to 128MB, for them, because that's the largest possible D-Bus message size. See https://bugs.freedesktop.org/show_bug.cgi?id=100220 for an example of the problems caused by limiting the snapshot length to 256KB for D-Bus. Have a snapshot length of 0 in a capture_file structure mean "there is no snapshot length for the file"; we don't need the has_snap field in that case, a value of 0 mean "no, we don't have a snapshot length". In dumpcap, start out with a pipe buffer size of 2KB, and grow it as necessary. When checking for a too-big packet from a pipe, check against the appropriate maximum - 128MB for DLT_DBUS, 256KB for everything else. Change-Id: Ib2ce7a0cf37b971fbc0318024fd011e18add8b20 Reviewed-on: https://code.wireshark.org/review/21952 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-06-03Don't keep the pcap/pcapng link-layer header type as interface data.Guy Harris1-8/+0
Either 1) it can be determined from the libwiretap encapsulation type, in which case it's redundant information or 2) there *is* no pcap/pcapng link-layer header type for that encapsulation type, in which case you need to check for the attempt to determine it failing and handle that failure appropriately. Change-Id: Ie9557b513365c1fc8c6df74b9c8239e29aad46bc Reviewed-on: https://code.wireshark.org/review/21924 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-04-20Take the error message generation out of the merge_files routines.Guy Harris1-206/+36
Have them just return the information needed for the caller to produce an error message, and have the callers use the new cfile_ routines for reporting errors. This requires that the "write failure alert box" routine take the *input* file name as an argument, so that, on a merge, if the problem is that a record from a given input file can't be written out to the type of output file we're generating, the input file name can be given, along with the record number in that file. Change-Id: If5a5e00539e7e652008a523dec92c0b359a48e71 Reviewed-on: https://code.wireshark.org/review/21257 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-12-04Have separate merge APIs for regular file/temporary file/standard output.Guy Harris1-88/+304
This is similar to what we have for opening a dump file - one API that uses the file name as specified, one that creates a temporary file and provides the file name, and one that uses the standard output. All of those APIs handle closing the output file. Change-Id: I56beea7be347402773460b9148ab31a8f8bc51e1 Reviewed-on: https://code.wireshark.org/review/19059 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-12-04Remove unnecessary cast (gchar = char) that removes const.Guy Harris1-1/+1
Change-Id: I3924c2b4a525c0ae5ab57b7f9867296586d78509 Reviewed-on: https://code.wireshark.org/review/19061 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-10-27merge.c: do not give a NULL pointer when saving SHB comment optionPascal Quantin1-1/+3
Bug: 13060 Change-Id: Ib3dd019f73305e4006b312d324502e4a138c6a16 Reviewed-on: https://code.wireshark.org/review/18514 Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com> Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Reviewed-by: Guy Harris <guy@alum.mit.edu>