Merging upstream version 2.4.1.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-06-27 06:33:15 +02:00
parent e3a0b7561b
commit 239a2c7899
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
43 changed files with 7626 additions and 515 deletions

1035
CHANGES Normal file

File diff suppressed because it is too large Load diff

View file

@ -6,7 +6,7 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in \
SUBDIRS = src plugins SUBDIRS = src plugins
dist_doc_DATA = README.md LICENSE CONTRIBUTORS dist_doc_DATA = README.md LICENSE CONTRIBUTORS CHANGES
EXTRA_DIST = isc m4 .clang-format fmt.sh EXTRA_DIST = isc m4 .clang-format fmt.sh

View file

@ -304,6 +304,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -352,6 +353,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
@ -376,7 +383,7 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in \
$(srcdir)/configure $(srcdir)/configure
SUBDIRS = src plugins SUBDIRS = src plugins
dist_doc_DATA = README.md LICENSE CONTRIBUTORS dist_doc_DATA = README.md LICENSE CONTRIBUTORS CHANGES
EXTRA_DIST = isc m4 .clang-format fmt.sh EXTRA_DIST = isc m4 .clang-format fmt.sh
all: all-recursive all: all-recursive

View file

@ -31,16 +31,17 @@ General support and discussion:
`dnscap` requires a couple of libraries beside a normal C compiling `dnscap` requires a couple of libraries beside a normal C compiling
environment with autoconf, automake, libtool and pkgconfig. environment with autoconf, automake, libtool and pkgconfig.
`dnscap` has a non-optional dependency on the PCAP library and LDNS. `dnscap` has a non-optional dependency on the PCAP library, LDNS, zlib,
liblz4, libzstd and liblzma.
To install the dependencies under Debian/Ubuntu: To install the dependencies under Debian/Ubuntu:
``` ```
apt-get install -y libpcap-dev libldns-dev zlib1g-dev libyaml-perl libssl-dev apt-get install -y libpcap-dev libldns-dev zlib1g-dev libyaml-perl libssl-dev liblz4-dev libzstd-dev liblzma-dev
``` ```
To install the dependencies under CentOS (with EPEL/PowerTools enabled): To install the dependencies under CentOS (with EPEL/PowerTools enabled):
``` ```
yum install -y libpcap-devel ldns-devel openssl-devel zlib-devel perl-YAML yum install -y libpcap-devel ldns-devel openssl-devel zlib-devel perl-YAML lz4-devel libzstd-devel xz-devel
``` ```
For the following OS you will need to install some of the dependencies For the following OS you will need to install some of the dependencies
@ -48,17 +49,20 @@ from source or Ports, these instructions are not included.
To install some of the dependencies under FreeBSD 10+ using `pkg`: To install some of the dependencies under FreeBSD 10+ using `pkg`:
``` ```
pkg install -y libpcap ldns p5-YAML openssl-devel pkg install -y libpcap ldns p5-YAML openssl-devel liblz4 zstd
``` ```
To install some of the dependencies under OpenBSD 5+ using `pkg_add`: To install some of the dependencies under OpenBSD 5+ using `pkg_add`:
``` ```
pkg_add libldns p5-YAML pkg_add libldns p5-YAML lz4 zstd xz
``` ```
NOTE: It is recommended to install the PCAP library from source/ports on NOTE: It is recommended to install the PCAP library from source/ports on
OpenBSD since the bundled version is an older and modified version. OpenBSD since the bundled version is an older and modified version.
Perl YAML is required by the Root Server Scaling Measurement (RSSM)
plugin's `dnscap-rssm-rssac002` script.
### Dependencies for `cryptopant.so` plugin ### Dependencies for `cryptopant.so` plugin
For this plugin a library call `cryptopANT` is required and the original For this plugin a library call `cryptopANT` is required and the original

791
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -32,11 +32,11 @@
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
AC_PREREQ(2.61) AC_PREREQ(2.69)
AC_INIT([dnscap], [2.3.1], [dnscap-users@dns-oarc.net], [dnscap], [https://github.com/DNS-OARC/dnscap/issues]) AC_INIT([dnscap], [2.4.1], [dnscap-users@dns-oarc.net], [dnscap], [https://github.com/DNS-OARC/dnscap/issues])
AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects])
AC_CONFIG_SRCDIR([src/dnscap.c]) AC_CONFIG_SRCDIR([src/dnscap.c])
AC_CONFIG_HEADER([src/config.h]) AC_CONFIG_HEADERS([src/config.h])
AC_CONFIG_MACRO_DIR([m4]) AC_CONFIG_MACRO_DIR([m4])
# Checks for programs. # Checks for programs.
@ -81,7 +81,6 @@ AM_EXTRA_RECURSIVE_TARGETS([gcov])
AC_CHECK_LIB([dl], [dlopen]) AC_CHECK_LIB([dl], [dlopen])
AC_CHECK_LIB([tinycbor], [cbor_parser_init]) AC_CHECK_LIB([tinycbor], [cbor_parser_init])
AM_CONDITIONAL([HAVE_CBOR], [test "x$ac_cv_lib_tinycbor_cbor_parser_init" = "xyes"]) AM_CONDITIONAL([HAVE_CBOR], [test "x$ac_cv_lib_tinycbor_cbor_parser_init" = "xyes"])
AC_CHECK_LIB([z], [gzopen])
PKG_CHECK_MODULES([libcrypto], [libcrypto], PKG_CHECK_MODULES([libcrypto], [libcrypto],
[AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have libcrypto.])]) [AC_DEFINE([HAVE_LIBCRYPTO], [1], [Define to 1 if you have libcrypto.])])
AC_CHECK_LIB([cryptopant], [scramble_init], [], [ AC_CHECK_LIB([cryptopant], [scramble_init], [], [
@ -90,6 +89,10 @@ AC_CHECK_LIB([cryptopant], [scramble_init], [], [
PKG_CHECK_MODULES([libldns], [libldns], , [ PKG_CHECK_MODULES([libldns], [libldns], , [
PKG_CHECK_MODULES([libldns], [ldns]) PKG_CHECK_MODULES([libldns], [ldns])
]) ])
PKG_CHECK_MODULES([liblz4], [liblz4 >= 1.8.0 liblz4 != 131],, [AC_MSG_ERROR([liblz4 not found])])
PKG_CHECK_MODULES([libzstd], [libzstd >= 1.3.0],, [AC_MSG_ERROR([libzstd not found])])
AC_CHECK_LIB([z], [gzopen],, [AC_MSG_ERROR([zlib not found])])
PKG_CHECK_MODULES([liblzma], [liblzma >= 5.2.0],, [AC_MSG_ERROR([liblzma not found])])
# Check for OS specific libraries # Check for OS specific libraries
case "$host_os" in case "$host_os" in
@ -109,12 +112,9 @@ esac
# Checks for header files. # Checks for header files.
AC_HEADER_RESOLV AC_HEADER_RESOLV
AC_HEADER_TIME
AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h]) AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdlib.h string.h])
AC_CHECK_HEADERS([sys/ioctl.h sys/param.h sys/socket.h sys/time.h unistd.h]) AC_CHECK_HEADERS([sys/ioctl.h sys/param.h sys/socket.h sys/time.h unistd.h])
AC_CHECK_HEADERS([ldns/ldns.h arpa/nameser_compat.h cbor.h cbor/cbor.h]) AC_CHECK_HEADERS([ldns/ldns.h arpa/nameser_compat.h cbor.h cbor/cbor.h])
AC_CHECK_HEADERS([sys/time.h])
AC_CHECK_HEADERS([zlib.h])
AC_CHECK_HEADERS([openssl/conf.h openssl/evp.h openssl/err.h]) AC_CHECK_HEADERS([openssl/conf.h openssl/evp.h openssl/err.h])
AC_CHECK_HEADERS([cryptopANT.h]) AC_CHECK_HEADERS([cryptopANT.h])
AC_CHECK_HEADERS([endian.h sys/endian.h machine/endian.h]) AC_CHECK_HEADERS([endian.h sys/endian.h machine/endian.h])
@ -122,12 +122,13 @@ AC_CHECK_HEADERS([endian.h sys/endian.h machine/endian.h])
# Checks for library functions. # Checks for library functions.
AC_CHECK_FUNCS([snprintf]) AC_CHECK_FUNCS([snprintf])
AC_CHECK_FUNCS([setreuid setresuid setregid setresgid setegid seteuid initgroups setgroups]) AC_CHECK_FUNCS([setreuid setresuid setregid setresgid setegid seteuid initgroups setgroups])
AC_CHECK_FUNCS([funopen fopencookie gzopen]) AC_CHECK_FUNCS([fopencookie funopen])
AS_IF([test "x$ac_cv_func_fopencookie$ac_cv_func_funopen" = "xnono"], [AC_MSG_ERROR([required function, fopencookie or funopen, not found])])
AC_CHECK_FUNCS([__assertion_failed]) AC_CHECK_FUNCS([__assertion_failed])
# Check for SECCOMP # Check for SECCOMP
SECCOMPFLAGS= SECCOMPFLAGS=
AC_ARG_ENABLE(seccomp, AC_HELP_STRING([--enable-seccomp], [Linux seccomp-bpf sandbox])) AC_ARG_ENABLE(seccomp, AS_HELP_STRING([--enable-seccomp], [Linux seccomp-bpf sandbox]))
case "$enable_seccomp" in case "$enable_seccomp" in
yes) yes)
AC_DEFINE_UNQUOTED([USE_SECCOMP], [1], [Define this to enable Linux seccomp-bpf sandbox.]) AC_DEFINE_UNQUOTED([USE_SECCOMP], [1], [Define this to enable Linux seccomp-bpf sandbox.])

View file

@ -252,6 +252,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -300,6 +301,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -9,7 +9,6 @@ fi
ln -fs "$srcdir/../../src/test/dns.pcap" dns.pcap-dist ln -fs "$srcdir/../../src/test/dns.pcap" dns.pcap-dist
../../src/dnscap -r dns.pcap-dist -g -P "$plugin" -? ../../src/dnscap -r dns.pcap-dist -g -P "$plugin" -?
#../../src/dnscap -r dns.pcap-dist -g -P "$plugin"
! ../../src/dnscap -r dns.pcap-dist -g -P "$plugin" -X ! ../../src/dnscap -r dns.pcap-dist -g -P "$plugin" -X
ln -fs "$srcdir/../../src/test/dnso1tcp.pcap" dnso1tcp.pcap-dist ln -fs "$srcdir/../../src/test/dnso1tcp.pcap" dnso1tcp.pcap-dist

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -459,6 +459,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -507,6 +508,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -453,6 +453,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -501,6 +502,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -452,6 +452,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -500,6 +501,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@

View file

@ -4,27 +4,31 @@ CLEANFILES = dnscap.1 *.gcda *.gcno *.gcov
SUBDIRS = test SUBDIRS = test
AM_CFLAGS = -I$(srcdir) \ AM_CFLAGS = -I$(srcdir) \
-I$(top_srcdir) \ -I$(top_srcdir) \
$(SECCOMPFLAGS) \ $(SECCOMPFLAGS) \
$(PTHREAD_CFLAGS) \ $(PTHREAD_CFLAGS) \
$(libcrypto_CFLAGS) \ $(libcrypto_CFLAGS) \
$(libldns_CFLAGS) $(libldns_CFLAGS) \
$(liblz4_CFLAGS) \
$(libzstd_CFLAGS) \
$(liblzma_CFLAGS)
EXTRA_DIST = dnscap.1.in EXTRA_DIST = dnscap.1.in
bin_PROGRAMS = dnscap bin_PROGRAMS = dnscap
dnscap_SOURCES = args.c assert.c bpft.c daemon.c dnscap.c dump_cbor.c \ dnscap_SOURCES = args.c assert.c bpft.c daemon.c dnscap.c dump_cbor.c \
dump_cds.c dump_dns.c dumper.c endpoint.c hashtbl.c iaddr.c log.c \ dump_cds.c dump_dns.c dumper.c endpoint.c hashtbl.c iaddr.c log.c \
network.c options.c pcaps.c sig.c tcpstate.c tcpreasm.c memzero.c \ network.c options.c pcaps.c sig.c tcpstate.c tcpreasm.c memzero.c \
pcap-thread/pcap_thread.c pcap-thread/pcap_thread_ext_frag.c \ pcap-thread/pcap_thread.c pcap-thread/pcap_thread_ext_frag.c \
ext/lookup3.c ext/lookup3.c
dist_dnscap_SOURCES = args.h bpft.h daemon.h dnscap_common.h dnscap.h \ dist_dnscap_SOURCES = args.h bpft.h daemon.h dnscap_common.h dnscap.h \
dump_cbor.h dump_cds.h dump_dns.h dumper.h endpoint.h hashtbl.h iaddr.h \ dump_cbor.h dump_cds.h dump_dns.h dumper.h endpoint.h hashtbl.h iaddr.h \
log.h network.h options.h pcaps.h sig.h tcpstate.h tcpreasm.h memzero.h \ log.h network.h options.h pcaps.h sig.h tcpstate.h tcpreasm.h memzero.h \
endian_compat.h \ endian_compat.h \
pcap-thread/pcap_thread.h pcap-thread/pcap_thread_ext_frag.h pcap-thread/pcap_thread.h pcap-thread/pcap_thread_ext_frag.h
dnscap_LDADD = $(PTHREAD_LIBS) $(libcrypto_LIBS) $(libldns_LIBS) dnscap_LDADD = $(PTHREAD_LIBS) $(libcrypto_LIBS) $(libldns_LIBS) \
$(liblz4_LIBS) $(libzstd_LIBS) $(liblzma_LIBS)
man1_MANS = dnscap.1 man1_MANS = dnscap.1

View file

@ -124,7 +124,8 @@ dist_dnscap_OBJECTS =
dnscap_OBJECTS = $(am_dnscap_OBJECTS) $(dist_dnscap_OBJECTS) dnscap_OBJECTS = $(am_dnscap_OBJECTS) $(dist_dnscap_OBJECTS)
am__DEPENDENCIES_1 = am__DEPENDENCIES_1 =
dnscap_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ dnscap_DEPENDENCIES = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \
$(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1)
AM_V_lt = $(am__v_lt_@AM_V@) AM_V_lt = $(am__v_lt_@AM_V@)
am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@) am__v_lt_ = $(am__v_lt_@AM_DEFAULT_V@)
am__v_lt_0 = --silent am__v_lt_0 = --silent
@ -341,6 +342,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -389,6 +391,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
@ -411,18 +419,21 @@ MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/config.h.in
CLEANFILES = dnscap.1 *.gcda *.gcno *.gcov CLEANFILES = dnscap.1 *.gcda *.gcno *.gcov
SUBDIRS = test SUBDIRS = test
AM_CFLAGS = -I$(srcdir) \ AM_CFLAGS = -I$(srcdir) \
-I$(top_srcdir) \ -I$(top_srcdir) \
$(SECCOMPFLAGS) \ $(SECCOMPFLAGS) \
$(PTHREAD_CFLAGS) \ $(PTHREAD_CFLAGS) \
$(libcrypto_CFLAGS) \ $(libcrypto_CFLAGS) \
$(libldns_CFLAGS) $(libldns_CFLAGS) \
$(liblz4_CFLAGS) \
$(libzstd_CFLAGS) \
$(liblzma_CFLAGS)
EXTRA_DIST = dnscap.1.in EXTRA_DIST = dnscap.1.in
dnscap_SOURCES = args.c assert.c bpft.c daemon.c dnscap.c dump_cbor.c \ dnscap_SOURCES = args.c assert.c bpft.c daemon.c dnscap.c dump_cbor.c \
dump_cds.c dump_dns.c dumper.c endpoint.c hashtbl.c iaddr.c log.c \ dump_cds.c dump_dns.c dumper.c endpoint.c hashtbl.c iaddr.c log.c \
network.c options.c pcaps.c sig.c tcpstate.c tcpreasm.c memzero.c \ network.c options.c pcaps.c sig.c tcpstate.c tcpreasm.c memzero.c \
pcap-thread/pcap_thread.c pcap-thread/pcap_thread_ext_frag.c \ pcap-thread/pcap_thread.c pcap-thread/pcap_thread_ext_frag.c \
ext/lookup3.c ext/lookup3.c
dist_dnscap_SOURCES = args.h bpft.h daemon.h dnscap_common.h dnscap.h \ dist_dnscap_SOURCES = args.h bpft.h daemon.h dnscap_common.h dnscap.h \
dump_cbor.h dump_cds.h dump_dns.h dumper.h endpoint.h hashtbl.h iaddr.h \ dump_cbor.h dump_cds.h dump_dns.h dumper.h endpoint.h hashtbl.h iaddr.h \
@ -430,7 +441,9 @@ dist_dnscap_SOURCES = args.h bpft.h daemon.h dnscap_common.h dnscap.h \
endian_compat.h \ endian_compat.h \
pcap-thread/pcap_thread.h pcap-thread/pcap_thread_ext_frag.h pcap-thread/pcap_thread.h pcap-thread/pcap_thread_ext_frag.h
dnscap_LDADD = $(PTHREAD_LIBS) $(libcrypto_LIBS) $(libldns_LIBS) dnscap_LDADD = $(PTHREAD_LIBS) $(libcrypto_LIBS) $(libldns_LIBS) \
$(liblz4_LIBS) $(libzstd_LIBS) $(liblzma_LIBS)
man1_MANS = dnscap.1 man1_MANS = dnscap.1
all: config.h all: config.h
$(MAKE) $(AM_MAKEFLAGS) all-recursive $(MAKE) $(AM_MAKEFLAGS) all-recursive

View file

@ -114,6 +114,16 @@ void set_iaddr(iaddr* from, iaddr* to)
} }
} }
long _get_pcap_thread_ftell(void)
{
return pcap_thread_ftell(&pcap_thread);
}
size_t _get_pkthdr_caplen(void)
{
return pkthdr_caplen;
}
#ifdef __linux__ #ifdef __linux__
extern char* strptime(const char*, const char*, struct tm*); extern char* strptime(const char*, const char*, struct tm*);
#endif #endif
@ -242,13 +252,6 @@ void check_gzip()
if (dot) { if (dot) {
wantgzip = (strcmp(dot, ".gz") == 0) ? TRUE : FALSE; wantgzip = (strcmp(dot, ".gz") == 0) ? TRUE : FALSE;
} }
#if !(HAVE_GZOPEN && (HAVE_FUNOPEN || HAVE_FOPENCOOKIE))
if (wantgzip) {
fprintf(stderr, "error: gzip compression requested but not supported\n");
exit(1);
}
#endif
} }
int is_responder(iaddr ia) int is_responder(iaddr ia)
@ -333,7 +336,7 @@ void parse_args(int argc, char* argv[])
break; break;
case 'r': case 'r':
if (!EMPTY(mypcaps)) if (!EMPTY(mypcaps))
usage("-r makes no sense after -i"); usage("-r makes no sense after -i, or specified multiple times");
pcap_offline = calloc(1, sizeof *pcap_offline); pcap_offline = calloc(1, sizeof *pcap_offline);
assert(pcap_offline != NULL); assert(pcap_offline != NULL);
INIT_LINK(pcap_offline, link); INIT_LINK(pcap_offline, link);
@ -625,6 +628,8 @@ void parse_args(int argc, char* argv[])
(*pl->extension)(DNSCAP_EXT_TCPSTATE_RESET, (tcpstate_reset_t)_tcpstate_reset); (*pl->extension)(DNSCAP_EXT_TCPSTATE_RESET, (tcpstate_reset_t)_tcpstate_reset);
(*pl->extension)(DNSCAP_EXT_SET_IADDR, (set_iaddr_t)set_iaddr); (*pl->extension)(DNSCAP_EXT_SET_IADDR, (set_iaddr_t)set_iaddr);
(*pl->extension)(DNSCAP_EXT_SET_OUTPUT_PKT, (set_output_pkt_t)set_output_pkt); (*pl->extension)(DNSCAP_EXT_SET_OUTPUT_PKT, (set_output_pkt_t)set_output_pkt);
(*pl->extension)(DNSCAP_EXT_GET_PCAP_THREAD_FTELL, (get_pcap_thread_ftell_t)_get_pcap_thread_ftell);
(*pl->extension)(DNSCAP_EXT_GET_PKTHDR_CAPLEN, (get_pkthdr_caplen_t)_get_pkthdr_caplen);
} }
snprintf(sn, sizeof(sn), "%s_getopt", pl->name); snprintf(sn, sizeof(sn), "%s_getopt", pl->name);
pl->getopt = dlsym(pl->handle, sn); pl->getopt = dlsym(pl->handle, sn);

View file

@ -33,9 +33,6 @@
/* Define to 1 if you have the `funopen' function. */ /* Define to 1 if you have the `funopen' function. */
#undef HAVE_FUNOPEN #undef HAVE_FUNOPEN
/* Define to 1 if you have the `gzopen' function. */
#undef HAVE_GZOPEN
/* Define to 1 if you have the `initgroups' function. */ /* Define to 1 if you have the `initgroups' function. */
#undef HAVE_INITGROUPS #undef HAVE_INITGROUPS
@ -196,9 +193,6 @@
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#undef HAVE_UNISTD_H #undef HAVE_UNISTD_H
/* Define to 1 if you have the <zlib.h> header file. */
#undef HAVE_ZLIB_H
/* Define to 1 if you have the `__assertion_failed' function. */ /* Define to 1 if you have the `__assertion_failed' function. */
#undef HAVE___ASSERTION_FAILED #undef HAVE___ASSERTION_FAILED
@ -235,10 +229,6 @@
backward compatibility; new code need not use it. */ backward compatibility; new code need not use it. */
#undef STDC_HEADERS #undef STDC_HEADERS
/* Define to 1 if you can safely include both <sys/time.h> and <time.h>. This
macro is obsolete. */
#undef TIME_WITH_SYS_TIME
/* Define this to enable Linux seccomp-bpf sandbox. */ /* Define this to enable Linux seccomp-bpf sandbox. */
#undef USE_SECCOMP #undef USE_SECCOMP

View file

@ -212,6 +212,8 @@ file produced by this utility or by
.BR tcpdump (1) .BR tcpdump (1)
(or simiar tools) as the input packet source. (or simiar tools) as the input packet source.
Can be given as "\-" to indicate standard input. Can be given as "\-" to indicate standard input.
Supports reading gz/xz/lz4/zst compressed PCAPs based on file extension.
.TP .TP
.BI "\-i " if .BI "\-i " if
Select an interface to be monitored. Select an interface to be monitored.

View file

@ -89,6 +89,7 @@ FILE* dumper_fp = 0;
time_t dumpstart; time_t dumpstart;
size_t msgcount = 0; size_t msgcount = 0;
size_t capturedbytes = 0; size_t capturedbytes = 0;
size_t pkthdr_caplen = 0;
char * dumpname, *dumpnamepart; char * dumpname, *dumpnamepart;
char* bpft; char* bpft;
unsigned dns_port = DNS_PORT; unsigned dns_port = DNS_PORT;

View file

@ -37,6 +37,7 @@
#ifdef __linux__ #ifdef __linux__
#define _GNU_SOURCE #define _GNU_SOURCE
#define _FILE_OFFSET_BITS 64 /* for fopencookie() */
#endif #endif
#include <sys/param.h> #include <sys/param.h>
@ -136,10 +137,6 @@
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#if HAVE_ZLIB_H
#include <zlib.h>
#endif
#include <ldns/ldns.h> #include <ldns/ldns.h>
#ifndef IPV6_VERSION #ifndef IPV6_VERSION
@ -358,7 +355,7 @@ struct plugin {
int (*start)(logerr_t*); int (*start)(logerr_t*);
void (*stop)(); void (*stop)();
int (*open)(my_bpftimeval); int (*open)(my_bpftimeval);
int (*close)(); int (*close)(my_bpftimeval);
output_t(*output); output_t(*output);
filter_t(*filter); filter_t(*filter);
void (*getopt)(int*, char**[]); void (*getopt)(int*, char**[]);
@ -416,6 +413,7 @@ extern FILE* dumper_fp;
extern time_t dumpstart; extern time_t dumpstart;
extern size_t msgcount; extern size_t msgcount;
extern size_t capturedbytes; extern size_t capturedbytes;
extern size_t pkthdr_caplen;
extern char * dumpname, *dumpnamepart; extern char * dumpname, *dumpnamepart;
extern char* bpft; extern char* bpft;
extern unsigned dns_port; extern unsigned dns_port;

View file

@ -37,17 +37,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h> #include <time.h>
#else
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else
#include <time.h>
#endif
#endif
/* Macros for printing timeval */ /* Macros for printing timeval */
#include <inttypes.h> #include <inttypes.h>
@ -158,6 +148,12 @@ typedef void (*set_iaddr_t)(iaddr* from, iaddr* to);
#define DNSCAP_EXT_SET_OUTPUT_PKT 6 #define DNSCAP_EXT_SET_OUTPUT_PKT 6
typedef void (*set_output_pkt_t)(u_char* pkt, const unsigned olen); typedef void (*set_output_pkt_t)(u_char* pkt, const unsigned olen);
#define DNSCAP_EXT_GET_PCAP_THREAD_FTELL 7
typedef long (*get_pcap_thread_ftell_t)(void);
#define DNSCAP_EXT_GET_PKTHDR_CAPLEN 8
typedef size_t (*get_pkthdr_caplen_t)(void);
/* /*
* Flags * Flags
*/ */

View file

@ -40,6 +40,8 @@
#include "pcaps.h" #include "pcaps.h"
#include "args.h" #include "args.h"
#include <zlib.h>
static u_char* _pkt; static u_char* _pkt;
static unsigned _olen; static unsigned _olen;
@ -377,7 +379,7 @@ int dumper_close(my_bpftimeval ts)
int x; int x;
if (!p->close) if (!p->close)
continue; continue;
x = (*p->close)(); x = (*p->close)(ts);
if (x) if (x)
logerr("%s_close returned %d", p->name, x); logerr("%s_close returned %d", p->name, x);
} }
@ -385,65 +387,47 @@ int dumper_close(my_bpftimeval ts)
return (ret); return (ret);
} }
#if HAVE_ZLIB_H #if HAVE_FOPENCOOKIE
#if HAVE_FUNOPEN static ssize_t gzip_cookie_write(void* cookie, const char* buf, size_t size)
static int #elif HAVE_FUNOPEN
gzip_cookie_write(void* cookie, const char* buf, int size) static int gzip_cookie_write(void* cookie, const char* buf, int size)
{
return gzwrite((gzFile)cookie, (voidpc)buf, (unsigned)size);
}
#elif HAVE_FOPENCOOKIE
static ssize_t
gzip_cookie_write(void* cookie, const char* buf, size_t size)
{
return gzwrite((gzFile)cookie, (voidpc)buf, (unsigned)size);
}
#endif #endif
{
return gzwrite((gzFile)cookie, (voidpc)buf, (unsigned)size);
}
static int static int gzip_cookie_close(void* cookie)
gzip_cookie_close(void* cookie)
{ {
return gzclose((gzFile)cookie); return gzclose((gzFile)cookie);
} }
#endif /* HAVE_ZLIB_H */
void dnscap_dump_open_gz(const char* path, FILE** fp) void dnscap_dump_open_gz(const char* path, FILE** fp)
{ {
#if HAVE_ZLIB_H *fp = 0;
#if HAVE_GZOPEN
if (wantgzip) {
gzFile z = gzopen(path, "w");
if (z == NULL) {
perror("gzopen");
return;
}
#if HAVE_FUNOPEN gzFile z = gzopen(path, "w");
*fp = funopen(z, NULL, gzip_cookie_write, NULL, gzip_cookie_close); if (z == NULL) {
if (*fp == NULL) { perror("gzopen");
perror("funopen");
return;
}
#elif HAVE_FOPENCOOKIE
{
static cookie_io_functions_t cookiefuncs = {
NULL, gzip_cookie_write, NULL, gzip_cookie_close
};
*fp = fopencookie(z, "w", cookiefuncs);
if (*fp == NULL) {
perror("fopencookie");
return;
}
}
#endif
return; return;
} }
#endif /* HAVE_GZOPEN */
#endif /* HAVE_ZLIB_H */
*fp = 0; #if HAVE_FOPENCOOKIE
return; static cookie_io_functions_t cookiefuncs = {
NULL, gzip_cookie_write, NULL, gzip_cookie_close
};
*fp = fopencookie(z, "w", cookiefuncs);
if (*fp == NULL) {
perror("fopencookie");
return;
}
#elif HAVE_FUNOPEN
*fp = funopen(z, NULL, gzip_cookie_write, NULL, gzip_cookie_close);
if (*fp == NULL) {
perror("funopen");
return;
}
#endif
} }
pcap_dumper_t* dnscap_pcap_dump_open(pcap_t* pcap, const char* path) pcap_dumper_t* dnscap_pcap_dump_open(pcap_t* pcap, const char* path)

View file

@ -123,7 +123,8 @@ void layer_pkt(u_char* user, const pcap_thread_packet_t* packet, const u_char* p
if (only_offline_pcaps && start_time != 0 && firstpkt->pkthdr.ts.tv_sec < start_time) if (only_offline_pcaps && start_time != 0 && firstpkt->pkthdr.ts.tv_sec < start_time)
return; return;
len = firstpkt->pkthdr.caplen; len = firstpkt->pkthdr.caplen;
pkthdr_caplen = len;
last_ts = firstpkt->pkthdr.ts; last_ts = firstpkt->pkthdr.ts;
if (stop_time != 0 && firstpkt->pkthdr.ts.tv_sec >= stop_time) { if (stop_time != 0 && firstpkt->pkthdr.ts.tv_sec >= stop_time) {
@ -286,6 +287,8 @@ void dl_pkt(u_char* user, const struct pcap_pkthdr* hdr, const u_char* pkt, cons
if (hdr->len != hdr->caplen) if (hdr->len != hdr->caplen)
return; return;
pkthdr_caplen = hdr->caplen;
/* Data link. */ /* Data link. */
vlan = MAX_VLAN; /* MAX_VLAN (0xFFF) is reserved and shouldn't appear on the wire */ vlan = MAX_VLAN; /* MAX_VLAN (0xFFF) is reserved and shouldn't appear on the wire */
switch (dlt) { switch (dlt) {

View file

@ -1,5 +1,4 @@
AC_DEFUN([AX_PCAP_THREAD_PCAP], [ AC_DEFUN([AX_PCAP_THREAD_PCAP], [
AC_HEADER_TIME
AC_CHECK_LIB([pcap], [pcap_open_live], [], [AC_MSG_ERROR([libpcap not found])]) AC_CHECK_LIB([pcap], [pcap_open_live], [], [AC_MSG_ERROR([libpcap not found])])
AC_CHECK_HEADER([pcap/pcap.h], [], [AC_MSG_ERROR([libpcap header not found])]) AC_CHECK_HEADER([pcap/pcap.h], [], [AC_MSG_ERROR([libpcap header not found])])
AC_CHECK_HEADERS([endian.h sys/endian.h machine/endian.h sys/time.h]) AC_CHECK_HEADERS([endian.h sys/endian.h machine/endian.h sys/time.h])

View file

@ -1,5 +1,5 @@
# =========================================================================== # ===========================================================================
# http://www.gnu.org/software/autoconf-archive/ax_pthread.html # https://www.gnu.org/software/autoconf-archive/ax_pthread.html
# =========================================================================== # ===========================================================================
# #
# SYNOPSIS # SYNOPSIS
@ -14,20 +14,24 @@
# flags that are needed. (The user can also force certain compiler # flags that are needed. (The user can also force certain compiler
# flags/libs to be tested by setting these environment variables.) # flags/libs to be tested by setting these environment variables.)
# #
# Also sets PTHREAD_CC to any special C compiler that is needed for # Also sets PTHREAD_CC and PTHREAD_CXX to any special C compiler that is
# multi-threaded programs (defaults to the value of CC otherwise). (This # needed for multi-threaded programs (defaults to the value of CC
# is necessary on AIX to use the special cc_r compiler alias.) # respectively CXX otherwise). (This is necessary on e.g. AIX to use the
# special cc_r/CC_r compiler alias.)
# #
# NOTE: You are assumed to not only compile your program with these flags, # NOTE: You are assumed to not only compile your program with these flags,
# but also to link with them as well. For example, you might link with # but also to link with them as well. For example, you might link with
# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS # $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
# $PTHREAD_CXX $CXXFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
# #
# If you are only building threaded programs, you may wish to use these # If you are only building threaded programs, you may wish to use these
# variables in your default LIBS, CFLAGS, and CC: # variables in your default LIBS, CFLAGS, and CC:
# #
# LIBS="$PTHREAD_LIBS $LIBS" # LIBS="$PTHREAD_LIBS $LIBS"
# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" # CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
# CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
# CC="$PTHREAD_CC" # CC="$PTHREAD_CC"
# CXX="$PTHREAD_CXX"
# #
# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant # In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to # has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to
@ -55,6 +59,7 @@
# #
# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> # Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG> # Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
# Copyright (c) 2019 Marc Stevens <marc.stevens@cwi.nl>
# #
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -67,7 +72,7 @@
# Public License for more details. # Public License for more details.
# #
# You should have received a copy of the GNU General Public License along # You should have received a copy of the GNU General Public License along
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <https://www.gnu.org/licenses/>.
# #
# As a special exception, the respective Autoconf Macro's copyright owner # As a special exception, the respective Autoconf Macro's copyright owner
# gives unlimited permission to copy, distribute and modify the configure # gives unlimited permission to copy, distribute and modify the configure
@ -82,7 +87,7 @@
# modified version of the Autoconf Macro, you may extend this special # modified version of the Autoconf Macro, you may extend this special
# exception to the GPL to apply to your modified version as well. # exception to the GPL to apply to your modified version as well.
#serial 23 #serial 31
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
AC_DEFUN([AX_PTHREAD], [ AC_DEFUN([AX_PTHREAD], [
@ -104,6 +109,7 @@ if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then
ax_pthread_save_CFLAGS="$CFLAGS" ax_pthread_save_CFLAGS="$CFLAGS"
ax_pthread_save_LIBS="$LIBS" ax_pthread_save_LIBS="$LIBS"
AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
AS_IF([test "x$PTHREAD_CXX" != "x"], [CXX="$PTHREAD_CXX"])
CFLAGS="$CFLAGS $PTHREAD_CFLAGS" CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
LIBS="$PTHREAD_LIBS $LIBS" LIBS="$PTHREAD_LIBS $LIBS"
AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS])
@ -123,10 +129,12 @@ fi
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
# libraries is broken (non-POSIX). # libraries is broken (non-POSIX).
# Create a list of thread flags to try. Items starting with a "-" are # Create a list of thread flags to try. Items with a "," contain both
# C compiler flags, and other items are library names, except for "none" # C compiler flags (before ",") and linker flags (after ","). Other items
# which indicates that we try without any flags at all, and "pthread-config" # starting with a "-" are C compiler flags, and remaining items are
# which is a program returning the flags for the Pth emulation library. # library names, except for "none" which indicates that we try without
# any flags at all, and "pthread-config" which is a program returning
# the flags for the Pth emulation library.
ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
@ -194,14 +202,47 @@ case $host_os in
# that too in a future libc.) So we'll check first for the # that too in a future libc.) So we'll check first for the
# standard Solaris way of linking pthreads (-mt -lpthread). # standard Solaris way of linking pthreads (-mt -lpthread).
ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags"
;; ;;
esac esac
# Are we compiling with Clang?
AC_CACHE_CHECK([whether $CC is Clang],
[ax_cv_PTHREAD_CLANG],
[ax_cv_PTHREAD_CLANG=no
# Note that Autoconf sets GCC=yes for Clang as well as GCC
if test "x$GCC" = "xyes"; then
AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
[/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
# if defined(__clang__) && defined(__llvm__)
AX_PTHREAD_CC_IS_CLANG
# endif
],
[ax_cv_PTHREAD_CLANG=yes])
fi
])
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) # GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
# Note that for GCC and Clang -pthread generally implies -lpthread,
# except when -nostdlib is passed.
# This is problematic using libtool to build C++ shared libraries with pthread:
# [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
# [2] https://bugzilla.redhat.com/show_bug.cgi?id=661333
# [3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555
# To solve this, first try -pthread together with -lpthread for GCC
AS_IF([test "x$GCC" = "xyes"], AS_IF([test "x$GCC" = "xyes"],
[ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) [ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"])
# Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first
AS_IF([test "x$ax_pthread_clang" = "xyes"],
[ax_pthread_flags="-pthread,-lpthread -pthread"])
# The presence of a feature test macro requesting re-entrant function # The presence of a feature test macro requesting re-entrant function
# definitions is, on some systems, a strong hint that pthreads support is # definitions is, on some systems, a strong hint that pthreads support is
@ -224,101 +265,6 @@ AS_IF([test "x$ax_pthread_check_macro" = "x--"],
[ax_pthread_check_cond=0], [ax_pthread_check_cond=0],
[ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
# Are we compiling with Clang?
AC_CACHE_CHECK([whether $CC is Clang],
[ax_cv_PTHREAD_CLANG],
[ax_cv_PTHREAD_CLANG=no
# Note that Autoconf sets GCC=yes for Clang as well as GCC
if test "x$GCC" = "xyes"; then
AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
[/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
# if defined(__clang__) && defined(__llvm__)
AX_PTHREAD_CC_IS_CLANG
# endif
],
[ax_cv_PTHREAD_CLANG=yes])
fi
])
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
ax_pthread_clang_warning=no
# Clang needs special handling, because older versions handle the -pthread
# option in a rather... idiosyncratic way
if test "x$ax_pthread_clang" = "xyes"; then
# Clang takes -pthread; it has never supported any other flag
# (Note 1: This will need to be revisited if a system that Clang
# supports has POSIX threads in a separate library. This tends not
# to be the way of modern systems, but it's conceivable.)
# (Note 2: On some systems, notably Darwin, -pthread is not needed
# to get POSIX threads support; the API is always present and
# active. We could reasonably leave PTHREAD_CFLAGS empty. But
# -pthread does define _REENTRANT, and while the Darwin headers
# ignore this macro, third-party headers might not.)
PTHREAD_CFLAGS="-pthread"
PTHREAD_LIBS=
ax_pthread_ok=yes
# However, older versions of Clang make a point of warning the user
# that, in an invocation where only linking and no compilation is
# taking place, the -pthread option has no effect ("argument unused
# during compilation"). They expect -pthread to be passed in only
# when source code is being compiled.
#
# Problem is, this is at odds with the way Automake and most other
# C build frameworks function, which is that the same flags used in
# compilation (CFLAGS) are also used in linking. Many systems
# supported by AX_PTHREAD require exactly this for POSIX threads
# support, and in fact it is often not straightforward to specify a
# flag that is used only in the compilation phase and not in
# linking. Such a scenario is extremely rare in practice.
#
# Even though use of the -pthread flag in linking would only print
# a warning, this can be a nuisance for well-run software projects
# that build with -Werror. So if the active version of Clang has
# this misfeature, we search for an option to squash it.
AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
# Create an alternate version of $ac_link that compiles and
# links in two steps (.c -> .o, .o -> exe) instead of one
# (.c -> exe), because the warning occurs only in the second
# step
ax_pthread_save_ac_link="$ac_link"
ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"`
ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
ax_pthread_save_CFLAGS="$CFLAGS"
for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
ac_link="$ax_pthread_save_ac_link"
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
[ac_link="$ax_pthread_2step_ac_link"
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
[break])
])
done
ac_link="$ax_pthread_save_ac_link"
CFLAGS="$ax_pthread_save_CFLAGS"
AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
])
case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
no | unknown) ;;
*) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
esac
fi # $ax_pthread_clang = yes
if test "x$ax_pthread_ok" = "xno"; then if test "x$ax_pthread_ok" = "xno"; then
for ax_pthread_try_flag in $ax_pthread_flags; do for ax_pthread_try_flag in $ax_pthread_flags; do
@ -328,10 +274,10 @@ for ax_pthread_try_flag in $ax_pthread_flags; do
AC_MSG_CHECKING([whether pthreads work without any flags]) AC_MSG_CHECKING([whether pthreads work without any flags])
;; ;;
-mt,pthread) *,*)
AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"`
PTHREAD_CFLAGS="-mt" PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"`
PTHREAD_LIBS="-lpthread" AC_MSG_CHECKING([whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"])
;; ;;
-*) -*)
@ -371,7 +317,13 @@ for ax_pthread_try_flag in $ax_pthread_flags; do
# if $ax_pthread_check_cond # if $ax_pthread_check_cond
# error "$ax_pthread_check_macro must be defined" # error "$ax_pthread_check_macro must be defined"
# endif # endif
static void routine(void *a) { a = 0; } static void *some_global = NULL;
static void routine(void *a)
{
/* To avoid any unused-parameter or
unused-but-set-parameter warning. */
some_global = a;
}
static void *start_routine(void *a) { return a; }], static void *start_routine(void *a) { return a; }],
[pthread_t th; pthread_attr_t attr; [pthread_t th; pthread_attr_t attr;
pthread_create(&th, 0, start_routine, 0); pthread_create(&th, 0, start_routine, 0);
@ -393,6 +345,80 @@ for ax_pthread_try_flag in $ax_pthread_flags; do
done done
fi fi
# Clang needs special handling, because older versions handle the -pthread
# option in a rather... idiosyncratic way
if test "x$ax_pthread_clang" = "xyes"; then
# Clang takes -pthread; it has never supported any other flag
# (Note 1: This will need to be revisited if a system that Clang
# supports has POSIX threads in a separate library. This tends not
# to be the way of modern systems, but it's conceivable.)
# (Note 2: On some systems, notably Darwin, -pthread is not needed
# to get POSIX threads support; the API is always present and
# active. We could reasonably leave PTHREAD_CFLAGS empty. But
# -pthread does define _REENTRANT, and while the Darwin headers
# ignore this macro, third-party headers might not.)
# However, older versions of Clang make a point of warning the user
# that, in an invocation where only linking and no compilation is
# taking place, the -pthread option has no effect ("argument unused
# during compilation"). They expect -pthread to be passed in only
# when source code is being compiled.
#
# Problem is, this is at odds with the way Automake and most other
# C build frameworks function, which is that the same flags used in
# compilation (CFLAGS) are also used in linking. Many systems
# supported by AX_PTHREAD require exactly this for POSIX threads
# support, and in fact it is often not straightforward to specify a
# flag that is used only in the compilation phase and not in
# linking. Such a scenario is extremely rare in practice.
#
# Even though use of the -pthread flag in linking would only print
# a warning, this can be a nuisance for well-run software projects
# that build with -Werror. So if the active version of Clang has
# this misfeature, we search for an option to squash it.
AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
[ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
# Create an alternate version of $ac_link that compiles and
# links in two steps (.c -> .o, .o -> exe) instead of one
# (.c -> exe), because the warning occurs only in the second
# step
ax_pthread_save_ac_link="$ac_link"
ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
ax_pthread_link_step=`AS_ECHO(["$ac_link"]) | sed "$ax_pthread_sed"`
ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
ax_pthread_save_CFLAGS="$CFLAGS"
for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
ac_link="$ax_pthread_save_ac_link"
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
[ac_link="$ax_pthread_2step_ac_link"
AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
[break])
])
done
ac_link="$ax_pthread_save_ac_link"
CFLAGS="$ax_pthread_save_CFLAGS"
AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
])
case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
no | unknown) ;;
*) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
esac
fi # $ax_pthread_clang = yes
# Various other checks: # Various other checks:
if test "x$ax_pthread_ok" = "xyes"; then if test "x$ax_pthread_ok" = "xyes"; then
ax_pthread_save_CFLAGS="$CFLAGS" ax_pthread_save_CFLAGS="$CFLAGS"
@ -438,7 +464,8 @@ if test "x$ax_pthread_ok" = "xyes"; then
AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
[ax_cv_PTHREAD_PRIO_INHERIT], [ax_cv_PTHREAD_PRIO_INHERIT],
[AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
[[int i = PTHREAD_PRIO_INHERIT;]])], [[int i = PTHREAD_PRIO_INHERIT;
return i;]])],
[ax_cv_PTHREAD_PRIO_INHERIT=yes], [ax_cv_PTHREAD_PRIO_INHERIT=yes],
[ax_cv_PTHREAD_PRIO_INHERIT=no]) [ax_cv_PTHREAD_PRIO_INHERIT=no])
]) ])
@ -460,18 +487,28 @@ if test "x$ax_pthread_ok" = "xyes"; then
[#handle absolute path differently from PATH based program lookup [#handle absolute path differently from PATH based program lookup
AS_CASE(["x$CC"], AS_CASE(["x$CC"],
[x/*], [x/*],
[AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], [
[AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])
AS_IF([test "x${CXX}" != "x"], [AS_IF([AS_EXECUTABLE_P([${CXX}_r])],[PTHREAD_CXX="${CXX}_r"])])
],
[
AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])
AS_IF([test "x${CXX}" != "x"], [AC_CHECK_PROGS([PTHREAD_CXX],[${CXX}_r],[$CXX])])
]
)
])
;; ;;
esac esac
fi fi
fi fi
test -n "$PTHREAD_CC" || PTHREAD_CC="$CC" test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
test -n "$PTHREAD_CXX" || PTHREAD_CXX="$CXX"
AC_SUBST([PTHREAD_LIBS]) AC_SUBST([PTHREAD_LIBS])
AC_SUBST([PTHREAD_CFLAGS]) AC_SUBST([PTHREAD_CFLAGS])
AC_SUBST([PTHREAD_CC]) AC_SUBST([PTHREAD_CC])
AC_SUBST([PTHREAD_CXX])
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
if test "x$ax_pthread_ok" = "xyes"; then if test "x$ax_pthread_ok" = "xyes"; then

View file

@ -2998,6 +2998,29 @@ int pcap_thread_open(pcap_thread_t* pcap_thread, const char* device, void* user)
} }
int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void* user) int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void* user)
{
FILE* fp;
int ret;
if (!file) {
return PCAP_THREAD_EINVAL;
}
if (!strcmp(file, "-")) {
return pcap_thread_open_offline_fp(pcap_thread, file, stdin, user);
}
if (!(fp = fopen(file, "r"))) {
return PCAP_THREAD_ERRNO;
}
if ((ret = pcap_thread_open_offline_fp(pcap_thread, file, fp, user))) {
fclose(fp);
}
return ret;
}
int pcap_thread_open_offline_fp(pcap_thread_t* pcap_thread, const char* file, FILE* fp, void* user)
{ {
pcap_t* pcap; pcap_t* pcap;
pcap_thread_pcaplist_t* pcaplist; pcap_thread_pcaplist_t* pcaplist;
@ -3009,6 +3032,9 @@ int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void*
if (!file) { if (!file) {
return PCAP_THREAD_EINVAL; return PCAP_THREAD_EINVAL;
} }
if (!fp) {
return PCAP_THREAD_EINVAL;
}
if (pcap_thread->running) { if (pcap_thread->running) {
return PCAP_THREAD_ERUNNING; return PCAP_THREAD_ERUNNING;
} }
@ -3028,9 +3054,11 @@ int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void*
return PCAP_THREAD_ENOMEM; return PCAP_THREAD_ENOMEM;
} }
pcaplist->fp = fp;
#ifdef HAVE_PCAP_OPEN_OFFLINE_WITH_TSTAMP_PRECISION #ifdef HAVE_PCAP_OPEN_OFFLINE_WITH_TSTAMP_PRECISION
if (pcap_thread->have_timestamp_precision) { if (pcap_thread->have_timestamp_precision) {
if (!(pcap = pcap_open_offline_with_tstamp_precision(pcaplist->name, pcap_thread->timestamp_precision, pcap_thread->errbuf))) { if (!(pcap = pcap_fopen_offline_with_tstamp_precision(pcaplist->fp, pcap_thread->timestamp_precision, pcap_thread->errbuf))) {
free(pcaplist->name); free(pcaplist->name);
free(pcaplist); free(pcaplist);
return PCAP_THREAD_EPCAP; return PCAP_THREAD_EPCAP;
@ -3038,7 +3066,7 @@ int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void*
} else } else
#endif #endif
{ {
if (!(pcap = pcap_open_offline(pcaplist->name, pcap_thread->errbuf))) { if (!(pcap = pcap_fopen_offline(pcaplist->fp, pcap_thread->errbuf))) {
free(pcaplist->name); free(pcaplist->name);
free(pcaplist); free(pcaplist);
return PCAP_THREAD_EPCAP; return PCAP_THREAD_EPCAP;
@ -3236,6 +3264,24 @@ int pcap_thread_close(pcap_thread_t* pcap_thread)
return PCAP_THREAD_OK; return PCAP_THREAD_OK;
} }
long pcap_thread_ftell(pcap_thread_t* pcap_thread)
{
if (!pcap_thread) {
return -1;
}
if (!pcap_thread->running) {
return -1;
}
if (!pcap_thread->step) {
return -1;
}
if (!pcap_thread->step->fp) {
return -1;
}
return ftell(pcap_thread->step->fp);
}
/* /*
* Engine * Engine
*/ */
@ -3444,9 +3490,17 @@ int pcap_thread_run(pcap_thread_t* pcap_thread)
end.tv_nsec = pcap_thread->timedrun_to.tv_usec * 1000; end.tv_nsec = pcap_thread->timedrun_to.tv_usec * 1000;
} }
int all_offline = 1;
for (pcaplist = pcap_thread->pcaplist; all_offline && pcaplist; pcaplist = pcaplist->next) {
if (!pcaplist->is_offline) {
all_offline = 0;
break;
}
}
#ifdef HAVE_PTHREAD #ifdef HAVE_PTHREAD
if (pcap_thread->use_threads) { if (pcap_thread->use_threads) {
int err, all_offline; int err;
switch (pcap_thread->queue_mode) { switch (pcap_thread->queue_mode) {
case PCAP_THREAD_QUEUE_MODE_COND: case PCAP_THREAD_QUEUE_MODE_COND:
@ -3498,17 +3552,10 @@ int pcap_thread_run(pcap_thread_t* pcap_thread)
pcap_thread->write_pos = 0; pcap_thread->write_pos = 0;
pcap_thread->pkts = 0; pcap_thread->pkts = 0;
all_offline = 1;
for (pcaplist = pcap_thread->pcaplist; all_offline && pcaplist; pcaplist = pcaplist->next) {
if (!pcaplist->is_offline) {
all_offline = 0;
break;
}
}
pcap_thread->running = 1; pcap_thread->running = 1;
pcap_thread->was_stopped = 0; pcap_thread->was_stopped = 0;
err = PCAP_THREAD_OK; err = PCAP_THREAD_OK;
pcap_thread->step = 0;
for (pcaplist = pcap_thread->pcaplist; pcaplist; pcaplist = pcaplist->next) { for (pcaplist = pcap_thread->pcaplist; pcaplist; pcaplist = pcaplist->next) {
pcaplist->pcap_thread = pcap_thread; pcaplist->pcap_thread = pcap_thread;
@ -3635,9 +3682,9 @@ int pcap_thread_run(pcap_thread_t* pcap_thread)
pcap_thread->running = 0; pcap_thread->running = 0;
return err; return err;
} else }
#endif #endif
{ if (!all_offline) {
fd_set fds, rfds; fd_set fds, rfds;
int max_fd = 0; int max_fd = 0;
struct timeval t1, t2; struct timeval t1, t2;
@ -3731,6 +3778,89 @@ int pcap_thread_run(pcap_thread_t* pcap_thread)
run = 1; run = 1;
} }
pcap_thread->step = pcaplist;
packets = pcap_dispatch(pcaplist->pcap, -1, _callback2, (u_char*)pcaplist);
if (packets == PCAP_ERROR) {
pcap_thread->status = -1;
PCAP_THREAD_SET_ERRBUF(pcap_thread, "pcap_dispatch()");
pcap_thread->running = 0;
return PCAP_THREAD_EPCAP;
}
if (pcaplist->is_offline && !packets) {
pcaplist->running = 0;
}
}
}
pcap_thread->running = 0;
} else {
pcap_thread->running = 1;
pcap_thread->was_stopped = 0;
for (pcaplist = pcap_thread->pcaplist; pcaplist; pcaplist = pcaplist->next) {
pcaplist->pcap_thread = pcap_thread;
if (pcap_thread->use_layers) {
pcaplist->layer_callback = &pcap_thread_callback;
}
if (pcap_thread->callback_ipv4_frag.new && !pcaplist->have_ipv4_frag_ctx) {
pcaplist->ipv4_frag_ctx = pcap_thread->callback_ipv4_frag.new(pcap_thread->callback_ipv4_frag.conf, pcaplist->user);
pcaplist->have_ipv4_frag_ctx = 1;
}
if (pcap_thread->callback_ipv6_frag.new && !pcaplist->have_ipv6_frag_ctx) {
pcaplist->ipv6_frag_ctx = pcap_thread->callback_ipv6_frag.new(pcap_thread->callback_ipv6_frag.conf, pcaplist->user);
pcaplist->have_ipv6_frag_ctx = 1;
}
pcaplist->running = 1;
pcaplist->timedrun = timedrun;
pcaplist->end = end;
}
while (run) {
if (timedrun) {
struct timeval now;
struct timeval diff;
if (gettimeofday(&now, 0)) {
PCAP_THREAD_SET_ERRBUF(pcap_thread, "gettimeofday()");
pcap_thread->running = 0;
return PCAP_THREAD_ERRNO;
}
if (now.tv_sec > end.tv_sec
|| (now.tv_sec == end.tv_sec && (now.tv_usec * 1000) >= end.tv_nsec)) {
break;
}
if (end.tv_sec > now.tv_sec) {
diff.tv_sec = end.tv_sec - now.tv_sec - 1;
diff.tv_usec = 1000000 - now.tv_usec;
diff.tv_usec += end.tv_nsec / 1000;
if (diff.tv_usec > 1000000) {
diff.tv_sec += diff.tv_usec / 1000000;
diff.tv_usec %= 1000000;
}
} else {
diff.tv_sec = 0;
if (end.tv_sec == now.tv_sec && (end.tv_nsec / 1000) > now.tv_usec) {
diff.tv_usec = (end.tv_nsec / 1000) - now.tv_usec;
} else {
diff.tv_usec = 0;
}
}
}
run = 0;
for (pcaplist = pcap_thread->pcaplist; pcaplist; pcaplist = pcaplist->next) {
int packets;
if (!pcaplist->running) {
continue;
} else {
run = 1;
}
pcap_thread->step = pcaplist;
packets = pcap_dispatch(pcaplist->pcap, -1, _callback2, (u_char*)pcaplist); packets = pcap_dispatch(pcaplist->pcap, -1, _callback2, (u_char*)pcaplist);
if (packets == PCAP_ERROR) { if (packets == PCAP_ERROR) {
pcap_thread->status = -1; pcap_thread->status = -1;

View file

@ -41,16 +41,10 @@
#endif #endif
#include <pcap/pcap.h> #include <pcap/pcap.h>
#include <sys/socket.h> #include <sys/socket.h>
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else
#ifdef HAVE_SYS_TIME_H #ifdef HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#else #endif
#include <time.h> #include <time.h>
#endif
#endif
#include <sys/types.h> #include <sys/types.h>
#include <netinet/in.h> #include <netinet/in.h>
#include <net/if_arp.h> #include <net/if_arp.h>
@ -66,6 +60,7 @@
#ifdef HAVE_MACHINE_ENDIAN_H #ifdef HAVE_MACHINE_ENDIAN_H
#include <machine/endian.h> #include <machine/endian.h>
#endif #endif
#include <stdio.h>
#ifndef __BYTE_ORDER #ifndef __BYTE_ORDER
#if defined(BYTE_ORDER) #if defined(BYTE_ORDER)
@ -517,7 +512,7 @@ struct pcap_thread {
/* clang-format off */ /* clang-format off */
#define PCAP_THREAD_PCAPLIST_T_INIT { \ #define PCAP_THREAD_PCAPLIST_T_INIT { \
0, 0, 0, \ 0, 0, 0, \
0, 0, 0, 0, 0, 0, 0, 0, \ 0, 0, 0, 0, 0, 0, 0, 0, 0, \
0, \ 0, \
PCAP_THREAD_PCAPLIST_T_INIT_THREAD \ PCAP_THREAD_PCAPLIST_T_INIT_THREAD \
{ 0, 0 }, \ { 0, 0 }, \
@ -533,6 +528,7 @@ struct pcap_thread_pcaplist {
pcap_thread_pcaplist_t* next; pcap_thread_pcaplist_t* next;
char* name; char* name;
FILE* fp;
pcap_t* pcap; pcap_t* pcap;
void* user; void* user;
int running; int running;
@ -636,10 +632,13 @@ int pcap_thread_set_callback_invalid(pcap_thread_t* pcap_thread, pcap_thread_lay
int pcap_thread_open(pcap_thread_t* pcap_thread, const char* device, void* user); int pcap_thread_open(pcap_thread_t* pcap_thread, const char* device, void* user);
int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void* user); int pcap_thread_open_offline(pcap_thread_t* pcap_thread, const char* file, void* user);
int pcap_thread_open_offline_fp(pcap_thread_t* pcap_thread, const char* file, FILE* fp, void* user);
int pcap_thread_add(pcap_thread_t* pcap_thread, const char* name, pcap_t* pcap, void* user); int pcap_thread_add(pcap_thread_t* pcap_thread, const char* name, pcap_t* pcap, void* user);
int pcap_thread_activate(pcap_thread_t* pcap_thread); int pcap_thread_activate(pcap_thread_t* pcap_thread);
int pcap_thread_close(pcap_thread_t* pcap_thread); int pcap_thread_close(pcap_thread_t* pcap_thread);
long pcap_thread_ftell(pcap_thread_t* pcap_thread);
int pcap_thread_run(pcap_thread_t* pcap_thread); int pcap_thread_run(pcap_thread_t* pcap_thread);
int pcap_thread_next(pcap_thread_t* pcap_thread); int pcap_thread_next(pcap_thread_t* pcap_thread);
int pcap_thread_next_reset(pcap_thread_t* pcap_thread); int pcap_thread_next_reset(pcap_thread_t* pcap_thread);

View file

@ -40,6 +40,12 @@
#include "pcap-thread/pcap_thread_ext_frag.h" #include "pcap-thread/pcap_thread_ext_frag.h"
#include <zlib.h>
#include <lz4frame.h>
#include <zstd.h>
#include <lzma.h>
#include <errno.h>
static void static void
drop_pkt(u_char* user, const struct pcap_pkthdr* hdr, const u_char* pkt, const char* name, const int dlt) drop_pkt(u_char* user, const struct pcap_pkthdr* hdr, const u_char* pkt, const char* name, const int dlt)
{ {
@ -72,6 +78,373 @@ void print_pcap_thread_error(const char* func, int err)
static pcap_thread_ext_frag_conf_t frag_conf_v4 = PCAP_THREAD_EXT_FRAG_CONF_T_INIT; static pcap_thread_ext_frag_conf_t frag_conf_v4 = PCAP_THREAD_EXT_FRAG_CONF_T_INIT;
static pcap_thread_ext_frag_conf_t frag_conf_v6 = PCAP_THREAD_EXT_FRAG_CONF_T_INIT; static pcap_thread_ext_frag_conf_t frag_conf_v6 = PCAP_THREAD_EXT_FRAG_CONF_T_INIT;
/* GZ compression */
#if HAVE_FOPENCOOKIE
static ssize_t gzip_cookie_read(void* cookie, char* buf, size_t size)
#elif HAVE_FUNOPEN
static int gzip_cookie_read(void* cookie, char* buf, int size)
#endif
{
return gzread((gzFile)cookie, buf, size);
}
#if HAVE_FOPENCOOKIE
static int gzip_cookie_seek(void* cookie, off_t* offset, int whence)
{
switch (whence) {
case SEEK_CUR:
if (offset) {
int ret = gztell((gzFile)cookie);
*offset = ret;
return 0;
}
default:
break;
}
return -1;
}
#elif HAVE_FUNOPEN
static off_t gzip_cookie_seek(void* cookie, off_t offset, int whence)
{
switch (whence) {
case SEEK_CUR:
return gztell((gzFile)cookie);
default:
break;
}
errno = EINVAL;
return -1;
}
#endif
static int gzip_cookie_close(void* cookie)
{
return gzclose((gzFile)cookie);
}
/* LZ4 compression */
struct _lz4_ctx {
LZ4F_dctx* ctx;
LZ4F_decompressOptions_t opts;
void * in, *out;
size_t in_size, out_size;
size_t in_have, out_have;
size_t in_at, out_at;
void* file;
size_t total_read;
};
#define lz4 ((struct _lz4_ctx*)cookie)
#if HAVE_FOPENCOOKIE
static ssize_t lz4_cookie_read(void* cookie, char* dst, size_t len)
#elif HAVE_FUNOPEN
static int lz4_cookie_read(void* cookie, char* dst, int len)
#endif
{
size_t need = len;
for (;;) {
if (lz4->out_have >= need) {
memcpy(dst, lz4->out + lz4->out_at, need);
lz4->out_have -= need;
lz4->out_at += need;
lz4->total_read += need;
return len;
}
memcpy(dst, lz4->out + lz4->out_at, lz4->out_have);
need -= lz4->out_have;
dst += lz4->out_have;
lz4->total_read += lz4->out_have;
ssize_t n = fread(lz4->in + lz4->in_at, 1, lz4->in_size - lz4->in_have, lz4->file);
if (n < 0) {
return n;
}
lz4->in_at += n;
lz4->in_have += n;
if (!lz4->in_have) {
if (need < len) {
return len - need;
}
return 0;
}
size_t dst_size = lz4->out_size, src_size = lz4->in_have;
size_t code = LZ4F_decompress(lz4->ctx, lz4->out, &dst_size, lz4->in, &src_size, &lz4->opts);
if (LZ4F_isError(code)) {
fprintf(stderr, "LZ4F_decompress() failed: %s\n", LZ4F_getErrorName(code));
exit(1);
}
if (src_size < lz4->in_have) {
lz4->in_have -= src_size;
memmove(lz4->in, lz4->in + src_size, lz4->in_have);
lz4->in_at = lz4->in_have;
} else {
lz4->in_at = 0;
lz4->in_have = 0;
}
lz4->out_at = 0;
lz4->out_have = dst_size;
}
}
#if HAVE_FOPENCOOKIE
static int lz4_cookie_seek(void* cookie, off_t* offset, int whence)
{
switch (whence) {
case SEEK_CUR:
if (offset) {
*offset = lz4->total_read;
return 0;
}
default:
break;
}
return -1;
}
#elif HAVE_FUNOPEN
static off_t lz4_cookie_seek(void* cookie, off_t offset, int whence)
{
switch (whence) {
case SEEK_CUR:
return lz4->total_read;
default:
break;
}
errno = EINVAL;
return -1;
}
#endif
static int lz4_cookie_close(void* cookie)
{
FILE* fp = lz4->file;
LZ4F_errorCode_t code;
if ((code = LZ4F_freeDecompressionContext(lz4->ctx))) {
fprintf(stderr, "LZ4F_freeDecompressionContext() failed: %s\n", LZ4F_getErrorName(code));
exit(1);
}
free(lz4->in);
free(lz4->out);
free(lz4);
return fclose(fp);
}
/* ZSTD compression */
struct _zstd_ctx {
ZSTD_DCtx* ctx;
ZSTD_inBuffer zin;
ZSTD_outBuffer zout;
void * in, *out;
size_t in_size, out_size;
size_t in_have, out_have;
size_t in_at, out_at;
void* file;
size_t total_read;
};
#define zstd ((struct _zstd_ctx*)cookie)
#if HAVE_FOPENCOOKIE
static ssize_t zstd_cookie_read(void* cookie, char* dst, size_t len)
#elif HAVE_FUNOPEN
static int zstd_cookie_read(void* cookie, char* dst, int len)
#endif
{
size_t need = len;
for (;;) {
if (zstd->out_have >= need) {
memcpy(dst, zstd->out + zstd->out_at, need);
zstd->out_have -= need;
zstd->out_at += need;
zstd->total_read += need;
return len;
}
memcpy(dst, zstd->out + zstd->out_at, zstd->out_have);
need -= zstd->out_have;
dst += zstd->out_have;
zstd->total_read += zstd->out_have;
if (zstd->zin.pos >= zstd->zin.size) {
ssize_t n = fread(zstd->in, 1, zstd->in_size, zstd->file);
if (n < 1) {
if (!n && need < len) {
return len - need;
}
return n;
}
zstd->zin.size = n;
zstd->zin.pos = 0;
}
zstd->zout.size = zstd->out_size;
zstd->zout.pos = 0;
size_t code = ZSTD_decompressStream(zstd->ctx, &zstd->zout, &zstd->zin);
if (ZSTD_isError(code)) {
fprintf(stderr, "ZSTD_decompressStream() failed: %s\n", ZSTD_getErrorName(code));
exit(1);
}
zstd->out_have = zstd->zout.pos;
zstd->out_at = 0;
}
}
#if HAVE_FOPENCOOKIE
static int zstd_cookie_seek(void* cookie, off_t* offset, int whence)
{
switch (whence) {
case SEEK_CUR:
if (offset) {
*offset = zstd->total_read;
return 0;
}
default:
break;
}
return -1;
}
#elif HAVE_FUNOPEN
static off_t zstd_cookie_seek(void* cookie, off_t offset, int whence)
{
switch (whence) {
case SEEK_CUR:
return zstd->total_read;
default:
break;
}
errno = EINVAL;
return -1;
}
#endif
static int zstd_cookie_close(void* cookie)
{
FILE* fp = zstd->file;
ZSTD_freeDCtx(zstd->ctx);
free(zstd->in);
free(zstd->out);
free(zstd);
return fclose(fp);
}
/* LZMA compression */
struct _lzma_ctx {
lzma_stream strm;
void * in, *out;
size_t in_size, out_size;
size_t in_have, out_have;
size_t in_at, out_at;
void* file;
size_t total_read;
};
#define lzma ((struct _lzma_ctx*)cookie)
static lzma_stream lzma_stream_init = LZMA_STREAM_INIT;
#if HAVE_FOPENCOOKIE
static ssize_t lzma_cookie_read(void* cookie, char* dst, size_t len)
#elif HAVE_FUNOPEN
static int lzma_cookie_read(void* cookie, char* dst, int len)
#endif
{
size_t need = len;
lzma_action action = LZMA_RUN;
uint8_t inbuf[BUFSIZ];
for (;;) {
if (lzma->out_have >= need) {
memcpy(dst, lzma->out + lzma->out_at, need);
lzma->out_have -= need;
lzma->out_at += need;
lzma->total_read += need;
return len;
}
memcpy(dst, lzma->out + lzma->out_at, lzma->out_have);
need -= lzma->out_have;
dst += lzma->out_have;
lzma->total_read += lzma->out_have;
ssize_t n = fread(inbuf, 1, sizeof(inbuf), lzma->file);
if (n < 0) {
return n;
}
if (!n) {
action = LZMA_FINISH;
}
lzma->strm.next_in = inbuf;
lzma->strm.avail_in = n;
lzma->strm.next_out = lzma->out;
lzma->strm.avail_out = lzma->out_size;
lzma_ret ret = lzma_code(&lzma->strm, action);
if (ret != LZMA_OK) {
if (ret == LZMA_STREAM_END) {
if (need < len) {
return len - need;
}
return 0;
}
fprintf(stderr, "lzma_code() failed: %d\n", ret);
exit(1);
}
lzma->out_at = 0;
lzma->out_have = lzma->out_size - lzma->strm.avail_out;
}
}
#if HAVE_FOPENCOOKIE
static int lzma_cookie_seek(void* cookie, off_t* offset, int whence)
{
switch (whence) {
case SEEK_CUR:
if (offset) {
*offset = lzma->total_read;
return 0;
}
default:
break;
}
return -1;
}
#elif HAVE_FUNOPEN
static off_t lzma_cookie_seek(void* cookie, off_t offset, int whence)
{
switch (whence) {
case SEEK_CUR:
return lzma->total_read;
default:
break;
}
errno = EINVAL;
return -1;
}
#endif
static int lzma_cookie_close(void* cookie)
{
FILE* fp = lzma->file;
lzma_end(&lzma->strm);
free(lzma->out);
free(lzma);
return fclose(fp);
}
/* compression end */
void open_pcaps(void) void open_pcaps(void)
{ {
mypcap_ptr mypcap; mypcap_ptr mypcap;
@ -167,9 +540,143 @@ void open_pcaps(void)
for (mypcap = HEAD(mypcaps); for (mypcap = HEAD(mypcaps);
mypcap != NULL; mypcap != NULL;
mypcap = NEXT(mypcap, link)) { mypcap = NEXT(mypcap, link)) {
if (pcap_offline) if (pcap_offline) {
err = pcap_thread_open_offline(&pcap_thread, mypcap->name, (u_char*)mypcap); FILE* fp = 0;
else
char* dot = strrchr(mypcap->name, '.');
if (dot) {
if (!strcasecmp(dot, ".gz")) {
gzFile cookie = gzopen(mypcap->name, "r");
if (cookie == NULL) {
perror("gzopen");
exit(1);
}
#if HAVE_FOPENCOOKIE
static cookie_io_functions_t cookiefuncs = {
gzip_cookie_read, 0, gzip_cookie_seek, gzip_cookie_close
};
fp = fopencookie(cookie, "r", cookiefuncs);
if (fp == NULL) {
perror("fopencookie");
exit(1);
}
#elif HAVE_FUNOPEN
fp = funopen(cookie, gzip_cookie_read, 0, gzip_cookie_seek, gzip_cookie_close);
if (fp == NULL) {
perror("funopen");
return;
}
#endif
} else if (!strcasecmp(dot, ".lz4")) {
LZ4F_errorCode_t code;
struct _lz4_ctx* cookie = calloc(1, sizeof(struct _lz4_ctx));
assert(cookie);
lz4->in_size = 256 * 1024;
assert((lz4->in = malloc(lz4->in_size)));
lz4->out_size = 256 * 1024;
assert((lz4->out = malloc(lz4->out_size)));
if ((code = LZ4F_createDecompressionContext(&lz4->ctx, LZ4F_VERSION))) {
fprintf(stderr, "LZ4F_createDecompressionContext() failed: %s\n", LZ4F_getErrorName(code));
exit(1);
}
lz4->opts.stableDst = 1;
if (!(lz4->file = fopen(mypcap->name, "r"))) {
perror("fopen");
exit(1);
}
#if HAVE_FOPENCOOKIE
static cookie_io_functions_t cookiefuncs = {
lz4_cookie_read, 0, lz4_cookie_seek, lz4_cookie_close
};
fp = fopencookie(cookie, "r", cookiefuncs);
if (fp == NULL) {
perror("fopencookie");
exit(1);
}
#elif HAVE_FUNOPEN
fp = funopen(cookie, lz4_cookie_read, 0, lz4_cookie_seek, lz4_cookie_close);
if (fp == NULL) {
perror("funopen");
return;
}
#endif
} else if (!strcasecmp(dot, ".zst")) {
struct _zstd_ctx* cookie = calloc(1, sizeof(struct _zstd_ctx));
assert(cookie);
assert((zstd->ctx = ZSTD_createDCtx()));
zstd->in_size = ZSTD_DStreamInSize();
assert((zstd->in = malloc(zstd->in_size)));
zstd->out_size = ZSTD_DStreamOutSize();
assert((zstd->out = malloc(zstd->out_size)));
zstd->zin.src = zstd->in;
zstd->zout.dst = zstd->out;
zstd->zout.size = zstd->out_size;
if (!(zstd->file = fopen(mypcap->name, "r"))) {
perror("fopen");
exit(1);
}
#if HAVE_FOPENCOOKIE
static cookie_io_functions_t cookiefuncs = {
zstd_cookie_read, 0, zstd_cookie_seek, zstd_cookie_close
};
fp = fopencookie(cookie, "r", cookiefuncs);
if (fp == NULL) {
perror("fopencookie");
exit(1);
}
#elif HAVE_FUNOPEN
fp = funopen(cookie, zstd_cookie_read, 0, zstd_cookie_seek, zstd_cookie_close);
if (fp == NULL) {
perror("funopen");
return;
}
#endif
} else if (!strcasecmp(dot, ".xz")) {
struct _lzma_ctx* cookie = calloc(1, sizeof(struct _lzma_ctx));
assert(cookie);
lzma->strm = lzma_stream_init;
lzma_ret ret = lzma_stream_decoder(&lzma->strm, UINT64_MAX, LZMA_CONCATENATED);
if (ret != LZMA_OK) {
fprintf(stderr, "lzma_stream_decoder() error: %d\n", ret);
exit(1);
}
lzma->out_size = 256 * 1024;
assert((lzma->out = malloc(lzma->out_size)));
if (!(lzma->file = fopen(mypcap->name, "r"))) {
perror("fopen");
exit(1);
}
#if HAVE_FOPENCOOKIE
static cookie_io_functions_t cookiefuncs = {
lzma_cookie_read, 0, lzma_cookie_seek, lzma_cookie_close
};
fp = fopencookie(cookie, "r", cookiefuncs);
if (fp == NULL) {
perror("fopencookie");
exit(1);
}
#elif HAVE_FUNOPEN
fp = funopen(cookie, lzma_cookie_read, 0, lzma_cookie_seek, lzma_cookie_close);
if (fp == NULL) {
perror("funopen");
return;
}
#endif
}
}
if (fp)
err = pcap_thread_open_offline_fp(&pcap_thread, mypcap->name, fp, (u_char*)mypcap);
else
err = pcap_thread_open_offline(&pcap_thread, mypcap->name, (u_char*)mypcap);
} else
err = pcap_thread_open(&pcap_thread, mypcap->name, (u_char*)mypcap); err = pcap_thread_open(&pcap_thread, mypcap->name, (u_char*)mypcap);
if (err == PCAP_THREAD_EPCAP) { if (err == PCAP_THREAD_EPCAP) {

View file

@ -28,7 +28,7 @@ TESTS = test1.sh test2.sh test3.sh test4.sh test5.sh test6.sh test7.sh \
test_tcpdns.sh test_sll2.sh test_tcpdns.sh test_sll2.sh
EXTRA_DIST = $(TESTS) \ EXTRA_DIST = $(TESTS) \
dns.gold dns.pcap \ dns.gold dns.pcap dns.pcap.gz dns.pcap.xz dns.pcap.lz4 dns.pcap.zst dns.gold2 \
frags.pcap \ frags.pcap \
1qtcppadd.pcap \ 1qtcppadd.pcap \
vlan11.gold vlan11.pcap \ vlan11.gold vlan11.pcap \

View file

@ -399,6 +399,7 @@ PKG_CONFIG_LIBDIR = @PKG_CONFIG_LIBDIR@
PKG_CONFIG_PATH = @PKG_CONFIG_PATH@ PKG_CONFIG_PATH = @PKG_CONFIG_PATH@
PTHREAD_CC = @PTHREAD_CC@ PTHREAD_CC = @PTHREAD_CC@
PTHREAD_CFLAGS = @PTHREAD_CFLAGS@ PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
PTHREAD_CXX = @PTHREAD_CXX@
PTHREAD_LIBS = @PTHREAD_LIBS@ PTHREAD_LIBS = @PTHREAD_LIBS@
RANLIB = @RANLIB@ RANLIB = @RANLIB@
SECCOMPFLAGS = @SECCOMPFLAGS@ SECCOMPFLAGS = @SECCOMPFLAGS@
@ -447,6 +448,12 @@ libdir = @libdir@
libexecdir = @libexecdir@ libexecdir = @libexecdir@
libldns_CFLAGS = @libldns_CFLAGS@ libldns_CFLAGS = @libldns_CFLAGS@
libldns_LIBS = @libldns_LIBS@ libldns_LIBS = @libldns_LIBS@
liblz4_CFLAGS = @liblz4_CFLAGS@
liblz4_LIBS = @liblz4_LIBS@
liblzma_CFLAGS = @liblzma_CFLAGS@
liblzma_LIBS = @liblzma_LIBS@
libzstd_CFLAGS = @libzstd_CFLAGS@
libzstd_LIBS = @libzstd_LIBS@
localedir = @localedir@ localedir = @localedir@
localstatedir = @localstatedir@ localstatedir = @localstatedir@
mandir = @mandir@ mandir = @mandir@
@ -494,7 +501,7 @@ TESTS = test1.sh test2.sh test3.sh test4.sh test5.sh test6.sh test7.sh \
test_tcpdns.sh test_sll2.sh test_tcpdns.sh test_sll2.sh
EXTRA_DIST = $(TESTS) \ EXTRA_DIST = $(TESTS) \
dns.gold dns.pcap \ dns.gold dns.pcap dns.pcap.gz dns.pcap.xz dns.pcap.lz4 dns.pcap.zst dns.gold2 \
frags.pcap \ frags.pcap \
1qtcppadd.pcap \ 1qtcppadd.pcap \
vlan11.gold vlan11.pcap \ vlan11.gold vlan11.pcap \

4998
src/test/dns.gold2 Normal file

File diff suppressed because it is too large Load diff

BIN
src/test/dns.pcap.gz Normal file

Binary file not shown.

BIN
src/test/dns.pcap.lz4 Normal file

Binary file not shown.

BIN
src/test/dns.pcap.xz Normal file

Binary file not shown.

BIN
src/test/dns.pcap.zst Normal file

Binary file not shown.

View file

@ -1,11 +1,25 @@
#!/bin/sh -xe #!/bin/sh -xe
test -e dns.pcap || ln -s "$srcdir/dns.pcap" dns.pcap test -e dns.pcap || ln -s "$srcdir/dns.pcap" dns.pcap
test -e dns.pcap.gz || ln -s "$srcdir/dns.pcap.gz" dns.pcap.gz
test -e dns.pcap.xz || ln -s "$srcdir/dns.pcap.xz" dns.pcap.xz
test -e dns.pcap.lz4 || ln -s "$srcdir/dns.pcap.lz4" dns.pcap.lz4
test -e dns.pcap.zst || ln -s "$srcdir/dns.pcap.zst" dns.pcap.zst
../dnscap -g -r dns.pcap 2>dns.out ../dnscap -g -r dns.pcap 2>dns.out
# stdout/stdin test
../dnscap -r dns.pcap -w - | ../dnscap -r - -g 2>>dns.out
# compression tests
../dnscap -g -r dns.pcap.gz 2>>dns.out
../dnscap -g -r dns.pcap.xz 2>>dns.out
../dnscap -g -r dns.pcap.lz4 2>>dns.out
../dnscap -g -r dns.pcap.zst 2>>dns.out
# compress write test
../dnscap -r dns.pcap -w test -W .pcap.gz
../dnscap -g -r test.20161020.152301.075993.pcap.gz 2>>dns.out
mv dns.out dns.out.old mv dns.out dns.out.old
grep -v "^libgcov profiling error:" dns.out.old > dns.out grep -v "^libgcov profiling error:" dns.out.old > dns.out
rm dns.out.old rm dns.out.old
diff dns.out "$srcdir/dns.gold" diff dns.out "$srcdir/dns.gold2"