mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
IP: Cleanup initialization, make a few functions consistent with others
This commit is contained in:
parent
36557f3086
commit
a312851d6e
2 changed files with 26 additions and 35 deletions
|
@ -766,7 +766,7 @@ IPv6_Hdr_Chain* IPv6_Hdr_Chain::Copy(const ip6_hdr* new_hdr) const
|
||||||
{
|
{
|
||||||
reporter->InternalWarning("empty IPv6 header chain");
|
reporter->InternalWarning("empty IPv6 header chain");
|
||||||
delete rval;
|
delete rval;
|
||||||
return 0;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
const u_char* new_data = (const u_char*)new_hdr;
|
const u_char* new_data = (const u_char*)new_hdr;
|
||||||
|
|
55
src/IP.h
55
src/IP.h
|
@ -148,11 +148,7 @@ public:
|
||||||
/**
|
/**
|
||||||
* Initializes the header chain from an IPv6 header structure.
|
* Initializes the header chain from an IPv6 header structure.
|
||||||
*/
|
*/
|
||||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len) :
|
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, int len)
|
||||||
#ifdef ENABLE_MOBILE_IPV6
|
|
||||||
homeAddr(0),
|
|
||||||
#endif
|
|
||||||
finalDst(0)
|
|
||||||
{ Init(ip6, len, false); }
|
{ Init(ip6, len, false); }
|
||||||
|
|
||||||
~IPv6_Hdr_Chain();
|
~IPv6_Hdr_Chain();
|
||||||
|
@ -236,23 +232,13 @@ protected:
|
||||||
// point to a fragment
|
// point to a fragment
|
||||||
friend class FragReassembler;
|
friend class FragReassembler;
|
||||||
|
|
||||||
IPv6_Hdr_Chain() :
|
IPv6_Hdr_Chain() = default;
|
||||||
length(0),
|
|
||||||
#ifdef ENABLE_MOBILE_IPV6
|
|
||||||
homeAddr(0),
|
|
||||||
#endif
|
|
||||||
finalDst(0)
|
|
||||||
{}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the header chain from an IPv6 header structure, and replaces
|
* Initializes the header chain from an IPv6 header structure, and replaces
|
||||||
* the first next protocol pointer field that points to a fragment header.
|
* the first next protocol pointer field that points to a fragment header.
|
||||||
*/
|
*/
|
||||||
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, uint16_t next, int len) :
|
IPv6_Hdr_Chain(const struct ip6_hdr* ip6, uint16_t next, int len)
|
||||||
#ifdef ENABLE_MOBILE_IPV6
|
|
||||||
homeAddr(0),
|
|
||||||
#endif
|
|
||||||
finalDst(0)
|
|
||||||
{ Init(ip6, len, true, next); }
|
{ Init(ip6, len, true, next); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -282,20 +268,20 @@ protected:
|
||||||
/**
|
/**
|
||||||
* The summation of all header lengths in the chain in bytes.
|
* The summation of all header lengths in the chain in bytes.
|
||||||
*/
|
*/
|
||||||
uint16_t length;
|
uint16_t length = 0;
|
||||||
|
|
||||||
#ifdef ENABLE_MOBILE_IPV6
|
#ifdef ENABLE_MOBILE_IPV6
|
||||||
/**
|
/**
|
||||||
* Home Address of the packet's source as defined by Mobile IPv6 (RFC 6275).
|
* Home Address of the packet's source as defined by Mobile IPv6 (RFC 6275).
|
||||||
*/
|
*/
|
||||||
IPAddr* homeAddr;
|
IPAddr* homeAddr = nullptr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The final destination address in chain's first Routing header that has
|
* The final destination address in chain's first Routing header that has
|
||||||
* non-zero segments left.
|
* non-zero segments left.
|
||||||
*/
|
*/
|
||||||
IPAddr* finalDst;
|
IPAddr* finalDst = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -311,7 +297,7 @@ public:
|
||||||
* @param arg_del whether to take ownership of \a arg_ip4 pointer's memory.
|
* @param arg_del whether to take ownership of \a arg_ip4 pointer's memory.
|
||||||
*/
|
*/
|
||||||
IP_Hdr(const struct ip* arg_ip4, bool arg_del)
|
IP_Hdr(const struct ip* arg_ip4, bool arg_del)
|
||||||
: ip4(arg_ip4), ip6(0), del(arg_del), ip6_hdrs(0)
|
: ip4(arg_ip4), del(arg_del)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,9 +313,9 @@ public:
|
||||||
* @param c an already-constructed header chain to take ownership of.
|
* @param c an already-constructed header chain to take ownership of.
|
||||||
*/
|
*/
|
||||||
IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del, int len,
|
IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del, int len,
|
||||||
const IPv6_Hdr_Chain* c = 0)
|
const IPv6_Hdr_Chain* c = nullptr)
|
||||||
: ip4(0), ip6(arg_ip6), del(arg_del),
|
: ip6(arg_ip6), ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len)),
|
||||||
ip6_hdrs(c ? c : new IPv6_Hdr_Chain(ip6, len))
|
del(arg_del)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +383,7 @@ public:
|
||||||
{
|
{
|
||||||
if ( ip4 )
|
if ( ip4 )
|
||||||
return ((const u_char*) ip4) + ip4->ip_hl * 4;
|
return ((const u_char*) ip4) + ip4->ip_hl * 4;
|
||||||
else
|
|
||||||
return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
|
return ((const u_char*) ip6) + ip6_hdrs->TotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -409,9 +395,9 @@ public:
|
||||||
const ip6_mobility* MobilityHeader() const
|
const ip6_mobility* MobilityHeader() const
|
||||||
{
|
{
|
||||||
if ( ip4 )
|
if ( ip4 )
|
||||||
return 0;
|
return nullptr;
|
||||||
else if ( (*ip6_hdrs)[ip6_hdrs->Size()-1]->Type() != IPPROTO_MOBILITY )
|
else if ( (*ip6_hdrs)[ip6_hdrs->Size()-1]->Type() != IPPROTO_MOBILITY )
|
||||||
return 0;
|
return nullptr;
|
||||||
else
|
else
|
||||||
return (const ip6_mobility*)(*ip6_hdrs)[ip6_hdrs->Size()-1]->Data();
|
return (const ip6_mobility*)(*ip6_hdrs)[ip6_hdrs->Size()-1]->Data();
|
||||||
}
|
}
|
||||||
|
@ -425,7 +411,7 @@ public:
|
||||||
{
|
{
|
||||||
if ( ip4 )
|
if ( ip4 )
|
||||||
return ntohs(ip4->ip_len) - ip4->ip_hl * 4;
|
return ntohs(ip4->ip_len) - ip4->ip_hl * 4;
|
||||||
else
|
|
||||||
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength();
|
return ntohs(ip6->ip6_plen) + 40 - ip6_hdrs->TotalLength();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -433,7 +419,12 @@ public:
|
||||||
* Returns the length of the IP packet (length of headers and payload).
|
* Returns the length of the IP packet (length of headers and payload).
|
||||||
*/
|
*/
|
||||||
uint32_t TotalLen() const
|
uint32_t TotalLen() const
|
||||||
{ return ip4 ? ntohs(ip4->ip_len) : ntohs(ip6->ip6_plen) + 40; }
|
{
|
||||||
|
if ( ip4 )
|
||||||
|
return ntohs(ip4->ip_len);
|
||||||
|
|
||||||
|
return ntohs(ip6->ip6_plen) + 40;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns length of IP packet header (includes extension headers for IPv6).
|
* Returns length of IP packet header (includes extension headers for IPv6).
|
||||||
|
@ -543,8 +534,8 @@ public:
|
||||||
RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const;
|
RecordVal* BuildPktHdrVal(RecordVal* pkt_hdr, int sindex) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const struct ip* ip4;
|
const struct ip* ip4 = nullptr;
|
||||||
const struct ip6_hdr* ip6;
|
const struct ip6_hdr* ip6 = nullptr;
|
||||||
|
const IPv6_Hdr_Chain* ip6_hdrs = nullptr;
|
||||||
bool del;
|
bool del;
|
||||||
const IPv6_Hdr_Chain* ip6_hdrs;
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue