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);
53 int UTHRemoveSessionFromFlow(Flow *f);
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__ */
75