IEEE 802.11: Add a test to check the 802.11s Mesh ID in management frames
The newly added pcap file contains a Mesh Beacon frame, a Wildcard Probe
Request and a Mesh Probe Response. The test case checks if the "Mesh ID"
field is properly parsed by the IEEE 802.11 printer.
Guy Harris [Wed, 11 Aug 2021 10:18:54 +0000 (03:18 -0700)]
Add a space at the end of the first line, to provoke a build.
(There doesn't appear to be an obvious way to force a rebuild, and a
change to libpcap doesn't force a rebuild of programs such as tcpdump
for which the CI build includes a build with the tip of the main branch
of libpcap.)
Guy Harris [Wed, 11 Aug 2021 08:44:51 +0000 (01:44 -0700)]
Get rid of duplicate definition of __has_attribute.
compiler-tests.h already checks whether __has_attribute and, if not,
defines it as a macro that always returns 0 (so that we use the "what
version of the compiler is this?" fallback checks for a given
attribute). We include compiler-tests.h before we define
__has_attribute ourselves, so we don't need to do it ourselves.
Guy Harris [Wed, 11 Aug 2021 08:05:52 +0000 (01:05 -0700)]
Make the tests a bit easier to read.
Add comments and indentation.
Handle XL C a bit more like the other compilers. Make the first test be
"is this someting that's not XL C", as is the case for other compilers;
that test is done as "are both __xlC__ and __ibmxl__ undefined". If
either of them are defined, use __ibmxl_version__ if __ibmxl__ is
defined, and use __xlC__ otherwise.
Every .c file that included netdissect-stdinc.h generated a warning:
In file included from ./netdissect-stdinc.h:42:
./ftmacros.h:48:11: warning: '__EXTENSIONS__' macro redefined
[-Wmacro-redefined]
<built-in>:345:9: note: previous definition is here
Guy Harris [Sun, 8 Aug 2021 07:36:42 +0000 (00:36 -0700)]
On Solaris, for 64-bit builds, use the 64-bit pcap-config.
There are two versions of pcap-config supplied on Solaris (or, at least,
on 64-bit Solaris) - a version that has the right --libs output to find
the 32-bit libraries and a version that has the right --libs output to
find the 64-bit libraries.
Try to figure out whether we're doing a 32-bit or 64-bit build (based on
the pointer size) and, for 64-bit builds, run the 64-bit version of
pcap-config.
Denis Ovsienko [Thu, 5 Aug 2021 13:18:55 +0000 (14:18 +0100)]
Use basename() and dirname() right on FreeBSD. [skip appveyor]
On FreeBSD CMake runs Clang with -std=gnu99, which used to emit three
warnings in a Capsicum-specific block along the following lines:
tcpdump.c:2432:32: warning: '_Generic' is a C11 extension
[-Wc11-extensions]
/usr/include/libgen.h:61:21: note: expanded from macro 'basename'
basename)(x)
/usr/include/sys/cdefs.h:325:2: note: expanded from macro '__generic'
_Generic(expr, t: yes, default: no)
(In the same context Autoconf does not request a specific C standard
from Clang, so it happens to use C17 and there is no warning.)
Type-generic expressions support in C99 mode seems to be a quirk of
Clang that cannot be disabled and is harmless in this context, so
introduce and use another pair of diagnostic control macros (for Clang
only) to squelch the warnings.
While at it, study the reason for _Generic use in /usr/include/libgen.h
and realize that tcpdump.c still assumes the behaviour before FreeBSD
12.0. Add two temporary buffers around basename() and dirname() calls
to get consistent results regardless of which FreeBSD version it is.
Denis Ovsienko [Tue, 3 Aug 2021 23:20:36 +0000 (00:20 +0100)]
Fix auto-enabling of Capsicum on FreeBSD with Autoconf. [skip appveyor]
Even after commit 6393bb6 --with-sandbox-capsicum didn't work entirely
as documented, as it defaulted to disabled:
checking whether to sandbox using capsicum... no
checking whether to sandbox using Casper library... no
Get the test condition right so it does what it says:
checking sys/capsicum.h usability... yes
checking sys/capsicum.h presence... yes
checking for sys/capsicum.h... yes
checking for cap_enter... yes
checking for cap_rights_limit... yes
checking for cap_ioctls_limit... yes
checking for openat... yes
checking for cap_init in -lcasper... yes
checking for cap_gethostbyaddr in -lcap_dns... yes
checking whether to sandbox using capsicum... yes
checking whether to sandbox using Casper library... yes
Denis Ovsienko [Tue, 3 Aug 2021 22:38:48 +0000 (23:38 +0100)]
Squelch a warning with Capsicum enabled. [skip appveyor]
The Capsicum workaround I added in commit 706c79e causes a side effect
on FreeBSD 11.4, 12.2 and 13.0 with local libpcap when Capsicum is
enabled, that is, in CMake builds (Capsicum detection is broken in
Autoconf builds, as it turns out). Add a workaround for the side effect
as well and get rid of another warning and respective exemption:
tcpdump.c:2286:3: warning: implicit declaration of function 'bpf_dump'
is invalid in C99 [-Wimplicit-function-declaration]
Guy Harris [Tue, 3 Aug 2021 19:58:34 +0000 (12:58 -0700)]
configure: special-case macOS /usr/bin/pcap-config as we do in CMake.
macOS's /usr/bin/pcap-config is incorrectly generated - pcap-config
--cflags includes -I/usr/local/include and pcap-config --libs includes
-L/usr/local/lib, even though it's the pcap-config file for the libpcap
that comes with the OS and should omit those.
Denis Ovsienko [Tue, 3 Aug 2021 17:23:13 +0000 (18:23 +0100)]
Define PRINTFLIKE_FUNCPTR() exactly for XL C. [skip appveyor]
XL C full version consists of 4 numbers. Introduce an additional macro
for testing the two least significant numbers. Using the fix lists
published by IBM, tell XL C 16.1 that has the bug interpreting the
__format__ attribute of a function pointer from XL C 16.1 that has not.
Rejig the #if block to make it easier to follow.
CMake: Add a way to request -Werror and equivalents.
As it turns out, most FreeBSD/CMake tcpdump builds were emitting some
warnings. This was difficult to notice because make returned success
regardless of the warnings because the compiler never received -Werror
because there was no way to tell CMake to append any compiler flags at
the build time, but not at the buildsystem generation time. In other
words, the command "make CFLAGS=-Werror" had the same effect as just
"make".
Implement the desired behaviour with "cmake -DEXTRA_CFLAGS='xyz'" and
set the variable in build.sh when and as required. Reword the comment
for clarity and define two known exemptions.
Cirrus CI: Fixup the previous commit. [skip appveyor]
Failed to start an instance: [...]
Number of vCPUs should be multiple of 2 if greater than 2, while 3.0 is
requested. Memory size for 3.0 vCPU instance should be between 2816MiB
and 19968MiB, while 2048MiB is requested.
...because the former uses PRINTFLIKE_FUNCPTR(). However, it didn't
have the #include. However, the problem was not visible because most
files that included netdissect.h also included (directly or through
another header) funcattrs.h beforehand. The only exceptions were the
following two files, which apparently have not been compiled anywhere
for a long time:
In file included from missing/strdup.c:38:
./netdissect.h:254:8: error: expected ':', ',', ';', '}' or
'__attribute__' before 'PRINTFLIKE_FUNCPTR'
In file included from missing/snprintf.c:45:
./netdissect.h:254:8: error: expected ':', ',', ';', '}' or
'__attribute__' before 'PRINTFLIKE_FUNCPTR'
Add the missing #include to netdissect.h to eliminate this space for
failure.
IEEE 802.11: include the "TA" field while printing Block Ack Control frame
As per the IEEE 802.11-2016 std, section 9.3.1.9, Fig 9-32, the Block Ack
control frame has the Transmitter Address field. So include this TA field
when printing the BA frame to stdout if the "eflag" is enabled.
XL C 16.1.1 Community Edition for Linux generated three warnings for
every file:
In file included from ./tcpdump.c:155:
./netdissect.h:254:8: warning: 1540-2990 The attribute
"__attribute__((format(printf, 2, 3)))" is not supported. The
attribute is ignored.
PRINTFLIKE_FUNCPTR(2, 3);
^
./netdissect.h:259:10: warning: 1540-2990 The attribute
" __attribute__((format(printf, 3, 4)))" is not supported.
The attribute is ignored.
PRINTFLIKE_FUNCPTR(3, 4);
^
./netdissect.h:263:9: warning: 1540-2990 The attribute
" __attribute__((format(printf, 2, 3)))" is not supported. The
attribute is ignored.
PRINTFLIKE_FUNCPTR(2, 3);
^
As it turns out, this is a bug in the compiler. In compiler-tests.h
update ND_IS_AT_LEAST_XL_C_VERSION() to tell newer XL C versions. In
funcattrs.h exempt XL C 16.1 from PRINTFLIKE_FUNCPTR().
In the course of preparing these changes notice that XL C uses the Clang
block in diag-control.h (XL C mimics both Clang and GCC to some extent),
although the behaviour is different between the two compilers. Add a new
block for XL C there.
In build_common.sh add more comments to explain XL C quirks and detect
XL C for Linux too so it receives the right CFLAGS. Update CHANGES to
mention this and earlier improvements.
This way if an iteration includes a local libpcap, the latter is always
compiled with the same CC. This works around odd linking problems on
AIX 7 and Solaris 9 and 10 when one C compiler is GCC and the other is
the vendor's compiler, for example:
* GCC used for libpcap, XL C used for tcpdump:
ld: 0711-317 ERROR: Undefined symbol: .__udivdi3
ld: 0711-317 ERROR: Undefined symbol: .__umoddi3
* GCC used for libpcap, Sun C used for tcpdump:
Undefined first referenced
symbol in file
__ctzsi2 ../libpcap/libpcap.a(optimize.o)
__udivdi3 ../libpcap/libpcap.a(sf-pcapng.o)
__umoddi3 ../libpcap/libpcap.a(sf-pcapng.o)
ld: fatal: Symbol referencing errors. No output written to conftest
Similar issues associated with a mix of GCC and Clang had happened on
FreeBSD/AArch64 earlier (addressed in tcpslice commit 75b7771), and
still seem to happen on OpenBSD/AArch64. Hopefully removing the
toolchain mix from the problem space will make it easier to fix other
problems.
Call print_so_deps() just after "make install", so if dynamic linking
has failed for some reason, the failure to run tcpdump binary will not
prevent printing the details. Lose "tcpdump --version" because version
information is a part of "tcpdump -h" output.
-- Installing: /tmp/tcpdump_build_matrix.XXyKaiEo/bin/tcpdump
-- Set runtime path of "/tmp/tcpdump_build_matrix.XXyKaiEo/bin/tcpdump" to ""
-- Installing: /tmp/tcpdump_build_matrix.XXyKaiEo/share/man/man1/tcpdump.1
$ /tmp/tcpdump_build_matrix.XXyKaiEo/bin/tcpdump --version
ld.so.1: tcpdump: fatal: libpcap.so.1: open failed: No such file or directory
GCC 8.3.0 on AIX 7.1 produced a warning for every file that has a call
to nd_trunc_longjmp():
In file included from ./cpack.c:39:
./extract.h: In function 'nd_trunc_longjmp':
./extract.h:586:1: warning: 'noreturn' function does return
As far as longjmp(3) man page and <setjmp.h> header go, longjmp() is as
noreturn in AIX as everywhere else, but not in a way that GCC can tell.
Disabling -Wsuggest-attribute=noreturn and -Wmissing-noreturn had no
apparent effect, so instead of using diag-control.h add an infinite loop
on AIX to squelch the warning.
In build_common.sh add minimal heuristics to print_cc_version() to help
it run the right command; add cc_id() and cc_werr_cflags() to pick the
right CFLAGS for the current compiler instead of the previously
hard-coded "-Werror". Add some comments.
In build.sh remove the CFLAGS exemptions for AIX and Solaris 9 builds,
which are in a better shape now and can complete specific subsets of the
full matrix without a warning. Set CFLAGS from cc_werr_cflags() to make
the best effort to catch as many warnings as possible. Let's see how well
that works.
Sun C 5.9 does not support C99. GCC 4.6.4 recognizes -std=gnu99, but
does not support the z length modifier in printf(3). In either case 18
tests fail in the following manner:
Make these tests conditional and disable them when HAVE_NO_PRINTF_Z is
defined. Modify the Autoconf leg of the build process to define the
macro when printf() does not handle %zu as expected. The CMake leg looks
broken on Solaris 9 with 2.8.9 now, so leave it be for now.
Guy Harris [Sun, 25 Jul 2021 10:02:54 +0000 (03:02 -0700)]
configure: use AC_COMPILE_IFELSE() and AC_LANG_SOURCE() for testing flags.
That lets us completely control the program that's compiled with the
compiler flag we're testing, so we can make it a minimal program that
uses only prototype declarations and that therefore won't generate
warnings with some -W flags, e.g. -Wold-style-definition, and thus won't
falsely report those flags as unsupported.
Guy Harris [Sun, 25 Jul 2021 09:22:42 +0000 (02:22 -0700)]
configure: use ac_c_werror_flag to force unknown compiler flags to fail.
It's not a documented feature, but it's what the documented
AC_LANG_WERROR has used for 13 years, and there's no push/pop mechanism
for AC_LANG_WERROR, so you can't ensure that "fail even on warnings"
will be applied *only* in AC_LBL_CHECK_COMPILER_OPT(), as that's what we
want. (If we can make sure that *no* compiler tests will produce
warnings, except for the ones we *want* to fail if they produce
warnings, we could just do AC_LANG_WERROR, but that might be tricky to
ensure in the general case.)
We do this because not all compilers have a command-line flag to force
all warnings, *including* warnings from unknown commad-line flags (I'm
looking at *you* IBM XL C!), so we have to have the test check to make
sure no warnings are produced (which, for AC_TRY_COMPILE(), means
"nothing is written to the standard output").
In addition, AC_TRY_COMPILE() generates a return; don't add one:
If we pass [return 0] to AC_TRY_COMPILE(), the test program it compiles
has two "return 0;" statements in a row, and one of the -W flags we
tests reports a warning for that.
We were testing whether a -W flag is supported by checking the standard
error of the compiler to see if *any* error/warning messages are
generated, and treating the flag as unsupported if any are, that meant
that -Wunreachable-code-return was be treated as unsupported even though
it *is* supported.
This should fix that. (I'm so glad autoconf makes this all so difficult
to do correctly....)
Guy Harris [Sat, 24 Jul 2021 08:51:02 +0000 (01:51 -0700)]
Suppress "casting away const" warnings in missing/getopt_long.c.
It's explicitly cheating in some places; just cast away the warnings.
Add a Clang version testing macro to compiler-tests.h.
Move the diagnostic control #defines from netdissect-stdinc.h to
diag-control.h, libpcap-style, so that they can be used by code that
doesn't use (or need) netdissect-stdinc.h. This also means that we can
limit the inclusion of diag-control.h, and the definition of those
Do them more libpcap-style, with separate DIAG_OFF/DIAG_ON pairs for
particular issues, rather than having DIAG_OFF() and DIAG_ON() macros
that take -W option names as arguments; that way, if we need to define
them for compilers that don't have the GCC/Clang syntax for those
pragmas, e.g. MSVC, we can do so.
Start using build_common.sh, make default assignments early and
uniformly, use Solaris-compatible command substitution and exports,
install bc on linux-amd64, deduplicate and reformat some long commands.
Run "make -s" without CFLAGS=-Werror when warnings are expected.
This implements initial support for AIX and Solaris in the tcpdump build
matrix scripts.
Solaris 9 has Perl 5.6.1, which does not support constant declaration
using a hash reference:
$ make check
./tests/TESTrun
Constant name 'HASH(0x2d8f0)' has invalid characters at ./tests/TESTrun
line 24
BEGIN failed--compilation aborted at ./tests/TESTrun line 24.
*** Error code 255
make: Fatal error: Command failed for target `check'
Declare one constant at a time to work around that and get "make check"
to start running tests (18 of which fail, but that's another issue).
Guy Harris [Mon, 19 Jul 2021 01:45:23 +0000 (18:45 -0700)]
802.11: fetch the CF and TIM IEs a field at a time.
That should squelch Coverity CIDs 1487524 and 1487523; it also means
that we convert the 2-byte fields from little-endian byte order to host
order, and also avoids issues with padding in the structures we use.
Compiling user-provided source code and running the resulting binary
with sudo was a security problem, thus instead of fixing two no-op
blocks remove them altogether. If anyone later needs to debug features
that require higher privileges, they will need to come up with a better
solution. Simplify the debug output test condition and rephrase the
associated comment for clarity.
Running ldd on Linux only originates from the Travis CI setup, where the
OS was either Linux or macOS. However, ldd is available in BSD systems
too, and macOS seems to have its own tool for the same job.
Gokul Sivakumar [Sun, 27 Jun 2021 10:43:06 +0000 (16:13 +0530)]
Fix the misleading comment regarding "From DS", "To DS" Frame Control Flags
In the case where the "From DS" bit is not set and the "To DS" bit is set
in the Frame Control Bitmask, the comment line in the corresponding if else
block was misleading that the "From DS" bit is set and the "To DS" bit is
not set.