Commit graph

19483 commits

Author SHA1 Message Date
Arne Welzel
df4beb6054 af_packet: AF_Packet: Use negative socket_fd for error indication
Technically, socket() can return 0, so shouldn't use it as an
indication of a non existent / closed socket.

I'm not 100% sure about the Close() contract here: If something
goes haywire with a packet source Zeek calls FatalError without
calling Close() nor properly destructing the PktSrc. Oh yikes.
2025-08-20 08:52:26 -07:00
Arne Welzel
17d60e4ab9 af_packet: AF_Packet: Remove usages of inline
...not sure why they are marked inline.
2025-08-20 08:52:26 -07:00
Arne Welzel
d9d7b76c5d af_packet: Add guarded zeek/zeek-version.h include.
With zeek/zeek#2802, zeek-config.h will not provide ZEEK_VERSION_NUMBER
when a plugin is compiled as a builtin/static plugin into Zeek. This is
done to avoid tree-wide ccache busting when just the version changes.
2025-08-20 08:52:26 -07:00
Arne Welzel
67d3b0697f af_packet: RX_Ring: Add include for string
When compiling with clang and libc++ like done when using Google's
hongfuzz in the oss-fuzz setup, the following errors are produced:

    Step #3 - "compile-honggfuzz-address-x86_64": /src/zeek/auxil/zeek-af_packet-plugin/src/RX_Ring.cc:19:9: error: no matching conversion for functional-style cast from 'const char[15]' to 'RX_RingException'
    Step #3 - "compile-honggfuzz-address-x86_64":                 throw RX_RingException("invalid socket");
    Step #3 - "compile-honggfuzz-address-x86_64":                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Step #3 - "compile-honggfuzz-address-x86_64": /src/zeek/auxil/zeek-af_packet-plugin/src/RX_Ring.h:14:7: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const char[15]' to 'const RX_RingException' for 1st argument
    Step #3 - "compile-honggfuzz-address-x86_64": class RX_RingException : public std::runtime_error {
    Step #3 - "compile-honggfuzz-address-x86_64":       ^
    Step #3 - "compile-honggfuzz-address-x86_64": /src/zeek/auxil/zeek-af_packet-plugin/src/RX_Ring.h:14:7: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const char[15]' to 'RX_RingException' for 1st argument
    Step #3 - "compile-honggfuzz-address-x86_64": /src/zeek/auxil/zeek-af_packet-plugin/src/RX_Ring.h:16:2: note: candidate constructor not viable: no known conversion from 'const char[15]' to 'const std::string' (aka 'const basic_string<char, char_traits<char>, allocator<char>>') for 1st argument
    Step #3 - "compile-honggfuzz-address-x86_64":         RX_RingException(const std::string& what_arg) : std::runtime_error(what_arg) {}
    Step #3 - "compile-honggfuzz-address-x86_64":

The problem can be reproduced outside of hongfuzz by compiling this
plugin with with clang/libc++:

    export CXX=clang++-14
    export CXXFLAGS=-stdlib=libc++
    ./configure
    make

Include <string> in RX_Ring.h to ensure the required const char * to
std::string conversion are available to any users of RX_RingException.
2025-08-20 08:52:26 -07:00
Jan Grashoefer
165d60236c af_packet: Increase version number. 2025-08-20 08:52:26 -07:00
Jan Grashoefer
61a3538106 af_packet: Add info if TP_STATUS_CSUM_VALID is not defined. 2025-08-20 08:52:26 -07:00
Arne Welzel
e0d7dba113 af_packet: Define TP_STATUS_CSUM_VALID when not defined
On some older Linux distributions (CentOS 7), the if_packet.h header does
not yet include TP_STATUS_CSUM_VALID (introduced in March 2015). Simply
define it if it's not there.
2025-08-20 08:52:26 -07:00
Jan Grashoefer
7d0841ae31 af_packet: Improve the README. 2025-08-20 08:52:26 -07:00
Arne Welzel
90d61cae72 af_packet: Make block_size and block_timeout configurable
This lowers the default timeout from 100msec to 10msec and increases the default
block_size from 16KB to 32KB. Both are aligned with what Suricata uses as defaults.

The block_size is likely too conservative for high-performance, tuning
guides recommend starting with 1MB block size.

Fixes #37.
2025-08-20 08:52:26 -07:00
Jan Grashoefer
8d2979e935 af_packet: Cleanup checksum offloading support. 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
cd297e13dd af_packet: Support checksum offloading (requires Zeek 5.1). 2025-08-20 08:52:26 -07:00
Arne Welzel
ffbb2823da af_packet: Remove compile_options() again
This seems to trickle through to base Zeek code when done like that.

https://cirrus-ci.com/task/4788073346105344?logs=build#L2298
2025-08-20 08:52:26 -07:00
Arne Welzel
6ad8e3ed24 af_packet: Add -Wunused and -Werror
This would've found the enable_defrag issue and also points out another
unused variable.
2025-08-20 08:52:26 -07:00
Arne Welzel
41331e5605 af_packet: Fix enable_defrag
Seems enable_defrag was never actually passed down to the relevant functions.
Remove the default parameters to ensure we properly pass it down.
2025-08-20 08:52:26 -07:00
Arne Welzel
62b28177ee af_packet: Remove linux/version.h include
Not sure why this is needed. On my system it defines LINUX_VERSION_CODE
and KERNEL_VERSION and neither is used within the plugin.
2025-08-20 08:52:26 -07:00
Arne Welzel
1dc6718621 af_packet: Remove FindKernelHeaders, not needed
There's been some wondering why kernel headers are required to compile
this plugin as it's not providing a kernel module or otherwise provides
functionality related to kernel APIs. AF_PACKET sockets are provided
through user-space APIs.

There may have been historical reasons, but let's move forward and
remove the dependency.

Fixes #29 #24
2025-08-20 08:52:26 -07:00
Jan Grashoefer
46f364c3dd af_packet: Increase version number. 2025-08-20 08:52:26 -07:00
Jan Grashoefer
630d1edff9 af_packet: Make link type configurable. 2025-08-20 08:52:26 -07:00
Jan Grashoefer
7be67782c2 af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Michael Dopheide
e2f40fc5b1 af_packet: Create README file which zeek's ConfigurePackaging.cmake requires 2025-08-20 08:52:25 -07:00
Jan Grashoefer
716916a97d af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
448e69471c af_packet: Convert README formatting to Markdown. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
1fe008945e af_packet: Hacked VLAN support. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
b38894a329 af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Christian Kreibich
96384be689 af_packet: Avoid Zeek script double-loading problems
The plugin mechanism automatically picks up the scripts folder for
plugin-related Zeek scripts. When a package's zkg.meta also declares the scripts
folder the location for package-level scripts, the scripts get installed
redundantly in two places. Zeek cannot recognize them as duplicates, triggering
various errors relating to double-defined symbols.

This moves the package-level scripts to a subdirectory with a placeholder. The
placeholder avoids the zkg install-time warning, whose original fix in e3aea1
introduced this problem.
2025-08-20 08:52:25 -07:00
Jan Grashoefer
74f9d11776 af_packet: Fix Zeek version dependency. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
e945e2c8bb af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
45b3dbf267 af_packet: Slightly reorder README. 2025-08-20 08:52:25 -07:00
Johanna Amann
e4aa85d2a6 af_packet: Add FANOUT_CBPF and FANOUT_EBPF 2025-08-20 08:52:25 -07:00
Michael Dopheide
79842b25c1 af_packet: Namespace changes adding zeek:: as well as zeek/ prefix for include files. 2025-08-20 08:52:25 -07:00
Vlad Grigorescu
e3c5865684 af_packet: GetFanoutMode: Fix case statement (missing breaks).
Without this, you can't actually set the fanout mode to anything but HASH.
2025-08-20 08:52:25 -07:00
Jan Grashoefer
62356c38dd af_packet: Fixed test baseline to include defrag option. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
130f7f7272 af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
4deb8f6402 af_packet: Add support for defragmentation of IP packets. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
57dd239917 af_packet: Increase version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
8aa35fed6f af_packet: Add upgrade note to README. 2025-08-20 08:52:25 -07:00
Tim Wojtulewicz
8d0bc4a804 af_packet: Add some missing includes due to changes in Zeek 3.1 2025-08-20 08:52:25 -07:00
Tim Wojtulewicz
a7195a7a75 af_packet: File naming and build system changes to support deprecation changes in Zeek 3.0 2025-08-20 08:52:25 -07:00
Jan Grashoefer
1f1627ad73 af_packet: Increased version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
5e3ae6227b af_packet: Updated README. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
eb3dc4b563 af_packet: Include info files for distribution. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
9cc01769b4 af_packet: Minor improvements to fix compiler warnings. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
b6e52b262c af_packet: Increased version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
4eaa201821 af_packet: Updated README regarding --with-latest-kernel. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
3adaef434b af_packet: Added buffer_size option to broctl plugin.
The buffer size can now be set in node.cfg using the
af_packet_buffer_size key.
2025-08-20 08:52:25 -07:00
Jan Grashoefer
a89379c353 af_packet: Added bro-pkg instructions to the README. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
1a107bd838 af_packet: Increased version number. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
1dfb115e35 af_packet: Fixed broctl example. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
478265b4f2 af_packet: Fixed compatibility for kernel versions < 3.14. 2025-08-20 08:52:25 -07:00
Jan Grashoefer
742b0820bc af_packet: Imported version 1.1 of the plugin. 2025-08-20 08:52:25 -07:00