Commit Graph

3577 Commits

Author SHA1 Message Date
Guy Harris 8176a16798 pcapng: fix indentation. 2021-06-16 03:31:27 -07:00
Guy Harris 25a254823f wsutil: add a header that defines some "round to power of 2" macros.
Add macros to round to multiples of 2, 4, 8, 16, and 32.

Use them instead of independently defined macros.

(We don't define a general "round to a power of 2" macro to avoid the
risk of somebody passing something other than a power of 2 to it.)
2021-06-16 02:01:23 -07:00
Guy Harris 016f193111 pcapng: fix routine name.
This processes pcapng files, not pcap files, so call it
pcapng_process_unhandled_option(), not pcap_process_unhandled_option().
2021-06-12 14:08:16 -07:00
João Valverde dc7f0b88bb Refactor our logging and extend the wslog API
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-11 09:40:28 +00:00
yuanjungong ca42e4a9ad Wiretap: Fix a resource leak
call destroy_k12_file_data to destory file_data before return.
2021-06-09 17:09:44 +00:00
Michael Tuexen 4ddae68508 pcapng: add support for custom blocks 2021-06-06 21:15:35 +00:00
João Valverde 4aff36d501 Replace g_assert() with ws_assert() in places 2021-06-06 20:05:26 +00:00
João Valverde 4e4bef09f9 wiretap: Remove some redundant debug information
It is not necessary to include the function name and/or locations,
ws_debug() includes that information,
2021-06-06 19:48:54 +00:00
Guy Harris 7477431325 wiretap: un-export some routines.
wtap_file_get_shb_for_new_file() and wtap_file_get_nrb_for_new_file()
are intended to be used only internally to libwiretap and by libwiretap
plugins.
2021-05-31 04:39:59 -07:00
Guy Harris 162251176a ascend: set rec->rec_type.
REC_TYPE_PACKET is 0, so if it's been initialized to 0, and never gets
overwritten, this fixes code withotu fixing a visible bug, but it should
be done anyway.
2021-05-31 02:44:57 -07:00
Guy Harris 883f159c8b pcapng: fix some more WTAP_ERR_BAD_FILE err_info strings.
Just say "pcapng:", rather than giving the function name, to match the
style used here and for other capture file formats.
2021-05-29 23:17:27 -07:00
Guy Harris 5827009e7a pcapng: remove a second colon from a debug message. 2021-05-29 22:52:59 -07:00
Guy Harris 82dcb9196a wiretap: clean up WTAP_ERR_BAD_FILE error messages.
Consistently give a file type name at the beginning of the message.
2021-05-29 18:08:24 -07:00
Michael Tuexen 86b28f0d4b wiretap: improve code consistency in pcapng.c 2021-05-30 01:08:14 +02:00
Guy Harris 48ba793ef6 erf: clean up handling the return value when getting and option value.
Make the variable into which we put the return value of
wtap_block_get_nth_string_option_value() a wtap_opttype_return_val, as
that's the type of the return value - it's not a boolean, it's a status
code with multiple values.

Explicitly check that value against WTAP_OPTTYPE_SUCCESS.  Yes,
WTAP_OPTTYPE_SUCCESS is 0, so

	if (xxx)

is equivalent to

	if (xxx != WTAP_OPTTYPE_SUCCESS)

but it's better to make it explict, so it's clear that it's checking for
failure.
2021-05-24 23:39:26 -07:00
Guy Harris 54e6b249c1 wiretap: change wtapng_mandatory_section_t to wtapng_section_mandatory_t.
This is consistent with other names for block mandatory data structures.
2021-05-24 04:06:20 -07:00
Guy Harris 7f6c5d0137 k12: plug a memory leak.
If the two putative number-of-records values don't match (meaning one of
them is presumably the number of records and the other one isn't - we
don't know which is the case), free up the private data structure we
allocated before returning an error.
2021-05-23 23:14:27 -07:00
Guy Harris 297b6c5407 erf: set USERAPPL if we have the application version but not the name.
Just say "(Unknown application) <version>".

This also means that we don't leak the app_version string if there's no
app_name string.
2021-05-23 19:37:09 -07: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
João Valverde de00cdd512 pcapng: Fix debug statements 2021-05-24 01:13:19 +00:00
Guy Harris 976ccc9a00 netscaler: plug a memory leak.
Free the read buffer if the first read fails.
2021-05-23 17:56:18 -07:00
Martin Mathieson f54221b579 DCT2000: allow for longer lines/PDUs 2021-05-20 12:05:23 +00:00
Guy Harris bc8bb0152e commview: add support for newer NCFX file format. 2021-05-11 07:40:51 +00:00
Alexis La Goutte b4898e653a wtap_opttypes(wiretap): Fix Dead Store
Value stored to 'block_type' is never read
2021-05-06 07:18:22 +00:00
Guy Harris 57a1514ac7 Cast away the return value of g_strlcpy() and g_strlcat().
Most of the time, the return value tells us nothing useful, as we've
already decided that we're perfectly willing to live with string
truncation.  Hopefully this keeps Coverity from whining that those
routines could return an error code (NARRATOR: They don't) and thus that
we're ignoring the possibility of failure (as indicated, we've already
decided that we can live with string truncation, so truncation is *NOT*
a failure).
2021-04-30 03:19:19 -07:00
Guy Harris eb4d68033e Don't cast away upper bits when assigning to a nstime_t's secs field.
The secs field is a time_t, which is not necessarily 32 bits.  If it's
not, casting away the upper bits, by casting to guint32, introduces a
Y2.038K bug.

Either cast to time_t or, if you're assigning a time_t to it, don't
bother with the cast.
2021-04-28 21:31:15 +00:00
Guy Harris bdc878e2f7 wiretap: clean up freeing of if_filter options.
Use if_filter_free() in wtap_block_free_option(), don't duplicate it.

Move if_filter_dup() and if_filter_free() before the latter is first
used.
2021-04-27 10:22:00 -07:00
Daniel Dulaney e35efdee8d TIFF: Add a basic TIFF dissector 2021-04-24 10:42:59 +00:00
Gerald Combs e513ed41d2 Wiretap: Fix some compiler warnings.
Make various _dump_can_write_encap and _dump_open routines static. Add a
couple of casts.
2021-04-16 20:09:42 +00:00
Gerald Combs c92637bcd8 Add missing prototypes to lemon-generated code.
Add static prototypes for the parser interface functions. Fixes
-Wmissing-prototypes found by clang.
2021-04-16 18:38:26 +00:00
Tomasz Moń 4bd5830cda CMake: Add ENABLE_VLD option for MSVC
Calling cmake with -DENABLE_VLD=ON when building with Visual Studio,
results in debug configuration being linked to Visual Leak Detector.
By default, Visual Leak Detector outputs the leak summary to Visual
Studio debug window. When ENABLE_VLD is active, VLD is linked to all
wireshark libraries and executables.
2021-04-10 21:53:59 +00:00
Guy Harris 7de6b0822a pcapng: expand a comment and tweak the version test.
Drop in the comment from libpcap about version 1.2 (I wrote that
comment, and generously double-license it under the BSD license and the
GPL :-)).

Redo the version test as

    if (!({version is one we handle}))

to match the way it's done in libpcap.
2021-04-08 19:38:26 -07:00
Loris Degioanni 7894b1d0ea sysdig: a couple more fixes
- parse the number of system call arguments in a way that works for both V1 and V2 event blocks
- returned the correct error string when unable to read the nparams entry from a sysdig event block V2
2021-04-09 01:24:53 +00:00
Loris Degioanni cbbe660504 sysdig: implementation fixes
- make sure nparams is initialized
- validate block_total_length in the correct way for sysdig event blocks
2021-04-09 01:24:53 +00:00
Loris Degioanni 8c70dd8d17 sysdig: simplified the separate handling of the two different sysdig block types 2021-04-09 01:24:53 +00:00
Loris Degioanni fbe8d3a00f sysdig: support the most recent version of sysdig
Update the pcap-ng reader and sysdig event dissector to support the second version of the sysdig event block, which was introduced after Wireshark's original implementation
2021-04-09 01:24:53 +00:00
Guy Harris c01dd585c7 netmon: fill in all of the 802.11 pseudo-header in the dissector.
All the NetMon reading code does is initialize the pseudo-header; the
bulk of the work is done in the dissector.  Give the dissector its own
pseudo-header structure, and do the initialization there.

That's the way other packet formats in which the 802.11 radio metadata
is a header at the beginning of the packet data, such as radiotap, work.
2021-04-02 07:46:32 +00:00
João Valverde d7401147b4 CMake: Remove non existent '/codecs' include path
The '/codecs' dir was removed in g63af1da7e7.

Avoid using include_directories(), prefer target_include_directories().
Remove some unnecessary CMAKE_CURRENT_*_DIR includes and some other
small cleanups while at it.
2021-03-29 00:00:57 +00:00
Dario Lombardo ea929d6401 wsutils: add local implementation of g_memdup2.
g_memdup() was deprecated and replaced with g_memdup2() in GLib 2.68,
we provide our own copy of g_memdup2() for older GLib versions.
2021-03-25 09:38:10 +00:00
Guy Harris e434d404d0 Move even more headers outside extern "C".
If a header declares a function, or anything else requiring the extern
"C" decoration, have it wrap the declaration itself; don't rely on the
header itself being included inside extern "C".
2021-03-16 04:33:00 -07:00
Guy Harris a892a161d7 pcapng: add some comments warning not to cheat.
Add comments in various switch statements warning people *not* to add
standardized block types or option codes that aren't in the pcapng spec.
If you want a standardized block or option type, go through the
standards process.
2021-03-16 00:52:42 -07:00
Guy Harris 8f965899b3 Remove unnecessary includes of wiretap/pcap-encap.h. 2021-03-15 16:04:02 -07:00
Guy Harris ce20c00049 Remove unnecessary inclues of wiretap/pcapng.h. 2021-03-15 15:29:40 -07:00
Guy Harris 03d6f39a99 libwiretap: make wtap_wtap_encap_to_pcap_encap() private to the library.
Only a tiny amount of code outside libwiretap needs to know about
pcap/pcapng LINKTYPE_ values, and all that code needs to know is, for a
given LINKTYPE_ value, what the corresponding WTAP_ENCAP_ value is.
Nothing should need to know, for a given WTAP_ENCAP_ value, what its
LINKTYPE_ value is.

Make it the case that nothing *does* need to know, for a given
WTAP_ENCAP_ value, what its LINKTYPE_ value is.  Export
wtap_dump_can_write_encap() and use *that*, in the "import hex dump"
code, what formats can be written to a pcap file.
2021-03-14 14:22:16 -07:00
Guy Harris 610dffbb19 pcapng: make sure the packet encapsulation matches the interface encapsulation.
If an attempt is made to write a packet with one encapsulation for an
interface with a different encapsulation, report an internal error.
2021-03-13 22:00:21 -08:00
Guy Harris 5d39e36198 doc: Clean up lists of file types.
Add missing entries, regularize the descriptions, etc..

Note that pcap and pcapng are the native formats.

Fix various issues.

Update the editcap -F output to match urrent reality.

While we're at it, sort the libwiretap modules, putting observer.c in
the right place.
2021-03-13 10:02:02 +00:00
Guy Harris c473eba8dc observer: rename source and update name.
Name the source to the code to read Observer files after the file
format, not the company that created it, got bought by JDSU, and then
ended up in Viavi when JDSU split.

Refer to the file format as "Viavi Observer" to reflect that.
2021-03-11 16:01:27 -08:00
Guy Harris 2561f1e9f8 libwiretap: don't have a central table of file type/subtype name mappings.
Let individual file type/subtype modules register their
backwards-compatibility names, rather than having a centralized table
that would need to be updated along with the module.
2021-03-11 13:56:40 -08:00
Guy Harris 98485a1c27 pcapng: small cleanups in pcap_open().
We don't need to initialize first_section before calling
pcapng_read_section_header_block(); it doesn't depend on it being
initialized, and sets byte_swapped, version_major, and version_minor if
what it reads is a valid SHB, so we don't need to set those in
pcap_open().

We don't need to set shb_off until we've deemed this to be a pcapng
file, so do so at the same point that we initialize

We also don't need to initialize wblock until we call
pcapng_read_section_header_block(), so do so all in one place.
2021-03-11 12:49:24 -08:00
Guy Harris e0afa7f2a4 Observer is now a product of Viavi.
JDSU bought Network Instruments, and then split into Viavi and Lumentum,
with Viavi getting Observer.
2021-03-11 20:02:14 +00:00
Guy Harris aab0bd12a5 pcapng: clean up pcapng_block_read().
Instead of pcapng_open() calling pcap_block_read() to do all the work of
reading the initial SHB, have it do the read of the initial SHB itself,
by calling the same routines that pcap_block_read() calls.

That way, pcap_block_read() doesn't have to be prepared to be called to
read that block, so it can treat all issues with an SHB that it reads as
errors, rather than possibly reporting them as "not a pcapng file", and
it doesn't have to support being called without a pointer to the
pcapng_t for the file being read, as it no longer ever is.  It can now
just return a gboolean success/failure indication.

That makes pcapng_open() a little more complicated but it makes
pcap_block_read() less complicated.

Fix some use of : as ' in comments while we're at it.
2021-03-11 10:27:36 +00:00
Guy Harris f669bf2ec9 pcapng: ignore if_filter options with an unknown type.
We don't know how to process the type, so just ignore it.
2021-03-11 04:44:19 +00:00
Guy Harris 7446a16247 pcapng: get rid of the local pcapng_t in pcapng_open().
Pass a null pointer to pcapng_read_block(), instead.  In
pcapng_read_block(), treat that as the indication that we're trying to
read the purported first SHB, rather than treating a null section_info
pointer as that indication.

This addreses one, but not all, of the problems reported in issue #17281.
2021-03-10 22:06:58 +00:00
Guy Harris 598e32f933 commview: use the data rate to determine the modulation.
The band field of the header doesn't necessarily indicate the modulation
of the packet; use the data rate to determine the modulation.
2021-03-10 11:09:57 -08:00
Guy Harris dcd3e26a81 several: make the phy reflect the packet modulation.
Use the data rate and channel to determine 11b vs. 11g vs. 11a for:

* Aruba Networks encapsulated remote mirroring;
* Prism headers;
* *Peek remote protocol;
* Network Instruments^W^WViavi Observer;
* *Peek classic format;
* Shomiti Surveyor.

Note why we *don't* need to do that for NetMon captures.
2021-03-10 09:45:26 +00:00
Guy Harris 31dc280d25 radiotap, wlancap, wiretap: make the "phy" reflect the packet modulation.
Do more fixups of the "phy" based on the data rate, so that it reflects
the modulation used for the packet.

Note, in comments, why we're doing this, and that there's no reiable
way, in radiotap, to determine the type of channel on which capturing is
being done, as some packet providers use the channel field to indicate
the channel type and others use it to indicate the modulation.

Only provide the "short preamble" for "11b", as that's now being used to
mean "DSSS modulation" - packets on an 11g channel will be marked as
"11g" if they're OFDM or "11b" if they're DSSS.

Make some other cleanups while we're at it.
2021-03-08 18:40:32 -08:00
Guy Harris 6b830718d2 niobserver: some work.
Put all the TLV stuff together.  *If* some TLVs are only in the file
header and others are only in packets, thot should be the split; it
appears that the TLVS with a type with the 0x01 bit clear are for the
file header, so perhaps they can be split based on that.

Don't include the TLV header in the structure for the time_info TLV;
that matches other TLV structures.  Write the time_info TLV in two
parts, as we do with the comment TLV.

Consistently use _TO_LE macros in our _TO_LE_IN_PLACE macros.

Add _FROM_LE_IN_PLACE and _TO_LE_IN_PLACE macros for the network_load
TLV.

Use %z, now that we require C99-or-later.

Check the length of TLVs.

Note some things found in files while reverse engineering.
2021-03-05 18:08:10 -08:00
Guy Harris 2627bd4b84 snoop: expand a comment.
There's a bunch of information about the Shomiti wireless header that
would be Nice To Have.  Note it.
2021-03-04 20:40:30 -08:00
Guy Harris 8f700ab1f3 peektagged: guess the PHY for 11b/11g/11a.
FOr 11b and 11g, also set the metadata to provide the "short preamble"
indication.

Add some macros to wsutil/802_11-utils.h to help there, as I threatened
to do in the previous commit. :-)
2021-03-04 16:07:23 -08:00
Guy Harris 25d44cde11 wsutil: rename frequency-utils.[ch] to 802_11-utils.[ch].
It's 802.11-specific, and may include non-frequency/channel-related
items in the future.
2021-03-04 15:41:00 -08:00
Guy Harris b8d90bb548 netxray: update a comment.
Add additional information derived from more reverse engineering.
2021-03-03 15:19:18 -08:00
João Valverde e536166b38 Fix warnings with GCC and -O3
When building with GCC 10.2.0 and optimization level 3 some new
warnings turn up. Fix them.

./epan/crypt/dot11decrypt_util.c: In function ‘dot11decrypt_derive_pmk_r0’:
../epan/crypt/dot11decrypt_util.c:308:5: error: ‘sha256_res’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  308 |     memcpy(pmk_r0_name, sha256_res, 16);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../epan/crypt/dot11decrypt_util.c: In function ‘dot11decrypt_derive_pmk_r1’:
../epan/crypt/dot11decrypt_util.c:357:5: error: ‘sha256_res’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  357 |     memcpy(pmk_r1_name, sha256_res, 16);
      |     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

../wiretap/wtap_opttypes.c: In function ‘wtap_block_add_if_filter_option’:
../wiretap/wtap_opttypes.c:782:12: error: ‘*((void *)&filter_dest+8)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  782 |     return filter_dest;
      |            ^~~~~~~~~~~
../wiretap/wtap_opttypes.c: In function ‘wtap_block_set_if_filter_option_value’:
../wiretap/wtap_opttypes.c:782:12: error: ‘*((void *)&filter_dest+8)’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
  782 |     return filter_dest;
      |            ^~~~~~~~~~~
2021-03-03 15:15:25 +00:00
Gerald Combs 481b490b82 Miscellaneous EditorConfig fixes
In the top-level .editorconfig, note that we don't use CMake's standard
indentation.

Remove ascendtext.[ch] from wiretap/.editorconfig since it's no longer
needed.
2021-03-02 19:13:54 +00:00
João Valverde 7f105d3981 CMake: Use CheckAPI's abort/termoutput with dissectors only
I believe this was the original intention, to use these API restricitons
with dissectors only (not that I necessarily agree with that policy either),
and through copy-paste and lack of clear guidelines it spread to other
parts of the build.

Rename the checkAPI groups to make it very clear that this is dissector-only.

This doesn't mean, of course, that good programming practices shouldn't be
followed everywhere. In particular assertions need to be used properly.
Don't use them to catch runtime errors or validate input data.

This commit will be followed by another removing the various ugly hacks
people have been using to get around the checkAPI hammer.
2021-03-01 20:59:39 +00:00
Guy Harris 7665075241 wiretap: make WTAP_FILE_TYPE_SUBTYPE_UNKNOWN -1 rather than an index.
And get rid of the entry for that type in the table of type/subtypes.
2021-02-24 17:30:47 -08:00
Guy Harris 9191746670 wiretap: add a block type for systemd journal entries.
Those are used by more than one file type, so we should provide a block
type for them.  (We don't *currently* use that block type, or the packet
block type, but this makes them available for future use.)
2021-02-24 03:09:03 -08:00
Guy Harris 7ffc11e38f wiretap: add some additional bounds checks for file type/subtype values.
Check to make sure the value is non-negative and less than the number of
file type/subtypes.

Make it clearer than one check is unnecessary:

* pull wtap_dump_open_check() into wtap_dump_init_dumper(), so it's
clear that wtap_dump_init_dumper() ensures the validity of the file
type/subtype value early on (wtap_dump_can_open() fails if it's not
valid);

* pull wtap_dump_alloc_wdh() into wtap_dump_init_dumper(), so that the
allocation and all the initialiation is done there - that makes it clear
that it sets the file_type_subtype member of the wtap_dumper structure
before wtap_dump_init_dumper() returns;

* have wtap_dump_open_finish() use that value rather than being passed
the type/subtype value explicitly, so it's clear that it's dealing with
a validated value.
2021-02-24 10:36:05 +00:00
Guy Harris ed86f51e49 wiretap: rename wtap_register_file_type_subtypes().
It only registers one file type/subtype, so rename it to
wtap_register_file_type_subtype().

That will also force plugins to be recompiled; that will produce compile
errors for some plugins that didn't change to match the new contents of
the file_type_subtype_info structure.

Also check to make sure that the registered file type/subtype supports
at least one type of block; a file type/subtype that doesn't return
*any* blocks and doesn't permit *any* block types to be written is not
very useful.  That should also catch most if not all other plugins that
didn't change to match the new contents of the file_type_subtype_info
structure.

Don't make errors registering a file type/subtype fatal; just complain,
don't register the bogus file type/subtype, and drive on.
2021-02-23 20:39:16 -08:00
Guy Harris 166159f15d wiretap: eliminate the pcap/nspcap/pcapng WTAP_FILE_TYPE_SUBTYPE_ values.
Register the pcap and pcapng file types/subtypes rather than hardwiring
them into the table.

Call the registration routines for them directly, rather than through a
generated table; they're always supposed to be there, as some code in
Wireshark either writes only one of those formats or defaults to writing
one of those formats.  Don't run their source code through the
registration-routine-finder script.

Have the file type/subtype codes for them be directly exported to the
libwiretap core, and provide routines to return each of them, to be used
by the aforementioned code.

When reporting errors with cfile_write_failure_message(), use
wtap_dump_file_type_subtype() to get the file type/subtype value for the
wtap_dumper to which we're writing, rather than hardcoding it.

Have the "export PDU" code capable of supporting arbitrary file
types/subtypes, although we currently only use pcapng.

Get rid of declarations of now-static can_write_encap and
dump_open routines in various headers.
2021-02-23 21:56:20 +00:00
Guy Harris d50f712a85 wiretap: fix use of wrong index as array subscript.
"i" and "j" are too similar, so it's easy to use the wrong one if you're
using both as array indices and not easy enough to notice the mistake.

Use somewhat more meaningful names when we fix the index.

Fixes #17252.
2021-02-22 12:55:35 -08:00
Guy Harris 00d2661459 wiretap: fix dependency in CMakeLists.txt.
wtap_modules.c depends on ${WIRETAP_MODULE_FILES} rather than
${WIRETAP_NONGENERATED_FILES}.
2021-02-22 19:45:44 +00:00
Guy Harris 842a7cccf9 wiretap: have file handlers advertise blocks and options supported.
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-21 23:18:35 +00:00
Martin Mathieson cd77e5aa5f Some more spelling fixes.
Also add more words to dictionary file.
2021-02-21 09:59:04 +00:00
Guy Harris 1f595c435c BER: get rid of WTAP_FILE_TYPE_SUBTYPE_BER.
Save a copy of the pathname used to open a file in the wtap structure.
This allows the BER file reader to put a pointer to it in the
pseudo-header; it also would allow file readers to attempt to read
"associated" files that have the same name as the file, but with a
different extension.

Instead of having cf_open() special-case BER files, and calling a
routine in the BER dissector to specify the file name to the dissector,
have separate dissectors for "dissect packet payload as BER" and
"dissect a file as BER", and have the latter get the pathname of the
file from the pseudo-header and determine the ASN.1 syntax from that.

(Side-effect - this means that you can now dissect a BER file, and have
the syntax be determined by the file extension, in TShark as well; the
above cf_open() special-casing was *not* done in TShark, so it didn't
work before.  Now the application code doesn't need to do any of that,
so it works in TShark as well as Wireshark.)
2021-02-20 01:36:26 -08:00
Guy Harris c80c16759b wiretap: eliminate two WTAP_FILE_TYPE_SUBTYPE_ values.
Eliminate WTAP_FILE_TYPE_SUBTYPE_ERF and
WTAP_FILE_TYPE_SUBTYPE_SYSTEMD_JOURNAL - instead, fetch the values by
name, using wtap_name_to_file_type_subtype().

This requires that wtap_init() be called before epan_init(); that's
currently the case, but put in comments to indicate why it must continue
to be the case.
2021-02-19 23:20:24 +00:00
Guy Harris 8b775000bc wiretap: register BUSMASTER log and candump file formats.
*Don't* use WTAP_FILE_TYPE_SUBTYPE_UNKNOWN for the file type/subtype.
2021-02-18 07:48:11 +00:00
Guy Harris a931d73e64 wiretap: fix return value of wtap_register_file_type_subtypes().
It was returning the length of the array *after* we added the new entry,
which is the index that would be used for the *next* entry added.
Return, instead, the length of the array *before* we add the new entry.
2021-02-17 21:40:21 -08:00
Guy Harris edc17b6589 wiretap: update the count of builtin types early.
We need to update the count of builtin types after copying over the
entries from the fixed table; otherwise, slot 0, for
WTAP_FILE_TYPE_SUBTYPE_UNKNOWN, will get assigned to the first
non-fixed-table builtin module.

Fix a comment (is a "builtin plugin" like a "square circle"?).
2021-02-17 19:43:11 -08:00
Guy Harris ba9b08a710 netscaler: fix a comment. 2021-02-17 16:37:04 -08:00
Guy Harris a7256d50b5 wiretap: more work on file type/subtypes.
Provide a wiretap routine to get an array of all savable file
type/subtypes, sorted with pcap and pcapng at the top, followed by the
other types, sorted either by the name or the description.

Use that routine to list options for the -F flag for various commands

Rename wtap_get_savable_file_types_subtypes() to
wtap_get_savable_file_types_subtypes_for_file(), to indicate that it
provides an array of all file type/subtypes in which a given file can be
saved.  Have it sort all types, other than the default type/subtype and,
if there is one, the "other" type (both of which are put at the top), by
the name or the description.

Don't allow wtap_register_file_type_subtypes() to override any existing
registrations; have them always register a new type.  In that routine,
if there are any emply slots in the table, due to an entry being
unregistered, use it rather than allocating a new slot.

Don't allow unregistration of built-in types.

Rename the "dump open table" to the "file type/subtype table", as it has
entries for all types/subtypes, even if we can't write them.

Initialize that table in a routine that pre-allocates the GArray before
filling it with built-in types/subtypes, so it doesn't keep getting
reallocated.

Get rid of wtap_num_file_types_subtypes - it's just a copy of the size
of the GArray.

Don't have wtap_file_type_subtype_description() crash if handed an
file type/subtype that isn't a valid array index - just return NULL, as
we do with wtap_file_type_subtype_name().

In wtap_name_to_file_type_subtype(), don't use WTAP_FILE_TYPE_SUBTYPE_
names for the backwards-compatibility names - map those names to the
current names, and then look them up.  This reduces the number of
uses of hardwired WTAP_FILE_TYPE_SUBTYPE_ values.

Clean up the type of wtap_module_count - it has no need to be a gulong.

Have built-in wiretap file handlers register names to be used for their
file type/subtypes, rather than building the table in init.lua.

Add a new Lua C function get_wtap_filetypes() to construct the
wtap_filetypes table, based on the registered names, and use it in
init.lua.

Add a #define WSLUA_INTERNAL_FUNCTION to register functions intended
only for internal use in init.lua, so they can be made available from
Lua without being documented.

Get rid of WTAP_NUM_FILE_TYPES_SUBTYPES - most code has no need to use
it, as it can just request arrays of types, and the space of
type/subtype codes can be sparse due to registration in any case, so
code has to be careful using it.

wtap_get_num_file_types_subtypes() is no longer used, so remove it.  It
returns the number of elements in the file type/subtype array, which is
not necessarily the name of known file type/subtypes, as there may have
been some deregistered types, and those types do *not* get removed from
the array, they just get cleared so that they're available for future
allocation (we don't want the indices of any registered types to changes
if another type is deregistered, as those indicates are the type/subtype
values, so we can't shrink the array).

Clean up white space and remove some comments that shouldn't have been
added.
2021-02-17 21:54:28 +00:00
Guy Harris 3387eef836 wiretap: remove duplicate declaration of wtap_block_get_type(). 2021-02-14 20:06:21 +00:00
Guy Harris b8b3531883 wiretap: register most built-in file types from its module.
Remove most of the built-in file types from the table in
wiretap/file_access.c and, instead, have the file types register
themselves, using wtap_register_file_type_subtypes().

This reduces the source code changes needed to add a new file type from
three (add the handler, add the file type to the table in file_access.c,
add a #define for the file type in wiretap/wtap.h) to one (add the
handler).  (It also requires adding the handler's source file to
wiretap/CMakeLists.txt, but that's required in both cases.)

A few remain because the WTAP_FILE_TYPE_SUBTYPE_ #define is used
elsewhere; that needs to be fixed.

Fix the wiretap/CMakefile.txt file to scan k12text.l, as that now
contains a registration routine.  In the process, avoid scanning files
that don't implement a file type and won't ever have a registration
routine.

Add a Lua routine to fetch the total number of file types; we use that
in some code to construct the wtap_filetypes table, which we need to do
in order to continue to have all the values that used to come from the
WTAP_FILE_TYPE_SUBTYPE_ types.

While we're at it, add modelines to a file that lacked them.
2021-02-14 00:58:46 -08:00
Guy Harris 8ec5906fd6 iseries: report Unicode files as Unicode rather than ASCII.
While we're at it, that's "Unicode", not "UNICODE" - it's not an
initialism, and isn't all-caps.
2021-02-13 20:23:08 -08:00
Guy Harris 8bba6ebe5c wiretap: remove spaces from file format names.
File format names are used on the command line, so don't require them to
be quoted - replace the space in "systemd journal" with an underscore.
2021-02-13 10:35:58 -08:00
Guy Harris 24acef0885 wiretap: file types have a name and a description.
The "short name" is really just the name, used to look it up.  The
"name" is really a description intended solely for human consumption.
Rename the fields, and the functions that access them, to match.

The "description" maintained by Lua for file type handlers is used
*only* for one debugging message; we should probably just eliminate it.
Call it an "internal description" for now.
2021-02-13 01:25:39 -08:00
Guy Harris a1e03ea89e Remove the existing "custom block" mechanism:
For most file types, blocks for which we don't have a wtap_block_type_t
aren't "custom", they're just "file-type specific".  Add
WTAP_BLOCK_FT_SPECIFIC_REPORT and WTAP_BLOCK_FT_SPECIFIC_EVENT block
types; the "mandatory" part of those blocks includes a
file-type-specific block type value, with specific values assigned to
specific block types (either as part of the file type's definition, or
by us if necessary).

For pcapng files, blocks for which we don't have a wtap_block_type_t are
either "local" (block type has the high-order bit set), are defined in
the current spec but aren't supported yet (which we should fix), or are
*not* defined in the current spec and are *not* "local" (in which case
whoever's using the block number should submit a pull request to the
spec to register the block type *and* give it a specification, so we can
add support).  For "local" block types and for not-yet-supported
non-"local" block types, they should be handled as file-type-specific
blocks with the file-type-specific block value being the pcapng block
type code, with plugin support in the pcapng code to read *and* write
those blocks.

Move the structures for the "mandatory" parts of blocks to
wiretap/wtap_opttypes.h, right after the definition of
wtap_block_type_t.
2021-02-10 09:05:41 +00:00
Guy Harris f0c54cc480 wiretap: add an API to get the type of a block.
When registering a custom block type, set the block type field of the
wtap_blocktype_t structure.  (We may do custom blocks differently, so
this is just for now.)

When registering a standard block type, don't pass in the block type, as
we can just use the type in the wtap_blocktype_t structure.
2021-02-09 21:23:44 -08:00
Guy Harris 09684644ee wiretap: clean up WTAP_BLOCK_ names.
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.
2021-02-09 22:32:57 +00:00
Guy Harris 85de5ed784 btsnoop: fix writing of btsnoop files.
In answer to the question "How do we support multiple backends?", this
is the answer - what they mean is "how do we support multiple
encapsulation types for the *same* file format", and the answer is "you
have one dump open routine that writes the appropriate encapsulation
type in the header, depending on the encapulation type, and you have one
dump write routine that generates the appropriate packet header and
writes out the packet, depending on the encapsulation type".

Fix the generation of the packet header when writing H1 and H4 packets,
and *don't* strip off the first octet of the packet data when writing H1
packets - that octet isn't generated when reading H1 packets, it's read
from the file.

Tested by running several H1 and H4 captures through "editcap -F
btsnoop" and making sure that the files are identical.
2021-02-07 09:58:39 +00:00
Guy Harris 1cbafa47b9 wiretap: add a mechanism for built-in modules to have a register routine.
Currently, only pcapng has one, and it does nothing, but this mechanism
will be used more in the future.

Update comments in epan/dissectors/CMakeLists.txt and ui/taps.h while
we're at it.
2021-02-06 17:54:19 -08:00
Guy Harris 12960c81c4 pcapng: write out the FCS length IDB option. 2021-02-06 13:50:30 -08:00
Guy Harris 910c489a4a pcapng: fix build without plugins.
Just remove some HAVE_PLUGINS checks.  Those tables will eventually
handle built-in block and option types as well.
2021-02-06 13:07:12 -08:00
João Valverde 89fee9321e Avoid exposing HAVE_PLUGINS in the public API
Instead *_register_plugin() is turned into a noop (with a warning).

The test suit is failing with ENABLE_PLUGINS=Off (it was already failing
before and this patch didn't affect that).

Closes #17202.
2021-02-06 16:35:51 +00:00
Guy Harris eb066c6091 wiretap: use a hash table for option types.
Option types aren't guaranteed to be small integers, so store option
types for a block type in a hash table, so we don't need to have a big
array to handle the custom option types (the type values of which aren't
small integers) and with local-use option types (the type values of
which also aren't small integers).

Make all the option type structures const while we're at it.
2021-02-04 22:09:23 -08:00
Guy Harris 44abff6934 pcapng: expand the plugin option handlers to support writing options.
The options get unmarshalled (deserialized) when you read them; they
need to get marshalled (serialized) when you write them.  This requires
an option handler to have more than one function.

While we're at it, in the declarations for function types for *block*
reader and writer plugins, add names to the prototype function
arguments, to make it a bit clearer what those arguments are.
2021-02-05 01:34:04 +00:00
Guy Harris 712490f214 pcapng: have common code to handle otherwise-unhandled options.
That code looks for a plugin handler if there's no built-in handler.

Change the handler signature so that it can add an option.
2021-02-04 21:37:53 +00:00
Guy Harris 42dc21a346 pcapng: pull common processing code into subroutines. 2021-02-04 00:59:16 -08:00
Guy Harris fbdd2446e1 pcapng: Fix copy-and-pasteo.
Found by Coverity; fixes Coverity CID 1472770.

(At least *this* Coverity report doesn't use that tainted word
"tainted", which, most of the time, means "ZOMG UR PROGRAM READS
EXTERNAL FILEZ!!!!111ONE!!!")
2021-02-02 21:33:24 -08:00
Guy Harris 0773147a55 wiretap: redo the way we handle if_filter IDB options.
Change the data structure for that option to have a type field,
indicating that it's either a pcap filter string or a BPF program,
followed by a union with a string-pointer member for pcap filter strings
and an instruction-count-and-pointer-to-instructions structure for BPF
programs.

Have routines to add, set, and fetch that option that handle that
structure; discard the "generic structured option" routines.  That means
there's more type checking possible at compile time.

Add more code to handle BPF programs.

When writing pcapng files, check, both for that option and for string
options, whether the option length is too big for the data to fit in a
pcapng option, and don't write it if it is.  (XXX - truncate the data?
Report an error?)
2021-02-01 16:50:01 -08:00
Richard Sharpe fb2a0b4a71 ieee80211: Add support for S1G including PV1.
S1G adapters should be shipping soon since Silex America has a dev-kit
available, so it is about time to add support for this.

Change-Id: I0225d87f78efbcbe88476921d4fce3d56a3ce0cd
2021-02-01 19:34:55 +00:00