/src/suricata7/src/detect-engine-uint.c
Line | Count | Source |
1 | | /* Copyright (C) 2020 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 Philippe Antoine <p.antoine@catenacyber.fr> |
22 | | * |
23 | | */ |
24 | | |
25 | | #include "suricata-common.h" |
26 | | |
27 | | #include "util-byte.h" |
28 | | #include "detect-parse.h" |
29 | | #include "detect-engine-uint.h" |
30 | | |
31 | | int DetectU32Match(const uint32_t parg, const DetectUintData_u32 *du32) |
32 | 45.7k | { |
33 | 45.7k | return rs_detect_u32_match(parg, du32); |
34 | 45.7k | } |
35 | | |
36 | | /** |
37 | | * \brief This function is used to parse u32 options passed via some u32 keyword |
38 | | * |
39 | | * \param u32str Pointer to the user provided u32 options |
40 | | * |
41 | | * \retval DetectU32Data pointer to DetectU32Data on success |
42 | | * \retval NULL on failure |
43 | | */ |
44 | | |
45 | | DetectUintData_u32 *DetectU32Parse(const char *u32str) |
46 | 23.7k | { |
47 | 23.7k | return rs_detect_u32_parse(u32str); |
48 | 23.7k | } |
49 | | |
50 | | void |
51 | | PrefilterPacketU32Set(PrefilterPacketHeaderValue *v, void *smctx) |
52 | 18.4k | { |
53 | 18.4k | const DetectUintData_u32 *a = smctx; |
54 | 18.4k | v->u8[0] = a->mode; |
55 | 18.4k | v->u32[1] = a->arg1; |
56 | 18.4k | v->u32[2] = a->arg2; |
57 | 18.4k | } |
58 | | |
59 | | bool |
60 | | PrefilterPacketU32Compare(PrefilterPacketHeaderValue v, void *smctx) |
61 | 12.5k | { |
62 | 12.5k | const DetectUintData_u32 *a = smctx; |
63 | 12.5k | if (v.u8[0] == a->mode && |
64 | 12.5k | v.u32[1] == a->arg1 && |
65 | 12.3k | v.u32[2] == a->arg2) |
66 | 12.3k | return true; |
67 | 216 | return false; |
68 | 12.5k | } |
69 | | |
70 | | //same as u32 but with u8 |
71 | | int DetectU8Match(const uint8_t parg, const DetectUintData_u8 *du8) |
72 | 137k | { |
73 | 137k | return rs_detect_u8_match(parg, du8); |
74 | 137k | } |
75 | | |
76 | | /** |
77 | | * \brief This function is used to parse u8 options passed via some u8 keyword |
78 | | * |
79 | | * \param u8str Pointer to the user provided u8 options |
80 | | * |
81 | | * \retval DetectU8Data pointer to DetectU8Data on success |
82 | | * \retval NULL on failure |
83 | | */ |
84 | | |
85 | | DetectUintData_u8 *DetectU8Parse(const char *u8str) |
86 | 58.5k | { |
87 | 58.5k | return rs_detect_u8_parse(u8str); |
88 | 58.5k | } |
89 | | |
90 | | void PrefilterPacketU8Set(PrefilterPacketHeaderValue *v, void *smctx) |
91 | 36.0k | { |
92 | 36.0k | const DetectUintData_u8 *a = smctx; |
93 | 36.0k | v->u8[0] = a->mode; |
94 | 36.0k | v->u8[1] = a->arg1; |
95 | 36.0k | v->u8[2] = a->arg2; |
96 | 36.0k | } |
97 | | |
98 | | bool PrefilterPacketU8Compare(PrefilterPacketHeaderValue v, void *smctx) |
99 | 1.99k | { |
100 | 1.99k | const DetectUintData_u8 *a = smctx; |
101 | 1.99k | if (v.u8[0] == a->mode && v.u8[1] == a->arg1 && v.u8[2] == a->arg2) |
102 | 1.89k | return true; |
103 | 108 | return false; |
104 | 1.99k | } |
105 | | |
106 | | // same as u32 but with u16 |
107 | | int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16) |
108 | 47.0k | { |
109 | 47.0k | return rs_detect_u16_match(parg, du16); |
110 | 47.0k | } |
111 | | |
112 | | /** |
113 | | * \brief This function is used to parse u16 options passed via some u16 keyword |
114 | | * |
115 | | * \param u16str Pointer to the user provided u16 options |
116 | | * |
117 | | * \retval DetectU16Data pointer to DetectU16Data on success |
118 | | * \retval NULL on failure |
119 | | */ |
120 | | |
121 | | DetectUintData_u16 *DetectU16Parse(const char *u16str) |
122 | 50.4k | { |
123 | 50.4k | return rs_detect_u16_parse(u16str); |
124 | 50.4k | } |
125 | | |
126 | | void PrefilterPacketU16Set(PrefilterPacketHeaderValue *v, void *smctx) |
127 | 31.3k | { |
128 | 31.3k | const DetectUintData_u16 *a = smctx; |
129 | 31.3k | v->u8[0] = a->mode; |
130 | 31.3k | v->u16[1] = a->arg1; |
131 | 31.3k | v->u16[2] = a->arg2; |
132 | 31.3k | } |
133 | | |
134 | | bool PrefilterPacketU16Compare(PrefilterPacketHeaderValue v, void *smctx) |
135 | 1.57k | { |
136 | 1.57k | const DetectUintData_u16 *a = smctx; |
137 | 1.57k | if (v.u8[0] == a->mode && v.u16[1] == a->arg1 && v.u16[2] == a->arg2) |
138 | 1.30k | return true; |
139 | 264 | return false; |
140 | 1.57k | } |
141 | | |
142 | | int DetectU64Match(const uint64_t parg, const DetectUintData_u64 *du64) |
143 | 2.97k | { |
144 | 2.97k | return rs_detect_u64_match(parg, du64); |
145 | 2.97k | } |
146 | | |
147 | | DetectUintData_u64 *DetectU64Parse(const char *u64str) |
148 | 65.2k | { |
149 | 65.2k | return rs_detect_u64_parse(u64str); |
150 | 65.2k | } |