suricata
util-unittest-helper.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 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 Pablo Rincon Crespo <pablo.rincon.crespo@gmail.com>
22  */
23 
24 #ifndef __UTIL_UNITTEST_HELPER__
25 #define __UTIL_UNITTEST_HELPER__
26 
27 #ifdef UNITTESTS
28 uint32_t UTHSetIPv4Address(const char *);
29 
30 Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t);
31 Packet *UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto);
32 Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
33 Packet *UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t);
34 
35 Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
36 
37 int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
38 Packet **UTHBuildPacketArrayFromEth(uint8_t **, int *, int);
39 Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
40 
41 void UTHFreePacket(Packet *);
42 void UTHFreePackets(Packet **, int);
43 
44 void UTHAssignFlow(Packet *p, Flow *f);
45 Flow *UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
46 void UTHFreeFlow(Flow *flow);
47 int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len);
48 int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn);
50 
51 int UTHAppendSigs(DetectEngineCtx *, const char **, int);
52 int UTHMatchPackets(DetectEngineCtx *, Packet **, int);
53 int UTHPacketMatchSig(Packet *p, const char *);
54 int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int);
55 
56 int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int);
57 int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int);
58 int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
59 
60 uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
61 Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
62  uint16_t , uint16_t );
63 
64 int UTHParseSignature(const char *str, bool expect);
65 #endif
66 
67 void UTHRegisterTests(void);
68 
69 #endif /* __UTIL_UNITTEST_HELPER__ */
Packet ** UTHBuildPacketArrayFromEth(uint8_t **, int *, int)
int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn)
uint32_t UTHSetIPv4Address(const char *)
return the uint32_t for a ipv4 address string
Packet * UTHBuildPacketFromEth(uint8_t *, uint16_t)
UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.
uint16_t src
int UTHMatchPackets(DetectEngineCtx *, Packet **, int)
main detection engine ctx
Definition: detect.h:724
Packet * UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
int UTHRemoveSessionFromFlow(Flow *f)
Packet * UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *)
UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports (IPV6) ...
#define str(s)
uint16_t dst
void UTHFreeFlow(Flow *flow)
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Packet * UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *)
UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports...
Packet * UTHBuildPacketIPV6Real(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t)
UTHBuildPacketReal is a function that create tcp/udp packets for unittests specifying ip and port sou...
int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int)
int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int)
int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int)
int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len)
uint16_t Port
Definition: decode.h:233
int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int)
int UTHAppendSigs(DetectEngineCtx *, const char **, int)
void UTHAssignFlow(Packet *p, Flow *f)
int UTHPacketMatchSig(Packet *p, const char *)
Packet * UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t)
UTHBuildPacketSrcDstPorts is a wrapper that build packets specifying src and dst ports and defaulting...
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
void UTHFreePacket(Packet *)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself...
void UTHFreePackets(Packet **, int)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself...
Packet * UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t)
UTHBuildPacketReal is a function that create tcp/udp packets for unittests specifying ip and port sou...
void UTHRegisterTests(void)
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t)
uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t)
Flow data structure.
Definition: flow.h:325