mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Review usage of Reporter::InternalError, addresses BIT-1045.
Replaced some with InternalWarning or InternalAnalyzerError, the later being a new method which signals the analyzer to not process further input. Some usages I just removed if they didn't make sense or clearly couldn't happen. Also did some minor refactors of related code while reviewing/exploring ways to get rid of InternalError usages. Also, for TCP content file write failures there's a new event: "contents_file_write_failure".
This commit is contained in:
parent
6734260136
commit
b828a6ddc7
51 changed files with 532 additions and 267 deletions
80
src/IP.h
80
src/IP.h
|
@ -176,7 +176,14 @@ public:
|
|||
* Returns whether the header chain indicates a fragmented packet.
|
||||
*/
|
||||
bool IsFragment() const
|
||||
{ return chain[chain.size()-1]->Type() == IPPROTO_FRAGMENT; }
|
||||
{
|
||||
if ( chain.empty() )
|
||||
{
|
||||
reporter->InternalWarning("empty IPv6 header chain");
|
||||
return false;
|
||||
}
|
||||
return chain[chain.size()-1]->Type() == IPPROTO_FRAGMENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns pointer to fragment header structure if the chain contains one.
|
||||
|
@ -216,9 +223,13 @@ public:
|
|||
#ifdef ENABLE_MOBILE_IPV6
|
||||
if ( homeAddr )
|
||||
return IPAddr(*homeAddr);
|
||||
else
|
||||
#endif
|
||||
return IPAddr(((const struct ip6_hdr*)(chain[0]->Data()))->ip6_src);
|
||||
if ( chain.empty() )
|
||||
{
|
||||
reporter->InternalWarning("empty IPv6 header chain");
|
||||
return IPAddr();
|
||||
}
|
||||
return IPAddr(((const struct ip6_hdr*)(chain[0]->Data()))->ip6_src);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -230,8 +241,12 @@ public:
|
|||
{
|
||||
if ( finalDst )
|
||||
return IPAddr(*finalDst);
|
||||
else
|
||||
return IPAddr(((const struct ip6_hdr*)(chain[0]->Data()))->ip6_dst);
|
||||
if ( chain.empty() )
|
||||
{
|
||||
reporter->InternalWarning("empty IPv6 header chain");
|
||||
return IPAddr();
|
||||
}
|
||||
return IPAddr(((const struct ip6_hdr*)(chain[0]->Data()))->ip6_dst);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -305,32 +320,6 @@ protected:
|
|||
*/
|
||||
class IP_Hdr {
|
||||
public:
|
||||
/**
|
||||
* Attempts to construct the header from some blob of data based on IP
|
||||
* version number. Caller must have already checked that the header
|
||||
* is not truncated.
|
||||
* @param p pointer to memory containing an IPv4 or IPv6 packet.
|
||||
* @param arg_del whether to take ownership of \a p pointer's memory.
|
||||
* @param len the length of data, in bytes, pointed to by \a p.
|
||||
*/
|
||||
IP_Hdr(const u_char* p, bool arg_del, int len)
|
||||
: ip4(0), ip6(0), del(arg_del), ip6_hdrs(0)
|
||||
{
|
||||
if ( ((const struct ip*)p)->ip_v == 4 )
|
||||
ip4 = (const struct ip*)p;
|
||||
else if ( ((const struct ip*)p)->ip_v == 6 )
|
||||
{
|
||||
ip6 = (const struct ip6_hdr*)p;
|
||||
ip6_hdrs = new IPv6_Hdr_Chain(ip6, len);
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( arg_del )
|
||||
delete [] p;
|
||||
reporter->InternalError("bad IP version in IP_Hdr ctor");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct the header wrapper from an IPv4 packet. Caller must have
|
||||
* already checked that the header is not truncated.
|
||||
|
@ -365,15 +354,12 @@ public:
|
|||
*/
|
||||
~IP_Hdr()
|
||||
{
|
||||
if ( ip6 )
|
||||
delete ip6_hdrs;
|
||||
delete ip6_hdrs;
|
||||
|
||||
if ( del )
|
||||
{
|
||||
if ( ip4 )
|
||||
delete [] (struct ip*) ip4;
|
||||
else
|
||||
delete [] (struct ip6_hdr*) ip6;
|
||||
delete [] (struct ip*) ip4;
|
||||
delete [] (struct ip6_hdr*) ip6;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,8 +458,14 @@ public:
|
|||
* For IPv6 header chains, returns the type of the last header in the chain.
|
||||
*/
|
||||
uint8 LastHeader() const
|
||||
{ return ip4 ? IPPROTO_RAW :
|
||||
((*ip6_hdrs)[ip6_hdrs->Size()-1])->Type(); }
|
||||
{
|
||||
if ( ip4 )
|
||||
return IPPROTO_RAW;
|
||||
size_t i = ip6_hdrs->Size();
|
||||
if ( i > 0 )
|
||||
return (*ip6_hdrs)[i-1]->Type();
|
||||
return IPPROTO_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the protocol type of the IP packet's payload, usually an
|
||||
|
@ -481,8 +473,14 @@ public:
|
|||
* header's Next Header value.
|
||||
*/
|
||||
unsigned char NextProto() const
|
||||
{ return ip4 ? ip4->ip_p :
|
||||
((*ip6_hdrs)[ip6_hdrs->Size()-1])->NextHdr(); }
|
||||
{
|
||||
if ( ip4 )
|
||||
return ip4->ip_p;
|
||||
size_t i = ip6_hdrs->Size();
|
||||
if ( i > 0 )
|
||||
return (*ip6_hdrs)[i-1]->NextHdr();
|
||||
return IPPROTO_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IPv4 Time to Live or IPv6 Hop Limit field.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue