Refactor IP_Hdr class ctors (addresses #532).

They now take an explicit flag argument toggling whether the other
pointer argument needs to be released on destruction.
This commit is contained in:
Jon Siwek 2012-02-27 12:25:41 -06:00
parent ada5f38d04
commit dfad686d7c
7 changed files with 16 additions and 26 deletions

View file

@ -641,7 +641,7 @@ const IP_Hdr* ConnCompressor::PendingConnToPacket(const PendingConn* c)
int packet_length = sizeof(*ip) + sizeof(*tp);
ip = (struct ip*) new char[packet_length];
tp = (struct tcphdr*) (((char*) ip) + sizeof(*ip));
ip_hdr = new IP_Hdr(ip);
ip_hdr = new IP_Hdr(ip, true);
// Constant fields.
ip->ip_v = 4;

View file

@ -125,7 +125,7 @@ void FragReassembler::AddFragment(double t, const IP_Hdr* ip, const u_char* pkt,
void FragReassembler::Overlap(const u_char* b1, const u_char* b2, int n)
{
IP_Hdr proto_h((const struct ip*) proto_hdr);
IP_Hdr proto_h(proto_hdr, false);
if ( memcmp((const void*) b1, (const void*) b2, n) )
s->Weird("fragment_inconsistency", &proto_h);
@ -157,7 +157,7 @@ void FragReassembler::BlockInserted(DataBlock* /* start_block */)
// can happen for benign reasons when we're
// intermingling parts of two fragmented packets.
IP_Hdr proto_h((const struct ip*) proto_hdr);
IP_Hdr proto_h(proto_hdr, false);
s->Weird("fragment_size_inconsistency", &proto_h);
// We decide to analyze the contiguous portion now.
@ -171,7 +171,7 @@ void FragReassembler::BlockInserted(DataBlock* /* start_block */)
else if ( last_block->upper > frag_size )
{
IP_Hdr proto_h((const struct ip*) proto_hdr);
IP_Hdr proto_h(proto_hdr, false);
s->Weird("fragment_size_inconsistency", &proto_h);
frag_size = last_block->upper;
}
@ -214,7 +214,7 @@ void FragReassembler::BlockInserted(DataBlock* /* start_block */)
}
delete reassembled_pkt;
reassembled_pkt = new IP_Hdr(reassem4);
reassembled_pkt = new IP_Hdr(reassem4, true);
DeleteTimer();
}

View file

@ -9,23 +9,13 @@
class IP_Hdr {
public:
IP_Hdr(struct ip* arg_ip4)
: ip4(arg_ip4), ip6(0), del(1)
IP_Hdr(const struct ip* arg_ip4, bool arg_del)
: ip4(arg_ip4), ip6(0), del(arg_del)
{
}
IP_Hdr(const struct ip* arg_ip4)
: ip4(arg_ip4), ip6(0), del(0)
{
}
IP_Hdr(struct ip6_hdr* arg_ip6)
: ip4(0), ip6(arg_ip6), del(1)
{
}
IP_Hdr(const struct ip6_hdr* arg_ip6)
: ip4(0), ip6(arg_ip6), del(0)
IP_Hdr(const struct ip6_hdr* arg_ip6, bool arg_del)
: ip4(0), ip6(arg_ip6), del(arg_del)
{
}
@ -90,7 +80,7 @@ public:
private:
const struct ip* ip4;
const struct ip6_hdr* ip6;
int del;
bool del;
};
#endif

View file

@ -196,7 +196,7 @@ void PIA_TCP::FirstPacket(bool is_orig, const IP_Hdr* ip)
ip4->ip_p = IPPROTO_TCP;
// Cast to const so that it doesn't delete it.
ip4_hdr = new IP_Hdr((const struct ip*) ip4);
ip4_hdr = new IP_Hdr(ip4, false);
}
if ( is_orig )

View file

@ -27,9 +27,9 @@ PacketSortElement::PacketSortElement(PktSrc* arg_src,
{
const struct ip* ip = (const struct ip*) (pkt + hdr_size);
if ( ip->ip_v == 4 )
ip_hdr = new IP_Hdr(ip);
ip_hdr = new IP_Hdr(ip, false);
else
ip_hdr = new IP_Hdr((const struct ip6_hdr*) ip);
ip_hdr = new IP_Hdr((const struct ip6_hdr*) ip, false);
if ( ip_hdr->NextProto() == IPPROTO_TCP &&
// Note: can't sort fragmented packets

View file

@ -415,7 +415,7 @@ public:
}
const IP_Hdr IP() const
{ return IP_Hdr((struct ip *) (pkt + hdr_size)); }
{ return IP_Hdr((struct ip *) (pkt + hdr_size), true); }
void Describe(ODesc* d) const;

View file

@ -275,13 +275,13 @@ void NetSessions::NextPacket(double t, const struct pcap_pkthdr* hdr,
const struct ip* ip = (const struct ip*) (pkt + hdr_size);
if ( ip->ip_v == 4 )
{
IP_Hdr ip_hdr(ip);
IP_Hdr ip_hdr(ip, false);
DoNextPacket(t, hdr, &ip_hdr, pkt, hdr_size);
}
else if ( ip->ip_v == 6 )
{
IP_Hdr ip_hdr((const struct ip6_hdr*) (pkt + hdr_size));
IP_Hdr ip_hdr((const struct ip6_hdr*) (pkt + hdr_size), false);
DoNextPacket(t, hdr, &ip_hdr, pkt, hdr_size);
}