/src/suricata7/src/tmqh-simple.c
Line | Count | Source |
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 | | |
35 | | Packet *TmqhInputSimple(ThreadVars *t); |
36 | | void TmqhOutputSimple(ThreadVars *t, Packet *p); |
37 | | void TmqhInputSimpleShutdownHandler(ThreadVars *); |
38 | | |
39 | | void TmqhSimpleRegister (void) |
40 | 71 | { |
41 | 71 | tmqh_table[TMQH_SIMPLE].name = "simple"; |
42 | 71 | tmqh_table[TMQH_SIMPLE].InHandler = TmqhInputSimple; |
43 | 71 | tmqh_table[TMQH_SIMPLE].InShutdownHandler = TmqhInputSimpleShutdownHandler; |
44 | 71 | tmqh_table[TMQH_SIMPLE].OutHandler = TmqhOutputSimple; |
45 | 71 | } |
46 | | |
47 | | Packet *TmqhInputSimple(ThreadVars *t) |
48 | 0 | { |
49 | 0 | PacketQueue *q = t->inq->pq; |
50 | |
|
51 | 0 | StatsSyncCountersIfSignalled(t); |
52 | |
|
53 | 0 | SCMutexLock(&q->mutex_q); |
54 | |
|
55 | 0 | if (q->len == 0) { |
56 | | /* if we have no packets in queue, wait... */ |
57 | 0 | SCCondWait(&q->cond_q, &q->mutex_q); |
58 | 0 | } |
59 | |
|
60 | 0 | if (q->len > 0) { |
61 | 0 | Packet *p = PacketDequeue(q); |
62 | 0 | SCMutexUnlock(&q->mutex_q); |
63 | 0 | return p; |
64 | 0 | } else { |
65 | | /* return NULL if we have no pkt. Should only happen on signals. */ |
66 | 0 | SCMutexUnlock(&q->mutex_q); |
67 | 0 | return NULL; |
68 | 0 | } |
69 | 0 | } |
70 | | |
71 | | void TmqhInputSimpleShutdownHandler(ThreadVars *tv) |
72 | 0 | { |
73 | 0 | int i; |
74 | |
|
75 | 0 | if (tv == NULL || tv->inq == NULL) { |
76 | 0 | return; |
77 | 0 | } |
78 | | |
79 | 0 | for (i = 0; i < (tv->inq->reader_cnt + tv->inq->writer_cnt); i++) { |
80 | 0 | SCMutexLock(&tv->inq->pq->mutex_q); |
81 | 0 | SCCondSignal(&tv->inq->pq->cond_q); |
82 | 0 | SCMutexUnlock(&tv->inq->pq->mutex_q); |
83 | 0 | } |
84 | 0 | } |
85 | | |
86 | | void TmqhOutputSimple(ThreadVars *t, Packet *p) |
87 | 0 | { |
88 | 0 | SCLogDebug("Packet %p, p->root %p, alloced %s", p, p->root, BOOL2STR(p->pool == NULL)); |
89 | |
|
90 | 0 | PacketQueue *q = t->outq->pq; |
91 | |
|
92 | 0 | SCMutexLock(&q->mutex_q); |
93 | 0 | PacketEnqueue(q, p); |
94 | 0 | SCCondSignal(&q->cond_q); |
95 | 0 | SCMutexUnlock(&q->mutex_q); |
96 | 0 | } |
97 | | |