/src/suricata8/src/tx-bit.c
Line | Count | Source |
1 | | /* Copyright (C) 2014-2021 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 | | * Implements per ippair bits. Actually, not a bit, |
24 | | * but called that way because of Snort's flowbits. |
25 | | * It's a binary storage. |
26 | | * |
27 | | * \todo move away from a linked list implementation |
28 | | * \todo use different datatypes, such as string, int, etc. |
29 | | */ |
30 | | |
31 | | #include "suricata-common.h" |
32 | | #include "threads.h" |
33 | | #include "tx-bit.h" |
34 | | #include "detect.h" |
35 | | #include "util-var.h" |
36 | | #include "util-debug.h" |
37 | | #include "rust.h" |
38 | | |
39 | | static XBit *TxBitGet(AppLayerTxData *txd, uint32_t idx) |
40 | 0 | { |
41 | 0 | for (GenericVar *gv = txd->txbits; gv != NULL; gv = gv->next) { |
42 | 0 | if (gv->type == DETECT_XBITS && gv->idx == idx) { |
43 | 0 | return (XBit *)gv; |
44 | 0 | } |
45 | 0 | } |
46 | | |
47 | 0 | return NULL; |
48 | 0 | } |
49 | | |
50 | | static int TxBitAdd(AppLayerTxData *txd, uint32_t idx) |
51 | 0 | { |
52 | 0 | XBit *xb = TxBitGet(txd, idx); |
53 | 0 | if (xb == NULL) { |
54 | 0 | xb = SCMalloc(sizeof(XBit)); |
55 | 0 | if (unlikely(xb == NULL)) |
56 | 0 | return -1; |
57 | | |
58 | 0 | xb->type = DETECT_XBITS; |
59 | 0 | xb->idx = idx; |
60 | 0 | xb->next = NULL; |
61 | 0 | SCTIME_INIT(xb->expire); // not used by tx bits |
62 | |
|
63 | 0 | GenericVarAppend(&txd->txbits, (GenericVar *)xb); |
64 | 0 | return 1; |
65 | 0 | } |
66 | 0 | return 0; |
67 | 0 | } |
68 | | |
69 | | int TxBitIsset(AppLayerTxData *txd, uint32_t idx) |
70 | 0 | { |
71 | 0 | XBit *xb = TxBitGet(txd, idx); |
72 | 0 | if (xb != NULL) { |
73 | 0 | SCLogDebug("isset %u return 1", idx); |
74 | 0 | return 1; |
75 | 0 | } |
76 | 0 | SCLogDebug("isset %u r 0", idx); |
77 | 0 | return 0; |
78 | 0 | } |
79 | | |
80 | | int TxBitSet(AppLayerTxData *txd, uint32_t idx) |
81 | 0 | { |
82 | 0 | int r = TxBitAdd(txd, idx); |
83 | 0 | SCLogDebug("set %u r %d", idx, r); |
84 | 0 | return (r == 1); |
85 | 0 | } |