diff --git a/src/iosource/af_packet/scripts/init.zeek b/src/iosource/af_packet/scripts/init.zeek index 9a6abc000c..26a7582df8 100644 --- a/src/iosource/af_packet/scripts/init.zeek +++ b/src/iosource/af_packet/scripts/init.zeek @@ -11,6 +11,8 @@ export { const enable_hw_timestamping = F &redef; ## Toggle whether to use PACKET_FANOUT. const enable_fanout = T &redef; + ## Toggle defragmentation of IP packets using PACKET_FANOUT_FLAG_DEFRAG. + const enable_defrag = F &redef; ## Fanout Mode. const fanout_mode = FANOUT_HASH &redef; ## Fanout ID. diff --git a/src/iosource/af_packet/src/AF_Packet.cc b/src/iosource/af_packet/src/AF_Packet.cc index 41884e6409..fac05971f4 100644 --- a/src/iosource/af_packet/src/AF_Packet.cc +++ b/src/iosource/af_packet/src/AF_Packet.cc @@ -28,6 +28,7 @@ void AF_PacketSource::Open() uint64_t buffer_size = BifConst::AF_Packet::buffer_size; bool enable_hw_timestamping = BifConst::AF_Packet::enable_hw_timestamping; bool enable_fanout = BifConst::AF_Packet::enable_fanout; + bool enable_defrag = BifConst::AF_Packet::enable_defrag; socket_fd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); @@ -129,7 +130,7 @@ inline bool AF_PacketSource::EnablePromiscMode() return (ret >= 0); } -inline bool AF_PacketSource::ConfigureFanoutGroup(bool enabled) +inline bool AF_PacketSource::ConfigureFanoutGroup(bool enabled, bool defrag) { if ( enabled ) { @@ -137,7 +138,7 @@ inline bool AF_PacketSource::ConfigureFanoutGroup(bool enabled) int ret; fanout_id = BifConst::AF_Packet::fanout_id; - fanout_arg = ((fanout_id & 0xffff) | (GetFanoutMode() << 16)); + fanout_arg = ((fanout_id & 0xffff) | (GetFanoutMode(defrag) << 16)); ret = setsockopt(socket_fd, SOL_PACKET, PACKET_FANOUT, &fanout_arg, sizeof(fanout_arg)); @@ -176,15 +177,22 @@ inline bool AF_PacketSource::ConfigureHWTimestamping(bool enabled) return true; } -inline uint32_t AF_PacketSource::GetFanoutMode() +inline uint32_t AF_PacketSource::GetFanoutMode(bool defrag) { + uint32_t fanout_mode; + switch ( BifConst::AF_Packet::fanout_mode->AsEnum() ) { - case BifEnum::AF_Packet::FANOUT_CPU: return PACKET_FANOUT_CPU; + case BifEnum::AF_Packet::FANOUT_CPU: fanout_mode = PACKET_FANOUT_CPU; #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0) - case BifEnum::AF_Packet::FANOUT_QM: return PACKET_FANOUT_QM; + case BifEnum::AF_Packet::FANOUT_QM: fanout_mode = PACKET_FANOUT_QM; #endif - default: return PACKET_FANOUT_HASH; + default: fanout_mode = PACKET_FANOUT_HASH; } + + if ( defrag ) + fanout_mode |= PACKET_FANOUT_FLAG_DEFRAG; + + return fanout_mode; } void AF_PacketSource::Close() diff --git a/src/iosource/af_packet/src/AF_Packet.h b/src/iosource/af_packet/src/AF_Packet.h index f1585ce702..c8e9ab5d8f 100644 --- a/src/iosource/af_packet/src/AF_Packet.h +++ b/src/iosource/af_packet/src/AF_Packet.h @@ -69,9 +69,9 @@ private: bool BindInterface(); bool EnablePromiscMode(); - bool ConfigureFanoutGroup(bool enabled); + bool ConfigureFanoutGroup(bool enabled, bool defrag=false); bool ConfigureHWTimestamping(bool enabled); - uint32_t GetFanoutMode(); + uint32_t GetFanoutMode(bool defrag=false); }; } diff --git a/src/iosource/af_packet/src/af_packet.bif b/src/iosource/af_packet/src/af_packet.bif index 334121ea05..da05ec930e 100644 --- a/src/iosource/af_packet/src/af_packet.bif +++ b/src/iosource/af_packet/src/af_packet.bif @@ -12,5 +12,6 @@ enum FanoutMode %{ const buffer_size: count; const enable_hw_timestamping: bool; const enable_fanout: bool; +const enable_defrag: bool; const fanout_mode: FanoutMode; const fanout_id: count;