Commit graph

9733 commits

Author SHA1 Message Date
Tim Wojtulewicz
168ff0b8a2 Update src/3rdparty submodule for doctest v2.4.12 and include fix 2025-09-08 10:52:06 -07:00
Tim Wojtulewicz
4d338ccd7d Fix clang-tidy warning from recent SVCB merge 2025-09-03 16:50:07 -07:00
Tim Wojtulewicz
7142b9efde Merge remote-tracking branch 'klemensya/svcparams'
* klemensya/svcparams:
  Parse SVCB/HTTPS SvcParams list
2025-09-03 15:36:03 -07:00
Tim Wojtulewicz
26ea7cc655 Clang-tidy fixes for recent IDPtr changes 2025-09-03 15:34:29 -07:00
Tim Wojtulewicz
e3b22cd21f Merge remote-tracking branch 'origin/topic/vern/emphasize-IDPtrs'
* origin/topic/vern/emphasize-IDPtrs:
  fixup! fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  annotate a number of BTests as unsuited for -O gen-C++ testing due to multiple Zeek runs
  BTest baseline updates for -O gen-C++ - all minor tweaks
  BTest updates for script optimization tracking of BiFs
  regression test for former ASAN issue with script optimization of lambdas
  shift much of the internal use of ID* identifier pointers over to IDPtr objects
  maintenance update for script optimization's knowledge of BiFs
  logger fix for interoperability with -O gen-C++ code
2025-09-03 15:33:43 -07:00
Evan Typanski
42f7a2d88c Merge remote-tracking branch 'origin/topic/vern/field-assign-parsing'
* origin/topic/vern/field-assign-parsing:
  tightened up parsing of $field=X record constructor expressions
2025-09-03 16:21:24 -04:00
Vern Paxson
3ff3eee398 fixup! fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 12:42:58 -07:00
Vern Paxson
a6f9d69c91 fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:20:29 -07:00
Vern Paxson
7397dc6568 fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:38 -07:00
Vern Paxson
34831aa7d3 fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:38 -07:00
Vern Paxson
693aa244f9 shift much of the internal use of ID* identifier pointers over to IDPtr objects 2025-09-03 11:19:31 -07:00
Vern Paxson
1c7c1b62f6 maintenance update for script optimization's knowledge of BiFs 2025-09-03 11:14:22 -07:00
Vern Paxson
fb344a20ea logger fix for interoperability with -O gen-C++ code 2025-09-03 11:14:22 -07:00
Klemens Nanni
397f7e5c0e Parse SVCB/HTTPS SvcParams list
Add full support for RFC 9460's SvcParams list.

Amend the existing `dns_svcb_rr` record by a vector of new
`dns_svcb_param` records containing aptly typed SvcParamKey and
SvcParamValue pairs.  Example output:

```
@load base/protocols/dns
event dns_HTTPS( c: connection , msg: dns_msg , ans: dns_answer , https: dns_svcb_rr ) {
	for (_, param in https$svc_params)
		print to_json(param);  # filter uninitialised values
}
```

```
$ dig https cloudflare-ech.com +short | tr [:space:] \\n
1
.
alpn="h3,h2"
ipv4hint=104.18.10.118,104.18.11.118
ech=AEX+DQBBHgAgACBGL2e9TiFwjK/w1Zg9AmRm7mgXHz3PjffP0mTFNMxmDQAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA=
ipv6hint=2606:4700::6812:a76,2606:4700::6812:b76
```

```
{"key":1,"alpn":["h3","h2"]}
{"key":4,"hint":["104.18.10.118","104.18.11.118"]}
{"key":5,"ech":"AEX+DQBBHgAgACBGL2e9TiFwjK/w1Zg9AmRm7mgXHz3PjffP0mTFNMxmDQAEAAEAAQASY2xvdWRmbGFyZS1lY2guY29tAAA="}
{"key":6,"hint":["2606:4700::6812:a76","2606:4700::6812:b76"]}
```

Values with malformed data or belonging to invalid/reserved keys
are passed raw bytes in network order for script-level inspection.

Follow up to "Initial Support to DNS SVCB/HTTPS RR"
https://github.com/zeek/zeek/pull/1808
2025-09-03 09:53:55 +03:00
Tim Wojtulewicz
3c7885abdf Fix a few more random clang-tidy findings 2025-09-02 16:51:34 +00:00
Tim Wojtulewicz
aa3940f16d Use std::numbers::pi instead of hard-coded value 2025-09-02 16:51:23 +00:00
Tim Wojtulewicz
66aefc6a54 Use std::scoped_lock instead of std::lock_guard 2025-09-02 16:42:52 +00:00
Tim Wojtulewicz
b592b6c998 Use .contains() instead of .find() or .count() 2025-09-02 16:42:52 +00:00
Vern Paxson
36862a18d6 tightened up parsing of $field=X record constructor expressions 2025-08-31 15:14:26 -07:00
Arne Welzel
9a7678f15a cluster/Backend: Fallback to current network time when current event has not timestamp
When a WebSocket client sends an event to Zeek without explicit network
timestamp metadata, Zeek would use -1.0 as a timestamp for any events
published while handling this event. Instead, it seems far more sensible
to use the current network time in that scenario.
2025-08-20 19:56:50 +02:00
Arne Welzel
01fe022e07 cluster/serializer/broker: Do not send empty metadata vectors around
Event when there's no metadata attached to an event, we'd still use the
constructor passing an empty metadata vector, resulting in an on-the-wire
representation with an empty trailing vector.

Particularly visible when just snooping events via websocat. There also
seems to be some bug with the timestamp -1 handling.
2025-08-20 19:55:38 +02:00
Tim Wojtulewicz
6002f63a37 af_packet: Remove submodule, adapt CMake/code for Zeek build 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
62e27ee6f7 af_packet: pre-commit fixes 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
709f876947 af_packet: Fix initialization 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
f92bffcfd9 af_packet: Ensure all of the member fields get initialized 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
1f7c2f42bc af_packet: Require CMake 3.15 to match Zeek's requirement 2025-08-20 08:52:26 -07:00
Jan Grashoefer
a4cd5dd452 af_packet: Note that Zeek ships with a built-in version.
Closes #64.
2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
c55fad5094 af_packet: Use cstdint instead of stdint.h 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
ba15e3e3b2 af_packet: Use override for overriding parent methods 2025-08-20 08:52:26 -07:00
Tim Wojtulewicz
69cae88bb0 af_packet: Use 'pragma once' instead of include guards 2025-08-20 08:52:26 -07:00
Arne Welzel
aefa52821c af_packet: AF_Packet: Fix wrong vlan when PCP or DEI bits are set in tp_vlan_tci
A user reported vlan ids > 4095 being logged by Zeek [1]. For populating
packet->vlan, mask away Priority Code Point (PCP) and Drop Eligible
Indicator (DEI) bits from the tp_vlan_tci field, else we're not setting
the correct value on the packet.

Fixes #60

[1] https://community.zeek.org/t/zeek-reporting-vlan-ids-above-4095-bug-found/7000
2025-08-20 08:52:26 -07:00
Arne Welzel
c3a13304cb af_packet: AF_Packet: Check interface for upness
When using af_packet with an interface that was not up, the following
non-informative error was reported:

    $ /opt/zeek-5.2/bin/zeek -i af_packet::replay
    fatal error: problem with interface af_packet::replay (Invalid argument)

With this change, the error now includes information about the
interface being down:

    $ ZEEK_PLUGIN_PATH=$(pwd)/build zeek -Ci af_packet::replay
    fatal error: problem with interface af_packet::replay (interface is down)

Fixes #51
2025-08-20 08:52:26 -07:00
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