suricata
detect-engine-uint.c
Go to the documentation of this file.
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 {
33  return rs_detect_u32_match(parg, du32);
34 }
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 {
47  return rs_detect_u32_parse(u32str);
48 }
49 
50 void
52 {
53  const DetectUintData_u32 *a = smctx;
54  v->u8[0] = a->mode;
55  v->u32[1] = a->arg1;
56  v->u32[2] = a->arg2;
57 }
58 
59 bool
61 {
62  const DetectUintData_u32 *a = smctx;
63  if (v.u8[0] == a->mode &&
64  v.u32[1] == a->arg1 &&
65  v.u32[2] == a->arg2)
66  return true;
67  return false;
68 }
69 
70 //same as u32 but with u8
71 int DetectU8Match(const uint8_t parg, const DetectUintData_u8 *du8)
72 {
73  return rs_detect_u8_match(parg, du8);
74 }
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 {
87  return rs_detect_u8_parse(u8str);
88 }
89 
91 {
92  const DetectUintData_u8 *a = smctx;
93  v->u8[0] = a->mode;
94  v->u8[1] = a->arg1;
95  v->u8[2] = a->arg2;
96 }
97 
99 {
100  const DetectUintData_u8 *a = smctx;
101  if (v.u8[0] == a->mode && v.u8[1] == a->arg1 && v.u8[2] == a->arg2)
102  return true;
103  return false;
104 }
105 
106 // same as u32 but with u16
107 int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
108 {
109  return rs_detect_u16_match(parg, du16);
110 }
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 {
123  return rs_detect_u16_parse(u16str);
124 }
125 
127 {
128  const DetectUintData_u16 *a = smctx;
129  v->u8[0] = a->mode;
130  v->u16[1] = a->arg1;
131  v->u16[2] = a->arg2;
132 }
133 
135 {
136  const DetectUintData_u16 *a = smctx;
137  if (v.u8[0] == a->mode && v.u16[1] == a->arg1 && v.u16[2] == a->arg2)
138  return true;
139  return false;
140 }
141 
142 int DetectU64Match(const uint64_t parg, const DetectUintData_u64 *du64)
143 {
144  return rs_detect_u64_match(parg, du64);
145 }
146 
147 DetectUintData_u64 *DetectU64Parse(const char *u64str)
148 {
149  return rs_detect_u64_parse(u64str);
150 }
util-byte.h
detect-engine-uint.h
PrefilterPacketU16Set
void PrefilterPacketU16Set(PrefilterPacketHeaderValue *v, void *smctx)
Definition: detect-engine-uint.c:126
DetectU32Match
int DetectU32Match(const uint32_t parg, const DetectUintData_u32 *du32)
Definition: detect-engine-uint.c:31
DetectU32Parse
DetectUintData_u32 * DetectU32Parse(const char *u32str)
This function is used to parse u32 options passed via some u32 keyword.
Definition: detect-engine-uint.c:45
PrefilterPacketU32Set
void PrefilterPacketU32Set(PrefilterPacketHeaderValue *v, void *smctx)
Definition: detect-engine-uint.c:51
PrefilterPacketHeaderValue::u8
uint8_t u8[16]
Definition: detect-engine-prefilter-common.h:24
PrefilterPacketHeaderValue::u16
uint16_t u16[8]
Definition: detect-engine-prefilter-common.h:25
DetectU8Parse
DetectUintData_u8 * DetectU8Parse(const char *u8str)
This function is used to parse u8 options passed via some u8 keyword.
Definition: detect-engine-uint.c:85
PrefilterPacketHeaderValue::u32
uint32_t u32[4]
Definition: detect-engine-prefilter-common.h:26
PrefilterPacketU8Set
void PrefilterPacketU8Set(PrefilterPacketHeaderValue *v, void *smctx)
Definition: detect-engine-uint.c:90
PrefilterPacketU32Compare
bool PrefilterPacketU32Compare(PrefilterPacketHeaderValue v, void *smctx)
Definition: detect-engine-uint.c:60
DetectU8Match
int DetectU8Match(const uint8_t parg, const DetectUintData_u8 *du8)
Definition: detect-engine-uint.c:71
DetectU16Match
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
Definition: detect-engine-uint.c:107
DetectU16Parse
DetectUintData_u16 * DetectU16Parse(const char *u16str)
This function is used to parse u16 options passed via some u16 keyword.
Definition: detect-engine-uint.c:121
PrefilterPacketU16Compare
bool PrefilterPacketU16Compare(PrefilterPacketHeaderValue v, void *smctx)
Definition: detect-engine-uint.c:134
suricata-common.h
DetectU64Parse
DetectUintData_u64 * DetectU64Parse(const char *u64str)
Definition: detect-engine-uint.c:147
detect-parse.h
DetectU64Match
int DetectU64Match(const uint64_t parg, const DetectUintData_u64 *du64)
Definition: detect-engine-uint.c:142
PrefilterPacketU8Compare
bool PrefilterPacketU8Compare(PrefilterPacketHeaderValue v, void *smctx)
Definition: detect-engine-uint.c:98
PrefilterPacketHeaderValue
Definition: detect-engine-prefilter-common.h:23