From: Guy Harris Date: Fri, 1 Jul 2016 04:29:14 +0000 (-0700) Subject: Clean up {DAG, Septel, Myricom SNF}-only builds. X-Git-Tag: libpcap-1.8.0-bp~4 X-Git-Url: https://git.tcpdump.org/libpcap/commitdiff_plain/56889e2bb6d732af2fd881bc24e45a2c1a51e38b?ds=inline Clean up {DAG, Septel, Myricom SNF}-only builds. In the core code, treat them similarly to other builds. In the configure script, ensure that no other pcap-XXX.c file is built, so we have only the entries for the capture mechanism in question in the tables for pcap_findalldevs() and pcap_create(), so that those routines are the only ones called. If XXX_ONLY is defined in pcap-XXX.c, define a stub pcap_platform_finddevs() that finds no regular interfaces and a stub pcap_create_interface() that fails with a "we only support XXX" error message. --- diff --git a/configure b/configure index ffda89b1..98fa0e6b 100755 --- a/configure +++ b/configure @@ -6086,15 +6086,30 @@ fi ;; dag) + # + # --with-pcap=dag is the only way to get here, and it means + # "DAG support but nothing else" + # V_DEFS="$V_DEFS -DDAG_ONLY" + xxx_only=yes ;; septel) + # + # --with-pcap=septel is the only way to get here, and it means + # "Septel support but nothing else" + # V_DEFS="$V_DEFS -DSEPTEL_ONLY" + xxx_only=yes ;; snf) + # + # --with-pcap=snf is the only way to get here, and it means + # "SNF support but nothing else" + # V_DEFS="$V_DEFS -DSNF_ONLY" + xxx_only=yes ;; null) @@ -6325,6 +6340,10 @@ else # User requested DAG-only libpcap, so we'd better have # the DAG API. want_dag=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want DAG support. + want_dag=no else # # Use DAG API if present, otherwise don't @@ -6629,6 +6648,10 @@ else # User requested Septel-only libpcap, so we'd better have # the Septel API. want_septel=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want Septel support. + want_septel=no else # # Use Septel API if present, otherwise don't @@ -6714,6 +6737,10 @@ else # User requested Sniffer-only libpcap, so we'd better have # the Sniffer API. want_snf=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want SNF support. + want_snf=no else # # Use Sniffer API if present, otherwise don't @@ -6867,10 +6894,16 @@ if test "${with_turbocap+set}" = set; then : else - # - # Use TurboCap API if present, otherwise don't - # - want_turbocap=ifpresent + if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want TurboCap support. + want_turbocap=no + else + # + # Use TurboCap API if present, otherwise don't + # + want_turbocap=ifpresent + fi fi @@ -8244,6 +8277,12 @@ else 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 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; } @@ -8379,23 +8418,24 @@ fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the platform could support netfilter sniffing" >&5 +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 + 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 @@ -8427,20 +8467,21 @@ fi 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 - NETFILTER_SRC=pcap-netfilter-linux.c - fi - ;; -*) - { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 + NETFILTER_SRC=pcap-netfilter-linux.c + fi + ;; + *) + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 $as_echo "no" >&6; } - ;; -esac + ;; + esac +fi @@ -8452,6 +8493,12 @@ else fi +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want Bluetooth support. + enable_bluetooth=no +fi + if test "x$enable_bluetooth" != "xno" ; then case "$host_os" in linux*) @@ -8581,6 +8628,12 @@ else fi +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want canusb support. + enable_canusb=no +fi + if test "x$enable_canusb" != "xno" ; then case "$host_os" in linux*|uclinux*) @@ -8677,6 +8730,12 @@ else fi +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want CAN support. + enable_can=no +fi + if test "x$enable_can" != "xno" ; then case "$host_os" in linux*) @@ -8726,6 +8785,12 @@ else fi +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want D-Bus support. + enable_dbus=no +fi + if test "x$enable_dbus" != "xno"; then if test "x$enable_dbus" = "xyes"; then case "$host_os" in diff --git a/configure.in b/configure.in index d7301869..a1fa0121 100644 --- a/configure.in +++ b/configure.in @@ -595,15 +595,30 @@ bpf) ;; dag) + # + # --with-pcap=dag is the only way to get here, and it means + # "DAG support but nothing else" + # V_DEFS="$V_DEFS -DDAG_ONLY" + xxx_only=yes ;; septel) + # + # --with-pcap=septel is the only way to get here, and it means + # "Septel support but nothing else" + # V_DEFS="$V_DEFS -DSEPTEL_ONLY" + xxx_only=yes ;; snf) + # + # --with-pcap=snf is the only way to get here, and it means + # "SNF support but nothing else" + # V_DEFS="$V_DEFS -DSNF_ONLY" + xxx_only=yes ;; null) @@ -758,6 +773,10 @@ AC_HELP_STRING([--with-dag@<:@=DIR@:>@],[include Endace DAG support (located in # User requested DAG-only libpcap, so we'd better have # the DAG API. want_dag=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want DAG support. + want_dag=no else # # Use DAG API if present, otherwise don't @@ -878,6 +897,10 @@ AC_HELP_STRING([--with-septel@<:@=DIR@:>@],[include Septel support (located in d # User requested Septel-only libpcap, so we'd better have # the Septel API. want_septel=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want Septel support. + want_septel=no else # # Use Septel API if present, otherwise don't @@ -953,6 +976,10 @@ AC_HELP_STRING([--with-snf@<:@=DIR@:>@],[include Myricom SNF support (located in # User requested Sniffer-only libpcap, so we'd better have # the Sniffer API. want_snf=yes + elif test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want SNF support. + want_snf=no else # # Use Sniffer API if present, otherwise don't @@ -1051,10 +1078,16 @@ AC_HELP_STRING([--with-turbocap@<:@=DIR@:>@],[include Riverbed TurboCap support turbocap_root=$withval fi ],[ - # - # Use TurboCap API if present, otherwise don't - # - want_turbocap=ifpresent + if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want TurboCap support. + want_turbocap=no + else + # + # Use TurboCap API if present, otherwise don't + # + want_turbocap=ifpresent + fi ]) ac_cv_lbl_turbocap_api=no @@ -1444,6 +1477,12 @@ AC_ARG_ENABLE([usb], [], [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) @@ -1516,21 +1555,22 @@ AC_SUBST(PCAP_SUPPORT_USB) AC_SUBST(USB_SRC) dnl check for netfilter sniffing support -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([ +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([ AC_INCLUDES_DEFAULT #include #include @@ -1544,17 +1584,18 @@ AC_INCLUDES_DEFAULT [], 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]) - NETFILTER_SRC=pcap-netfilter-linux.c - fi - ;; -*) - AC_MSG_RESULT(no) - ;; -esac + 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]) + NETFILTER_SRC=pcap-netfilter-linux.c + fi + ;; + *) + AC_MSG_RESULT(no) + ;; + esac +fi AC_SUBST(PCAP_SUPPORT_NETFILTER) AC_SUBST(NETFILTER_SRC) @@ -1563,6 +1604,12 @@ AC_ARG_ENABLE([bluetooth], [], [enable_bluetooth=ifsupportavailable]) +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want Bluetooth support. + enable_bluetooth=no +fi + if test "x$enable_bluetooth" != "xno" ; then dnl check for Bluetooth sniffing support case "$host_os" in @@ -1642,6 +1689,12 @@ AC_ARG_ENABLE([canusb], [], [enable_canusb=ifsupportavailable]) +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want canusb support. + enable_canusb=no +fi + if test "x$enable_canusb" != "xno" ; then dnl check for canusb support case "$host_os" in @@ -1688,6 +1741,12 @@ AC_ARG_ENABLE([can], [], [enable_can=ifsupportavailable]) +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want CAN support. + enable_can=no +fi + if test "x$enable_can" != "xno" ; then dnl check for CAN sniffing support case "$host_os" in @@ -1725,6 +1784,12 @@ AC_ARG_ENABLE([dbus], [], [enable_dbus=ifavailable]) +if test "xxx_only" = yes; then + # User requested something-else-only pcap, so they don't + # want D-Bus support. + enable_dbus=no +fi + if test "x$enable_dbus" != "xno"; then if test "x$enable_dbus" = "xyes"; then case "$host_os" in diff --git a/pcap-dag.c b/pcap-dag.c index 23853b30..c7a6783e 100644 --- a/pcap-dag.c +++ b/pcap-dag.c @@ -1349,3 +1349,31 @@ dag_get_datalink(pcap_t *p) return p->linktype; } + +#ifdef DAG_ONLY +/* + * This libpcap build supports only DAG cards, not regular network + * interfaces. + */ + +/* + * There are no regular interfaces, just DAG interfaces. + */ +int +pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) +{ + *alldevsp = NULL; + return (0); +} + +/* + * Attempts to open a regular interface fail. + */ +pcap_t * +pcap_create_interface(const char *device, char *errbuf) +{ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "This version of libpcap only supports DAG cards"); + return NULL; +} +#endif diff --git a/pcap-septel.c b/pcap-septel.c index 8e0b4a33..88dc89df 100644 --- a/pcap-septel.c +++ b/pcap-septel.c @@ -291,3 +291,31 @@ septel_setnonblock(pcap_t *p, int nonblock, char *errbuf) fprintf(errbuf, PCAP_ERRBUF_SIZE, "Non-blocking mode not supported on Septel devices"); return (-1); } + +#ifdef SEPTEL_ONLY +/* + * This libpcap build supports only Septel cards, not regular network + * interfaces. + */ + +/* + * There are no regular interfaces, just Septel interfaces. + */ +int +pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) +{ + *alldevsp = NULL; + return (0); +} + +/* + * Attempts to open a regular interface fail. + */ +pcap_t * +pcap_create_interface(const char *device, char *errbuf) +{ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "This version of libpcap only supports Septel cards"); + return (NULL); +} +#endif diff --git a/pcap-snf.c b/pcap-snf.c index a72fdd88..207c4959 100644 --- a/pcap-snf.c +++ b/pcap-snf.c @@ -490,3 +490,31 @@ snf_create(const char *device, char *ebuf, int *is_ours) ps->snf_boardnum = boardnum; return p; } + +#ifdef SNF_ONLY +/* + * This libpcap build supports only SNF cards, not regular network + * interfaces.. + */ + +/* + * There are no regular interfaces, just DAG interfaces. + */ +int +pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) +{ + *alldevsp = NULL; + return (0); +} + +/* + * Attempts to open a regular interface fail. + */ +pcap_t * +pcap_create_interface(const char *device, char *errbuf) +{ + pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE, + "This version of libpcap only supports SNF cards"); + return NULL; +} +#endif diff --git a/pcap.c b/pcap.c index c579b837..38078a8c 100644 --- a/pcap.c +++ b/pcap.c @@ -303,46 +303,6 @@ pcap_next_ex(pcap_t *p, struct pcap_pkthdr **pkt_header, return (p->read_op(p, 1, p->oneshot_callback, (u_char *)&s)); } -#if defined(DAG_ONLY) -int -pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) -{ - return (dag_findalldevs(alldevsp, errbuf)); -} - -pcap_t * -pcap_create(const char *device, char *errbuf) -{ - int is_ours; - return (dag_create(device, errbuf, &is_ours)); -} -#elif defined(SEPTEL_ONLY) -int -pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) -{ - return (septel_findalldevs(alldevsp, errbuf)); -} - -pcap_t * -pcap_create(const char *device, char *errbuf) -{ - int is_ours; - return (septel_create(device, errbuf, &is_ours)); -} -#elif defined(SNF_ONLY) -int -pcap_findalldevs(pcap_if_t **alldevsp, char *errbuf) -{ - return (snf_findalldevs(alldevsp, errbuf)); -} - -pcap_t * -pcap_create(const char *device, char *errbuf) -{ - int is_ours; - return (snf_create(device, errbuf, &is_ours)); -} -#else /* regular pcap */ struct capture_source_type { int (*findalldevs_op)(pcap_if_t **, char *); pcap_t *(*create_op)(const char *, char *, int *); @@ -517,7 +477,6 @@ pcap_create(const char *device, char *errbuf) p->opt.device = device_str; return (p); } -#endif static void initialize_ops(pcap_t *p)