mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
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.
This commit is contained in:
parent
17d60e4ab9
commit
df4beb6054
1 changed files with 11 additions and 6 deletions
|
@ -34,6 +34,9 @@ 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;
|
||||||
|
|
||||||
|
socket_fd = -1;
|
||||||
|
rx_ring = nullptr;
|
||||||
|
|
||||||
checksum_mode = zeek::BifConst::AF_Packet::checksum_validation_mode->AsEnum();
|
checksum_mode = zeek::BifConst::AF_Packet::checksum_validation_mode->AsEnum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,12 +229,14 @@ uint32_t AF_PacketSource::GetFanoutMode(bool defrag)
|
||||||
|
|
||||||
void AF_PacketSource::Close()
|
void AF_PacketSource::Close()
|
||||||
{
|
{
|
||||||
if ( ! socket_fd )
|
if ( socket_fd < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
delete rx_ring;
|
delete rx_ring;
|
||||||
|
rx_ring = nullptr;
|
||||||
|
|
||||||
close(socket_fd);
|
close(socket_fd);
|
||||||
socket_fd = 0;
|
socket_fd = -1;
|
||||||
|
|
||||||
Closed();
|
Closed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue