Don't speak of Linux usbmon as generic USB sniffing support.
It's a Linux-specific mechanism; on at least two other platforms,
FreeBSD and macOS, USB sniffing takes place through BPF, so it's not
something that we allow to be disabled.
Clean up the checks for Linux-specific mechanisms, putting them inside a
general "Is this Linux?" test.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 758f12b..afdaba6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -202,7 +202,9 @@
#
# Additional capture modules.
#
-option(DISABLE_USB "Disable USB sniffing support" OFF)
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ option(DISABLE_LINUX_USBMON "Disable Linux usbmon USB sniffing support" OFF)
+endif()
option(DISABLE_BLUETOOTH "Disable Bluetooth sniffing support" OFF)
option(DISABLE_NETMAP "Disable netmap support" OFF)
option(DISABLE_DPDK "Disable DPDK support" OFF)
@@ -1476,11 +1478,13 @@
# Check for additional native sniffing capabilities.
#
-# Check for USB sniffing support on Linux.
-# On FreeBSD, it uses BPF, so we don't need to do anything special here.
-if(NOT DISABLE_USB)
- if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
- set(PCAP_SUPPORT_USB TRUE)
+#
+# Various Linux-specific mechanisms.
+#
+if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ # Check for usbmon USB sniffing support.
+ if(NOT DISABLE_LINUX_USBMON)
+ set(PCAP_SUPPORT_LINUX_USBMON TRUE)
set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-usb-linux.c)
set(LINUX_USB_MON_DEV /dev/usbmon)
#
@@ -1510,10 +1514,9 @@
endif(HAVE_LINUX_COMPILER_H)
endif()
endif()
-endif()
-# Check for netfilter sniffing support.
-if(CMAKE_SYSTEM_NAME STREQUAL "Linux")
+ #
+ # Check for netfilter sniffing support.
#
# Life's too short to deal with trying to get this to compile
# if you don't get the right types defined with
diff --git a/cmakeconfig.h.in b/cmakeconfig.h.in
index 8f3c192..ac013d7 100644
--- a/cmakeconfig.h.in
+++ b/cmakeconfig.h.in
@@ -334,6 +334,9 @@
/* target host supports DPDK */
#cmakedefine PCAP_SUPPORT_DPDK 1
+/* target host supports Linux usbmon for USB sniffing */
+#cmakedefine PCAP_SUPPORT_LINUX_USBMON 1
+
/* target host supports netfilter sniffing */
#cmakedefine PCAP_SUPPORT_NETFILTER 1
@@ -346,9 +349,6 @@
/* target host supports RDMA sniffing */
#cmakedefine PCAP_SUPPORT_RDMASNIFF 1
-/* target host supports USB sniffing */
-#cmakedefine PCAP_SUPPORT_USB 1
-
/* Define to 1 if you have the ANSI C header files. */
#cmakedefine STDC_HEADERS 1
diff --git a/config.h.in b/config.h.in
index fa895b1..e6acd20 100644
--- a/config.h.in
+++ b/config.h.in
@@ -337,6 +337,9 @@
/* target host supports DPDK */
#undef PCAP_SUPPORT_DPDK
+/* target host supports Linux usbmon for USB sniffing */
+#undef PCAP_SUPPORT_LINUX_USBMON
+
/* target host supports netfilter sniffing */
#undef PCAP_SUPPORT_NETFILTER
@@ -349,9 +352,6 @@
/* target host supports RDMA sniffing */
#undef PCAP_SUPPORT_RDMASNIFF
-/* target host supports USB sniffing */
-#undef PCAP_SUPPORT_USB
-
/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS
diff --git a/configure b/configure
index 48849d6..b2b8eba 100755
--- a/configure
+++ b/configure
@@ -629,7 +629,7 @@
PCAP_SUPPORT_DPDK
PCAP_SUPPORT_NETMAP
PCAP_SUPPORT_NETFILTER
-PCAP_SUPPORT_USB
+PCAP_SUPPORT_LINUX_USBMON
EXTRA_NETWORK_LIBS
RPCAPD_LIBS
INSTALL_RPCAPD
@@ -1407,8 +1407,8 @@
--disable-universal don't build universal on macOS
--enable-shared build shared libraries [default=yes, if support
available]
- --enable-usb enable USB capture support [default=yes, if support
- available]
+ --enable-usb enable Linux usbmon USB capture support
+ [default=yes, if support available]
--enable-netmap enable netmap support [default=yes, if support
available]
--enable-bluetooth enable Bluetooth support [default=yes, if support
@@ -11022,6 +11022,9 @@
+#
+# Various Linux-specific mechanisms.
+#
# Check whether --enable-usb was given.
if test "${enable_usb+set}" = set; then :
enableval=$enable_usb;
@@ -11030,39 +11033,38 @@
fi
-if test "xxx_only" = yes; then
- # User requested something-else-only pcap, so they don't
- # want USB support.
- enable_usb=no
-fi
+#
+# If somebody requested an XXX-only pcap, that doesn't include
+# additional mechanisms.
+#
+if test "xxx_only" != yes; then
+ case "$host_os" in
+ linux*)
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Linux usbmon USB sniffing support" >&5
+$as_echo_n "checking for Linux usbmon USB sniffing support... " >&6; }
+ if test "x$enable_usb" != "xno" ; then
-if test "x$enable_usb" != "xno" ; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for USB sniffing support" >&5
-$as_echo_n "checking for USB sniffing support... " >&6; }
- case "$host_os" in
- linux*)
+$as_echo "#define PCAP_SUPPORT_LINUX_USBMON 1" >>confdefs.h
-$as_echo "#define PCAP_SUPPORT_USB 1" >>confdefs.h
-
- MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+ MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }
- ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
- if test $? -ne 0 ; then
- ac_usb_dev_name="usbmon"
- fi
+ ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
+ if test $? -ne 0 ; then
+ ac_usb_dev_name="usbmon"
+ fi
cat >>confdefs.h <<_ACEOF
#define LINUX_USB_MON_DEV "/dev/$ac_usb_dev_name"
_ACEOF
- { $as_echo "$as_me:${as_lineno-$LINENO}: Device for USB sniffing is /dev/$ac_usb_dev_name" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: Device for USB sniffing is /dev/$ac_usb_dev_name" >&5
$as_echo "$as_me: Device for USB sniffing is /dev/$ac_usb_dev_name" >&6;}
- #
- # Do we have a version of <linux/compiler.h> available?
- # If so, we might need it for <linux/usbdevice_fs.h>.
- #
- for ac_header in linux/compiler.h
+ #
+ # Do we have a version of <linux/compiler.h> available?
+ # If so, we might need it for <linux/usbdevice_fs.h>.
+ #
+ for ac_header in linux/compiler.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "linux/compiler.h" "ac_cv_header_linux_compiler_h" "$ac_includes_default"
if test "x$ac_cv_header_linux_compiler_h" = xyes; then :
@@ -11074,11 +11076,11 @@
done
- if test "$ac_cv_header_linux_compiler_h" = yes; then
- #
- # Yes - include it when testing for <linux/usbdevice_fs.h>.
- #
- for ac_header in linux/usbdevice_fs.h
+ if test "$ac_cv_header_linux_compiler_h" = yes; then
+ #
+ # Yes - include it when testing for <linux/usbdevice_fs.h>.
+ #
+ for ac_header in linux/usbdevice_fs.h
do :
ac_fn_c_check_header_compile "$LINENO" "linux/usbdevice_fs.h" "ac_cv_header_linux_usbdevice_fs_h" "#include <linux/compiler.h>
"
@@ -11091,8 +11093,8 @@
done
- else
- for ac_header in linux/usbdevice_fs.h
+ else
+ for ac_header in linux/usbdevice_fs.h
do :
ac_fn_c_check_header_mongrel "$LINENO" "linux/usbdevice_fs.h" "ac_cv_header_linux_usbdevice_fs_h" "$ac_includes_default"
if test "x$ac_cv_header_linux_usbdevice_fs_h" = xyes; then :
@@ -11104,20 +11106,20 @@
done
- fi
- if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
- #
- # OK, does it define bRequestType? Older versions of the kernel
- # define fields with names like "requesttype, "request", and
- # "value", rather than "bRequestType", "bRequest", and
- # "wValue".
- #
- ac_fn_c_check_member "$LINENO" "struct usbdevfs_ctrltransfer" "bRequestType" "ac_cv_member_struct_usbdevfs_ctrltransfer_bRequestType" "
- $ac_includes_default
- #ifdef HAVE_LINUX_COMPILER_H
- #include <linux/compiler.h>
- #endif
- #include <linux/usbdevice_fs.h>
+ fi
+ if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
+ #
+ # OK, does it define bRequestType? Older versions of the kernel
+ # define fields with names like "requesttype, "request", and
+ # "value", rather than "bRequestType", "bRequest", and
+ # "wValue".
+ #
+ ac_fn_c_check_member "$LINENO" "struct usbdevfs_ctrltransfer" "bRequestType" "ac_cv_member_struct_usbdevfs_ctrltransfer_bRequestType" "
+ $ac_includes_default
+ #ifdef HAVE_LINUX_COMPILER_H
+ #include <linux/compiler.h>
+ #endif
+ #include <linux/usbdevice_fs.h>
"
if test "x$ac_cv_member_struct_usbdevfs_ctrltransfer_bRequestType" = xyes; then :
@@ -11129,43 +11131,23 @@
fi
- fi
- ;;
- freebsd*)
- #
- # This just uses BPF in FreeBSD 8.4 and later; we don't need
- # to check for anything special for capturing.
- #
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes, in FreeBSD 8.4 and later" >&5
-$as_echo "yes, in FreeBSD 8.4 and later" >&6; }
- ;;
-
- *)
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+ fi
+ else
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }
- ;;
-esac
-fi
+ fi
-
-if test "xxx_only" != yes; then
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the platform could support netfilter sniffing" >&5
-$as_echo_n "checking whether the platform could support netfilter sniffing... " >&6; }
- case "$host_os" in
- linux*)
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
-$as_echo "yes" >&6; }
- #
- # Life's too short to deal with trying to get this to compile
- # if you don't get the right types defined with
- # __KERNEL_STRICT_NAMES getting defined by some other include.
- #
- # Check whether the includes Just Work. If not, don't turn on
- # netfilter support.
- #
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can compile the netfilter support" >&5
+ #
+ # Life's too short to deal with trying to get this to compile
+ # if you don't get the right types defined with
+ # __KERNEL_STRICT_NAMES getting defined by some other include.
+ #
+ # Check whether the includes Just Work. If not, don't turn on
+ # netfilter support.
+ #
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we can compile the netfilter support" >&5
$as_echo_n "checking whether we can compile the netfilter support... " >&6; }
- if ${ac_cv_netfilter_can_compile+:} false; then :
+ if ${ac_cv_netfilter_can_compile+:} false; then :
$as_echo_n "(cached) " >&6
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -11197,23 +11179,20 @@
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
fi
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_netfilter_can_compile" >&5
+ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_netfilter_can_compile" >&5
$as_echo "$ac_cv_netfilter_can_compile" >&6; }
- if test $ac_cv_netfilter_can_compile = yes ; then
+ if test $ac_cv_netfilter_can_compile = yes ; then
$as_echo "#define PCAP_SUPPORT_NETFILTER 1" >>confdefs.h
- MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
- fi
- ;;
- *)
- { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
-$as_echo "no" >&6; }
- ;;
- esac
+ MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
+ fi
+ ;;
+ esac
fi
+
# Check whether --enable-netmap was given.
if test "${enable_netmap+set}" = set; then :
enableval=$enable_netmap;
diff --git a/configure.ac b/configure.ac
index d396b30..b60a8cc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2217,93 +2217,77 @@
AC_SUBST(RPCAPD_LIBS)
AC_SUBST(EXTRA_NETWORK_LIBS)
+#
+# Various Linux-specific mechanisms.
+#
AC_ARG_ENABLE([usb],
-[AC_HELP_STRING([--enable-usb],[enable USB capture support @<:@default=yes, if support available@:>@])],
+[AC_HELP_STRING([--enable-usb],[enable Linux usbmon USB capture support @<:@default=yes, if support available@:>@])],
[],
[enable_usb=yes])
-if test "xxx_only" = yes; then
- # User requested something-else-only pcap, so they don't
- # want USB support.
- enable_usb=no
-fi
-
-if test "x$enable_usb" != "xno" ; then
- dnl check for USB sniffing support
- AC_MSG_CHECKING(for USB sniffing support)
- case "$host_os" in
- linux*)
- AC_DEFINE(PCAP_SUPPORT_USB, 1, [target host supports USB sniffing])
- MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
- AC_MSG_RESULT(yes)
- ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
- if test $? -ne 0 ; then
- ac_usb_dev_name="usbmon"
- fi
- AC_DEFINE_UNQUOTED(LINUX_USB_MON_DEV, "/dev/$ac_usb_dev_name", [path for device for USB sniffing])
- AC_MSG_NOTICE(Device for USB sniffing is /dev/$ac_usb_dev_name)
- #
- # Do we have a version of <linux/compiler.h> available?
- # If so, we might need it for <linux/usbdevice_fs.h>.
- #
- AC_CHECK_HEADERS(linux/compiler.h)
- if test "$ac_cv_header_linux_compiler_h" = yes; then
- #
- # Yes - include it when testing for <linux/usbdevice_fs.h>.
- #
- AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
- else
- AC_CHECK_HEADERS(linux/usbdevice_fs.h)
- fi
- if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
- #
- # OK, does it define bRequestType? Older versions of the kernel
- # define fields with names like "requesttype, "request", and
- # "value", rather than "bRequestType", "bRequest", and
- # "wValue".
- #
- AC_CHECK_MEMBERS([struct usbdevfs_ctrltransfer.bRequestType],,,
- [
- AC_INCLUDES_DEFAULT
- #ifdef HAVE_LINUX_COMPILER_H
- #include <linux/compiler.h>
- #endif
- #include <linux/usbdevice_fs.h>
- ])
- fi
- ;;
- freebsd*)
- #
- # This just uses BPF in FreeBSD 8.4 and later; we don't need
- # to check for anything special for capturing.
- #
- AC_MSG_RESULT([yes, in FreeBSD 8.4 and later])
- ;;
-
- *)
- AC_MSG_RESULT(no)
- ;;
-esac
-fi
-AC_SUBST(PCAP_SUPPORT_USB)
-
-dnl check for netfilter sniffing support
+#
+# If somebody requested an XXX-only pcap, that doesn't include
+# additional mechanisms.
+#
if test "xxx_only" != yes; then
- AC_MSG_CHECKING(whether the platform could support netfilter sniffing)
- case "$host_os" in
- linux*)
- AC_MSG_RESULT(yes)
- #
- # Life's too short to deal with trying to get this to compile
- # if you don't get the right types defined with
- # __KERNEL_STRICT_NAMES getting defined by some other include.
- #
- # Check whether the includes Just Work. If not, don't turn on
- # netfilter support.
- #
- AC_MSG_CHECKING(whether we can compile the netfilter support)
- AC_CACHE_VAL(ac_cv_netfilter_can_compile,
- AC_TRY_COMPILE([
+ case "$host_os" in
+ linux*)
+ dnl check for USB sniffing support
+ AC_MSG_CHECKING(for Linux usbmon USB sniffing support)
+ if test "x$enable_usb" != "xno" ; then
+ AC_DEFINE(PCAP_SUPPORT_LINUX_USBMON, 1, [target host supports Linux usbmon for USB sniffing])
+ MODULE_C_SRC="$MODULE_C_SRC pcap-usb-linux.c"
+ AC_MSG_RESULT(yes)
+ ac_usb_dev_name=`udevinfo -q name -p /sys/class/usb_device/usbmon 2>/dev/null`
+ if test $? -ne 0 ; then
+ ac_usb_dev_name="usbmon"
+ fi
+ AC_DEFINE_UNQUOTED(LINUX_USB_MON_DEV, "/dev/$ac_usb_dev_name", [path for device for USB sniffing])
+ AC_MSG_NOTICE(Device for USB sniffing is /dev/$ac_usb_dev_name)
+ #
+ # Do we have a version of <linux/compiler.h> available?
+ # If so, we might need it for <linux/usbdevice_fs.h>.
+ #
+ AC_CHECK_HEADERS(linux/compiler.h)
+ if test "$ac_cv_header_linux_compiler_h" = yes; then
+ #
+ # Yes - include it when testing for <linux/usbdevice_fs.h>.
+ #
+ AC_CHECK_HEADERS(linux/usbdevice_fs.h,,,[#include <linux/compiler.h>])
+ else
+ AC_CHECK_HEADERS(linux/usbdevice_fs.h)
+ fi
+ if test "$ac_cv_header_linux_usbdevice_fs_h" = yes; then
+ #
+ # OK, does it define bRequestType? Older versions of the kernel
+ # define fields with names like "requesttype, "request", and
+ # "value", rather than "bRequestType", "bRequest", and
+ # "wValue".
+ #
+ AC_CHECK_MEMBERS([struct usbdevfs_ctrltransfer.bRequestType],,,
+ [
+ AC_INCLUDES_DEFAULT
+ #ifdef HAVE_LINUX_COMPILER_H
+ #include <linux/compiler.h>
+ #endif
+ #include <linux/usbdevice_fs.h>
+ ])
+ fi
+ else
+ AC_MSG_RESULT(no)
+ fi
+
+ #
+ # Life's too short to deal with trying to get this to compile
+ # if you don't get the right types defined with
+ # __KERNEL_STRICT_NAMES getting defined by some other include.
+ #
+ # Check whether the includes Just Work. If not, don't turn on
+ # netfilter support.
+ #
+ AC_MSG_CHECKING(whether we can compile the netfilter support)
+ AC_CACHE_VAL(ac_cv_netfilter_can_compile,
+ AC_TRY_COMPILE([
AC_INCLUDES_DEFAULT
#include <sys/socket.h>
#include <netinet/in.h>
@@ -2314,21 +2298,19 @@
#include <linux/netfilter/nfnetlink.h>
#include <linux/netfilter/nfnetlink_log.h>
#include <linux/netfilter/nfnetlink_queue.h>],
- [],
- ac_cv_netfilter_can_compile=yes,
- ac_cv_netfilter_can_compile=no))
- AC_MSG_RESULT($ac_cv_netfilter_can_compile)
- if test $ac_cv_netfilter_can_compile = yes ; then
- AC_DEFINE(PCAP_SUPPORT_NETFILTER, 1,
- [target host supports netfilter sniffing])
- MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
- fi
- ;;
- *)
- AC_MSG_RESULT(no)
- ;;
- esac
+ [],
+ ac_cv_netfilter_can_compile=yes,
+ ac_cv_netfilter_can_compile=no))
+ AC_MSG_RESULT($ac_cv_netfilter_can_compile)
+ if test $ac_cv_netfilter_can_compile = yes ; then
+ AC_DEFINE(PCAP_SUPPORT_NETFILTER, 1,
+ [target host supports netfilter sniffing])
+ MODULE_C_SRC="$MODULE_C_SRC pcap-netfilter-linux.c"
+ fi
+ ;;
+ esac
fi
+AC_SUBST(PCAP_SUPPORT_LINUX_USBMON)
AC_SUBST(PCAP_SUPPORT_NETFILTER)
AC_ARG_ENABLE([netmap],
diff --git a/pcap.c b/pcap.c
index 8cd9d6b..fa44c71 100644
--- a/pcap.c
+++ b/pcap.c
@@ -91,7 +91,7 @@
#include "pcap-tc.h"
#endif /* HAVE_TC_API */
-#ifdef PCAP_SUPPORT_USB
+#ifdef PCAP_SUPPORT_LINUX_USBMON
#include "pcap-usb-linux.h"
#endif
@@ -533,7 +533,7 @@
#ifdef PCAP_SUPPORT_BT_MONITOR
{ bt_monitor_findalldevs, bt_monitor_create },
#endif
-#ifdef PCAP_SUPPORT_USB
+#ifdef PCAP_SUPPORT_LINUX_USBMON
{ usb_findalldevs, usb_create },
#endif
#ifdef PCAP_SUPPORT_NETFILTER
@@ -1427,7 +1427,7 @@
#ifdef PCAP_SUPPORT_BT
|| strstr(device, "bluetooth") != NULL
#endif
-#ifdef PCAP_SUPPORT_USB
+#ifdef PCAP_SUPPORT_LINUX_USBMON
|| strstr(device, "usbmon") != NULL
#endif
#ifdef HAVE_SNF_API