af_packet: Cleanup checksum offloading support.

This commit is contained in:
Jan Grashoefer 2022-09-26 12:17:47 +02:00 committed by Tim Wojtulewicz
parent cd297e13dd
commit 8d2979e935
4 changed files with 15 additions and 20 deletions

View file

@ -25,13 +25,15 @@ If everything built and installed correctly, you should see this::
Zeek::AF_Packet - Packet acquisition via AF_Packet (dynamic, version 3.2.0) Zeek::AF_Packet - Packet acquisition via AF_Packet (dynamic, version 3.2.0)
[Packet Source] AF_PacketReader (interface prefix "af_packet"; supports live input) [Packet Source] AF_PacketReader (interface prefix "af_packet"; supports live input)
[Type] AF_Packet::FanoutMode [Type] AF_Packet::FanoutMode
[Type] AF_Packet::ChecksumMode
[Constant] AF_Packet::buffer_size [Constant] AF_Packet::buffer_size
[Constant] AF_Packet::enable_hw_timestamping [Constant] AF_Packet::enable_hw_timestamping
[Constant] AF_Packet::enable_fanout
[Constant] AF_Packet::enable_defrag [Constant] AF_Packet::enable_defrag
[Constant] AF_Packet::enable_fanout
[Constant] AF_Packet::fanout_mode [Constant] AF_Packet::fanout_mode
[Constant] AF_Packet::fanout_id [Constant] AF_Packet::fanout_id
[Constant] AF_Packet::link_type [Constant] AF_Packet::link_type
[Constant] AF_Packet::checksum_validation_mode
## Upgrade from Bro to Zeek ## Upgrade from Bro to Zeek

View file

@ -5,17 +5,6 @@
module AF_Packet; module AF_Packet;
export { export {
# The various modes of checksum offloading. OFF means we will set the
# checksum variables to true, trusting that they are correct no matter
# what the kernel or zeek thinks. ON means we will ignore the kernel
# checksums and let Zeek check them. KERNEL means we will trust the
# kernel checksums and let Zeek skip checking them.
type Checksum_Mode : enum {
OFF,
ON,
KERNEL
};
## Size of the ring-buffer. ## Size of the ring-buffer.
const buffer_size = 128 * 1024 * 1024 &redef; const buffer_size = 128 * 1024 * 1024 &redef;
## Toggle whether to use hardware timestamps. ## Toggle whether to use hardware timestamps.
@ -24,12 +13,12 @@ export {
const enable_fanout = T &redef; const enable_fanout = T &redef;
## Toggle defragmentation of IP packets using PACKET_FANOUT_FLAG_DEFRAG. ## Toggle defragmentation of IP packets using PACKET_FANOUT_FLAG_DEFRAG.
const enable_defrag = F &redef; const enable_defrag = F &redef;
## Fanout Mode. ## Fanout mode.
const fanout_mode = FANOUT_HASH &redef; const fanout_mode = FANOUT_HASH &redef;
## Fanout ID. ## Fanout ID.
const fanout_id = 23 &redef; const fanout_id = 23 &redef;
## Link type (default Ethernet). ## Link type (default Ethernet).
const link_type = 1 &redef; const link_type = 1 &redef;
## Checksum offloading option. ## Checksum validation mode.
const checksum_offloading_mode: Checksum_Mode = KERNEL &redef; const checksum_validation_mode: ChecksumMode = CHECKSUM_ON &redef;
} }

View file

@ -21,7 +21,7 @@ AF_PacketSource::AF_PacketSource(const std::string& path, bool is_live)
props.path = path; props.path = path;
props.is_live = is_live; props.is_live = is_live;
checksum_mode = zeek::BifConst::AF_Packet::checksum_offloading_mode->AsEnum(); checksum_mode = zeek::BifConst::AF_Packet::checksum_validation_mode->AsEnum();
} }
void AF_PacketSource::Open() void AF_PacketSource::Open()
@ -280,8 +280,6 @@ bool AF_PacketSource::ExtractNextPacket(zeek::Packet* pkt)
break; break;
} }
} }
#else
fprintf(stderr, "bad version?\n");
#endif #endif
if ( current_hdr.len == 0 || current_hdr.caplen == 0 ) if ( current_hdr.len == 0 || current_hdr.caplen == 0 )

View file

@ -3,6 +3,7 @@
module AF_Packet; module AF_Packet;
## Available fanout modes.
enum FanoutMode %{ enum FanoutMode %{
FANOUT_HASH, # PACKET_FANOUT_HASH FANOUT_HASH, # PACKET_FANOUT_HASH
FANOUT_CPU, # PACKET_FANOUT_CPU FANOUT_CPU, # PACKET_FANOUT_CPU
@ -11,17 +12,22 @@ enum FanoutMode %{
FANOUT_EBPF, # PACKET_FANOUT_EBPF FANOUT_EBPF, # PACKET_FANOUT_EBPF
%} %}
## Available checksum validation modes.
enum ChecksumMode %{ enum ChecksumMode %{
## Ignore checksums, i.e. always assume they are correct.
CHECKSUM_OFF, CHECKSUM_OFF,
## Let Zeek compute and verify checksums.
CHECKSUM_ON, CHECKSUM_ON,
## Let the kernel handle checksum offloading.
## Note: Semantics may depend on the kernel and driver version.
CHECKSUM_KERNEL, CHECKSUM_KERNEL,
%} %}
const buffer_size: count; const buffer_size: count;
const enable_hw_timestamping: bool; const enable_hw_timestamping: bool;
const enable_fanout: bool;
const enable_defrag: bool; const enable_defrag: bool;
const enable_fanout: bool;
const fanout_mode: FanoutMode; const fanout_mode: FanoutMode;
const fanout_id: count; const fanout_id: count;
const link_type: count; const link_type: count;
const checksum_offloading_mode: ChecksumMode; const checksum_validation_mode: ChecksumMode;