mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
Cleanup/improve PList usage and Event API
Majority of PLists are now created as automatic/stack objects, rather than on heap and initialized either with the known-capacity reserved upfront or directly from an initializer_list (so there's no wasted slack in the memory that gets allocated for lists containing a fixed/known number of elements). Added versions of the ConnectionEvent/QueueEvent methods that take a val_list by value. Added a move ctor/assign-operator to Plists to allow passing them around without having to copy the underlying array of pointers.
This commit is contained in:
parent
78dcbcc71a
commit
8bc65f09ec
92 changed files with 1585 additions and 1679 deletions
|
@ -33,12 +33,11 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
|
|||
|
||||
if ( check_ip )
|
||||
{
|
||||
val_list* args = new val_list;
|
||||
args->append(ip->BuildPktHdrVal());
|
||||
val_list args{ip->BuildPktHdrVal()};
|
||||
|
||||
try
|
||||
{
|
||||
discard_packet = check_ip->Call(args)->AsBool();
|
||||
discard_packet = check_ip->Call(&args)->AsBool();
|
||||
}
|
||||
|
||||
catch ( InterpreterException& e )
|
||||
|
@ -46,8 +45,6 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
|
|||
discard_packet = false;
|
||||
}
|
||||
|
||||
delete args;
|
||||
|
||||
if ( discard_packet )
|
||||
return discard_packet;
|
||||
}
|
||||
|
@ -88,21 +85,20 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
|
|||
const struct tcphdr* tp = (const struct tcphdr*) data;
|
||||
int th_len = tp->th_off * 4;
|
||||
|
||||
val_list* args = new val_list;
|
||||
args->append(ip->BuildPktHdrVal());
|
||||
args->append(BuildData(data, th_len, len, caplen));
|
||||
val_list args{
|
||||
ip->BuildPktHdrVal(),
|
||||
BuildData(data, th_len, len, caplen),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
discard_packet = check_tcp->Call(args)->AsBool();
|
||||
discard_packet = check_tcp->Call(&args)->AsBool();
|
||||
}
|
||||
|
||||
catch ( InterpreterException& e )
|
||||
{
|
||||
discard_packet = false;
|
||||
}
|
||||
|
||||
delete args;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -113,21 +109,20 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
|
|||
const struct udphdr* up = (const struct udphdr*) data;
|
||||
int uh_len = sizeof (struct udphdr);
|
||||
|
||||
val_list* args = new val_list;
|
||||
args->append(ip->BuildPktHdrVal());
|
||||
args->append(BuildData(data, uh_len, len, caplen));
|
||||
val_list args{
|
||||
ip->BuildPktHdrVal(),
|
||||
BuildData(data, uh_len, len, caplen),
|
||||
};
|
||||
|
||||
try
|
||||
{
|
||||
discard_packet = check_udp->Call(args)->AsBool();
|
||||
discard_packet = check_udp->Call(&args)->AsBool();
|
||||
}
|
||||
|
||||
catch ( InterpreterException& e )
|
||||
{
|
||||
discard_packet = false;
|
||||
}
|
||||
|
||||
delete args;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -137,20 +132,17 @@ int Discarder::NextPacket(const IP_Hdr* ip, int len, int caplen)
|
|||
{
|
||||
const struct icmp* ih = (const struct icmp*) data;
|
||||
|
||||
val_list* args = new val_list;
|
||||
args->append(ip->BuildPktHdrVal());
|
||||
val_list args{ip->BuildPktHdrVal()};
|
||||
|
||||
try
|
||||
{
|
||||
discard_packet = check_icmp->Call(args)->AsBool();
|
||||
discard_packet = check_icmp->Call(&args)->AsBool();
|
||||
}
|
||||
|
||||
catch ( InterpreterException& e )
|
||||
{
|
||||
discard_packet = false;
|
||||
}
|
||||
|
||||
delete args;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue