aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-08-22 17:36:30 +0000
committerGuy Harris <guy@alum.mit.edu>2013-08-22 17:36:30 +0000
commit347ea71bae842d3da717c8c45a3529f1027dd338 (patch)
tree045edb6d5425bbaf73a7a535f705eb1bd9f88e6f /dumpcap.c
parent4409bc28775a43e0ead1fb788178c2945aa05316 (diff)
Only enable the Linux kernel BPF JIT compiler if we're on Linux.
Unless we're going to do something if that fails, there's no point in having enable_kernel_bpf_jit_compiler() return a success/failure indication. Fix indentation. svn path=/trunk/; revision=51475
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c32
1 files changed, 22 insertions, 10 deletions
diff --git a/dumpcap.c b/dumpcap.c
index bd8dc0c824..582821c799 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -171,24 +171,30 @@ static void capture_loop_stop(void);
/** Close a pipe, or socket if \a from_socket is TRUE */
static void cap_pipe_close(int pipe_fd, gboolean from_socket _U_);
-/* Enable kernel BPF jit compiler if available */
-int enable_kernel_bpf_jit_compiler(void)
+#ifdef __linux__
+/*
+ * Enable kernel BPF JIT compiler if available.
+ * If any calls fail, just drive on - the JIT compiler might not be
+ * enabled, but filtering will still work, and it's not clear what
+ * we could do if the calls fail; should we just report the error
+ * and not continue to capture, should we report it as a warning, or
+ * what?
+ */
+void
+enable_kernel_bpf_jit_compiler(void)
{
int fd;
- ssize_t ret;
-
- const char *file = "/proc/sys/net/core/bpf_jit_enable";
+ static const char file[] = "/proc/sys/net/core/bpf_jit_enable";
fd = open(file, O_WRONLY);
if (fd < 0)
- return -1;
+ return;
- ret = write(fd, "1", (unsigned int)strlen("1"));
+ write(fd, "1", strlen("1"));
close(fd);
- return ret;
}
-
+#endif
#if !defined (__linux__)
#ifndef HAVE_PCAP_BREAKLOOP
@@ -238,6 +244,10 @@ int enable_kernel_bpf_jit_compiler(void)
/* whatever the deal with pcap_breakloop, linux doesn't support timeouts
* in pcap_dispatch(); on the other hand, select() works just fine there.
* Hence we use a select for that come what may.
+ *
+ * XXX - with TPACKET_V1 and TPACKET_V2, it currently uses select()
+ * internally, and, with TPACKET_V3, once that's supported, it'll
+ * support timeouts, at least as I understand the way the code works.
*/
#define MUST_DO_SELECT
#endif
@@ -4403,7 +4413,9 @@ main(int argc, char *argv[])
#endif /* SIGINFO */
#endif /* _WIN32 */
- enable_kernel_bpf_jit_compiler();
+#ifdef __linux__
+ enable_kernel_bpf_jit_compiler();
+#endif
/* ----------------------------------------------------------------- */
/* Privilege and capability handling */