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 void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h);
40 void UTHSetIPV6Hdr(Packet *p, IPV6Hdr *ip6h);
41 void UTHSetTCPHdr(Packet *p, TCPHdr *tcph);
42 
43 uint32_t UTHSetIPv4Address(const char *);
44 
45 Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t);
46 Packet *UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto);
47 Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
48 Packet *UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t);
49 
50 Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
51 
52 int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
53 Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
54 
55 void UTHFreePacket(Packet *);
56 void UTHFreePackets(Packet **, int);
57 
58 void UTHAssignFlow(Packet *p, Flow *f);
59 Flow *UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
60 void UTHFreeFlow(Flow *flow);
61 int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len);
62 int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn);
64 
65 int UTHAppendSigs(DetectEngineCtx *, const char **, int);
66 int UTHMatchPackets(DetectEngineCtx *, Packet **, int);
67 int UTHPacketMatchSig(Packet *p, const char *);
68 int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int);
69 
70 int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int);
71 int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int);
72 int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
73 
74 uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
75 Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
76  uint16_t , uint16_t );
77 
78 void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len);
79 int UTHParseSignature(const char *str, bool expect);
80 #endif
81 
82 void UTHRegisterTests(void);
83 
84 #endif /* SURICATA_UTIL_UNITTEST_HELPER */
UTHMatchPackets
int UTHMatchPackets(DetectEngineCtx *, Packet **, int)
Definition: util-unittest-helper.c:712
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:487
UTHSetIPV4Hdr
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)
Definition: util-unittest-helper.c:126
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:436
UTHFreePacket
void UTHFreePacket(Packet *)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:467
UTHSetIPV6Hdr
void UTHSetIPV6Hdr(Packet *p, IPV6Hdr *ip6h)
Definition: util-unittest-helper.c:131
UTHSetIPv4Address
uint32_t UTHSetIPv4Address(const char *)
return the uint32_t for a ipv4 address string
Definition: util-unittest-helper.c:148
UTHPacketMatchSig
int UTHPacketMatchSig(Packet *p, const char *)
Definition: util-unittest-helper.c:804
Flow_
Flow data structure.
Definition: flow.h:356
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:841
UTHAddStreamToFlow
int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len)
Definition: util-unittest-helper.c:494
UTHRegisterTests
void UTHRegisterTests(void)
Definition: util-unittest-helper.c:1123
UTHPacketMatchSigMpm
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t)
Definition: util-unittest-helper.c:750
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:969
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:172
UTHSetTCPHdr
void UTHSetTCPHdr(Packet *p, TCPHdr *tcph)
Definition: util-unittest-helper.c:136
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:482
UTHBuildPacketFromEth
Packet * UTHBuildPacketFromEth(uint8_t *, uint16_t)
UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.
Definition: util-unittest-helper.c:376
IPV6Hdr_
Definition: decode-ipv6.h:32
Packet_
Definition: decode.h:473
Port
uint16_t Port
Definition: decode.h:214
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:260
UTHCheckPacketMatchResults
int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int)
IPV4Hdr_
Definition: decode-ipv4.h:72
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:400
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:450
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:359
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:510
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:853
UTHAssignFlow
void UTHAssignFlow(Packet *p, Flow *f)
Definition: util-unittest-helper.c:474
UTHRemoveSessionFromFlow
int UTHRemoveSessionFromFlow(Flow *f)
Definition: util-unittest-helper.c:530
TCPHdr_
Definition: decode-tcp.h:149
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:418
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:890