suricata
tmqh-simple.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2013 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Simple queue handler
24  */
25 
26 #include "suricata.h"
27 #include "packet-queue.h"
28 #include "decode.h"
29 #include "threads.h"
30 #include "threadvars.h"
31 
32 #include "tm-queuehandlers.h"
33 #include "tmqh-simple.h"
34 
38 
39 void TmqhSimpleRegister (void)
40 {
41  tmqh_table[TMQH_SIMPLE].name = "simple";
45 }
46 
48 {
49  PacketQueue *q = t->inq->pq;
50 
52 
53  SCMutexLock(&q->mutex_q);
54 
55  if (q->len == 0) {
56  /* if we have no packets in queue, wait... */
57  SCCondWait(&q->cond_q, &q->mutex_q);
58  }
59 
60  if (q->len > 0) {
61  Packet *p = PacketDequeue(q);
63  return p;
64  } else {
65  /* return NULL if we have no pkt. Should only happen on signals. */
67  return NULL;
68  }
69 }
70 
72 {
73  int i;
74 
75  if (tv == NULL || tv->inq == NULL) {
76  return;
77  }
78 
79  for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) {
83  }
84 }
85 
87 {
88  SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, BOOL2STR(p->pool == NULL));
89 
90  PacketQueue *q = t->outq->pq;
91 
92  SCMutexLock(&q->mutex_q);
93  PacketEnqueue(q, p);
94  SCCondSignal(&q->cond_q);
96 }
97 
Tmq_::writer_cnt
uint16_t writer_cnt
Definition: tm-queues.h:34
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
PacketEnqueue
void PacketEnqueue(PacketQueue *q, Packet *p)
Definition: packet-queue.c:175
PacketQueue_
simple fifo queue for packets with mutex and cond Calling the mutex or triggering the cond is respons...
Definition: packet-queue.h:49
threads.h
Tmq_::pq
PacketQueue * pq
Definition: tm-queues.h:35
Tmqh_::OutHandler
void(* OutHandler)(ThreadVars *, Packet *)
Definition: tm-queuehandlers.h:40
Packet_::pool
struct PktPool_ * pool
Definition: decode.h:639
packet-queue.h
TmqhInputSimpleShutdownHandler
void TmqhInputSimpleShutdownHandler(ThreadVars *)
Definition: tmqh-simple.c:71
ThreadVars_::outq
Tmq * outq
Definition: threadvars.h:104
SCMutexLock
#define SCMutexLock(mut)
Definition: threads-debug.h:117
Tmqh_::InHandler
Packet *(* InHandler)(ThreadVars *)
Definition: tm-queuehandlers.h:38
PacketQueue_::mutex_q
SCMutex mutex_q
Definition: packet-queue.h:56
Tmqh_::InShutdownHandler
void(* InShutdownHandler)(ThreadVars *)
Definition: tm-queuehandlers.h:39
decode.h
SCCondWait
#define SCCondWait
Definition: threads-debug.h:141
tmqh-simple.h
SCMutexUnlock
#define SCMutexUnlock(mut)
Definition: threads-debug.h:119
BOOL2STR
#define BOOL2STR(b)
Definition: util-debug.h:527
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
Packet_
Definition: decode.h:476
Tmqh_::name
const char * name
Definition: tm-queuehandlers.h:37
PacketQueue_::cond_q
SCCondT cond_q
Definition: packet-queue.h:57
tm-queuehandlers.h
SCCondSignal
#define SCCondSignal
Definition: threads-debug.h:139
ThreadVars_::inq
Tmq * inq
Definition: threadvars.h:90
TMQH_SIMPLE
@ TMQH_SIMPLE
Definition: tm-queuehandlers.h:29
PacketQueue_::len
uint32_t len
Definition: packet-queue.h:52
tmqh_table
Tmqh tmqh_table[TMQH_SIZE]
Definition: tm-queuehandlers.c:37
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
PacketDequeue
Packet * PacketDequeue(PacketQueue *q)
Definition: packet-queue.c:216
threadvars.h
TmqhInputSimple
Packet * TmqhInputSimple(ThreadVars *t)
Definition: tmqh-simple.c:47
Packet_::root
struct Packet_ * root
Definition: decode.h:622
TmqhSimpleRegister
void TmqhSimpleRegister(void)
Definition: tmqh-simple.c:39
suricata.h
StatsSyncCountersIfSignalled
void StatsSyncCountersIfSignalled(ThreadVars *tv)
Definition: counters.c:449
TmqhOutputSimple
void TmqhOutputSimple(ThreadVars *t, Packet *p)
Definition: tmqh-simple.c:86
Tmq_::reader_cnt
uint16_t reader_cnt
Definition: tm-queues.h:33