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)
35Flow *TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
36int TestHelperBufferToFile(const char *name, const uint8_t *data, size_t size);
37#endif
38#ifdef UNITTESTS
39void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h);
40void UTHSetIPV6Hdr(Packet *p, IPV6Hdr *ip6h);
41void UTHSetTCPHdr(Packet *p, TCPHdr *tcph);
42
43uint32_t UTHSetIPv4Address(const char *);
44
45Packet *UTHBuildPacketReal(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *, uint16_t, uint16_t);
46Packet *UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto);
47Packet *UTHBuildPacketSrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
48Packet *UTHBuildPacketSrcDstPorts(uint8_t *, uint16_t, uint8_t ipproto, uint16_t, uint16_t);
49
50Packet *UTHBuildPacketIPV6SrcDst(uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *);
51
52int UTHPacketMatchSigMpm(Packet *, char *, uint16_t);
53Packet *UTHBuildPacketFromEth(uint8_t *, uint16_t);
54
55void UTHFreePacket(Packet *);
56void UTHFreePackets(Packet **, int);
57
58void UTHAssignFlow(Packet *p, Flow *f);
59Flow *UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp);
60void UTHFreeFlow(Flow *flow);
61int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len);
62int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn);
64
65int UTHAppendSigs(DetectEngineCtx *, const char **, int);
67int UTHPacketMatchSig(Packet *p, const char *);
68int UTHCheckPacketMatch(Packet *, uint32_t *, uint32_t *, int);
69
70int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int);
71int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int);
72int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int);
73
74uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t);
75Packet *UTHBuildPacketIPV6Real(uint8_t *, uint16_t , uint8_t ipproto, const char *, const char *,
76 uint16_t , uint16_t );
77
78void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len);
79int UTHParseSignature(const char *str, bool expect);
80#endif
81
82void UTHRegisterTests(void);
83
84#endif /* SURICATA_UTIL_UNITTEST_HELPER */
uint16_t dst
uint16_t src
uint16_t Port
Definition decode.h:218
main detection engine ctx
Definition detect.h:932
Flow data structure.
Definition flow.h:356
#define str(s)
const char * name
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)
int TestHelperBufferToFile(const char *name, const uint8_t *data, size_t size)
writes the contents of a buffer into a file
int UTHAppendSigs(DetectEngineCtx *, const char **, int)
int UTHGenericTest(Packet **, int, const char **, uint32_t *, uint32_t *, int)
int UTHRemoveSessionFromFlow(Flow *f)
void * UTHmemsearch(const void *big, size_t big_len, const void *little, size_t little_len)
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...
Packet * UTHBuildPacket(uint8_t *, uint16_t, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
int UTHAddSessionToFlow(Flow *f, uint32_t ts_isn, uint32_t tc_isn)
int UTHMatchPacketsWithResults(DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int)
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)
void UTHFreePackets(Packet **, int)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
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...
void UTHAssignFlow(Packet *p, Flow *f)
uint32_t UTHSetIPv4Address(const char *)
return the uint32_t for a ipv4 address string
void UTHFreePacket(Packet *)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
void UTHFreeFlow(Flow *flow)
Flow * TestHelperBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
uint32_t UTHBuildPacketOfFlows(uint32_t, uint32_t, uint8_t)
int UTHCheckPacketMatchResults(Packet *, uint32_t *, uint32_t *, int)
int UTHPacketMatchSigMpm(Packet *, char *, uint16_t)
void UTHRegisterTests(void)
int UTHAddStreamToFlow(Flow *f, int direction, uint8_t *data, uint32_t data_len)
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
int UTHMatchPackets(DetectEngineCtx *, Packet **, int)
void UTHSetTCPHdr(Packet *p, TCPHdr *tcph)
void UTHSetIPV6Hdr(Packet *p, IPV6Hdr *ip6h)
Packet * UTHBuildPacketFromEth(uint8_t *, uint16_t)
UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.
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 UTHPacketMatchSig(Packet *p, const char *)
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)