aboutsummaryrefslogtreecommitdiffstats
path: root/wiretap/wtap_opttypes.c
AgeCommit message (Collapse)AuthorFilesLines
2018-11-20wiretap: add read/write support for Decryption Secrets Block (DSB)Peter Wu1-0/+36
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-08-11Add support for reading and writing the new if_hardware IDB option.Guy Harris1-0/+9
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-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-01-20wiretap: use SPDX identifiers (partial work).Dario Lombardo1-13/+1
Change-Id: I28436e003ce7fe31d53e6663f3cc7aca00845e4b Reviewed-on: https://code.wireshark.org/review/25392 Petri-Dish: Dario Lombardo <lomato@gmail.com> Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com> Reviewed-by: Gerald Combs <gerald@wireshark.org>
2017-10-26Add a ws_in6_addr typedef for struct e_in6_addr.Guy Harris1-3/+3
That allows a parallel typedef of ws_in4_addr for guint32. Change-Id: I03b230247065e0e3840eb87635315a8e523ef562 Reviewed-on: https://code.wireshark.org/review/24073 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2017-02-14wiretap: fix wtap_opttypes_cleanup() functionPascal Quantin1-16/+9
Change-Id: I475e2bc54af470e380e23e5dd98198885e189d6f Reviewed-on: https://code.wireshark.org/review/20106 Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com>
2017-02-14wiretap: add cleanup routine.Dario Lombardo1-0/+20
The cleanup routine has been added to exit section of the applications. Those which required a exit restyle have been patched as well. Change-Id: I3a8787f0718ac7fef00dc58176869c7510fda7b1 Reviewed-on: https://code.wireshark.org/review/19949 Petri-Dish: Dario Lombardo <lomato@gmail.com> Reviewed-by: Peter Wu <peter@lekensteyn.nl> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Dario Lombardo <lomato@gmail.com>
2017-01-20Fix typo.Guy Harris1-1/+1
Change-Id: I46be1220c8e789e1006cfbf7cff60e9556ff2caf Reviewed-on: https://code.wireshark.org/review/19685 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-18block->options is never null; don't check for it.Guy Harris1-2/+1
A wtap_block_t always has an array of options, even if it's empty. Fixes CID 1364135. Change-Id: Ib1ba791ddcac078ec34def321d63d140c5576037 Reviewed-on: https://code.wireshark.org/review/16535 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-18Remove wtap_block_num_options_of_type().Guy Harris1-36/+0
It's not used; currently, everything that accesses instances of a multiple-instance-allowed option do so in a loop that iterates over option instances by fetching values of the Nth option until the attempt to fetch the option fails, making only one pass over the options. Change-Id: Ife9583a5d246027dbfc133ab58027ef6641d65ef Reviewed-on: https://code.wireshark.org/review/16534 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-16Add APIs to remove option instances from blocks.Guy Harris1-16/+106
That will allow deletion of comments, stripping of options when sanitizing captures, etc.. Change-Id: I9667ba2ccf4e548ff3b7d500796b260a437bcea0 Reviewed-on: https://code.wireshark.org/review/16485 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-15Squelch a compiler warning.Guy Harris1-1/+1
Explicitly cst the results of g_memdup(). Change-Id: I20fd1f355e68735d7cc9bbeb41717a1c2a74de37 Reviewed-on: https://code.wireshark.org/review/16477 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-15wtap_opttypes.c: Fix build error.Michael Mann1-1/+1
Change-Id: I3ee146d441e4d59701c72ed85dcb4efe97766df8 Reviewed-on: https://code.wireshark.org/review/16473 Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-07-15Do a deep copy in wtap_block_add_custom_option().Guy Harris1-1/+39
That way, we don't have to worry about multiple instances of an option pointing to the same data. and having to worry about freeing data that's pointed to by another instance. Change-Id: I3470a9eebf346023713fd0d6ff2451d727c25089 Reviewed-on: https://code.wireshark.org/review/16471 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-15Squelch compiler warnings.Guy Harris1-2/+2
Cast some numerical values to wtap_block_type_t. Change-Id: I56651c62045880638175c39174341feffb4b1068 Reviewed-on: https://code.wireshark.org/review/16451 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-15Fix signature of wtap_opttype_block_register().Guy Harris1-1/+1
It gets passed a wtap_block_type_t value, so declare it as such. Change-Id: I6980cab7e1885c9920b2a75e12f9d2d2a64d6f96 Reviewed-on: https://code.wireshark.org/review/16450 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-07-14Redo the block options APIs.Guy Harris1-414/+824
A block can have zero or more instances of a given option. We distinguish between "one instance only" options, where a block can have zero or one instance, and "multiple instances allowed" options, where a block can have zero or more instances. For "one instance only" options: "add" routines add an instance if there isn't one already and fail if there is; "set" routines add an instance if there isn't one already and change the value of the existing instance if there is one; "set nth" routines fail; "get" routines return the value of the instance if there is one and fail if there isn't; "get nth" routines fail. For "multiple instances allowed" options: "add" routines add an instance; "set" routines fail; "set nth" routines set the value of the nth instance if there is one and fail otherwise; "get" routines fail; "get nth" routines get the value if the nth instance if there is one and fail otherwise. Rename "optionblock" to just "block"; it describes the contents of a block, including both mandatory items and options. Add some support for NRB options, including IPv4 and IPv6 option types. Change-Id: Iad184f668626c3d1498b2ed00c7f1672e4abf52e Reviewed-on: https://code.wireshark.org/review/16444 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-06-15wtap: Make default_filter staticStig Bjørlykke1-2/+1
Address of stack memory associated with local variable 'default_filter' is still referred to by the global variable 'filter_option' upon returning to the caller. This will be a dangling reference. Change-Id: I6160a37f05b8aea245b723ec50803e4062886738 Reviewed-on: https://code.wireshark.org/review/14427 Petri-Dish: Stig Bjørlykke <stig@bjorlykke.org> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-06-06Add a routine to get an array of all instances of a string option.Guy Harris1-0/+30
Use it for OPT_COMMENT in the SHB, as there may be ore than one instance of OPT_COMMENT in an SHB. Also, use wtap_optionblock_get_option_string for OPT_SHB_HARDWARE, OPT_SHB_OS, and OPT_SHB_USERAPPL; they're specified as "only one instance allowed". Change-Id: I23ad87e41e40b7ae1155e96c0523a6f8caad5204 Reviewed-on: https://code.wireshark.org/review/15750 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-06-01Add data structures necessary to support multiple Section Header blocks.Michael Mann1-0/+12
This doesn't try to use any data from multiple Section Header blocks, it just converts single Section Header block usage into a GArray, so the potential is there to then use/support multiple Section Header blocks within a file format (like pcapng) Change-Id: I6ad1f7b8daf4b1ad7ba0eb1ecf2e170421505486 Reviewed-on: https://code.wireshark.org/review/15636 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-30If routines return a wtap_opttype_return_val, declare them as doing so.Guy Harris1-10/+10
Also, improve the doxygen comments. Change-Id: I57929dfba23d926fd806ac001a5a3924bb636ae0 Reviewed-on: https://code.wireshark.org/review/15634 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-05-26Remove write capabilities from wtap_optionblocks.Michael Mann1-419/+26
The write functionality was too PCAPNG-specific and the intention is to keep the option blocks as generic as possible. So moved the write functionality back to pcapng.c and added a wtap_opttype API to loop through all options in the block (wtap_optionblock_foreach_option) Change-Id: Iaf49126a1a3e2ed60ae02c52878ca22671dac335 Reviewed-on: https://code.wireshark.org/review/15525 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-22Add wtap_optionblock_set_option_string_formatMichael Mann1-2/+21
Also add a length parameter to wtap_optionblock_set_option_string Change-Id: I8c7bbc48aa96b5c2a91ab9a17980928d6894f1ee Reviewed-on: https://code.wireshark.org/review/15505 Reviewed-by: Anthony Coddington <anthony.coddington@endace.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-21wtap_opttypes: fix no previous prototype for function ↵Alexis La Goutte1-1/+1
'wtap_opttype_write_data_uint64_timestamp' [-Wmissing-prototypes] Change-Id: I36244dee9cd5667d498ab0a4ba98b83e8fe84ac8 Reviewed-on: https://code.wireshark.org/review/15514 Reviewed-by: Anders Broman <a.broman58@gmail.com>
2016-05-21Add ability to add custom block types.Michael Mann1-11/+39
Change-Id: I2d23148c6f8d847aacec1d25cb694793ec9bb84e Reviewed-on: https://code.wireshark.org/review/15504 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-05-17Correctly write out the isb_startime and isb_endtime options.Guy Harris1-2/+17
They're not marshalled as a 64-bit integer in pcapng files, they're marshelled as 2 32-bit integers, the first of which is the upper 64 bits of the value and the second of which is the lower 64 bits of the value. Bug: 12349 Change-Id: I2bde51ac11b2518ef2ddaecf43672c984f26081a Reviewed-on: https://code.wireshark.org/review/15492 Reviewed-by: Guy Harris <guy@alum.mit.edu>
2016-05-04wiretap: fix writing of 1 bytes long options in pcapng filesPascal Quantin1-3/+8
the option length should be 1 byte, not 4 bytes. Change-Id: I1b356c7ce101f9bbdc9793fc280b6564e12f303f Reviewed-on: https://code.wireshark.org/review/15265 Reviewed-by: Pascal Quantin <pascal.quantin@gmail.com> Petri-Dish: Pascal Quantin <pascal.quantin@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-04-19wtap: fix leak in optionblock management.Dario Lombardo1-2/+5
Found by valgrind: ==14298== at 0x4C2CE8E: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) ==14298== by 0xA66C6AE: g_realloc (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0) ==14298== by 0xA63BB32: ??? (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0) ==14298== by 0xA63BEB7: g_array_append_vals (in /lib/x86_64-linux-gnu/libglib-2.0.so.0.4002.0) ==14298== by 0xA193252: wtap_optionblock_add_option (wtap_opttypes.c:352) ==14298== by 0xA19361C: shb_create (wtap_opttypes.c:607) ==14298== by 0xA192F96: wtap_optionblock_create (wtap_opttypes.c:126) ==14298== by 0xA168784: wtap_open_offline (file_access.c:824) ==14298== by 0x11D47C: cf_open (tshark.c:4194) ==14298== by 0x117852: main (tshark.c:2183) et al. Change-Id: Ic16595ed3c12b9ed6c2813852ceb594c29ece929 Reviewed-on: https://code.wireshark.org/review/15004 Petri-Dish: Dario Lombardo <lomato@gmail.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Evan Huus <eapache@gmail.com> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-03-09Initialize write function pointers when copying a new wtap block option.Michael Mann1-0/+2
Issue found by Clang (Assigned value is garbage or undefined). Change-Id: I9a3ab41dd01becbd454af02f2567ea3a2beeba40 Reviewed-on: https://code.wireshark.org/review/14399 Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
2016-03-06Improve wiretap block capabilities.Michael Mann1-175/+606
Make a more formal method for registering options within a block and do it all with a single function (wtap_optionblock_add_block). Add ability for block to be able to write itself, refactored out of pcapng.c. This was implemented for SHB, ISB, and IDB blocks. Name resolution (NRB), while possible, seemed a little messy for the moment. Change-Id: Ie855c8550c7c7d96cfc188c0cd90bfbc4d5f0ee8 Reviewed-on: https://code.wireshark.org/review/14357 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-03-03Refactor wiretap option block types into a registration system.Michael Mann1-189/+259
Also required mergecap to look for plugins to initialize wiretap option blocks. Change-Id: I4208d1028dd0f94f185393801d72025329266cb7 Reviewed-on: https://code.wireshark.org/review/14300 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-03-03Allocate GArray when copying stat blocks within IDB block.Michael Mann1-1/+1
Don't treat it like a GList Bug: 12220 Change-Id: I057649a26d135516c6e8d4fb028c6cb9dcda2e7c Reviewed-on: https://code.wireshark.org/review/14326 Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-03-01NULL check GArray to prevent assertion.Michael Mann1-1/+2
Change-Id: I52de10a1d96b6ef7294ad8be9ec9195defca4b53 Reviewed-on: https://code.wireshark.org/review/14266 Petri-Dish: Michael Mann <mmann78@netscape.net> Reviewed-by: Graham Bloice <graham.bloice@trihedral.com> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-03-01Prevent use-after-free issues with pcapng.c/wtap_opttypes.cMichael Mann1-3/+8
Bug: 12173 Change-Id: Ifff28491073d50e088b26847830a3bc8835f4282 Reviewed-on: https://code.wireshark.org/review/14180 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>
2016-02-23Making wiretap option blocks more generic.Michael Mann1-0/+505
This was inspired by https://code.wireshark.org/review/9729/, but takes it in a different direction where all options are put into an array, regardless of whether they are "standard" or "custom". It should be easier to add "custom" options in this design. Some, but not all blocks have been converted. Descriptions of some of the block options have been moved from wtap.h to pcapng.h as it seems to be the one that implements the description of the blocks. Also what could be added/refactored is registering block behavior. Change-Id: I3dffa38f0bb088f98749a4f97a3b7655baa4aa6a Reviewed-on: https://code.wireshark.org/review/13667 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org> Reviewed-by: Michael Mann <mmann78@netscape.net>