Denis Ovsienko [Fri, 7 Feb 2025 11:52:39 +0000 (11:52 +0000)]
Reimplement the tests similarly to libpcap. [skip appveyor]
Import TESTlib.pm, TESTst.pm and TESTmt.pm from libpcap. In TESTrun use
strict and warnings, also address all Perl issues that manifest because
of that, remove old code that the imported files make redundant and
clean the rest up. Ibid., remove the core dump file before every test
and apply the "only this one test" mode even if the test does not come
from the TESTLIST file; focus on tcpdump specifics and have the imported
files handle all test/result logistics.
The latter among other things places all temporary test files in a
proper temporary directory rather than the source tree, which in turn
eliminates the tests/NEW and tests/DIFF temporary directories, which
also includes *.out.raw.stderr files; the .passed and .failed files have
been gone since commit b82970c in 2020. This way, the tests/.gitignore
file no longer has a purpose, so remove it and the associated exemption
for TEST_DIST in Makefile. Remove failure-outputs.txt from the
top-level .gitignore as well. Prune "make distclean" as well.
Merge tests/*.tests into TESTrun: these are a part of the source tree
rather than volatile external data, so instead of implementing the
required run-time logistics just place the Perl data structures in the
only Perl script that uses them. Convert "config_set" and
"config_unset" using "skip" and equivalent Perl expressions.
Since these changes rewrite most of TESTrun, reindent and reformat it to
match the code style of the new files.
Denis Ovsienko [Mon, 20 Jan 2025 14:01:45 +0000 (14:01 +0000)]
PTP: Refine timestamp printing.
In ptp_print_timestamp_identity() and ptp_print_announce_msg() use
ptp_print_timestamp() to deduplicate code. In ptp_print_timestamp()
change the format to SECONDS.NANOSECONDS and indicate an invalid
nanoseconds value. Update the tests. This resolves GH issue #1260.
Denis Ovsienko [Mon, 20 Jan 2025 13:59:44 +0000 (13:59 +0000)]
Report invalid microseconds as "us", not "ms".
In timeval-operations.h for microseconds and nanoseconds define both the
maximum number of units per second and the string to use for reporting
an invalid value. Use the new macros in ts_frac_print() and update a
test.
For consistency in print-arista.c instead of MAX_VALID_NS and
BOGUS_NS_STR use the macros from timeval-operations.h.
Francois-Xavier Le Bail [Fri, 17 Jan 2025 11:11:13 +0000 (12:11 +0100)]
Update the GitHub issue template for the new workflow
Summary:
Create the .github/ISSUE_TEMPLATE directory
Rename the file ISSUE_TEMPLATE to .github/ISSUE_TEMPLATE/issue_template.md
Update this file with some keywords (name, about, ...)
Add a .github/ISSUE_TEMPLATE/config.yml file containing
"blank_issues_enabled: false".
Bill Fenner [Tue, 11 Oct 2022 20:10:46 +0000 (13:10 -0700)]
ISO: avoid undefined behavior and integer overflow in the fletcher checksum calculation
The fletcher checksum calculation would sometimes left-shift
a negative number, which is an undefined operation. Rework the
code to avoid this.
checksum.c:186:20: runtime error: left shift of negative value -36
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior checksum.c:186:20
Unlike some checksum routines that use the defined semantics of
2's-complement unsigned overflow to their advantage, this one
gets the wrong value if it is allowed to overflow, due to the
use of mod-255.
Convert c1 to uint64_t to avoid overflow.
checksum.c:163:16: runtime error: unsigned integer overflow: NNN + NNN
cannot be represented in type 'unsigned int'
Use integers during subtraction to avoid implicit conversion to unsigned
when calculating both x and y
checksum.c:172:18: runtime error: unsigned integer overflow: NNN - NNN
cannot be represented in type 'unsigned int'
checksum.c:172:9: runtime error: implicit conversion from type
'unsigned int' of value NNN (32-bit, unsigned) to type 'int' changed
the value to -NNN (32-bit, signed)
checksum.c:173:12: runtime error: unsigned integer overflow: NNN - NNN
cannot be represented in type 'unsigned int'
checksum.c:173:9: runtime error: implicit conversion from type
'unsigned int' of value NNN (32-bit, unsigned) to type 'int' changed
the value to -NNN (32-bit, signed)
Thus sizeof(*fsidp) is > 14.
Delete the else block as dead code and the two useless if.
This should remove two Visual Studio warnings:
parsenfsfh.c(318,25): warning C4127: conditional expression is constant
parsenfsfh.c(319,22): warning C4127: conditional expression is constant
Guy Harris [Tue, 7 Jan 2025 20:02:17 +0000 (12:02 -0800)]
Fix comments. [skip ci]
Yes, the offending set of *BSDs (FreeBSD, DragonFly BSD, and
CupertinoBSD) all do define IPPROTO_PIGP. And the #defines are
IPPROTO_xxx, not IP_PROTO_xxx.
Guy Harris [Tue, 7 Jan 2025 07:23:21 +0000 (23:23 -0800)]
Add comments about the IGRP/EIGRP protocol number and #define mess.
The current IANA protocol number assignments page lists 9 as "any
private interior gateway (used by Cisco for their IGRP)" and 88 as
"EIGRP" from Cisco.
Recent FreeBSD and DragonFly BSD <netinet/in.h> headers define
IP_PROTO_IGRP as 9 and IP_PROTO_IGRP as 88. We define IP_PROTO_PIGP
("private interior gateway protocol") as 9 and IP_PROTO_EIGRP as 88;
those names* better match what the current protocol number assignments
say.
Guy Harris [Sat, 4 Jan 2025 23:29:19 +0000 (15:29 -0800)]
tcpdump: show error message for PCAP_ERROR_CAPTURE_NOTSUP.
If an attempt to open a capture device failed because capturing isn't
supported on that device, check whether an error message with a further
explanation was provided and, if so, report it.
Francois-Xavier Le Bail [Fri, 3 Jan 2025 15:08:32 +0000 (16:08 +0100)]
IP: Use ND_TTEST_LEN() instead of a custom bounds check
This avoids an invalid-pointer-pair AddressSanitizer error with options
-fsanitize=address -fsanitize=pointer-compare
and
ASAN_OPTIONS=detect_invalid_pointer_pairs=1
The error was:
ip_printroute_asan : TEST FAILED[...]
0x60600000006a is located 14 bytes after 60-byte region
[0x606000000020,0x60600000005c)
allocated by thread T0 here:
#0 0x558ce1c5390e in malloc
(/home/cpe/soft-origin/tcpdump/my-tcpdump/tcpdump+0x1fd90e)
#1 0x558ce1efbba3 in pcap_check_header
/home/cpe/soft-origin/tcpdump/my-libpcap/sf-pcap.c:480:14
0x60600000005c is located 0 bytes after 60-byte region
[0x606000000020,0x60600000005c)
allocated by thread T0 here:
#0 0x558ce1c5390e in malloc
(/home/cpe/soft-origin/tcpdump/my-tcpdump/tcpdump+0x1fd90e)
#1 0x558ce1efbba3 in pcap_check_header
/home/cpe/soft-origin/tcpdump/my-libpcap/sf-pcap.c:480:14
SUMMARY: AddressSanitizer: invalid-pointer-pair
/home/cpe/soft-origin/tcpdump/my-tcpdump/print-ip.c:429:55 in ip_print
Francois-Xavier Le Bail [Sun, 22 Dec 2024 14:12:56 +0000 (15:12 +0100)]
Add sub-second packet timestamp checks for invalid micro/nano
Now prints e.g.:
2 17:16:10.1000000 (invalid ms) IP [...]
3 17:16:10.2147483648 (invalid ms) IP [...]
or
2 17:16:10.1000000000 (invalid ns) IP [...]
3 17:16:10.2147483648 (invalid ns) IP [...]
Denis Ovsienko [Tue, 17 Dec 2024 19:33:40 +0000 (19:33 +0000)]
Cirrus CI: Do not install coreutils on macOS. [skip appveyor]
libpcap build & test process now tolerates a missing timeout(1), so
let's keep the build environment as close to the original as possible.
This reverts commit 673a2fe.
Guy Harris [Tue, 17 Dec 2024 09:52:52 +0000 (01:52 -0800)]
pflog: don't use PF_ as a prefix for #defines.
PF_ is used as a prefix for packet family values, and that may cause a
collision between PF_ packet family values, such as PF_DIVERT, and PF_
action valus, such as... PF_DIVERT.
Use PFACT_ for action values and PFDIR_ for direction values.
Guy Harris [Tue, 17 Dec 2024 08:22:06 +0000 (00:22 -0800)]
pflog: handle all types of pflog files, as best as can be done.
We can distinguish between FreeBSD, OpenBSD, and everything else
(NetBSD, DragonFly BSD, and Darwin) based on the length field in the
header.
For NetBSD, DragonFly BSD, and Darwin, the differences are the meaning
of certain reason and action codes; we just mark those with the OSes and
meanings, so the user will have to figure out whether reason code 15 is
"state-locked' (NetBSD)" or "dummynet" (Darwin)". The other ones
shouldn't occur on OSes other than Darwin, but we mark it just in case
they do.
Fix the handling of "UID not present"; that's 0xFFFFFFFFU in FreeBSD,
OpenBSD, and DragonFly BSD, but it's 0x7FFFFFFFU in NetBSD and Darwin,
so for "neither NetBSD nor OpenBSD" we check for both of those values.
Do the checks for minimum and maximum header lengths before we round
the header length up.
Guy Harris [Sun, 15 Dec 2024 21:54:01 +0000 (13:54 -0800)]
CI: install coreutils with Homebrew on macOS. [skip appveyor]
We need it because we do an install of libpcap, including "make check",
and "make check" requires Homebrew's coreutils in order to get the
timeout command.
Guy Harris [Wed, 11 Dec 2024 02:54:32 +0000 (18:54 -0800)]
CI: expand the matrix for AppVeyor and fix issues that finds.
Add ARM64 builds for VS 2019 and VS 2022.
Fix cmake/Modules/FindPCAP.cmake to look in the right directory for pcap
libraries if the build isn't being done for 32-bit or 64-bit x86.
Use the -A flag for all generators; according to the CMake
documentation, they're supported for all generators in CMake 3.1 and
later and, on Windows, we require CMake 3.12 or later. That ensures
that CMAKE_GENERATOR_PLATFORM will be set, so that we can use it to
determine the right directory in which to look for pcap libraries.
Guy Harris [Tue, 10 Dec 2024 18:55:23 +0000 (10:55 -0800)]
autotools, CMake: fix issues with snprintf test and sanitizers.
Avoid trying to cast negative values to unsigned types, or doing shifts
of signed types, in order not to have the test program fail if we're
building with undefined-behavior sanitizers enabled.
See the-tcpdump-group/libpcap#1396 for the equivalent libpcap issue.
Guy Harris [Tue, 10 Dec 2024 04:35:24 +0000 (20:35 -0800)]
CMake: check whether check_c_source_runs() works.
That's the simplest way to check whether we can use
check_c_source_runs() to test for a suitable snprintf; it's easier than
trying to find out the target instruction set architecture and comparing
it with the host instruction set architecture, as CMake doesn't provide
any mechanism to provide the target instruction set architecture, on all
platforms, in a form that can be compared with the host instruction set
architecture, and even if the target is different, we may be able to run
code for that instruction set architecture if, for example, it's a
32-bit version of the instruction set architecture on which the build is
being done, or if there's a binary emulator.
Francois-Xavier Le Bail [Sun, 8 Dec 2024 22:08:52 +0000 (23:08 +0100)]
Fix two undefined behaviors for the pcap_loop() call
Limit the --skip argument to INT_MAX.
Limit the sum of -c and --skip arguments to INT_MAX.
Fix the regression in 3eab64d3: The '--skip 0' option is allowed to get
the first packet in some loop e.g. in a shell script.
The errors were:
tcpdump.c:2696:8: runtime error: implicit conversion from type 'int' of
value -1 (32-bit, signed) to type 'u_int' (aka 'unsigned int')
changed the value to 4294967295 (32-bit, unsigned)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcpdump.c:2696:8
tcpdump.c:2696:8: runtime error: implicit conversion from type 'u_int'
(aka 'unsigned int') of value 4294967295 (32-bit, unsigned) to type
'int' changed the value to -1 (32-bit, signed)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior tcpdump.c:2696:8
Guy Harris [Mon, 9 Dec 2024 21:17:56 +0000 (13:17 -0800)]
autotools, CMake: add a comment.
We should have our own copies of the ONC RPC headers, rather than
relying on the OS to supply them. We've already done that for most if
not all other protocols.
Francois-Xavier Le Bail [Fri, 6 Dec 2024 13:56:17 +0000 (14:56 +0100)]
LISP: Add two length checks for "invalid" cases
Moreover:
Update a ND_ICHECK_U to ND_ICHECKMSG_U().
Add an "unsuported address family identifier" message.
Add two test cases (a pcap with two outputs, with/without -v).
Francois-Xavier Le Bail [Thu, 21 Nov 2024 12:36:49 +0000 (13:36 +0100)]
LISP: Modernize packet parsing
Define ND_LONGJMP_FROM_TCHECK and remove a 'trunc' label.
Make a bounds check conditional.
Use ND_ICHECK_U() for a length test.
Fix a bounds check, not invalid, but truncated.
(The bounds check is done by hex_print_with_offset() via hex_print().)
Use ND_TTEST_LEN() instead of testing ndo->ndo_snapend.
Remove an useless variable ('packet_iterator' same as 'bp').
Remove/update some comments.
Fix some indentations.
Remove some extra blank lines.
Guy Harris [Wed, 13 Nov 2024 07:30:01 +0000 (23:30 -0800)]
CMake: fix to support CMake 3.31.
Expand the "still support old versions of CMake, for the benefit of
people with older versions, but avoid deprecation warnings/errors"
section to handle the deprecation of pre-3.10 versions by 3.31.
Casper Andersson [Mon, 11 Mar 2024 17:49:47 +0000 (18:49 +0100)]
ptp: Add test for management packets
Test setup:
ip link add link vethA type veth peer name vethB
ip link set dev vethA up
ip link set dev vethB up
ptp4l -2 -P -S -i vethA &
tcpdump -i vethA 'ether[14] = 0xD' -w ptp_management.pcap &
Tcpdump filtering on only management packets (0xD) to skip capturing
other traffic that is already covered by other tests.
Sidenote: the management packets contains a TLV at the end and I
included 5 of them (out of the total ~50 listed in the
standard). Tcpdump currently does not print the TLV.
Casper Andersson [Mon, 11 Mar 2024 17:06:11 +0000 (18:06 +0100)]
ptp: Fix management packet fields
`bp` was modified inside the function but the change was not
reflected back outside, resulting in the fields afterwards accessing
the wrong part of the packet.
Guy Harris [Tue, 8 Oct 2024 19:40:21 +0000 (12:40 -0700)]
Make tcpdump find wpcap.dll on Windows if it's not in the system library.
See https://npcap.com/guide/npcap-devguide.html#npcap-feature-native-dll-implicitly
for details on what's being done.
Fix '-tt' option printing when time > 2106-02-07T06:28:15Z
Currently the printing with '-tt' option (unix time) is incorrect.
Some examples:
1) test: time_2106_overflow-tt
0.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56
Should be: 4294967296.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56
2) test: time_2107-tt 28315904.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56
Should be: 4323283200.000000 IP 192.168.1.11.43966 > 209.87.249.18.53: UDP, length 56
Two build examples:
64-bit build: tv->tv_sec has type '__time_t' (aka 'long').
32-bit build with _TIME_BITS=64: tv->tv_sec has type '__time64_t'
(aka 'long long').
Using 'unsigned' cast is incorrect for these 64-bit data.
Thus convert to 'int64_t' and print with '"%" PRId64'.
Add two test cases (existing pcapng printed with -tt).