Ethereal-dev: Re: [Ethereal-dev] captures on FreeBSD hang UI (potential patch)

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Nathan Jennings <njen@xxxxxxxxxxxx>
Date: Sat, 04 Dec 2004 18:38:29 -0500
Guy Harris wrote:
Nathan Jennings said:

I'm using the attached patch (against latest svn) successfully on
FreeBSD 4.9-RELEASE to prevent UI hangs during captures. In other words,
without the patch, which enables select() on the BPF pcap fd, the main
window and capture info dialog will not respond to input unless traffic
matching the capture filter continues filling the buffer.

That sounds like a FreeBSD 4.9 bug - one that would also cause tcpdump,
when run without the -w flag, not to print any packets until traffic
matching the capture filter fills the buffer.

Perhaps adding kqueue support to BPF broke things - but there's nothing
obvious in the differences between 4.6 (which definitely works) and 4.9
that would break things,

I found this email/patch and tried it, without success; although I manually applied the patch and probably messed it up. :o( I don't know, maybe this isn't the problem. At least to me, it seems to match the problem I'm experiencing and you described. It applies to 4.9-RELEASE:

http://lists.freebsd.org/pipermail/freebsd-bugs/2004-March/005856.html

so you should test with tcpdump on a low-traffic
network to see if the symptoms in question occur.


I'm not sure how to do this in a manner that would help. If it would help in some way, just let me know how and I'll do it. Running "tcpdump host 1.2.3.4" (we have no "1.2.3.4" host) and pressing <ctrl-c> doesn't tell you very much, I'd guess. At least with Ethereal, I get a GUI clue. I looked briefly at the tcpdump source in /usr/src/contrib and I think it ultimately calls pcap_loop(). (Does this help?)

Anyway, getting back to Ethereal...

As a workaround, I've used the attached "configure" patch successfully on FreeBSD 4.9-RELEASE and 4.10-RELEASE. This is just another version of my initial patch that instead uses an argument to "configure" that forces the use of select(). At least this way you have the option of using select() without modifying the source.

Would anyone have any concerns with using the attached patch? Maybe it would help in other situations on other OSes/versions too, now or in the future.

Thanks for your feedback and help,
-Nathan
Index: configure.in
===================================================================
--- configure.in	(revision 12628)
+++ configure.in	(working copy)
@@ -636,6 +636,25 @@
 	AC_ETHEREAL_PCAP_CHECK
 fi
 
+#
+# Check if select should be forced for use on libpcap file descriptors.
+# (Used to override bugs in some kernels; for example FreeBSD.)
+#
+AC_ARG_ENABLE(pcap-select,
+	[  --enable-pcap-select    use select on libpcap file descriptors. [default=no]],
+	enable_pcap_select=$enableval,
+	enable_pcap_select=no)
+#AM_CONDITIONAL(MUST_DO_SELECT, test x$enable_pcap_select = xyes)
+if test $want_pcap = yes ; then
+	AC_MSG_CHECKING(whether to use select on libpcap file descriptors)
+	if test "x$enable_pcap_select" = "xno" ; then
+		AC_MSG_RESULT(no)
+	else
+		AC_MSG_RESULT(yes)
+		AC_DEFINE(MUST_DO_SELECT,, [Define to force use of select on libpcap file descriptors.])
+	fi
+fi
+
 dnl zlib check
 AC_MSG_CHECKING(whether to use zlib for reading compressed capture files)
 
@@ -1298,6 +1317,12 @@
 	snmp_libs_message="yes (ucd-snmp)"
 fi
 
+if test "x$enable_pcap_select" = "xyes" ; then
+	pcap_select_message="yes"
+else
+	pcap_select_message="no"
+fi
+
 echo ""
 echo "The Ethereal package has been configured with the following options."
 echo "                    Build ethereal : $enable_ethereal"
@@ -1318,6 +1343,7 @@
 echo "            Build profile binaries : $enable_profile_build"
 fi
 echo "                  Use pcap library : $want_pcap"
+echo "       Use select for pcap library : $pcap_select_message"
 echo "                  Use zlib library : $zlib_message"
 echo "                  Use pcre library : $pcre_message"
 echo "              Use kerberos library : $krb5_message"
Index: capture_loop.c
===================================================================
--- capture_loop.c	(revision 12628)
+++ capture_loop.c	(working copy)
@@ -118,10 +118,16 @@
  * XXX - the various BSDs appear to define BSD in <sys/param.h>; we don't
  * want to include it if it's not present on this platform, however.
  */
-#if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && \
-    !defined(__bsdi__) && !defined(__APPLE__) && !defined(_WIN32) && \
-    !defined(__CYGWIN__)
-# define MUST_DO_SELECT
+
+/* Skip if already defined.
+ * (User told "configure" to force use of select.)
+ */
+#ifndef MUST_DO_SELECT
+#  if !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__OpenBSD__) && \
+      !defined(__bsdi__) && !defined(__APPLE__) && !defined(_WIN32) && \
+      !defined(__CYGWIN__)
+#    define MUST_DO_SELECT
+#  endif
 #endif