Guy Harris [Sat, 10 Jun 2023 07:52:23 +0000 (00:52 -0700)]
gre: clean up GRE "version 1" (PPTP) parsing of "key" field.
In the PPTP (RFC 2637) version of the PPTP header, the "key" field,
which must be present, consists of a 2-byte big-endian payload length
followed by a 2-byte big-endian call ID. Dissect it as such, and report
an error if the K bit *isn't* set.
Guy Harris [Wed, 7 Jun 2023 02:56:17 +0000 (19:56 -0700)]
Ignore failures when setting the default "any" device DLL to LINUX_SLL2.
If the user didn't explicitly request DLT_LINUX_SLL2 with -y, attempt to
set the link-layer type on the "any" device to DLT_LINUX_SLL2, but, if
that fails, just drive on - it could be the Solaris or macOS "any"
device, neither of which support the Linux-style headers, or it could be
a tcpdump built with a newer libpcap but dynamically-linked, and running
on a system with an older libpcap that doesn't support DLT_LINUX_SLL2.
Jonas Chianu [Fri, 31 Mar 2023 16:24:22 +0000 (12:24 -0400)]
Moved source port equal BCM_LI_PORT to bottom of long if else chain
BCM_LI_SHIM (BCM_LI_PORT) value is set to 49152, therefore when the
source port is 49152, it does not matter what the true destination is,
it defaults to Broadcom. So tcpdump interprets any packet with source
UDP port of 49152 as BCM_LI_SHIM (Broadcom). Ports 49152+, by
definition are ephemeral ports so it's totally reasonable that, for
example, BFD is using that source port for their packets. To prevent,
for example, BFD packets from being wrongly identified as BCM_LI_SHIM
packets, the "else if" statement has been moved to bottom of long chain.
Bill Fenner [Tue, 11 Oct 2022 20:16:20 +0000 (13:16 -0700)]
OSPF6: Fix an undefined behavior
Handle ls_length shorter than sizeof(lsa_hdr) in the same way as OSPF.
Use a u_int32 to hold a loop variable initialized with GET_BE_U_4.
print-ospf6.c:815:46: runtime error: signed integer overflow:
-2147483648 - 1 cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior print-ospf6.c:817:46
Francois-Xavier Le Bail [Fri, 12 May 2023 16:29:25 +0000 (18:29 +0200)]
mobile: Modernize packet parsing
Use ND_TCHECK_SIZE() and enable ND_LONGJMP_FROM_TCHECK.
Use ND_ICHECK_U() for length check and add standard "invalid" section.
Use nd_print_protocol().
Francois-Xavier Le Bail [Mon, 8 May 2023 08:41:28 +0000 (10:41 +0200)]
Makefile.in: Use the variable MAKE instead of the make command
From https://www.gnu.org/software/make/manual/make.html#MAKE-Variable:
```
Recursive make commands should always use the variable MAKE, not the
explicit command name 'make', as shown here:
subsystem:
cd subdir && $(MAKE)
```
This should avoid the following warning when running 'make releasecheck'
in some cases:
make[1]: warning: jobserver unavailable: using -j1. Add '+' to parent
make rule.
Cirrus CI: Avoid perl warnings about setting locale, Linux task
The warnings were like:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
Bill Fenner [Tue, 11 Oct 2022 20:13:58 +0000 (13:13 -0700)]
SNMP: Fix two undefined behaviors
When converting an integer from ASN.1, use an unsigned value
for the partial result and assign it to the integer part of
the union at the end, to avoid shifting a negative number left.
print-snmp.c:545:19: runtime error: left shift of negative value -1
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior print-snmp.c:545:19
OID elements are unsigned; a large-enough oid value could result
in the undefined behavior of shifting a signed integer left through
the sign bit, so simply store them as unsigned.
print-snmp.c:751:11: runtime error: left shift of 268435455 by 7 places
cannot be represented in type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior print-snmp.c:751:11
Dominique Martinet [Fri, 21 Jan 2022 01:27:07 +0000 (10:27 +0900)]
child_cleanup: reap as many child processes as possible
Under load it's possible multiple child processes have been killed before
we start processing the SIGCHILD signal, leaving zombie processes behind
everytime we miss a process.
Reap as many processes as possible instead of assuming one handler
call = one process like we currently did.
Can be reproduced by running the following commands in parallel:
- tcpdump -i lo -w /tmp/test -C 1 -z /usr/bin/true
- iperf3 -s
- iperf3 -c localhost
This should avoid error like:
./print-rt6.c:36:18: error: no previous extern declaration for
non-static variable 'srh_tlv_type' [-Werror,-Wmissing-variable-declarations]
const struct tok srh_tlv_type[] = {
^
./print-rt6.c:36:7: note: declare 'static' if the variable is not
intended to be used outside of this translation unit
const struct tok srh_tlv_type[] = {
^
Guy Harris [Tue, 11 Apr 2023 00:06:02 +0000 (17:06 -0700)]
cdp: don't explicitly check for T_DEV_ID when printing.
Instead, have an additional element in a struct cdp_tlvinfo that
indicates whether to print the TLV in all modes or only in verbose mode;
that would allow other TLVs to printed in non-verbose mode.
Also, use the usual (sizeof x / sizeof x[0]) trick to determine how big
the table is, rather than having a defined size.
bootp/dhcp6: DHCPv4/v6 ZTP and SZTP option support
DHCPv4: RFC8572 specifies the SZTP redirect tag.
DHCPv6: RFC5970 specifies the boot file URL, used for ZTP,
and RFC8572 specifies the SZTP redirect tag
The base DHCPv6 RFC3315 specifies the user class option.
Guy Harris [Mon, 10 Apr 2023 07:27:05 +0000 (00:27 -0700)]
cdp: only hex-dump unknown TLVs in verbose mode.
If we're not in verbose mode, we only show the Device ID TLV, so there's
no good reason to show a hex dump of other TLVs if we don't happen to
have a printer for them - especially given that we don't show the type
value for the TLV, so it's not clear to what type value those hex bytes
correspond. Furthermore, the hex dump causes the non-verbose output to
be multiple lines, and causes the ", length N" to show up at the end of
the hex dump rather than at the end of the first line.
I.e., it seems as if either 1) printing the hex dump in non-verbose mode
wasn't intended or 2) it was intended by whoever intended it didn't look
into what it would involve.
Fixup the comment and have the case block actually fall through
consistently with the comment and the OpenBSD implementation. Update
the test case, which now has the IPv4 packet after the WCCP header. The
indentation does not represent the header nesting, but the same stands
for the OpenBSD implementation.
Francois-Xavier Le Bail [Sun, 12 Mar 2023 17:57:56 +0000 (18:57 +0100)]
instrument functions: Use an environment variable instead of config files
If the environment variable INSTRUMENT is
- unset or set to an empty string, print nothing, like with no
instrumentation
- set to "all" or "a", print all the functions names
- set to "global" or "g", print only the global functions names
The configuration with --enable-instrument-functions remains.
Note that before this change, the default was to print all functions.
Now it is to print nothing. So by default 'make check' runs without errors.
This allows to run:
$ INSTRUMENT=a ./tcpdump ...
$ INSTRUMENT=g ./tcpdump ...
$ INSTRUMENT= ./tcpdump ...
or
$ export INSTRUMENT=global
$ ./tcpdump ...
This also allows to run the statically compiled binary on another host
after copying it.
It is no longer necessary to modify the configuration with:
$ make instrument_all
$ make instrument_global
$ make instrument_off
(Targets removed.)
Update .gitignore, CONTRIBUTING.md and Makefile.in accordingly.
Moreover:
Reduce the scope of a variable.
Rename a variable.
Remove '\n' in the perror() call.
Remove 2 spaces in function calls (style).
Denis Ovsienko [Fri, 24 Feb 2023 23:10:04 +0000 (23:10 +0000)]
Untangle detection of pcap_findalldevs().
tcpdump.c requires both HAVE_PCAP_IF_T and HAVE_PCAP_FINDALLDEVS to
manage the code that depends on pcap_findalldevs(). Other than that,
the Autoconf and CMake checks that produce these two macros do not
relate directly, so having the check for pcap_if_t conditional on the
check for pcap_findalldevs() is an unnecessary complication.
More importantly, in the CMake case this places the check_type_size()
for pcap_if_t into a context with CMAKE_REQUIRED_LIBRARIES already set
to PCAP_LIBRARIES. This works only if check_type_size() does not have
to check for <sys/types.h>, <stdint.h> or <stddef.h> implicitly. This
was the case so long as another check_type_size() before the
CMAKE_REQUIRED_LIBRARIES change made the implicit checks and cached the
results, but removing that earlier instance resulted in a warning:
Policy CMP0075 is not set: Include file check macros honor
CMAKE_REQUIRED_LIBRARIES. Run "cmake --help-policy CMP0075" for policy
details. Use the cmake_policy command to set the policy and suppress this
warning.
CMAKE_REQUIRED_LIBRARIES is set to:
/usr/lib/x86_64-linux-gnu/libpcap.so
For compatibility with CMake 3.11 and below this check is ignoring it.
To fix that, in both Autoconf and CMake make the two checks separate and
unconditional and place the check for pcap_if_t where it fits better.
In CMake remove the earlier workaround with in6_addr.
Guy Harris [Sat, 25 Feb 2023 09:51:45 +0000 (01:51 -0800)]
tcpdump.c: fix a comment. [skip ci]
Some versions of Mac OS X (as it was then called) *did*, in fact, ship
with a libpcap that had pcap_findalldevs() but a pcap.h that didn't
define pcap_if_t; it's not a question of "may ship", it's a fact of "did
ship".
Denis Ovsienko [Tue, 21 Feb 2023 08:02:28 +0000 (08:02 +0000)]
Detect OS IPv6 support using AF_INET6 only.
tcpdump source code has not been using struct in6_addr since commit 0c9cfdc in 2019, so lose the conditional structure declaration, which is
a no-op.
Since commit de7c619 in 2015 netdissect-stdinc.h on Windows defines
HAVE_OS_IPV6_SUPPORT if AF_INET6 if defined, which makes it equivalent
to AF_INET6. On Unix-like systems taking struct in6_addr out of scope
would make HAVE_OS_IPV6_SUPPORT equivalent to AF_INET6, thus after
removing struct in6_addr remove HAVE_OS_IPV6_SUPPORT together with
Autoconf and CMake checks that define it. Leave an unrelated CMake
workaround in place for later debugging.
On Windows do not define AF_INET6 if it is not defined, which makes
AF_INET6 a universal indicator of the OS IPv6 support on all supported
OSes. The few remaining use cases that genuinely need AF_INET6 use it
to make OS API calls, so if the macro is not defined, it most likely
means such an API call in the best case would return just a well-formed
error status. With this in mind, in win32_gethostbyaddr() and
ip6addr_string() guard all IPv6-specific code with #ifdef AF_INET6. In
tcpdump.c add a comment to note why a guard is not required for
Casper-specific conditional code that uses AF_INET6.
This way when the OS does not support IPv6, IPv6 addresses will not
resolve to names, which is expected. Other than that, tcpdump should be
able to process IPv6 addresses the usual way regardless if the OS would
be able to process the packets with these addresses.