Commit Graph

95 Commits

Author SHA1 Message Date
João Valverde 84f963dfa2 Move ui/version_info.[ch] to wsutil 2023-02-07 23:17:37 +00:00
João Valverde c62aa67d2c Move ui/exit_codes.h to include/ 2023-02-07 10:12:08 +00:00
Guy Harris e5951765d8 Dissector names are not protocol names.
A given protocol's packet format may depend, for example, on which
lower-level protocol is transporting the protocol in question.  For
example, protocols that run atop both byte-stream protocols such as TCP
and TLS, and packet-oriented protocols such as UDP or DTLS, might begin
the packet with a length when running atop a byte-stream protocol, to
indicate where this packet ends and the next packet begins in the byte
stream, but not do so when running atop a packet-oriented protocol.

Dissectors can handle this in various ways:

For example, the dissector could attempt to determine the protocol over
which the packet was transported.

Unfortunately, many of those mechanisms do so by fetching data from the
packet_info structure, and many items in that structure act as global
variables, so that, for example, if there are two two PDUs for protocol
A inside a TCP segment, and the first protocol for PDU A contains a PDU
for protocol B, and protocol B's dissector, or a dissector it calls,
modifies the information in the packet_info structure so that it no
longer indicates that the parent protocol is TCP, the second PDU for
protocol A might not be correctly dissected.

Another such mechanism is to query the previous element in the layers
structure of the packet_info structure, which is a list of protocol IDs.

Unfortunately, that is not a list of earlier protocols in the protocol
stack, it's a list of earlier protocols in the dissection, which means
that, in the above example, when the second PDU for protocol A is
dissected, the list is {...,TCP,A,B,...,A}, which means that the
previous element in the list is not TCP, so, again, the second PDU for
protocol A will not be correctly dissected.

An alternative is to have multiple dissectors for the same protocol,
with the part of the protocol that's independent of the protocol
transporting the PDU being dissected by common code.  Protocol B might
have an "over a byte-stream transport" dissector and an "over a packet
transport" dissector, with the first dissector being registered for use
over TCP and TLS and the other dissector being registered for use over
packet protocols.  This mechanism, unlike the other mechanisms, is not
dependent on information in the packet_info structure that might be
affected by dissectors other than the one for the protocol that
transports protocol B.

Furthermore, in a LINKTYPE_WIRESHARK_UPPER_PDU pcap or pcapng packet for
protocol B, there might not be any information to indicate the protocol
that transports protocol B, so there would have to be separate
dissectors for protocol B, with separate names, so that a tag giving the
protocol name would differ for B-over-byte-stream and B-over-packets.

So:

We rename EXP_PDU_TAG_PROTO_NAME and EXP_PDU_TAG_HEUR_PROTO_NAME to
EXP_PDU_TAG_DISSECTOR_NAME and EXP_PDU_TAG_HEUR_DISSECTOR_NAME, to
emphasize that they are *not* protocol names, they are dissector names
(which has always been the case - if there's a protocol with that name,
but no dissector with that name, Wireshark will not be able to handle
the packet, as it will try to look up a dissector given that name and
fail).

We fix that exported PDU dissector to refer to those tags as dissector
names, not protocol names.

We update documentation to refer to them as DISSECTOR_NAME tags, not
PROTO_NAME tags.  (If there is any documentation for this outside the
Wireshark source, it should be updated as well.)

We add comments for calls to dissector_handle_get_dissector_name() where
the dissector name is shown to the user, to indicate that it might be
that the protocol name should be used.

We update the TLS and DTLS dissectors to show the encapsulated protocol
as the string returned by dissector_handle_get_long_name(); as the
default is "Application Data", it appeaers that a descriptive name,
rather than a short API name, should be used.  (We continue to use the
dissector name in debugging messages, to indicate which dissector was
called.)
2022-09-10 22:37:11 -07:00
John Thacker 3f6c273e11 import_text: Check writable encap types against pcapng
Since Import from Hex Dump creates a pcapng temporary file, use
the list of encapsulations we can write to pcapng instead of pcap.

In particular, this makes WTAP_ENCAP_SYSTEMD_JOURNAL possible, so make
text_import capable of writing that encapsulation by using the proper
rec_type and block. It's not clear why someone would have a binary
hex dump of this text based format, but it works.
2022-01-16 03:34:34 +00:00
John Thacker f85f077b54 text_import: Allow fake IP headers with Raw IP encapsulation
In text2pcap and Import from Hex Dump, allow fake IP headers with
the appropriate versions when the Raw IP, Raw IPv4, and Raw IPv6
encapsulations are specified. In such cases, do not add a dummy
Ethernet header.

Continue to reject other encapsulations besides these, Ethernet,
and Wireshark Upper PDU when appropriate. Add some checks for the
encapsulation type in text_import as well, instead of just assuming
that the callers handle it correctly.
2022-01-11 08:46:44 -05:00
John Thacker ad035ed438 text2pcap: Case insensitive match for ISO time option
Let the user select ISO 8601 time format with "ISO", "iso",
or anything in between.
2022-01-11 05:12:13 +00:00
John Thacker 175e24a30b text_import: Add default IPv6 addresses
Add some default IPv6 addresses, used in place of the unspecified
address. These are unique local addresses as in RFC 4193 with
a global ID generated using the pseudo-random algorithm mentioned
therein.
2022-01-08 20:23:10 -05:00
Guy Harris 72a4210828 text_import: "localtime()" is an API, "local time" is local time. 2022-01-04 15:17:30 -08:00
John Thacker 42084c2d17 text2pcap: Move SHB and IDB setup to ui/text_import
Move the parameter setup to text_import, so that later it can
be called from the GUI, including the interface name. (This has
to be a separate function because these parameters need to be
set before the call to wtap_dump_open, which is different for
regular files vs temp files vs stdout.)
2021-12-30 17:05:06 +00:00
John Thacker 021c25e22c text2pcap: Use standard log debug level
Remove the '-d' option from text2pcap, and move the two levels
of debug messages in text2pcap and text_import to either
LOG_LEVEL_DEBUG or LOG_LEVEL_NOISY as appropriate.
2021-12-30 01:17:06 +00:00
John Thacker c1d7069a83 text_import: Only popup a warning about offsets the first time
Only warn about the parser getting an unexpected offset when
using OFFSET_NONE the first time. Use log warnings for subsequent
messages.

Strip off the whitespace/newline/colon from the offset when adding
it to the message, only output the offset number.
2021-12-29 14:45:10 +00:00
Guy Harris b38987573e text_import: use 4-space indentation for number_of_padding_bytes().
It's the only routine that doesn't use 4-space indentation.
2021-12-28 20:57:28 +00:00
John Thacker 44d27e975a text_import: Switch default IPv4 addresses to what text2pcap used
text2pcap used 10.1.1.1 and 10.2.2.2 for default IPv4 addresses,
and "Import From Hex Dump" used 1.1.1.1 and 2.2.2.2. The former
are a little bit better for defaults since they're RFC 1918
private IP addresses, so let's use them for the common code.
2021-12-28 11:00:46 -05:00
John Thacker 7dc79c9a2f text_import: Fix custom IPv6 address handling
Fix a case where one address but not the other was set to a nonzero
IPv6 address and direction was indiciated.
2021-12-27 10:28:44 -05:00
João Valverde 0d5bfd44a8 Use a wrapper function to call strptime()
Encapsulate the feature requirements for strptime() in a
portability wrapper.

Use _GNU_SOURCE to expose strptime. It should be enough on glibc
without the side-effect of selecting a particular SUS version,
which we don't need and might hide other definitions.
2021-12-27 14:07:32 +00:00
John Thacker 23355cddf6 import_text: Add ASCII identification checkbox
Add a checkbox for the extra detection for ASCII in a hex+ASCII
hexdump even when the text looks like hexbytes to Import from Hex
Dump. Save and restore it from the settings. Work towards #16724.
2021-12-26 19:13:25 -05:00
John Thacker 9e7b5c9189 text2pcap: Use debug level
Pass the debug level parameter from text2pcap to text_import
so that it is used as it was before to print internal parsing
information.
2021-12-25 15:52:46 -05:00
Gerald Combs 38dbb8486f text import: Remove an unneeded cast.
Don't bother casting to a guint32. We check for large values further on.
2021-12-25 19:43:35 +00:00
John Thacker f63571c3e8 text_import: Ignore offsets in no offset mode
If we're in the no offset mode and we parse an offset,
warn the user and ignore. At the very beginning of the file try
adding it to the preamble, maybe there's something unfortunate
like an all numeric time stamp format (ISO-8601 Basic).
2021-12-25 08:39:29 -05:00
John Thacker 857d518c17 text_import: Use time format directly
Also use g_strcmp0 for setting the ISO format.
2021-12-25 03:35:24 +00:00
John Thacker 54c4c7b0a6 text_import: Another explicit cast for unsigned long and clang 2021-12-24 21:54:40 -05:00
John Thacker 96c299c6b8 text_import: Reduce globals
A bunch of the globals are simply copied from the input parameter
text_import_info_t, just use them directly.

Move the count for packets read and written into the info type,
so that callers like text2pcap can access them as results.
2021-12-24 08:20:27 -05:00
John Thacker 48574e3a58 text_import: Report errors and warnings
Don't exit in the middle with unexpected values. Report a failure
and return a failed exit status when something goes really wrong.
Use warnings when appropriate, like when a time code value couldn't
be parsed.
2021-12-23 19:26:45 -05:00
John Thacker bc9cfa6340 text_import: Allow ISO8601 format times
Includes allowing the string "ISO" in the format string text box
in the GUI, so this works in "Import from Hex Dump" as well as
being for the text2pcap transition. Part of #16724.
2021-12-23 11:42:51 -05:00
John Thacker bc4b27bbe2 text_import: Report failure to write
Use report_message and report wtap_dump failures. Pass in
the output filename and keep track of the frame numbers for
the message parameters.

Report failure to initialize the lex scanner in text_import
instead of in the GUI, so that it would be reported from text2pcap,
and because text_import might have other failure cases that are
not the scanner.

The regex parser returns a positive number of packets processed
on success; save that number in text_import, and return zero on
success to our callers.
2021-12-23 15:49:04 +00:00
John Thacker 8d421de42c text_import: port ASCII identification from text2pcap
This is the special check for canonical hex+ASCII textdump
files that looks for the edge case where the beginning of the
ASCII column has strings that can be mistaken by the parser for
additional hex bytes. Not implemented in the GUI yet. Preparing
for text2pcap switchover. Related to #16724.
2021-12-22 20:08:29 -05:00
John Thacker 334d24ec5b text_import: Fix IPv6 payload length 2021-12-22 19:40:13 +00:00
John Thacker 6a74dae750 text_import: Add interface and internals for IPv6
Add IPv6 handling to text_import, including the ability to
handle dummy IPv6 addresses instead of IPv4. GUI support is
still TBD. This further reduces the number of text2pcap features
that ui/text_import does not yet support. Related to #16724.
2021-12-22 05:13:17 +00:00
John Thacker 3ff0c753a1 text_import: Add interface and internals for dummy IPv4 addresses
Add dummy IPv4 addresses to the text_import_info_t struct, and
use them if set in the same way text2pcap does. GUI support in
"Import from Hex Dump" is not added yet. This is also part of the
work for text2pcap to eventually call text_import. Related to #16724.
2021-12-22 02:41:11 +00:00
John Thacker 4cfae8e378 text_import: pcap_link_type -> wtap_encap_type
The encapsulation type that text_import expects and puts
directly into rec.rec_header.packet_header.pkt_encap is a
wiretap encap type, not a pcap link type. Fix the name and
comment appropriately.
2021-12-22 01:00:19 +00:00
John Thacker db10235d68 text_import: Handle SCTP and minimum packet lengths
Correctly handle when a minimum packet length forces fragmentation of
SCTP and we are generating dummy SCTP DATA chunk headers: mark fragmentation
in the chunk flags and set the transmission sequence number and
stream sequence number appropriately.

Port from text2pcap commit f8d48662c8
Part of #16724.
2021-12-18 22:45:02 -05:00
John Thacker f89d536503 text_import: Fix direction detection in Import from Hexdump
If the first character of the preamble indicates direction, it
needs to be skipped over and not tested as part of the timestamp.
2021-12-18 00:49:42 +00:00
John Thacker b4054d3879 text_import: Time delta between packets without timestamp
The "Import from Hex Dump" time delta for packets without a timestamp
was changed to be a nanosecond, but the time resolution for the file
created by import_text_dialog is the default, microseconds. Until
that is configurable, the time tick used needs to be microseconds like
it was before.

Clean up the code so that it's a little more consistent about when
and how the extra time tick is added, namely:
1. If there is no time format passed in.
2. If time format conversion for the packet fails for any reason.

We don't add an extra delta in other situations, e.g. if packets just
happen to have the same valid time value.

Fix #15562.
2021-12-17 13:37:29 +00:00
John Thacker 5f5f03f0e8 text_import: Fix spelling and grammar 2021-12-17 12:55:52 +00:00
John Thacker a74fabf73f text_import: Parse entire timestamp from hex dumps
_parse_time, which uses g_strlcpy, expects that end_field points
to the position after the end of the field (such as the \0.)
text_import_regex handles this correctly, but when importing from
hex dumps the last character of the timestamp was being cut off,
which makes a big difference when fractional seconds are not used.
2021-12-16 00:07:08 +00:00
João Valverde 59c082c046 Add new global header wireshark.h with guideline
Remove ws_diag_control.h from config.h because that was a workaround
for the lack of a public global header. Fix the resultant build errors.
2021-10-22 06:41:44 +00:00
Guy Harris c6717dc6b3 text_import.c: get EXP_PDU_TAG_PROTO_NAME from the header.
Don't hardcode 12, use EXP_PDU_TAG_PROTO_NAME from
wsutil/exported_pdu_tlvs.h.
2021-08-20 14:58:44 -07:00
Guy Harris e8a8fab18c text_import: create a wtap_block_t before calling wtap_block_add_...option.
Those routines can't add an option if there's no block to add it to;
this meant that neither the direction nor the sequence number would be
set when importing a packet.
2021-07-21 00:03:47 -07:00
Guy Harris ef542759d0 text_import: only add the packet flags if we have them.
If we don't know the packet direction, don't bother adding the packet
flags option.

While we're at it, don't bother casting a guint64 to guint64.
2021-07-20 14:45:52 -07:00
David Perry dc7089e831 Carry drop count/packet ID/queue ID as options on packet block 2021-07-19 21:25:40 +00: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 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
Gerald Combs 9222bd77cd Remove unneeded modelines in ui.
Remove the editor modeline blocks from the source files in ui that use 4
space indentation by running

perl -i -p0e 's{ \n+ /[ *\n]+ editor \s+ modelines .* shiftwidth= .* \*/ \s+ } {\n}gsix' $( ag -l shiftwidth=4 $( ag -g '\.(c|cpp|h|m|mm)') )

This gives us one source of indentation truth for these files, and it
*shouldn't* affect anyone since

- These files match the default in our top-level .editorconfig.

- The one notable editor that's likely to be used on these files and
*doesn't* support EditorConfig (Qt Creator) defaults to 4 space
indentation.
2021-04-20 07:43:39 +00:00
Guy Harris 2b9a6ee592 text_import: just suppress the two-initializers warning.
Stick with the simpler "init everything to invalid, and then override
that" mechanism, and just turn off the warning for thse structures.
2021-03-27 14:00:44 -07:00
Guy Harris fd39930f40 text_import: don't initialize array elements twice.
Some compilers warn about it with -Winitializer-overrides, and default
to setting that.
2021-03-27 12:35:01 -07:00
Paul Weiß 537c5f2955 Regex text imoprt: MSVC compiling and updated timestamps
replaced [min ... max] = val initiallizers with a macro expansion
removed __attibute__
updated timestamps to march
2021-03-26 06:44:25 +00:00
Paul Weiß 8c1b29a597 Regex based textfile import
Modularized the parser backend slightly to have the needed hooks
Modified the timestamp format slightly to enable arbitrary postion for
second fractions
Added a regex based seeking parser for textfiles as frontend alternative
to text_import_scanner.l
Regex is using the GLib implementation
Supported frame-data formats are bin, hex, oct and base64
Regex based importing UI
Fixed Meory-leak in ImportTextDialog::exec()
A new tab was added to the text_import ui to accomodate the new fields
Hints are available and styled accordingly
2021-03-26 06:44:25 +00:00
Martin Mathieson a5703f22cb More changes arising from PVS-Studio output.
/opt/SourceCode/wireshark/epan/dissectors/packet-ip.c	1556	err	V547 Expression 'opt == (1 | 0x00)' is always true.
/opt/SourceCode/wireshark/epan/dissectors/packet-ipdc.c	739	warn	V547 Expression 'payload_len < 4' is always false.
/opt/SourceCode/wireshark/ui/text_import.c	1049	err	V547 Expression 'info->offset_type == OFFSET_DEC' is always true.

None of these are actual bugfixes.

Bug: 16335
Change-Id: I6d0d3bb92c70ea625fc8b559e7a2bc5ba4e29e25
Reviewed-on: https://code.wireshark.org/review/37136
Petri-Dish: Martin Mathieson <martin.r.mathieson@googlemail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Martin Mathieson <martin.r.mathieson@googlemail.com>
2020-05-06 08:35:11 +00:00
Jaap Keuter c642c1a0a4 text import: make TCP dest port truly direction dependant
During introduction of proper direction support this line was left over,
causing TCP dest port to remain independant of direction. This change
simply drops the line.
See CID 1444115

Change-Id: I4ff362925e422bc57cfa3842127ddaf8695cf303
Reviewed-on: https://code.wireshark.org/review/32902
Petri-Dish: Anders Broman <a.broman58@gmail.com>
Tested-by: Petri Dish Buildbot
Reviewed-by: Anders Broman <a.broman58@gmail.com>
2019-04-20 06:59:27 +00:00