@@ -334,18 +334,18 @@ int NHTFlowCache::process_flow(Packet& packet, size_t flow_index, size_t hash_va
334334 return 0 ;
335335}
336336#ifdef WITH_CTT
337- bool NHTFlowCache::try_to_export_delayed_flow (const Packet& packet, const std::optional<size_t >& flow_index,
338- size_t row_begin) noexcept
337+ bool NHTFlowCache::try_to_export_delayed_flow (const Packet& packet, size_t flow_index) noexcept
339338{
340- const bool flow_is_waiting_for_export = flow_index.has_value ()
341- && m_flow_table[row_begin + flow_index.value ()]->is_waiting_for_export ;
342- if (flow_index.has_value () && flow_is_waiting_for_export
339+ if (!m_flow_table[flow_index]->is_in_ctt ) {
340+ return false ;
341+ }
342+ if (m_flow_table[flow_index]->is_waiting_for_export
343343 && (!packet.cttmeta .ctt_rec_matched || packet.ts > m_flow_table[row_begin + flow_index.value ()]->export_time )) {
344- plugins_pre_export (m_flow_table[row_begin + flow_index. value () ]->m_flow );
345- export_flow (row_begin + flow_index. value () );
344+ plugins_pre_export (m_flow_table[flow_index]->m_flow );
345+ export_flow (flow_index);
346346 return false ;
347347 }
348- return flow_is_waiting_for_export ;
348+ return m_flow_table[flow_index]-> is_waiting_for_export ;
349349}
350350#endif /* WITH_CTT */
351351
@@ -364,16 +364,18 @@ void NHTFlowCache::send_export_request_to_ctt(size_t ctt_flow_hash) noexcept
364364bool NHTFlowCache::try_to_export (size_t flow_index, bool call_pre_export, const timeval& now, int reason) noexcept
365365{
366366#ifdef WITH_CTT
367- if (!m_flow_table[flow_index]->is_waiting_for_export ) {
368- m_flow_table[flow_index]->is_waiting_for_export = true ;
369- send_export_request_to_ctt (m_flow_table[flow_index]->m_flow .flow_hash_ctt );
370- m_flow_table[flow_index]->export_time = {now.tv_sec + 1 , now.tv_usec };
371- return false ;
372- }
373- if (m_flow_table[flow_index]->export_time > now) {
374- return false ;
367+ if (m_flow_table[flow_index]->is_in_ctt ) {
368+ if (!m_flow_table[flow_index]->is_waiting_for_export ) {
369+ m_flow_table[flow_index]->is_waiting_for_export = true ;
370+ send_export_request_to_ctt (m_flow_table[flow_index]->m_flow .flow_hash_ctt );
371+ m_flow_table[flow_index]->export_time = {now.tv_sec + 1 , now.tv_usec };
372+ return false ;
373+ }
374+ if (m_flow_table[flow_index]->export_time > now) {
375+ return false ;
376+ }
377+ m_flow_table[flow_index]->is_waiting_for_export = false ;
375378 }
376- m_flow_table[flow_index]->is_waiting_for_export = false ;
377379#endif /* WITH_CTT */
378380 if (call_pre_export) {
379381 plugins_pre_export (m_flow_table[flow_index]->m_flow );
@@ -400,15 +402,14 @@ int NHTFlowCache::put_pkt(Packet &pkt)
400402 const size_t row_begin = hash_value.value () & m_line_mask;
401403 CacheRowSpan row_span (&m_flow_table[row_begin], m_line_size);
402404
403- #ifdef WITH_CTT
404- const bool flow_is_waiting_for_export = try_to_export_delayed_flow (pkt, flow_index, row_begin);
405- #else
406- constexpr bool flow_is_waiting_for_export = false ;
407- #endif /* WITH_CTT */
408-
409405 prefetch_export_expired ();
410406
411407 if (flow_found) {
408+ #ifdef WITH_CTT
409+ const bool flow_is_waiting_for_export = try_to_export_delayed_flow (pkt, flow_index.value () + row_begin);
410+ #else
411+ constexpr bool flow_is_waiting_for_export = false ;
412+ #endif /* WITH_CTT */
412413 /* Existing flow record was found, put flow record at the first index of flow line. */
413414 m_cache_stats.lookups += flow_index.value () + 1 ;
414415 m_cache_stats.lookups2 += (flow_index.value () + 1 ) * (flow_index.value () + 1 );
@@ -426,14 +427,12 @@ int NHTFlowCache::put_pkt(Packet &pkt)
426427 m_cache_stats.empty ++;
427428 } else {
428429#ifdef WITH_CTT
429- flow_index = row_span.find_if_export_timeout_expired (pkt.ts );
430- if (!flow_index.has_value ()) {
431- #endif /* WITH_CTT */
432- row_span.advance_flow_to (m_line_size - 1 , m_new_flow_insert_index);
433- flow_index = row_begin + m_new_flow_insert_index;
434- #ifdef WITH_CTT
435- }
430+ const size_t victim_index = row_span.find_victim (pkt.ts );
431+ #else
432+ const size_t victim_index = m_line_size - 1 ;
436433#endif /* WITH_CTT */
434+ row_span.advance_flow_to (victim_index, m_new_flow_insert_index);
435+ flow_index = row_begin + m_new_flow_insert_index;
437436 plugins_pre_export (m_flow_table[flow_index.value ()]->m_flow );
438437 export_flow (flow_index.value (), FLOW_END_NO_RES);
439438 m_cache_stats.not_empty ++;
0 commit comments