Commit Graph

3577 Commits

Author SHA1 Message Date
Guy Harris 4e80643cc0 Move LINKTYPE_WIRESHARK_UPPER_PDU definitions to a separate header.
Have wsutil/exported_pdu_tlvs.h define the LINKTYPE_WIRESHARK_UPPER_PDU
TLV type and length values, as well as the port type values written to
files in EXP_PDU_TAG_PORT_TYPE TLVs.

Update the comment that describes the LINKTYPE_WIRESHARK_UPPER_PDU TLVs
to more completely and correctly reflect reality (it was moved from
epan/exported_pdu.h to wsutil/exported_pdu_tlvs.h).

Rename those port type values from OLD_PT_ to EXP_PDU_PT_; there is
nothing "old" about them - yes, they originally had the same numerical
values as the PT_ enum values in libwireshark, but that's no longer the
case, and the two are now defined independently.  Rename routines that
map between libwireshark PT_ values and EXP_PDU_PT_ values to remove
"old" from the name while we're at it.

Don't include epan/exported_pdu.h if we only need the
LINKTYPE_WIRESHARK_UPPER_PDU definitions - just include
wsutil/exported_pdu_tlvs.h.

In extcap/udpdump.c, include wsutil/exported_pdu_tlvs.h rather than
defining the TLV types ourselves.
2021-08-20 02:18:19 -07:00
Guy Harris d679564d7b Use the wsutil/pint.h functions to fill in "exported PDU" headers.
That makes the code cleaner, including making it clearer that the fields
in those headers are big-endian.
2021-08-20 00:35:33 -07:00
David Perry 6e12643f19 [#17478] free blocks in more places
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-08-10 00:08:15 +00:00
Gerald Combs dead9f13e9 wiretap: Fix some BLF warnings.
Make a bunch of functions in blf.c static.
2021-08-04 09:51:05 -07:00
Dr. Lars Völker f27c98ad2b BLF: Cleanup and fix for start time 2021-08-04 14:58:03 +02:00
Jaap Keuter 85586f4b43 Fix header documentation and style
Fix some documentation found by in code check pipeline, and apply
code wrapping style consistently.
2021-08-04 06:00:28 +00:00
Alexis La Goutte a3f9c6bc45 erf: Fix Dead Store (found by Clang Anlyzer)
Although the value stored to 'tagtotallength' is used in the enclosing expression, the value is never actually read from 'tagtotallength'
2021-07-30 20:43:55 +00:00
Guy Harris cb98aa3730 nettrace 3GPP 32.423: move the name related code together.
Initialize name_str right before we fill it in if the name is present,
and note what we're doing, to make it a bit clearer what the
initializing code is doing.
2021-07-25 13:34:11 -07:00
Moshe Kaplan 49ca5fa8ab libwiretap: Avoid using uninit variable
Within wiretap/nettrace_3gpp_32_423.c,
set the first byte of the buffer
to a null byte to avoid potentially
accessing uninitiliazed memory.
Fixes Coverity 1471685.
2021-07-25 17:25:44 +00:00
Gerald Combs 539ad8a91b CMake: Remove unneeded GLIB2_LIBRARIES.
GLib is part of wsutil's link interface, so we don't need to link to it
explictly.
2021-07-21 10:05:21 +00:00
David Perry dc7089e831 Carry drop count/packet ID/queue ID as options on packet block 2021-07-19 21:25:40 +00:00
Gerald Combs 50da270b8a BLF: Fix Win32 compilation issues.
Fix

```
wiretap\blf.c(368,73): error C2220: the following warning is treated as an error [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): error C2220:         unsigned char *compressed_data = g_try_malloc0(tmp.infile_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): error C2220:                                                                         ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244: 'function': conversion from 'guint64' to 'gsize', possible loss of data [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244:         unsigned char *compressed_data = g_try_malloc0(tmp.infile_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(368,73): warning C4244:                                                                         ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244: 'function': conversion from 'guint64' to 'gsize', possible loss of data [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244:         unsigned char *buf = g_try_malloc0(tmp.real_length); [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(375,59): warning C4244:                                                           ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(blf_ethernetframeheader_t)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(654,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
  busmaster.c
wiretap\blf.c(733,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(733,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(blf_ethernetframeheader_ex_t)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(733,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(818,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018:         if (object_length < (data_start - block_start) + sizeof(canheader) + payload_length_valid + sizeof(can2trailer)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(859,27): warning C4018:                           ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(894,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(canheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(966,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(frheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1045,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018: '<': signed/unsigned mismatch [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018:     if (object_length < (data_start - block_start) + sizeof(frheader)) { [build\wiretap\wiretap.vcxproj]
wiretap\blf.c(1126,23): warning C4018:                       ^ [build\wiretap\wiretap.vcxproj]
```
2021-07-18 17:05:31 -07:00
Guy Harris c64a9bbde7 erf: make a copy of the first SHB comment.
We free it, but what wtap_block_get_nth_string_option_value() returns is
what's stored in the block, and it might get freed up out from under us.
Save a copy of it, so that when we free it, we're not double-freeing.
2021-07-16 15:59:58 -07:00
Dr. Lars Völker 796819c955 BLF: Support for BLF file format
This patch adds first support for the BLF file format.
2021-07-16 07:37:43 +00:00
Developer Alexander 2a1ebd1e91 can: more specific dissector tables for CAN IDs and extended IDs
Introduces two new dissector tables can.id and can.extended_id to enable a
more precise control of subdissectors dependent on the can id which is often
used to identify the the payload.

Since standard CAN IDs and extended IDs can be used in the same network and
their ranges overlap it is necessary to have two different dissector tables.

Existing Decode as dissector table can.subdissector stays as is to prevent a
breaking change. But new dissector tables can.id and can.extended_id get
priority over can.subdissector since they are more specific. Id they get a
match can.subdissector won't be called.

New dissector tables can.id and can.extended_id are accessible in lua scripts
via DissectorTable:add() while can.subdissector unfortunately is not.

For related Discussion see MR !3405
2021-07-15 07:29:46 +00:00
Guy Harris cc36b74139 pcapng: shuffle functions that process various option types.
Define them in the order in which wiretap/wtap_opttypes.h defines the
corresponding enum values for wtap_opttype_e.
2021-07-14 01:01:27 -07:00
Guy Harris 7b0c4950a5 wiretap: clean up option definitions a bit.
Spell out "DESCRIPTION" for the IDB description option, as it's spelled
out in the pcapng spec.

Put the #defines for various options in the same order as the block
types for them are in the pcapng spec.
2021-07-14 06:55:12 +00:00
Guy Harris 23f19e4a5d wiretap: iptrace/Sniffer/Peek classic always have packet flags.
For iptrace files, there's always a direction indication (which also
means that the flags field will never be zero - "outbound" and "inbound"
both have non-zero values - so the test for non-zero always succeeds, so
it's not even a useful test).

For Sniffer Ethernet/FDDI/synchronous serial line files, and for Peek
classic files, there are always flags; they might be zero if there were
no errors, but that doesn't mean that the lack of errors shouldn't be
noted with a flags field.

While we're at it, shuffle creating of the block next to the setting of
the record type - the block and record type should match, so the two
operations are doing related things.
2021-07-14 00:31:03 +00:00
Guy Harris fa9ee0f37a pcapng: process OPT_COMMENT in pcapng_process_options().
That option applies to all pcapng blocks, so handle it in common code.
2021-07-12 18:06:38 -07:00
David Perry 06ed6930dc Carry EPB flags as an option on the packet block
As requested by [this comment][1] on !2859, move `pack_flags` from a
dedicated field in `wtap_rec` to a block option on the packet block in
`wtap_rec.block`.

[1]: https://gitlab.com/wireshark/wireshark/-/merge_requests/2859#note_615984624
2021-07-12 12:41:57 -04:00
Guy Harris dd5907d2a3 Consistently refer to blocks that have been modified as "modified".
"User" sounds as if the blocks belong to the user; at most, the current
user might have modified them directly, but they might also have, for
example, run a Lua script that, unknown to them, modified comments.
Also, a file might have "user comments" added by a previous user, who
them wrote the file and and provided it to the current user.

"Modified" seems a bit clearer than "changed".
2021-07-08 00:05:35 -07:00
David Perry 73087d6fb4 Use wtap_blocks for packet comments
Mostly functioning proof of concept for #14329. This work is intended to
allow Wireshark to support multiple packet comments per packet.

Uses and expands upon the `wtap_block` API in `wiretap/wtap_opttypes.h`.
It attaches a `wtap_block` structure to `wtap_rec` in place of its
current `opt_comment` and `packet_verdict` members to hold OPT_COMMENT
and OPT_PKT_VERDICT option values.
2021-07-07 18:40:24 +00:00
Guy Harris 5f596c1e82 wiretap: add the ZigBee secret types.
They're in the spec, they belong here as well.
2021-07-01 11:09:36 +00:00
Guy Harris 33cff8c95b wiretap: change some comments.
Note that OPT_CUSTOM_STR_COPY is, specifically, a UTF-8 string.

Fix the comment for OPT_CUSTOM_STR_NO_COPY to say it's a UTF-8 string,
not binary data.
2021-07-01 08:56:34 +00:00
Guy Harris 70d69d5f91 wiretap: add WTAP_BLOCK_SYSDIG_EVENT block type for future use. 2021-07-01 06:29:50 +00:00
Guy Harris 689ff5a3ad pcapng: centralize access to members of the wtap_optval_t union.
Have the "compute option size" and "write option" routines take a
wtap_optval_t * as an argument and choose the appropriate member of the
union.
2021-06-29 14:54:48 -07:00
Guy Harris c0dc9106dd pcapng: clean up some function names.
Consistently use pcapng_compute_XXX_option_size() for routines to
compute the size of an option of type XXX and pcapng_write_XXX_option()
for routins to write out an option of type XXX.

Sort the routines by the order in which their option type values are
defined.
2021-06-28 17:20:26 -07:00
Guy Harris 73e058032f pcapng: have more common code for writing options.
Have common routines that iterate over all the options, processing
comment and custom options in common code (as they're defined
independently of particular block types), with callbacks to handle the
options for particular block types.
2021-06-28 15:14:36 -07:00
Joakim Andersson 9728438929 nordic_ble: Update display name of nordic_ble dissector
Replace all instances of "Nordic BLE Sniffer" with
"nRF Sniffer for Bluetooth LE" which is the name used by
nordic semiconductor for the development tool on the homepage.

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2021-06-28 11:52:14 +00:00
Guy Harris c1082bd99e wiretap: have the "for each option" routine return a success/fail indication.
Have the routine it calls return a Boolean value, with "true" meaning
"keep going" and "false" meaning "stop iterating and return a failure
indication".  If the callback routine never returns "false", the routine
returns "true" as a success indication.
2021-06-27 13:25:16 -07:00
Guy Harris ae10f11212 wtap_opttypes: clean up comments. 2021-06-27 04:27:59 -07:00
Guy Harris 9e6aa424f1 pcapng: have a common routine to write the "end of options" option. 2021-06-27 03:14:14 -07:00
João Valverde 472eaf911b "config.h" need not and should not be included in any header
config.h is included in the source file before including the
header that uses it.
2021-06-25 23:53:53 +01:00
Martin Mathieson af57fb94ac DT2000: Fix buffer length in wiretap code
CID: 1477941
2021-06-25 09:44:35 +01:00
Michael Tuexen 1f0a16e472 pcapng: add support for custom options 2021-06-23 04:38:27 +00:00
Dario Lombardo f62138c0d5 Fix some includes. 2021-06-22 19:25:43 +00:00
Guy Harris 1fe3ed4940 erf: fix a comment to match reality.
It's not that Wireshark only supports one copy of some block options,
it's that *the pcapng specification* only supports one instance of some
block options, and it's not that wtap_block_set_*_value() fails on
non-string values, it's that the set_XXX_option_value routines currently
only support changing the value of an existing option, not adding a new
instance of an option - the latter requires the add_XXX_option_value
routine.
2021-06-19 15:37:43 -07:00
João Valverde 8cf9791679 Replace some lingering references to g_log() 2021-06-19 02:34:36 +00:00
Guy Harris 39315979c6 pcap-common: set the time stamp precision correctly for LINKTYPE_ERF.
LINKTYPE_ERF pcap files are really ERF files inside a thin pcap wrapper
(don't even ask what a pcapng file with some or all interfaces being
LINKTYPE_ERF is...), so the time stamp comes from the ERF record, not
from the pcap packet header or pcapng block header.

The time stamp reslution for the record should reflect that, so set it
to WTAP_TSPREC_NSEC (ERF time stamps are fractional-power-of-2, not
fractional-power-of-10, so that's the best we can do).
2021-06-18 17:43:36 -07:00
Guy Harris 02cffb51a9 erf: handle errors in some routines more completely.
Have them take error code and error information string arguments and,
for various failures, fill them in as "internal error" indications.

Check their return codes to see if they got an error.
2021-06-18 16:22:54 -07:00
Guy Harris d69d1271f0 libpcap: don't generate a fake interface for LINKTYPE_ERF files.
The ERF code will generate interfaces based on the ERF records in the
file, so don't bother adding an additional dummy interface.
2021-06-18 15:34:49 -07:00
Guy Harris 49ec11f5aa erf: set the tsprecision value of a newly-created IDB.
Don't assume the default is correct, because there's no guarantee of
that - in fact, there's currently a guarantee that it's not, as it's
initialized to 0, which is WTAP_TSPREC_SECS.
2021-06-18 01:24:41 -07:00
Guy Harris 5eda4c0128 pcapng: update a comment to reflect the name cleanups. 2021-06-17 15:55:18 -07:00
Guy Harris 9773b5a4a7 Just call the block type for custom blocks WTAP_BLOCK_CUSTOM.
No need to add a redundant "_BLOCK" at the end.
2021-06-17 15:04:44 -07:00
Guy Harris 6eb3703379 Make various names match the name of the systemd journal export block.
The name of the block, in the pcapng specification is the systemd
Journal Export Block; add "export" after "journal" in various
variable/enum/define names.
2021-06-17 13:52:45 -07:00
Guy Harris 2c9d262ed1 pcapng: indentation cleanups. 2021-06-16 20:03:00 -07:00
Guy Harris 8aceee774a pcapng: get rid of some now-redundant rounding up of the block length.
Now that it's being done in common code, we don't need to do it in the
routines to read sysdig event blocks, systemd journal export blocks, or
unknown blocks.

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