From: Victor Julien Date: Fri, 12 Jul 2024 08:34:42 +0000 (+0200) Subject: pcap-file: limit setvbuf to linux X-Git-Tag: suricata-8.0.0-beta1~944 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cff82f16b35c262f98a837442ece8dffa78e43de;p=thirdparty%2Fsuricata.git pcap-file: limit setvbuf to linux As it fails to work correctly on FreeBSD and OpenBSD. On FreeBSD, these are the errors: Info: pcap: Pcap-file will use 4096 buffer size [PcapFileGlobalInit:source-pcap-file.c:159] Error: pcap: failed to get first packet timestamp. pcap_next_ex(): -2 [PeekFirstPacketTimestamp:source-pcap-file-helper.c:186] Warning: pcap: Failed to init pcap file input.pcap, skipping [ReceivePcapFileThreadInit:source-pcap-file.c:299] Error: pcap: pcap file reader thread failed to initialize [ReceivePcapFileLoop:source-pcap-file.c:185] --- diff --git a/configure.ac b/configure.ac index 1bdf823506..24dc01430a 100644 --- a/configure.ac +++ b/configure.ac @@ -274,7 +274,7 @@ ;; *-*-linux*) # Always compile with -fPIC on Linux for shared library support. - CFLAGS="${CFLAGS} -fPIC" + CFLAGS="${CFLAGS} -fPIC -DOS_LINUX" RUST_LDADD="-ldl -lrt -lm" can_build_shared_library="yes" AC_DEFINE([SYSTEMD_NOTIFY], [1], [make Suricata notify systemd on startup]) diff --git a/src/source-pcap-file-helper.c b/src/source-pcap-file-helper.c index c7303fa399..1c9f5933ba 100644 --- a/src/source-pcap-file-helper.c +++ b/src/source-pcap-file-helper.c @@ -208,7 +208,7 @@ TmEcode InitPcapFile(PcapFileFileVars *pfv) SCReturnInt(TM_ECODE_FAILED); } -#if defined(HAVE_SETVBUF) && !defined(OS_WIN32) +#if defined(HAVE_SETVBUF) && defined(OS_LINUX) if (pcap_g.read_buffer_size > 0) { errno = 0; if (setvbuf(pcap_file(pfv->pcap_handle), pfv->buffer, _IOFBF, pcap_g.read_buffer_size) < diff --git a/src/source-pcap-file-helper.h b/src/source-pcap-file-helper.h index 3068c14e3c..2de7d16cc3 100644 --- a/src/source-pcap-file-helper.h +++ b/src/source-pcap-file-helper.h @@ -84,7 +84,7 @@ typedef struct PcapFileFileVars_ /** flex array member for the libc io read buffer. Size controlled by * PcapFileGlobalVars::read_buffer_size. */ -#if defined(HAVE_SETVBUF) && !defined(OS_WIN32) +#if defined(HAVE_SETVBUF) && defined(OS_LINUX) char buffer[]; #endif } PcapFileFileVars; diff --git a/src/source-pcap-file.c b/src/source-pcap-file.c index 85f992d5ca..4492f4698e 100644 --- a/src/source-pcap-file.c +++ b/src/source-pcap-file.c @@ -146,7 +146,7 @@ void PcapFileGlobalInit(void) memset(&pcap_g, 0x00, sizeof(pcap_g)); SC_ATOMIC_INIT(pcap_g.invalid_checksums); -#if defined(HAVE_SETVBUF) && !defined(OS_WIN32) +#if defined(HAVE_SETVBUF) && defined(OS_LINUX) pcap_g.read_buffer_size = PCAP_FILE_BUFFER_SIZE_DEFAULT; const char *str = NULL;