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 #if defined(UNITTESTS) || defined(FUZZ)
28 Flow *TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
29 int TestHelperBufferToFile(const char *name, const uint8_t *data, size_t size);
30 #endif
31 #ifdef UNITTESTS
32 uint32_t UTHSetIPv4Address(const char *);
33 
34 Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t);
35 Packet *UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto);
36 Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
37 Packet *UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t);
38 
39 Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
40 
41 int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
42 Packet **UTHBuildPacketArrayFromEth(uint8_t **, int *, int);
43 Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
44 
45 void UTHFreePacket(Packet *);
46 void UTHFreePackets(Packet **, int);
47 
48 void UTHAssignFlow(Packet *p, Flow *f);
49 Flow *UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
50 void UTHFreeFlow(Flow *flow);
51 int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len);
52 int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn);
54 
55 int UTHAppendSigs(DetectEngineCtx *, const char **, int);
56 int UTHMatchPackets(DetectEngineCtx *, Packet **, int);
57 int UTHPacketMatchSig(Packet *p, const char *);
58 int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int);
59 
60 int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int);
61 int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int);
62 int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
63 
64 uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
65 Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
66  uint16_t , uint16_t );
67 
68 void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len);
69 int UTHParseSignature(const char *str, bool expect);
70 #endif
71 
72 void UTHRegisterTests(void);
73 
74 #endif /* __UTIL_UNITTEST_HELPER__ */
UTHMatchPackets
int UTHMatchPackets(DetectEngineCtx *, Packet **, int)
Definition: util-unittest-helper.c:770
TestHelperBuildFlow
Flow * TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:50
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:526
UTHBuildPacketSrcDstPorts
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...
Definition: util-unittest-helper.c:454
UTHFreePacket
void UTHFreePacket(Packet *)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:485
UTHSetIPv4Address
uint32_t UTHSetIPv4Address(const char *)
return the uint32_t for a ipv4 address string
Definition: util-unittest-helper.c:132
UTHPacketMatchSig
int UTHPacketMatchSig(Packet *p, const char *)
Definition: util-unittest-helper.c:882
Flow_
Flow data structure.
Definition: flow.h:347
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:767
UTHAddStreamToFlow
int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len)
Definition: util-unittest-helper.c:533
UTHRegisterTests
void UTHRegisterTests(void)
Definition: util-unittest-helper.c:1198
UTHPacketMatchSigMpm
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t)
Definition: util-unittest-helper.c:821
UTHGenericTest
int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int)
UTHmemsearch
void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len)
Definition: util-unittest-helper.c:1044
UTHAppendSigs
int UTHAppendSigs(DetectEngineCtx *, const char **, int)
UTHBuildPacketIPV6Real
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...
Definition: util-unittest-helper.c:156
UTHMatchPacketsWithResults
int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int)
UTHBuildFlow
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:521
UTHBuildPacketFromEth
Packet * UTHBuildPacketFromEth(uint8_t *, uint16_t)
UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.
Definition: util-unittest-helper.c:394
Packet_
Definition: decode.h:414
Port
uint16_t Port
Definition: decode.h:241
UTHBuildPacketReal
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...
Definition: util-unittest-helper.c:242
UTHCheckPacketMatchResults
int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int)
UTHBuildPacketArrayFromEth
Packet ** UTHBuildPacketArrayFromEth(uint8_t **, int *, int)
UTHBuildPacketSrcDst
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.
Definition: util-unittest-helper.c:418
TestHelperBufferToFile
int TestHelperBufferToFile(const char *name, const uint8_t *data, size_t size)
writes the contents of a buffer into a file
Definition: util-unittest-helper.c:101
UTHFreePackets
void UTHFreePackets(Packet **, int)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:468
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:337
str
#define str(s)
Definition: suricata-common.h:273
src
uint16_t src
Definition: app-layer-dnp3.h:5
UTHCheckPacketMatch
int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int)
UTHAddSessionToFlow
int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn)
Definition: util-unittest-helper.c:549
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
UTHBuildPacketOfFlows
uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t)
Definition: util-unittest-helper.c:931
UTHAssignFlow
void UTHAssignFlow(Packet *p, Flow *f)
Definition: util-unittest-helper.c:513
UTHRemoveSessionFromFlow
int UTHRemoveSessionFromFlow(Flow *f)
Definition: util-unittest-helper.c:569
UTHBuildPacketIPV6SrcDst
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)
Definition: util-unittest-helper.c:436
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:969