Commit Graph

1185 Commits

Author SHA1 Message Date
João Valverde a34a234cf2 wslog: Add ws_log_buffer()
Use the new API with dot11decrypt debug.
2021-09-18 10:59:10 +01:00
João Valverde dd59d1fcf9 ws_getopt: Add test suite skeleton with some basic tests 2021-09-17 14:15:55 +00:00
João Valverde fea994855d Revert "ws_getopt: Disable MSVC warning C4244"
This reverts commit ac3a30f61b.

Clang build also has this warning enabled. Fixed in
3c484f278b.
2021-09-17 02:45:50 +01:00
Gerald Combs 3c484f278b ws_getopt: Fix some clang warnings.
Fix

wsutil/ws_getopt.c:93:21: error: possible misuse of comma operator here [-Werror,-Wcomma]
                return ws_optind++, -1;
                                  ^
wsutil/ws_getopt.c:93:10: note: cast expression to void to silence warning
                return ws_optind++, -1;
                       ^~~~~~~~~~~
                       (void)(    )
wsutil/ws_getopt.c:188:11: error: possible misuse of comma operator here [-Werror,-Wcomma]
                                name++, opt++;
                                      ^
wsutil/ws_getopt.c:188:5: note: cast expression to void to silence warning
                                name++, opt++;
                                ^~~~~~
                                (void)( )
wsutil/ws_getopt.c:199:15: error: implicit conversion loses integer precision: 'long' to 'int' [-Werror,-Wshorten-64-to-32]
                        int l = arg-start;
                            ~   ~~~^~~~~~

Add a .editorconfig entry for ws_getopt.[ch].
2021-09-16 18:07:02 -07:00
João Valverde ac3a30f61b ws_getopt: Disable MSVC warning C4244 2021-09-17 00:43:54 +01:00
João Valverde 2deb1c95d9 Merge ws_getopt source files
No need to keep a separate ws_getopt_long.c file.
2021-09-17 00:43:54 +01:00
João Valverde 8df2a73594 Use the musl in-tree getopt_long() everywhere
Besides the obvious limitation of being unavailable on Windows,
the standard is vague about getopt() and getopt_long() has many
non-portable pitfalls and buggy implementations, that increase
the maintainance cost a lot. Also the GNU libc code currently
in the tree is not suited for embedding and is unmaintainable.

Own maintainership for getopt_long() and use the musl implementation
everywhere. This way we don't need to worry if optreset is available,
or if the $OPERATING_SYSTEM version behaves in subtly different ways.

The API is under the Wireshark namespace to avoid conflicts with
system headers.

Side-note, the Mingw-w64 9.0 getopt_long() implementation is buggy
with opterr and known to crash. In my experience it's a headache to
use the embedded getopt implementation if the system provides one.
2021-09-17 00:43:54 +01:00
João Valverde 7462e76884 Add musl getopt_long() source files to project
Copied verbatim from musl 1.2.2.

https://www.musl-libc.org
2021-09-17 00:28:06 +01:00
João Valverde 4d873d4ce2 wsutil/to_str: Use a macro to check buffer size 2021-09-17 00:08:41 +01:00
João Valverde 18c155a3ca wsutil: Remove ip6_to_str_buf_with_pfx()
Writing a string prefix shouldn't require a specialized function here.
2021-09-17 00:08:41 +01:00
João Valverde 364df939ea wsutil: Rewrite ip6_to_str_buf() 2021-09-17 00:08:40 +01:00
João Valverde d4c7978f68 wsutil: Add ip_to_str() 2021-09-16 23:18:53 +01:00
João Valverde 8c4a479c52 Move more numerical functions to wsutil/to_str.h 2021-09-16 20:55:03 +01:00
João Valverde 8304ced0e6 wsutil: Add some tests for word_to_hex() 2021-09-16 18:21:14 +01:00
João Valverde 24fd8c6740 Move more numerical epan/*to_str() routines to wsutil 2021-09-16 18:21:14 +01:00
João Valverde 44538f6e4d wsutil: Add tests for to_str_back() 2021-09-16 15:53:14 +00:00
João Valverde 8b70e24889 wsutil/to_str: Rename some functions for consistency 2021-09-16 15:53:14 +00:00
João Valverde 8a584222f1 Move epan/*to_str_back() functions to wsutil 2021-09-16 15:53:14 +00:00
João Valverde bd33320521 wslog: Add macro to validate arguments and return
Similar to g_return_if_fail(), etc.
2021-09-15 18:19:07 +00:00
João Valverde 20dc422550 wsutil: Add test for bytes_to_str_punct() 2021-09-15 18:38:57 +01:00
Graham Bloice 58207d2f8d Windows: Update displayed OS version info
MS has changed the registry key that holds the version for display
from 20H2 onwards.
2021-09-11 14:27:21 +00:00
Jorge Mora 981ec7f3c7 iwarp_mpa: fix iWarp MPA for NFS-over-RDMA
On the first packet of the conversation, the MPA layer is
dissected correctly followed by the DDP, RDMAP, RPC-over-RDMA,
RPC and NFS layers. The MPA layer sets the TCP conversation as
MPA protocol but when it dissects the RPC layer it also sets
the TCP conversation as RPC protocol thus overwriting the previous
protocol.

Added new port type PT_IWARP_MPA so that when the RPC layer
is dissected it does not overwrite the default protocol for
the TCP conversation which has already been set to MPA.

Fixes #15869.
2021-08-31 08:14:31 +00:00
Guy Harris e490f93072 wmem: don't check whether sizeof(type) is <= 0.
This should fix the cppcheck warning "The unsigned expression
'sizeof(struct _PKT_INFO)' will never be negative so it is either
pointless or an error to check if it is."

wmem_safe_mult() was only used to do an overflow-safe multiplication of
a type size and a count of elements of that type; replace it with
wmem_safe_mult_type_size(), which takes the type as the first argument,
and checks only whether the count of elements is <= 0.
2021-08-24 20:58:00 -07:00
Guy Harris 4de9f6ef83 Fix some issues with Exported PDUs.
Fix the description in wsutil/exported_pdu_tlvs.h to reflect reality
(i.e., to match what the code in Wireshark that reads the exported PDU
TLVs, and all code that writes them, does).

In the code that dissects them, treat all strings as FT_STRINGZPAD, as
any null bytes at the end of the string are padding, not part of the
string.

See merge request !3895 and issue #17535.
2021-08-21 02:31:45 -07:00
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
Alexis La Goutte 17f474406a nstime: Fix Dead Store (found by Clang Analyzer)
Although the value stored to 'n_scanned' is used in the enclosing expression, the value is never actually read from 'n_scanned'
2021-07-30 20:43:55 +00:00
João Valverde 0693674494 wslog: Add function to log directly without filtering
Used to write custom logging functions.
2021-07-29 20:17:44 +01:00
João Valverde 7b845e7194 wsutil: rename bytestring_to_str() -> bytes_to_str_punct() 2021-07-29 17:23:05 +00:00
João Valverde 177e5cda1f wsutil: Clean up unit test namespaces
Remove implicit root and separate tests for proper coverage.
2021-07-29 17:23:05 +00:00
João Valverde f0b02dd0ff wsutil: Add max length argument to bytes_to_str() 2021-07-29 17:23:04 +00:00
João Valverde 1ff6cc7b27 wsutil: Add some tests for bytes_to_str() 2021-07-29 17:23:04 +00:00
João Valverde c3bd5c9d91 Move bytes_to_str() to wsutil
This utility function is useful outside of epan. Move it to wsutil
and export the interface.

The move isn't completely clean as it requires duplicating two small
inline functions but that was necessary to avoiding moving too much at
once.
2021-07-29 17:23:04 +00:00
João Valverde 0983eb2456 wslog: Avoid macro duplication 2021-07-29 01:52:39 +01:00
João Valverde 925e01b23f Remove duplicate format_size() function
We have two format_size()s, with and without wmem scoped memory.
Move the wmem version to wsutil and add a convenience macro to
use g_malloc()ed memory.
2021-07-26 14:56:11 +00:00
João Valverde 7f9c1f5f92 Move wmem to wsutil
This allows wmem to be used from other libraries, namely wsutil.
It is often the case that a funtion exists in wsutil and cannot
be used with a wmem scope, requiring some code duplication or
extra memory allocations, or vice-versa, code in epan cannot be
moved to wsutil because it has a wmem dependency.

To this end wmem is moved to wsutil. Scope management remains part
of epan because those scope semantics are specific to dissection.
2021-07-26 14:56:11 +00:00
João Valverde 6ab67e2aa6 wslog: Minor fixes and cleanups 2021-07-25 18:21:31 +00:00
Gerald Combs 34ef2066e5 CMake: Don't bother checking for fcntl.h or floorl.
fcntl.h appears to be available on all of our supported platforms,
including Windows. We've also been including it without HAVE_FCNTL_H
guards in a few places (e.g. sshdump.c) without any issues for some
time.

floorl is part of C99.
2021-07-15 06:41:05 +00:00
Gerald Combs ff60fcf92d CMake: Adjust wsutil includes and linking.
Mark wsutil's includes SYSTEM PRIVATE. This exposed a lot of targets
that were indirectly picking up include paths via the wsutil target, so
add direct includes where needed. The G.722 and G.726 codecs were
implicilty including tiffio.h; find it explicitly instead.

Mark some of wsutil's libraries PRIVATE, but leave commonly-used ones
PUBLIC.

Ping #17477.
2021-07-14 03:56:05 +00:00
João Valverde 89acb935bc wsutil: Start adding a test suite 2021-07-11 14:39:13 +00:00
João Valverde 396d560744 wsutil: Revert some changes to format_size()
Revert change to format_size() added in
f509a83381. This commit broke formatting
with spaces and introduced some dead code.

Also replace unnecessary call to format_size_wmem() and remove
unnecessary casts (since our warning settings were fixed in the
mean time).
2021-07-11 14:39:13 +00:00
João Valverde 6498f1fce5 wslog: Fix representation of null domain
Map "" to "(none)", besides NULL.
2021-07-09 23:43:49 +01:00
João Valverde de59975fc1 wslog: fixup copyright 2021-07-09 18:25:02 +01:00
João Valverde cb61645941 wslog: Fix comment 2021-07-09 18:24:39 +01:00
João Valverde 4124986a9c wslog: Prefer more modern time APIs
Functions clock_gettime() and timespec_get() cover all the platforms
we support with sub-second resolution in a a portable manner. Fallback
to using time().

Pass a struct timespec to the log writer callback for maximum
flexibility.
2021-06-29 14:19:55 +00:00
Guy Harris c125236e57 wslog: don't assume how big struct timeval's tv_usec is.
At least according to the Single UNIX Standard, it merely has to be big
enough to hold a value in the range [-1, 1000000], and there must be
*an* environment in which it's no *larger* than a long.

Just cast it to long, and continue to print the result of dividing it by
1000 with %03ld.
2021-06-28 07:59:33 +00:00
João Valverde 3fc5eb3f1f wslog: Replace g_date_time_format()
Calling GLib functions inside the log writer is not safe,
it might infinitely recurse or abort if g_date_time_* logs
warnings because we registered our log handler for GLib itself.
2021-06-28 00:09:30 +01:00
João Valverde ceedd7b334 wslog: Update API documentation and improve code formatting 2021-06-26 00:44:23 +01:00
João Valverde c6a920686c wslog: Check environment initialization for errors
Initialiaze the cmdarg error stream earlier.

Dumpcap also needs to know earlier if it is running in capture
child mode.
2021-06-26 00:18:26 +01:00
João Valverde c2c256f0d8 wslog: Fatal messages should always be active 2021-06-26 00:18:26 +01: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
João Valverde 7aae691f7d wsutil: Rewrite ws_assert() to minimize dependencies
This includes as little as possible in the assertion header, so
that it can be included globally in every file without pulling
any unwanted definitions. In particular pulling stdlib.h is
avoided because that can have side effects if it wants to
include non-portable extensions.

It is possible to have side-effects from include glib.h too, for
example because of G_LOG_DOMAIN.

These side-effects are usually avoidable with careful ordering
of pre-processor directives but with multiple levels of indirections
it can be hard to track. Better to make it robust to these kinds
of failures in the first place.

Also integrate with our logger for a cohesive experience (but
keep it a private dependency).
2021-06-25 22:06:32 +00:00
João Valverde 53704fb971 wsutil: Rewrite ws_log() to minimize dependencies
Minimizing the dependencies on other wsutil and GLib functions
reduces the chance that we will have a weird recursion pattern
in wslog and makes the code easier to analyze.
2021-06-25 22:06:32 +00:00
João Valverde 129046b518 wsutil: Fix incorrect header include
wsutil should not have any dependency on epan, replace the
extraneous header.
2021-06-25 03:14:22 +00:00
João Valverde cd05ec7232 wslog: Register log handler with GLib
This avoids having to manage two different implementations.
For example with this change GLib functions will terminate
if Wireshark's fatal log level is set to a matching level
and the --log-file option will also output messages from
GLib itself.
2021-06-24 02:31:42 +01:00
João Valverde a370024ca9 wslog: Fix initialization with invalid environment
We can't write to stderr outside of the default writer context.
Wireshark and tshark will block if we do that and dumpcap is
running as capture child.
2021-06-24 02:26:28 +01:00
João Valverde eb3417e38f wslog: Slight color and format change
This changes color use to be the very similar with GLib to
maintain familiarity. The only difference is that Message
and Info use a different color than Debug.

Also use the more familiar format of <domain> <level> instead
of <level> <domain>.
2021-06-24 00:06:19 +01:00
João Valverde 752b0fc320 Debug: Lower priority to "noisy" for pipe spawn output
Spawn output can include very long multiline extcap arguments.
2021-06-23 17:45:44 +00:00
João Valverde 7bc3a5629e wslog: Fix crash using a custom log file
Add missing va_copy() call.
2021-06-23 17:09:24 +00:00
Dario Lombardo f62138c0d5 Fix some includes. 2021-06-22 19:25:43 +00:00
João Valverde 2080661e88 wslog: Documentation fixups 2021-06-21 22:39:54 +01:00
João Valverde 585ddc9283 wslog: Format and color amendments 2021-06-21 22:25:47 +01:00
João Valverde 759bb234d0 wslog: Check if we are initialized and add missing inits
Instead of receiving the program name from GLib, pass it explicitly
to ws_log_init() instead  and use that to initialize the GLib program
name.

ws_log_parse_args() will now exit the program when it encounters an
argument error if exit_failure >= 0.
2021-06-21 16:03:29 +00:00
João Valverde c216bb85e7 wslog: Reverse order for level priority
Consistently speaking of ascending priority for higher levels
seems slightly more intuitive. Use that instead.
2021-06-21 16:03:29 +00:00
João Valverde b23d2f8519 wslog: Cleanup the filter/match logic 2021-06-21 16:03:29 +00:00
João Valverde 3256e45b4e wslog: Critical and error are always active.
The intention was that "error" and "critical" are *always*
active (always...). Do that.
2021-06-21 16:03:29 +00:00
João Valverde 256f5f6e30 wslog: "Warning" can also be set as fatal 2021-06-21 16:03:29 +00:00
Pascal Quantin 3ea51dba87 NGAP: fix dissection of multiple NGAP messages in the same HTTP2 packet
Also add dissection for more containers
2021-06-21 13:33:55 +00:00
João Valverde 7dea683bf1 wslog: Shorten ws_log_message_is_active() name 2021-06-21 00:07:21 +00:00
Guy Harris 72b2cf6672 ws_assert: remove a stray semicolon at the end of an inline function. 2021-06-19 03:04:49 +00:00
João Valverde b4eddd32c1 wslog: Set registered name earlier 2021-06-19 02:07:34 +01:00
João Valverde dddb33e398 wslog: Be more obvious in the log that the domain is unset
Currently we are not filtering the unset (NULL) domain, on
the assumption that every log call should belong to a defined
domain.

However there are still many places in the codebase where this isn't
true and the fact that the null/default domain name is omitted from
the output and never filtered is probably surprising and user-unfriendly.
Users might understandably assume the filtering is buggy.

Give an indication, such as (none)-MESSAGE, to make this more
obvious.
2021-06-19 02:07:34 +01:00
João Valverde 7f17d18012 wslog: Fix domain filtering
Fixes 051a74378d.
2021-06-19 01:17:05 +01:00
João Valverde a6738d72a0 wslog: Add support for inverted debug matches
The --log-debug and --log-noisy now accepts a '!' to invert the
match and disable the debug (noisy respectively) log level for
the listed domains.

Note this is different from --log-domains, that option
enables/disables the entire log domain itself, regardless of log
level.
2021-06-18 10:43:39 +01:00
João Valverde 051a74378d wslog: Use NULL for empty/default domain 2021-06-18 10:43:39 +01:00
João Valverde c5b3842639 wslog: Add more documentation 2021-06-17 12:00:10 +01:00
João Valverde ff9acff6f2 Replace usage of GLogLevel flags everywhere
ws_log_domains.h needs to be included before wslog.h to be used
to define WS_LOG_DOMAIN. Also the definition for enum ws_log_level
needs to be exported for other APIs so move that to ws_log_domains.h
and rename the file to ws_log_defs.h to reflect the new scope.
2021-06-17 12:00:10 +01:00
João Valverde 02e34357bc wslog: Add a noisy debug level
This is intended to replace logging in dissectors that has a
debug level with #ifdef DEBUG_foo and an extra level guarded
by a #ifdef DEBUG_EXTRA_foo.

But generally it can be used as another level of granularity
for debugging output, to avoid flooding the log with too
much information with typical usage.

Rename the filter functions without the unnecessary 'str'
suffix.
2021-06-17 12:00:09 +01:00
João Valverde ac50926d6f wslog: Add a new log-debug option
Option --log-debug or WIRESHARK_LOG_DEBUG is a list
of domains that are set to a "debug" log level. This
takes precedence over the normal log level and domain
filter options.
2021-06-17 12:00:09 +01:00
João Valverde 01001485b9 wslog: Add a new log-fatal option
Enviroment variable WIRESHARK_LOG_FATAL and command line
option --log-fatal set the fatal log level. Messages with
fatal or highr priority cause the program to abort. By
default the fatal level is "error", but it can be set to
"critical" or "warning" with this option.
2021-06-17 12:00:09 +01:00
João Valverde 36c32de869 wslog: Add support for inverted domain matches
Domain filter expressions starting with '!' invert the match.
Only domains that do not match become active. Note that '!'
must be the first character in the filter and applies to the
whole expression.
2021-06-17 12:00:09 +01:00
João Valverde 05ed76d4c0 wslog: Use plain format with "message" level
Try out a simpler format with the default log level.

Don't display process and file/function information with "message"
level (experimental).
2021-06-17 12:00:09 +01:00
João Valverde 39df3ae3c0 Replace g_log() calls with ws_log() 2021-06-16 12:50:27 +00: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
João Valverde 2c6d897b58 wslog: Add ws_logv_full() 2021-06-15 18:51:40 +01:00
João Valverde e37b2ae637 wslog: Remove unused macro 2021-06-15 18:51:40 +01:00
João Valverde 477e7f7300 wslog: Do not filter default domain 2021-06-15 18:51:40 +01:00
João Valverde bec7b0c609 wslog: Fixup color support 2021-06-15 18:51:38 +01:00
João Valverde ac4a0c056b wslog: Use g_date_time_format() 2021-06-15 18:28:02 +01:00
João Valverde 41fd46310f wslog: Change log format to display everything
Revert from alternating between function name and file name,
show both instead.
2021-06-14 22:05:35 +00:00
João Valverde 95396973e7 wslog: Add basic color support
This is just a basic framework to improve on, if desired.
2021-06-14 22:05:35 +00:00
João Valverde 69a217b95b wslog: Use buffered I/O
Use standard buffered I/O instead of printing to a string.
This is more efficient, cleaner and allows custom output per stream.
2021-06-14 22:05:35 +00:00
João Valverde 59eff63794 wslog: Rename default log level 2021-06-14 22:05:35 +00:00
João Valverde 42c6c4781f wslog: Add a diagnostic message. 2021-06-14 22:05:35 +00:00
João Valverde b91801a870 wslog: Add a --log-file cmd line option 2021-06-14 22:05:35 +00:00
João Valverde e86ac706ca wslog: Parse cmd line options in one pass 2021-06-14 22:05:35 +00:00
João Valverde 2d2cfa8d14 wslog: Make a variable static 2021-06-14 22:05:35 +00:00
João Valverde 5ddc007023 wslog: Include pid in format 2021-06-14 14:18:38 +01:00
João Valverde 675c428dca wslog: Fix shadow variable 2021-06-14 13:13:12 +01:00
João Valverde 55f0fba85d wslog: Make error and critical levels not conditional 2021-06-14 13:13:12 +01:00
João Valverde 700d8e34db wslog: Rename environment vars to according to our conventions 2021-06-14 13:13:12 +01:00