Changes in response to Johanna's code review.

This commit is contained in:
Seth Hall 2020-10-15 12:42:48 -04:00
parent 2f05318a08
commit 56e234a762
3 changed files with 18 additions and 6 deletions

View file

@ -996,7 +996,7 @@ const UDP_ACTIVE = 1; ##< Endpoint has sent something.
const ignore_checksums = F &redef; const ignore_checksums = F &redef;
## Checksums are ignored for all packets with a src address within this set of ## Checksums are ignored for all packets with a src address within this set of
## addresses. Useful for cases where a host might be seeing packets collected ## networks. Useful for cases where a host might be seeing packets collected
## from local hosts before checksums were applied by hardware. This frequently ## from local hosts before checksums were applied by hardware. This frequently
## manifests when sniffing a local management interface on a host and Zeek sees ## manifests when sniffing a local management interface on a host and Zeek sees
## packets before the hardware has had a chance to apply the checksums. ## packets before the hardware has had a chance to apply the checksums.

View file

@ -1991,9 +1991,15 @@ ValPtr TableVal::FindOrDefault(const ValPtr& index)
return Default(index); return Default(index);
} }
bool TableVal::Contains(const IPAddr& addr) const bool TableVal::Contains(const IPAddr& addr)
{ {
return subnets ? subnets->Lookup(addr, true) != 0 : false; if ( ! subnets )
{
reporter->InternalError("LookupSubnets called on wrong table type");
return false;
}
return (subnets->Lookup(addr, true) != 0);
} }
Val* TableVal::Lookup(Val* index, bool use_default_val) Val* TableVal::Lookup(Val* index, bool use_default_val)

View file

@ -906,9 +906,15 @@ public:
[[deprecated("Remove in v4.1. Use Find() or FindOrDefault().")]] [[deprecated("Remove in v4.1. Use Find() or FindOrDefault().")]]
Val* Lookup(Val* index, bool use_default_val = true); Val* Lookup(Val* index, bool use_default_val = true);
// Returns true if this is a table[subnet]/set[subnet] and the /**
// given address was found in the table. Otherwise returns false. * Returns true if this is a table[subnet]/set[subnet] and the
bool Contains(const IPAddr& addr); * given address was found in the table. Otherwise returns false.
* @param addr The address to look for.
* @return Boolean value to indicate if addr is in the table or set. If
* self is not a table[subnet]/set[subnet] an internal error will be
* generated and false will be returned.
*/
bool Contains(const IPAddr& addr) const;
// For a table[subnet]/set[subnet], return all subnets that cover // For a table[subnet]/set[subnet], return all subnets that cover
// the given subnet. // the given subnet.