suricata
tmqh-packetpool.h File Reference
#include "decode.h"
#include "threads.h"
#include "util-atomic.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 . 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

typedef struct PktPool_ PktPool

Function Documentation

struct PktPoolLockedStack_ __attribute__ ( (aligned(CLS))  )
void PacketPoolDestroy ( void  )

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

References BUG_ON, Packet_::next, PacketFree(), PacketPoolGetPacket(), PktPool_::pending_count, PktPool_::pending_head, PktPool_::pending_pool, PktPool_::pending_tail, PktPool_::return_stack, and SC_ATOMIC_DESTROY.

Referenced by PostRunDeinit(), RunUnittests(), and TmThreadsSlotVarRun().

Here is the call graph for this function:

Here is the caller graph for this function:

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 244 of file tmqh-packetpool.c.

References BUG_ON, PktPool_::head, Packet_::next, PACKET_REINIT, and Packet_::pool.

Referenced by PacketGetFromQueueOrAlloc(), PacketPoolDestroy(), StreamTcpPseudoPacketCreateStreamEndPacket(), TmModuleDecodeNetmapRegister(), and TmqhInputPacketpool().

Here is the caller graph for this function:

void PacketPoolInit ( void  )

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

References BUG_ON, max_pending_packets, PacketGetFromAlloc(), PktPool_::return_stack, SC_ATOMIC_INIT, SC_ERR_FATAL, SCCondInit, SCLogDebug, SCLogError, SCMutexInit, SIZE_OF_PACKET, and unlikely.

Referenced by PostRunDeinit(), RunUnittests(), and TmThreadsSlotVarRun().

Here is the call graph for this function:

Here is the caller graph for this function:

void PacketPoolInitEmpty ( void  )

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

References BUG_ON, PktPool_::return_stack, SC_ATOMIC_INIT, SCCondInit, and SCMutexInit.

Referenced by TmThreadsSlotVarRun().

Here is the caller graph for this function:

void PacketPoolPostRunmodes ( void  )

Set the max_pending_return_packets value.

Set it to the max pending packets value, devided 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 575 of file tmqh-packetpool.c.

References max_pending_packets, SCLogDebug, TM_FLAG_DETECT_TM, and TmThreadCountThreadsByTmmFlags().

Referenced by main(), and RunModeUnixSocketGetDefaultMode().

Here is the call graph for this function:

Here is the caller graph for this function:

void PacketPoolReturnPacket ( Packet p)

Return packet to Packet pool.

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

References BUG_ON, PktPool_::head, Packet_::next, PACKET_RELEASE_REFS, PacketFree(), PktPool_::pending_count, PktPool_::pending_head, PktPool_::pending_pool, PktPool_::pending_tail, Packet_::pool, PktPool_::return_stack, SC_ATOMIC_GET, SC_ATOMIC_RESET, SCCondSignal, SCMutexLock, and SCMutexUnlock.

Referenced by PacketFreeOrRelease(), and PacketPoolWaitForN().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters
nnumber of packets needed

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

References Packet_::flags, PktPool_::head, Packet_::next, PacketPoolReturnPacket(), PacketPoolWait(), PKT_ALLOC, Packet_::pool, Packet_::ReleasePacket, PktPool_::return_stack, SC_ATOMIC_ADD, SCCondWait, SCMutexLock, and SCMutexUnlock.

Referenced by FlowDisableFlowManagerThread(), and FlowForceReassemblyForFlow().

Here is the call graph for this function:

Here is the caller graph for this function:

__attribute__::SC_ATOMIC_DECLARE ( int  ,
sync_now   
)
Packet* TmqhInputPacketpool ( ThreadVars )

Definition at line 439 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:

void TmqhPacketpoolRegister ( void  )

TmqhPacketpoolRegister .

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

References PktPool_::head, Tmqh_::InHandler, Tmqh_::name, Tmqh_::OutHandler, PktPool_::return_stack, 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:

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 549 of file tmqh-packetpool.c.

References PacketDequeue(), and TmqhOutputPacketpool().

Referenced by TmThreadsSlotVarRun().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

SCCondT cond

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

Packet* head

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

SCMutex mutex

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