suricata
util-unittest-helper.h File Reference

Go to the source code of this file.

Functions

uint32_t UTHSetIPv4Address (const char *)
 return the uint32_t for a ipv4 address string More...
 
PacketUTHBuildPacketReal (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 sources and destinations. More...
 
PacketUTHBuildPacket (uint8_t *, uint16_t, uint8_t ipproto)
 UTHBuildPacket is a wrapper that build packets with default ip and port fields. More...
 
PacketUTHBuildPacketSrcDst (uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *)
 UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports. More...
 
PacketUTHBuildPacketSrcDstPorts (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 IPs. More...
 
PacketUTHBuildPacketIPV6SrcDst (uint8_t *, uint16_t, uint8_t ipproto, const char *, const char *)
 UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports (IPV6) More...
 
int UTHPacketMatchSigMpm (Packet *, char *, uint16_t)
 
Packet ** UTHBuildPacketArrayFromEth (uint8_t **, int *, int)
 
PacketUTHBuildPacketFromEth (uint8_t *, uint16_t)
 UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes. More...
 
void UTHFreePacket (Packet *)
 UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself. More...
 
void UTHFreePackets (Packet **, int)
 UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself. More...
 
void UTHAssignFlow (Packet *p, Flow *f)
 
FlowUTHBuildFlow (int family, const char *src, const char *dst, Port sp, Port dp)
 
void UTHFreeFlow (Flow *flow)
 
int UTHAddStreamToFlow (Flow *f, int direction, uint8_t *data, uint32_t data_len)
 
int UTHAddSessionToFlow (Flow *f, uint32_t ts_isn, uint32_t tc_isn)
 
int UTHRemoveSessionFromFlow (Flow *f)
 
int UTHAppendSigs (DetectEngineCtx *, const char **, int)
 
int UTHMatchPackets (DetectEngineCtx *, Packet **, int)
 
int UTHPacketMatchSig (Packet *p, const char *)
 
int UTHCheckPacketMatch (Packet *, uint32_t *, uint32_t *, int)
 
int UTHCheckPacketMatchResults (Packet *, uint32_t *, uint32_t *, int)
 
int UTHMatchPacketsWithResults (DetectEngineCtx *, Packet **, int, uint32_t *, uint32_t *, int)
 
int UTHGenericTest (Packet **, int, const char **, uint32_t *, uint32_t *, int)
 
uint32_t UTHBuildPacketOfFlows (uint32_t, uint32_t, uint8_t)
 
PacketUTHBuildPacketIPV6Real (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 sources and destinations (IPV6) More...
 
int UTHParseSignature (const char *str, bool expect)
 parser a sig and see if the expected result is correct More...
 
void UTHRegisterTests (void)
 

Detailed Description

Function Documentation

int UTHAddSessionToFlow ( Flow f,
uint32_t  ts_isn,
uint32_t  tc_isn 
)
int UTHAddStreamToFlow ( Flow f,
int  direction,
uint8_t *  data,
uint32_t  data_len 
)

Definition at line 504 of file util-unittest-helper.c.

References TcpSession_::client, FAIL_IF_NOT, FAIL_IF_NULL, TcpStream_::last_ack, Flow_::proto, Flow_::protoctx, TcpStream_::sb, TcpSession_::server, and StreamingBufferAppend().

Referenced by DetectPcrePayloadMatch(), and DetectUricontentRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

int UTHAppendSigs ( DetectEngineCtx ,
const char **  ,
int   
)
void UTHAssignFlow ( Packet p,
Flow f 
)

Definition at line 438 of file util-unittest-helper.c.

References Packet_::flags, Packet_::flow, and PKT_HAS_FLOW.

Referenced by DetectFlowintFree().

Here is the caller graph for this function:

Flow* UTHBuildFlow ( int  family,
const char *  src,
const char *  dst,
Port  sp,
Port  dp 
)
Packet* UTHBuildPacket ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto 
)

UTHBuildPacket is a wrapper that build packets with default ip and port fields.

Parameters
payloadpointer to the payloadd buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
Return values
Packetpointer to the built in packet

Definition at line 262 of file util-unittest-helper.c.

References UTHBuildPacketReal().

Referenced by AlertFastLogInitCtx(), DetectAckRegister(), DetectAsn1Register(), DetectBase64DecodeDoMatch(), DetectBypassRegister(), DetectBytejumpDoMatch(), DetectBytetestDoMatch(), DetectDceIfaceRegister(), DetectDceOpnumRegister(), DetectDceStubDataRegister(), DetectDistanceRegister(), DetectDNP3Register(), DetectEngineInspectENIP(), DetectEngineInspectModbus(), DetectEngineInspectStream(), DetectEngineStateResetTxs(), DetectFastPatternRegister(), DetectFlowFree(), DetectFlowintFree(), DetectHttpRequestLineRegister(), DetectHttpResponseLineRegister(), DetectIcmpIdFree(), DetectIcmpSeqFree(), DetectICodeFree(), DetectIdFree(), DetectIPProtoRemoveAllSMs(), DetectIPRepFree(), DetectIsdataatFree(), DetectITypeFree(), DetectLuaRegister(), DetectPcrePayloadMatch(), DetectProtoContainsProto(), DetectRpcFree(), DetectSeqRegister(), DetectSshSoftwareVersionRegister(), DetectSshVersionRegister(), DetectTemplateRustBufferRegister(), DetectTosRegister(), DetectUricontentRegister(), DetectUrilenValidateContent(), DetectWindowFree(), DetectWithinRegister(), IPOnlyAddSignature(), MpmACRegister(), MpmACTileRegister(), RegisterModbusParsers(), SCACBSPrintInfo(), SCSigSignatureOrderingModuleCleanup(), SCThresholdConfParseFile(), SMTPParserCleanup(), UTHBuildPacketOfFlows(), and UTHParseSignature().

Here is the call graph for this function:

Packet** UTHBuildPacketArrayFromEth ( uint8_t **  ,
int *  ,
int   
)
Packet* UTHBuildPacketFromEth ( uint8_t *  raw_eth,
uint16_t  pktsize 
)

UTHBuildPacketFromEth is a wrapper that build a packet for the rawbytes.

Parameters
raw_ethpointer to the rawbytes containing an ethernet packet (and any other headers inside)
pktsizepointer to the length of the payload
Return values
Packetpointer to the built in packet; NULL if something fail

Definition at line 319 of file util-unittest-helper.c.

References DecodeEthernet(), PacketGetFromAlloc(), and unlikely.

Referenced by DetectPortHashFree(), and DetectSetupParseRegexes().

Here is the call graph for this function:

Here is the caller graph for this function:

Packet* UTHBuildPacketIPV6Real ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto,
const char *  src,
const char *  dst,
uint16_t  sport,
uint16_t  dport 
)

UTHBuildPacketReal is a function that create tcp/udp packets for unittests specifying ip and port sources and destinations (IPV6)

Parameters
payloadpointer to the payloadd buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
srcpointer to a string containing the ip source
dstpointer to a string containing the ip destination
sportpointer to a string containing the port source
dportpointer to a string containing the port destination
Return values
Packetpointer to the built in packet

Definition at line 81 of file util-unittest-helper.c.

References Packet_::dp, Packet_::dst, Address_::family, Packet_::ip6h, PacketGetFromAlloc(), Packet_::payload, payload_len, Packet_::payload_len, Packet_::proto, SCFree, SCMalloc, SET_PKT_LEN, Packet_::sp, Packet_::src, Packet_::tcph, TimeGet(), Packet_::ts, and unlikely.

Referenced by UTHBuildPacketIPV6SrcDst().

Here is the call graph for this function:

Here is the caller graph for this function:

Packet* UTHBuildPacketIPV6SrcDst ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto,
const char *  src,
const char *  dst 
)

UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports (IPV6)

Parameters
payloadpointer to the payload buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
Return values
Packetpointer to the built in packet

Definition at line 361 of file util-unittest-helper.c.

References UTHBuildPacketIPV6Real().

Referenced by IPOnlyAddSignature().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t UTHBuildPacketOfFlows ( uint32_t  ,
uint32_t  ,
uint8_t   
)

Definition at line 902 of file util-unittest-helper.c.

References Packet_::dst, Packet_::flow, FlowHandlePacket(), FLOWLOCK_UNLOCK, SC_ATOMIC_RESET, Packet_::src, UTHBuildPacket(), and UTHFreePacket().

Referenced by FlowUpdateState(), TmModuleFlowRecyclerRegister(), and UTHParseSignature().

Here is the call graph for this function:

Here is the caller graph for this function:

Packet* UTHBuildPacketReal ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto,
const char *  src,
const char *  dst,
uint16_t  sport,
uint16_t  dport 
)

UTHBuildPacketReal is a function that create tcp/udp packets for unittests specifying ip and port sources and destinations.

Parameters
payloadpointer to the payloadd buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
srcpointer to a string containing the ip source
dstpointer to a string containing the ip destination
sportpointer to a string containing the port source
dportpointer to a string containing the port destination
Return values
Packetpointer to the built in packet

Definition at line 167 of file util-unittest-helper.c.

References COPY_TIMESTAMP, GET_PKT_DATA, PacketCopyDataOffset(), PacketGetFromAlloc(), payload_len, SCFree, SET_PKT_LEN, TimeGet(), and unlikely.

Referenced by ActionInitConfig(), DetectDetectionFilterRegister(), DetectDnsQueryRegister(), DetectThresholdRegister(), SCThresholdConfParseFile(), StreamTcpUTAddPayload(), StreamTcpUTAddSegmentWithByte(), StreamTcpUTAddSegmentWithPayload(), TagTimeoutCheck(), UTHBuildPacket(), UTHBuildPacketSrcDst(), UTHBuildPacketSrcDstPorts(), and UTHParseSignature().

Here is the call graph for this function:

Here is the caller graph for this function:

Packet* UTHBuildPacketSrcDst ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto,
const char *  src,
const char *  dst 
)

UTHBuildPacketSrcDst is a wrapper that build packets specifying IPs and defaulting ports.

Parameters
payloadpointer to the payloadd buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
Return values
Packetpointer to the built in packet

Definition at line 343 of file util-unittest-helper.c.

References UTHBuildPacketReal().

Referenced by DetectFtpbounceRegister(), DetectGeoipRegister(), DetectSameipRegister(), IPOnlyAddSignature(), SCThresholdConfParseFile(), SigGroupHeadContainsSigId(), and UTHParseSignature().

Here is the call graph for this function:

Here is the caller graph for this function:

Packet* UTHBuildPacketSrcDstPorts ( uint8_t *  payload,
uint16_t  payload_len,
uint8_t  ipproto,
uint16_t  sport,
uint16_t  dport 
)

UTHBuildPacketSrcDstPorts is a wrapper that build packets specifying src and dst ports and defaulting IPs.

Parameters
payloadpointer to the payloadd buffer
payload_lenpointer to the length of the payload
ipprotoProtocols allowed atm are IPPROTO_TCP and IPPROTO_UDP
Return values
Packetpointer to the built in packet

Definition at line 379 of file util-unittest-helper.c.

References UTHBuildPacketReal().

Referenced by UTHParseSignature().

Here is the call graph for this function:

Here is the caller graph for this function:

int UTHCheckPacketMatch ( Packet ,
uint32_t *  ,
uint32_t *  ,
int   
)
int UTHCheckPacketMatchResults ( Packet ,
uint32_t *  ,
uint32_t *  ,
int   
)
void UTHFreeFlow ( Flow flow)

Definition at line 497 of file util-unittest-helper.c.

References FlowFree().

Referenced by AppLayerParserRestoreParserTable(), DetectEngineStateResetTxs(), DetectFlowintFree(), DetectPcrePayloadMatch(), DetectUricontentRegister(), HtpConfigRestoreBackup(), HTPFileClose(), and RegisterSMBParsers().

Here is the call graph for this function:

Here is the caller graph for this function:

int UTHGenericTest ( Packet **  ,
int  ,
const char **  ,
uint32_t *  ,
uint32_t *  ,
int   
)
int UTHMatchPackets ( DetectEngineCtx de_ctx,
Packet **  p,
int  num_packets 
)
Test:
UTHMatchPackets Match a packet or a array of packets against sigs of a de_ctx, but note that the return value doesn't mean that we have a match, we have to check it later with PacketAlertCheck()
Parameters
de_ctxpointer with the signatures loaded
ppointer to the array of packets
num_packetsnumber of packets in the array
Return values
return1 if all goes well
return0 if something fail

Definition at line 741 of file util-unittest-helper.c.

References DetectEngineThreadCtxDeinit(), DetectEngineThreadCtxInit(), SC_ERR_INVALID_ARGUMENT, SCLogError, SCSigOrderSignatures(), SCSigRegisterSignatureOrderingFuncs(), SCSigSignatureOrderingModuleCleanup(), SigGroupBuild(), SigGroupCleanup(), and SigMatchSignatures().

Referenced by DetectSetupParseRegexes(), and SCSigSignatureOrderingModuleCleanup().

Here is the call graph for this function:

Here is the caller graph for this function:

int UTHMatchPacketsWithResults ( DetectEngineCtx ,
Packet **  ,
int  ,
uint32_t *  ,
uint32_t *  ,
int   
)
int UTHPacketMatchSig ( Packet p,
const char *  sig 
)
Test:
Test if a packet match a signature given as string Hint: Useful for unittests with only one packet and one signature
Parameters
sigpointer to the string signature to test
sidsid number of the signature
Return values
return1 if match
return0 if not

Definition at line 853 of file util-unittest-helper.c.

References DE_QUIET, DetectEngineCtxFree(), DetectEngineCtxInit(), DetectEngineThreadCtxDeinit(), DetectEngineThreadCtxInit(), DetectEngineCtx_::flags, Signature_::id, PacketAlertCheck(), DetectEngineCtx_::sig_list, SigCleanSignatures(), SigGroupBuild(), SigGroupCleanup(), SigInit(), and SigMatchSignatures().

Referenced by DetectBytejumpDoMatch(), DetectBytetestDoMatch(), DetectDistanceRegister(), DetectIsdataatFree(), DetectPcrePayloadMatch(), DetectPortHashFree(), and DetectWithinRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

int UTHPacketMatchSigMpm ( Packet p,
char *  sig,
uint16_t  mpm_type 
)
Test:
Test if a packet match a signature given as string and a mpm_type Hint: Useful for unittests with only one packet and one signature
Parameters
sigpointer to the string signature to test
sidsid number of the signature
Return values
return1 if match
return0 if not

Definition at line 792 of file util-unittest-helper.c.

References DE_QUIET, DetectEngineCtxFree(), DetectEngineCtxInit(), DetectEngineThreadCtxDeinit(), DetectEngineThreadCtxInit(), DetectEngineCtx_::flags, Signature_::id, DetectEngineCtx_::mpm_matcher, PacketAlertCheck(), SCEnter, SCReturnInt, DetectEngineCtx_::sig_list, SigCleanSignatures(), SigGroupBuild(), SigGroupCleanup(), SigInit(), and SigMatchSignatures().

Referenced by DetectEngineInspectStream().

Here is the call graph for this function:

Here is the caller graph for this function:

void UTHRegisterTests ( void  )

Definition at line 1147 of file util-unittest-helper.c.

References UtRegisterTest().

Here is the call graph for this function:

int UTHRemoveSessionFromFlow ( Flow f)

Definition at line 540 of file util-unittest-helper.c.

References FAIL_IF_NOT, FAIL_IF_NULL, Flow_::proto, Flow_::protoctx, SCFree, and StreamTcpSessionCleanup().

Referenced by DetectPcrePayloadMatch(), and DetectUricontentRegister().

Here is the call graph for this function:

Here is the caller graph for this function:

uint32_t UTHSetIPv4Address ( const char *  str)

return the uint32_t for a ipv4 address string

Parameters
strValid ipaddress in string form (e.g. 1.2.3.4)
Return values
uintthe uin32_t representation

Definition at line 57 of file util-unittest-helper.c.

Referenced by DetectIPRepFree(), and ICMPv4GetCounterpart().

Here is the caller graph for this function: