Use shared_ptr for encapsulation data instead of raw pointer

This commit is contained in:
Tim Wojtulewicz 2020-10-12 13:15:52 -07:00
parent a7d4364334
commit 41dcd0cde0
16 changed files with 103 additions and 115 deletions

View file

@ -50,7 +50,7 @@ void AYIYA_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, uint6
if ( result == 0 )
{
ProtocolConfirmation();
const zeek::EncapsulationStack* e = Conn()->GetEncapsulation();
std:shared_ptr<EncapsulationStack> e = Conn()->GetEncapsulation();
EncapsulatingConn ec(Conn(), BifEnum::Tunnel::AYIYA);
packet_analysis::IPTunnel::ip_tunnel_analyzer->ProcessEncapsulatedPacket(
run_state::network_time, nullptr, inner, e, ec);

View file

@ -17,7 +17,7 @@ flow AYIYA_Flow
function process_ayiya(pdu: PDU): bool
%{
zeek::Connection* c = connection()->zeek_analyzer()->Conn();
const zeek::EncapsulationStack* e = c->GetEncapsulation();
std:shared_ptr<zeek::EncapsulationStack> e = c->GetEncapsulation();
if ( e && e->Depth() >= zeek::BifConst::Tunnel::max_depth )
{

View file

@ -62,7 +62,7 @@ void GTPv1_Analyzer::DeliverPacket(int len, const u_char* data, bool orig, uint6
std::move(gtp_hdr_val),
inner->ToPktHdrVal());
const zeek::EncapsulationStack* e = Conn()->GetEncapsulation();
std::shared_ptr<zeek::EncapsulationStack> e = Conn()->GetEncapsulation();
EncapsulatingConn ec(Conn(), BifEnum::Tunnel::GTPv1);
zeek::packet_analysis::IPTunnel::ip_tunnel_analyzer->ProcessEncapsulatedPacket(
run_state::network_time, nullptr, inner, e, ec);

View file

@ -649,7 +649,7 @@ flow GTPv1_Flow(is_orig: bool)
%{
ZeekAnalyzer a = connection()->zeek_analyzer();
zeek::Connection* c = a->Conn();
const zeek::EncapsulationStack* e = c->GetEncapsulation();
const std::shared_ptr<zeek::EncapsulationStack> e = c->GetEncapsulation();
connection()->set_valid(is_orig(), false);

View file

@ -158,7 +158,7 @@ void Teredo_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
return;
}
const EncapsulationStack* e = Conn()->GetEncapsulation();
std::shared_ptr<EncapsulationStack> e = Conn()->GetEncapsulation();
if ( e && e->Depth() >= BifConst::Tunnel::max_depth )
{

View file

@ -48,7 +48,7 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
return;
}
EncapsulationStack* outer = Conn()->GetEncapsulation();
std::shared_ptr<EncapsulationStack> outer = Conn()->GetEncapsulation();
if ( outer && outer->Depth() >= BifConst::Tunnel::max_depth )
{
@ -56,12 +56,8 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
return;
}
bool delete_outer = false;
if ( ! outer )
{
outer = new EncapsulationStack();
delete_outer = true;
}
outer = std::make_shared<EncapsulationStack>();
EncapsulatingConn inner(Conn(), BifEnum::Tunnel::VXLAN);
outer->Add(inner);
@ -83,9 +79,6 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
if ( ! pkt.l2_valid )
{
if ( delete_outer )
delete outer;
ProtocolViolation("VXLAN invalid inner ethernet frame",
(const char*) data, len);
return;
@ -97,9 +90,6 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
if ( ! pkt.ip_hdr )
{
if ( delete_outer )
delete outer;
ProtocolViolation("Truncated VXLAN or invalid inner IP",
(const char*) data, len);
return;
@ -110,9 +100,6 @@ void VXLAN_Analyzer::DeliverPacket(int len, const u_char* data, bool orig,
if ( vxlan_packet )
Conn()->EnqueueEvent(vxlan_packet, nullptr, ConnVal(),
pkt.ip_hdr->ToPktHdrVal(), val_mgr->Count(vni));
if ( delete_outer )
delete outer;
}
} // namespace zeek::analyzer::vxlan