suricata
tmqh-packetpool.h File Reference
#include "decode.h"
#include "threads.h"
Include dependency graph for tmqh-packetpool.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  PktPoolLockedStack_
 
struct  PktPool_
 

Typedefs

typedef struct PktPool_ PktPool
 

Functions

struct PktPoolLockedStack_ __attribute__ ((aligned(CLS))) PktPoolLockedStack
 
 SC_ATOMIC_DECLARE (int, sync_now)
 
PacketTmqhInputPacketpool (ThreadVars *)
 
void TmqhOutputPacketpool (ThreadVars *, Packet *)
 
void TmqhReleasePacketsToPacketPool (PacketQueue *)
 Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed, and wants to return the packets back to the packetpool. More...
 
void TmqhPacketpoolRegister (void)
 TmqhPacketpoolRegister \initonly. More...
 
PacketPacketPoolGetPacket (void)
 Get a new packet from the packet pool. More...
 
void PacketPoolWait (void)
 
void PacketPoolWaitForN (int n)
 Wait until we have the requested amount of packets in the pool. More...
 
void PacketPoolReturnPacket (Packet *p)
 Return packet to Packet pool. More...
 
void PacketPoolInit (void)
 
void PacketPoolInitEmpty (void)
 
void PacketPoolDestroy (void)
 
void PacketPoolPostRunmodes (void)
 Set the max_pending_return_packets value. More...
 

Variables

SCMutex mutex
 
SCCondT cond
 
Packethead
 

Detailed Description

Typedef Documentation

◆ PktPool

typedef struct PktPool_ PktPool

Function Documentation

◆ __attribute__()

struct PktPoolLockedStack_ __attribute__ ( (aligned(CLS))  )

◆ PacketPoolDestroy()

void PacketPoolDestroy ( void  )

Definition at line 316 of file tmqh-packetpool.c.

◆ PacketPoolGetPacket()

Packet* PacketPoolGetPacket ( void  )

Get a new packet from the packet pool.

Only allocates from the thread's local stack, or mallocs new packets. If the local stack is empty, first move all the return stack packets to the local stack.

Return values
Packetpointer, or NULL on failure.

Definition at line 167 of file tmqh-packetpool.c.

Referenced by FlowForceReassemblyPseudoPacketGet(), PacketGetFromQueueOrAlloc(), and TmqhInputPacketpool().

Here is the caller graph for this function:

◆ PacketPoolInit()

void PacketPoolInit ( void  )

Definition at line 284 of file tmqh-packetpool.c.

References max_pending_packets.

Referenced by PostRunDeinit().

Here is the caller graph for this function:

◆ PacketPoolInitEmpty()

void PacketPoolInitEmpty ( void  )

Definition at line 269 of file tmqh-packetpool.c.

◆ PacketPoolPostRunmodes()

void PacketPoolPostRunmodes ( void  )

Set the max_pending_return_packets value.

Set it to the max pending packets value, divided by the number of lister threads. Normally, in autofp these are the stream/detect/log worker threads.

The max_pending_return_packets value needs to stay below the packet pool size of the 'producers' (normally pkt capture threads but also flow timeout injection ) to avoid a deadlock where all the 'workers' keep packets in their return pools, while the capture thread can't continue because its pool is empty.

Definition at line 500 of file tmqh-packetpool.c.

References FatalError, max_pending_packets, RESERVED_PACKETS, TM_FLAG_DETECT_TM, and TmThreadCountThreadsByTmmFlags().

Here is the call graph for this function:

◆ PacketPoolReturnPacket()

void PacketPoolReturnPacket ( Packet p)

Return packet to Packet pool.

Definition at line 207 of file tmqh-packetpool.c.

Referenced by PacketFreeOrRelease(), and PacketGetFromQueueOrAlloc().

Here is the caller graph for this function:

◆ PacketPoolWait()

void PacketPoolWait ( void  )

Definition at line 69 of file tmqh-packetpool.c.

Referenced by FlowForceReassemblyPseudoPacketGet(), ReceiveErfFileLoop(), and ReceivePfringLoop().

Here is the caller graph for this function:

◆ PacketPoolWaitForN()

void PacketPoolWaitForN ( int  n)

Wait until we have the requested amount of packets in the pool.

In some cases waiting for packets is undesirable. Especially when a wait would happen under a lock of some kind, other parts of the engine could have to wait.

This function only returns when at least N packets are in our pool.

If counting in our pool's main stack didn't give us the number we are seeking, we check if the return stack is filled and add those to our main stack. Then we retry.

Parameters
nnumber of packets needed

Definition at line 98 of file tmqh-packetpool.c.

◆ SC_ATOMIC_DECLARE()

__attribute__::SC_ATOMIC_DECLARE ( int  ,
sync_now   
)

◆ TmqhInputPacketpool()

Packet* TmqhInputPacketpool ( ThreadVars )

Definition at line 351 of file tmqh-packetpool.c.

References PacketPoolGetPacket().

Referenced by TmqhPacketpoolRegister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TmqhOutputPacketpool()

◆ TmqhPacketpoolRegister()

void TmqhPacketpoolRegister ( void  )

TmqhPacketpoolRegister \initonly.

Definition at line 53 of file tmqh-packetpool.c.

References Tmqh_::InHandler, Tmqh_::name, Tmqh_::OutHandler, TMQH_PACKETPOOL, tmqh_table, TmqhInputPacketpool(), and TmqhOutputPacketpool().

Referenced by TmqhSetup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TmqhReleasePacketsToPacketPool()

void TmqhReleasePacketsToPacketPool ( PacketQueue pq)

Release all the packets in the queue back to the packetpool. Mainly used by threads that have failed, and wants to return the packets back to the packetpool.

Parameters
pqPointer to the packetqueue from which the packets have to be returned back to the packetpool
Warning
this function assumes that the pq does not use locking

Definition at line 466 of file tmqh-packetpool.c.

References DEBUG_VALIDATE_BUG_ON, Packet_::flow, PacketDequeue(), and TmqhOutputPacketpool().

Here is the call graph for this function:

Variable Documentation

◆ cond

SCCondT cond

Definition at line 2 of file tmqh-packetpool.h.

◆ head

Packet* head

Definition at line 4 of file tmqh-packetpool.h.

◆ mutex

SCMutex mutex

Definition at line 1 of file tmqh-packetpool.h.