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 SURICATA_UTIL_UNITTEST_HELPER
25 #define SURICATA_UTIL_UNITTEST_HELPER
26 
27 #if defined(UNITTESTS)
28 #include "flow.h"
29 #include "detect.h"
30 #elif defined(FUZZ)
31 #include "flow.h"
32 #endif
33 
34 #if defined(UNITTESTS) || defined(FUZZ)
35 Flow *TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
36 int TestHelperBufferToFile(const char *name, const uint8_t *data, size_t size);
37 #endif
38 #ifdef UNITTESTS
39 uint32_t UTHSetIPv4Address(const char *);
40 
41 Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t);
42 Packet *UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto);
43 Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
44 Packet *UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t);
45 
46 Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
47 
48 int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
49 Packet **UTHBuildPacketArrayFromEth(uint8_t **, int *, int);
50 Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
51 
52 void UTHFreePacket(Packet *);
53 void UTHFreePackets(Packet **, int);
54 
55 void UTHAssignFlow(Packet *p, Flow *f);
56 Flow *UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
57 void UTHFreeFlow(Flow *flow);
58 int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len);
59 int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn);
61 
62 int UTHAppendSigs(DetectEngineCtx *, const char **, int);
63 int UTHMatchPackets(DetectEngineCtx *, Packet **, int);
64 int UTHPacketMatchSig(Packet *p, const char *);
65 int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int);
66 
67 int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int);
68 int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int);
69 int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
70 
71 uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
72 Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
73  uint16_t , uint16_t );
74 
75 void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len);
76 int UTHParseSignature(const char *str, bool expect);
77 #endif
78 
79 void UTHRegisterTests(void);
80 
81 #endif /* SURICATA_UTIL_UNITTEST_HELPER */
UTHMatchPackets
int UTHMatchPackets(DetectEngineCtx *, Packet **, int)
Definition: util-unittest-helper.c:731
TestHelperBuildFlow
Flow * TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:52
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:506
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:455
UTHFreePacket
void UTHFreePacket(Packet *)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:486
UTHSetIPv4Address
uint32_t UTHSetIPv4Address(const char *)
return the uint32_t for a ipv4 address string
Definition: util-unittest-helper.c:134
UTHPacketMatchSig
int UTHPacketMatchSig(Packet *p, const char *)
Definition: util-unittest-helper.c:823
Flow_
Flow data structure.
Definition: flow.h:350
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:836
UTHAddStreamToFlow
int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len)
Definition: util-unittest-helper.c:513
UTHRegisterTests
void UTHRegisterTests(void)
Definition: util-unittest-helper.c:1138
UTHPacketMatchSigMpm
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t)
Definition: util-unittest-helper.c:769
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:984
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:158
UTHMatchPacketsWithResults
int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int)
detect.h
UTHBuildFlow
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:501
UTHBuildPacketFromEth
Packet * UTHBuildPacketFromEth(uint8_t *, uint16_t)
UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.
Definition: util-unittest-helper.c:395
Packet_
Definition: decode.h:436
Port
uint16_t Port
Definition: decode.h:229
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:244
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:419
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:103
UTHFreePackets
void UTHFreePackets(Packet **, int)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:469
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:338
str
#define str(s)
Definition: suricata-common.h:291
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:529
dst
uint16_t dst
Definition: app-layer-dnp3.h:4
flow.h
UTHBuildPacketOfFlows
uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t)
Definition: util-unittest-helper.c:872
UTHAssignFlow
void UTHAssignFlow(Packet *p, Flow *f)
Definition: util-unittest-helper.c:493
UTHRemoveSessionFromFlow
int UTHRemoveSessionFromFlow(Flow *f)
Definition: util-unittest-helper.c:549
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:437
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:909