]> The Tcpdump Group git mirrors - libpcap/commitdiff
Make extended Linux VLAN tests conditional.
authorDenis Ovsienko <[email protected]>
Mon, 3 Feb 2025 22:51:44 +0000 (22:51 +0000)
committerDenis Ovsienko <[email protected]>
Mon, 3 Feb 2025 23:12:29 +0000 (23:12 +0000)
Old Linux kernels do not include VLAN information in the auxiliary data,
in which case libpcap does not use BPF extensions for VLAN filtering, in
which case TESTrun accept blocks for VLAN with BPF extensions try to
test libpcap code that isn't compiled in the first place.

In Autoconf and CMake check whether SKF_AD_VLAN_TAG_PRESENT is defined.
In TESTrun add a new have_decl() subroutine to match the semantics of
AC_CHECK_DECLS() and use it to skip the test blocks if appropriate.

CMakeLists.txt
cmakeconfig.h.in
configure.ac
testprogs/TESTrun

index e24b4e655cb51666899854a30bd3c24d58d7958c..2a0c908a14d521876227b7070cfe1d132ba2b90d 100644 (file)
@@ -2139,6 +2139,11 @@ else(WIN32)
         endif()
 
         check_struct_has_member("struct tpacket_auxdata" tp_vlan_tci linux/if_packet.h HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI)
+
+        # This check is for TESTrun purposes, not for the C code.
+        # This and the #cmakedefine01 in cmakeconfig.h.in reproduce exactly the
+        # behaviour of "AC_CHECK_DECLS([SKF_AD_VLAN_TAG_PRESENT], ...".
+        check_symbol_exists(SKF_AD_VLAN_TAG_PRESENT linux/filter.h HAVE_DECL_SKF_AD_VLAN_TAG_PRESENT)
     elseif(PCAP_TYPE STREQUAL "bpf")
         #
         # Check whether we have the *BSD-style ioctls.
index 61f2b970bbe2ba8a9c41882394cf2c33d491c429..e00047bc5b000af2339829987230e70130e68ab0 100644 (file)
 /* Define to 1 if `tp_vlan_tci' is a member of `struct tpacket_auxdata'. */
 #cmakedefine HAVE_STRUCT_TPACKET_AUXDATA_TP_VLAN_TCI 1
 
+/* Define to 1 if you have the declaration of `SKF_AD_VLAN_TAG_PRESENT', and
+   to 0 if you don't. */
+#cmakedefine01 HAVE_DECL_SKF_AD_VLAN_TAG_PRESENT
+
 /* Define to 1 if `bRequestType' is a member of `struct
    usbdevfs_ctrltransfer'. */
 #cmakedefine HAVE_STRUCT_USBDEVFS_CTRLTRANSFER_BREQUESTTYPE 1
index 6e9fc14090ae8880aa6eb6555b0f2e4219936043..dad0db47d31d71d8b12354bc9bc9b73d5be013a6 100644 (file)
@@ -1107,6 +1107,9 @@ linux)
                #include <sys/types.h>
                #include <linux/if_packet.h>
            ])
+
+       # This check is for TESTrun purposes, not for the C code.
+       AC_CHECK_DECLS([SKF_AD_VLAN_TAG_PRESENT], [], [], [[#include <linux/filter.h>]])
        ;;
 
 bpf)
index 966e70eb0eee6f157cefd3e2ba386ce71e9f2540..20920e0dcf17c0735886d9554d4f243474e77d2c 100755 (executable)
@@ -102,6 +102,18 @@ sub is_not_linux {
        return $^O eq 'linux' ? '' : 'not running on Linux';
 }
 
+sub have_decl {
+       my ($name, $value) = @_;
+       $name = 'HAVE_DECL_' . $name;
+       # "Unlike the other â€˜AC_CHECK_*S’ macros, when a symbol is not declared,
+       # HAVE_DECL_symbol is defined to â€˜0’ instead of leaving HAVE_DECL_symbol
+       # undeclared." -- GNU Autoconf manual.
+       #
+       # (This requires the CMake leg to do the same for the same symbol.)
+       die "no $name in $config_h" unless defined $config{$name};
+       return int ($config{$name}) == $value ? "$name=$value" : '';
+}
+
 # In accept_blocks the top-level keys are test block names.  Each test block
 # defines one or more tests.  When possible, a test block name should be easy
 # to relate with the main filter expression, for example, ip_multicast for
@@ -2147,7 +2159,7 @@ my %accept_blocks = (
                        ',
        }, # vlan_netanalyzer_unary
        vlan_eth_linuxext_nullary => {
-               skip => is_not_linux(),
+               skip => (is_not_linux() or have_decl ('SKF_AD_VLAN_TAG_PRESENT', 0)),
                DLT => 'EN10MB',
                linuxext => 1,
                expr => 'vlan',
@@ -2163,7 +2175,7 @@ my %accept_blocks = (
                        ',
        }, # vlan_eth_linuxext_nullary
        vlan_eth_linuxext_unary => {
-               skip => is_not_linux(),
+               skip => (is_not_linux() or have_decl ('SKF_AD_VLAN_TAG_PRESENT', 0)),
                DLT => 'EN10MB',
                linuxext => 1,
                expr => 'vlan 10',
@@ -2186,7 +2198,7 @@ my %accept_blocks = (
                        ',
        }, # vlan_eth_linuxext_unary
        vlan_and_vlan_eth_linuxext => {
-               skip => is_not_linux(),
+               skip => (is_not_linux() or have_decl ('SKF_AD_VLAN_TAG_PRESENT', 0)),
                DLT => 'EN10MB',
                linuxext => 1,
                expr => 'vlan and vlan',