Skip to content

Commit 22618e4

Browse files
authored
Merge pull request #322 from CESNET/fix-fragmentation-cache
Fix fragmentation cache
2 parents 1bf051a + dffd2dc commit 22618e4

5 files changed

Lines changed: 24 additions & 23 deletions

File tree

src/plugins/input/parser/parser.cpp

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,8 @@ void parse_packet(
682682
return;
683683
}
684684
Packet* pkt = &opt->pblock->pkts[opt->pblock->cnt];
685+
// reset all packet data
686+
*pkt = Packet();
685687
uint16_t data_offset = 0;
686688

687689
DEBUG_MSG("---------- packet parser #%u -------------\n", ++s_total_pkts);
@@ -693,18 +695,6 @@ void parse_packet(
693695

694696
pkt->packet_len_wire = len;
695697
pkt->ts = ts;
696-
pkt->src_port = 0;
697-
pkt->dst_port = 0;
698-
pkt->ip_proto = 0;
699-
pkt->ip_ttl = 0;
700-
pkt->ip_flags = 0;
701-
pkt->ip_version = 0;
702-
pkt->ip_payload_len = 0;
703-
pkt->tcp_flags = 0;
704-
pkt->tcp_window = 0;
705-
pkt->tcp_options = 0;
706-
pkt->tcp_mss = 0;
707-
pkt->mplsTop = 0;
708698

709699
stats.seen_packets++;
710700

@@ -758,12 +748,14 @@ void parse_packet(
758748
}
759749

760750
l4_hdr_offset = data_offset;
761-
if (pkt->ip_proto == IPPROTO_TCP) {
762-
data_offset += parse_tcp_hdr(data + data_offset, caplen - data_offset, pkt, stats);
763-
stats.tcp_packets++;
764-
} else if (pkt->ip_proto == IPPROTO_UDP) {
765-
data_offset += parse_udp_hdr(data + data_offset, caplen - data_offset, pkt, stats);
766-
stats.udp_packets++;
751+
if (pkt->frag_off == 0) {
752+
if (pkt->ip_proto == IPPROTO_TCP) {
753+
data_offset += parse_tcp_hdr(data + data_offset, caplen - data_offset, pkt, stats);
754+
stats.tcp_packets++;
755+
} else if (pkt->ip_proto == IPPROTO_UDP) {
756+
data_offset += parse_udp_hdr(data + data_offset, caplen - data_offset, pkt, stats);
757+
stats.udp_packets++;
758+
}
767759
}
768760
} catch (const char* err) {
769761
DEBUG_MSG("%s\n", err);

src/plugins/storage/cache/src/cache.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -321,11 +321,15 @@ void NHTFlowCache::flush(Packet& pkt, size_t flow_index, int ret, bool source_fl
321321

322322
int NHTFlowCache::put_pkt(Packet& pkt)
323323
{
324-
int ret = plugins_pre_create(pkt);
325-
326324
if (m_enable_fragmentation_cache) {
327325
try_to_fill_ports_to_fragmented_packet(pkt);
328326
}
327+
return put_pkt_recursive(pkt);
328+
}
329+
330+
int NHTFlowCache::put_pkt_recursive(Packet& pkt)
331+
{
332+
int ret = plugins_pre_create(pkt);
329333

330334
if (!create_hash_key(pkt)) { // saves key value and key length into attributes NHTFlowCache::key
331335
// and NHTFlowCache::m_keylen
@@ -429,7 +433,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
429433
// Flows with FIN or RST TCP flags are exported when new SYN packet arrives
430434
m_flow_table[flow_index]->m_flow.end_reason = FLOW_END_EOF;
431435
export_flow(flow_index);
432-
put_pkt(pkt);
436+
put_pkt_recursive(pkt);
433437
return 0;
434438
}
435439

@@ -453,7 +457,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
453457
#ifdef FLOW_CACHE_STATS
454458
m_expired++;
455459
#endif /* FLOW_CACHE_STATS */
456-
return put_pkt(pkt);
460+
return put_pkt_recursive(pkt);
457461
}
458462

459463
/* Check if flow record is expired (active timeout). */
@@ -464,7 +468,7 @@ int NHTFlowCache::put_pkt(Packet& pkt)
464468
#ifdef FLOW_CACHE_STATS
465469
m_expired++;
466470
#endif /* FLOW_CACHE_STATS */
467-
return put_pkt(pkt);
471+
return put_pkt_recursive(pkt);
468472
}
469473

470474
ret = plugins_pre_update(flow->m_flow, pkt);

src/plugins/storage/cache/src/cache.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@ class NHTFlowCache
308308
FlowEndReasonStats m_flow_end_reason_stats = {};
309309
FlowRecordStats m_flow_record_stats = {};
310310

311+
int put_pkt_recursive(Packet& pkt);
311312
void try_to_fill_ports_to_fragmented_packet(Packet& packet);
312313
void flush(Packet& pkt, size_t flow_index, int ret, bool source_flow);
313314
bool create_hash_key(Packet& pkt);

src/plugins/storage/cache/src/fragmentationCache/fragmentationCache.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ void FragmentationCache::fill_missing_packet_data(
7474
{
7575
if (!is_fragmentation_data_timedouted(packet, fragmentation_data)) {
7676
fill_ports_to_packet(packet, fragmentation_data);
77+
} else {
78+
m_stats.timeouted_fragments++;
7779
}
7880
}
7981

@@ -104,6 +106,7 @@ telemetry::Content FragmentationCache::get_cache_telemetry()
104106
dict["fragmentedTraffic"] = telemetry::ScalarWithUnit {trafficPercentage, "%"};
105107
dict["fragmentedPackets"] = m_stats.fragmented_packets;
106108
dict["notFoundFragments"] = m_stats.not_found_fragments;
109+
dict["timeoutedFragments"] = m_stats.timeouted_fragments;
107110

108111
return dict;
109112
}

src/plugins/storage/cache/src/fragmentationCache/fragmentationCache.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ class FragmentationCache : TelemetryUtils {
9494
uint64_t first_fragments;
9595
uint64_t fragmented_packets;
9696
uint64_t not_found_fragments;
97+
uint64_t timeouted_fragments;
9798
uint64_t total_packets;
9899
};
99100

0 commit comments

Comments
 (0)