build_inner_connection: Avoid one extra Init()

Packet::Init() is not so cheap as one might think: It computes a
timestamp from { 0, 0 } using double division. Just avoid this
by not initializing an empty Packet.
This commit is contained in:
Arne Welzel 2023-11-01 10:13:51 +01:00
parent ec4ad2e80d
commit d08e347e5e

View file

@ -152,8 +152,6 @@ std::unique_ptr<Packet> build_inner_packet(Packet* outer_pkt, int* encap_index,
std::shared_ptr<EncapsulationStack> encap_stack, uint32_t inner_cap_len, std::shared_ptr<EncapsulationStack> encap_stack, uint32_t inner_cap_len,
const u_char* data, int link_type, BifEnum::Tunnel::Type tunnel_type, const u_char* data, int link_type, BifEnum::Tunnel::Type tunnel_type,
const Tag& analyzer_tag) { const Tag& analyzer_tag) {
auto inner_pkt = std::make_unique<Packet>();
assert(outer_pkt->cap_len >= inner_cap_len); assert(outer_pkt->cap_len >= inner_cap_len);
assert(outer_pkt->len >= outer_pkt->cap_len - inner_cap_len); assert(outer_pkt->len >= outer_pkt->cap_len - inner_cap_len);
@ -169,7 +167,8 @@ std::unique_ptr<Packet> build_inner_packet(Packet* outer_pkt, int* encap_index,
pkt_timeval ts; pkt_timeval ts;
ts.tv_sec = static_cast<time_t>(run_state::current_timestamp); ts.tv_sec = static_cast<time_t>(run_state::current_timestamp);
ts.tv_usec = static_cast<suseconds_t>((run_state::current_timestamp - static_cast<double>(ts.tv_sec)) * 1000000); ts.tv_usec = static_cast<suseconds_t>((run_state::current_timestamp - static_cast<double>(ts.tv_sec)) * 1000000);
inner_pkt->Init(link_type, &ts, inner_cap_len, inner_wire_len, data);
auto inner_pkt = std::make_unique<Packet>(link_type, &ts, inner_cap_len, inner_wire_len, data);
*encap_index = 0; *encap_index = 0;
if ( outer_pkt->session ) { if ( outer_pkt->session ) {