60static void IPRepRegisterTests(
void);
78static inline int8_t GetRep(
const SReputation *r,
const uint8_t cat,
const uint32_t
version)
89static int8_t GetHostRepSrc(
Packet *p, uint8_t cat, uint32_t
version)
98 int8_t val = GetRep(h->iprep, cat,
version);
116static int8_t GetHostRepDst(
Packet *p, uint8_t cat, uint32_t
version)
151 const DetectIPRepData *rd = (
const DetectIPRepData *)
ctx;
162 val = GetHostRepSrc(p, rd->cat,
version);
169 val = GetHostRepDst(p, rd->cat,
version);
178 val = GetHostRepSrc(p, rd->cat,
version);
184 val = GetHostRepDst(p, rd->cat,
version);
196 val = GetHostRepSrc(p, rd->cat,
version);
197 SCLogDebug(
"checking src -- val %d (looking for cat %u, val %u)", val, rd->cat,
212 val = GetHostRepDst(p, rd->cat,
version);
226 val = GetHostRepSrc(p, rd->cat,
version);
231 val = GetHostRepDst(p, rd->cat,
version);
238 val = GetHostRepSrc(p, rd->cat,
version);
244 val = GetHostRepDst(p, rd->cat,
version);
260 DetectIPRepData *cd = SCDetectIPRepParse(rawstr);
262 SCLogError(
"\"%s\" is not a valid setting for iprep", rawstr);
266 SCLogDebug(
"cmd %u, cat %u, op %u, val %u", cd->cmd, cd->cat, cd->du8.mode, cd->du8.arg1);
286 DetectIPRepData *fd = (DetectIPRepData *)ptr;
290 SCDetectIPRepFree(fd);
297static FILE *DetectIPRepGenerateCategoriesDummy(
void)
300 const char *buffer =
"1,BadHosts,Know bad hosts";
302 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
309static FILE *DetectIPRepGenerateCategoriesDummy2(
void)
313 "1,BadHosts,Know bad hosts\n"
314 "2,GoodHosts,Know good hosts\n";
316 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
323static FILE *DetectIPRepGenerateNetworksDummy(
void)
326 const char *buffer =
"10.0.0.0/24,1,20";
328 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
335static FILE *DetectIPRepGenerateNetworksDummy2(
void)
340 "192.168.0.0/16,2,127";
342 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
349static int DetectIPRepTest01(
void)
360 memset(&th_v, 0,
sizeof(th_v));
371 fd = DetectIPRepGenerateCategoriesDummy();
375 fd = DetectIPRepGenerateNetworksDummy();
380 "badhost\"; iprep:any,BadHosts,>,1; sid:1;rev:1;)");
402static int DetectIPRepTest02(
void)
413 memset(&th_v, 0,
sizeof(th_v));
424 fd = DetectIPRepGenerateCategoriesDummy();
428 fd = DetectIPRepGenerateNetworksDummy();
433 "badhost\"; iprep:src,BadHosts,>,1; sid:1; rev:1;)");
454static int DetectIPRepTest03(
void)
465 memset(&th_v, 0,
sizeof(th_v));
476 fd = DetectIPRepGenerateCategoriesDummy();
480 fd = DetectIPRepGenerateNetworksDummy();
485 "badhost\"; iprep:dst,BadHosts,>,1; sid:1; rev:1;)");
506static int DetectIPRepTest04(
void)
517 memset(&th_v, 0,
sizeof(th_v));
529 fd = DetectIPRepGenerateCategoriesDummy();
533 fd = DetectIPRepGenerateNetworksDummy();
538 "badhost\"; iprep:both,BadHosts,>,1; sid:1; rev:1;)");
559static int DetectIPRepTest05(
void)
570 memset(&th_v, 0,
sizeof(th_v));
581 fd = DetectIPRepGenerateCategoriesDummy();
585 fd = DetectIPRepGenerateNetworksDummy();
590 "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
611static int DetectIPRepTest06(
void)
622 memset(&th_v, 0,
sizeof(th_v));
633 fd = DetectIPRepGenerateCategoriesDummy();
637 fd = DetectIPRepGenerateNetworksDummy2();
642 "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
663static int DetectIPRepTest07(
void)
674 memset(&th_v, 0,
sizeof(th_v));
685 fd = DetectIPRepGenerateCategoriesDummy();
689 fd = DetectIPRepGenerateNetworksDummy2();
694 "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
715static int DetectIPRepTest08(
void)
726 memset(&th_v, 0,
sizeof(th_v));
738 fd = DetectIPRepGenerateCategoriesDummy();
742 fd = DetectIPRepGenerateNetworksDummy();
747 "badhost\"; iprep:any,BadHosts,>,1; sid:1; rev:1;)");
768static int DetectIPRepTest09(
void)
779 memset(&th_v, 0,
sizeof(th_v));
791 fd = DetectIPRepGenerateCategoriesDummy2();
795 fd = DetectIPRepGenerateNetworksDummy2();
800 "alert tcp any any -> any any (msg:\"test\"; iprep:src,BadHosts,>,9; sid:1; rev:1;)");
821static FILE *DetectIPRepGenerateNetworksDummy3(
void)
824 const char *buffer =
"192.168.0.0/16,1,127";
826 fd =
SCFmemopen((
void *)buffer, strlen(buffer),
"r");
833static int DetectIPRepTest10(
void)
844 memset(&th_v, 0,
sizeof(th_v));
856 fd = DetectIPRepGenerateCategoriesDummy2();
860 fd = DetectIPRepGenerateNetworksDummy3();
865 "alert tcp any any -> any any (msg:\"test\"; iprep:src,BadHosts,isset; sid:1; rev:1;)");
883static int DetectIPRepTest11(
void)
894 memset(&th_v, 0,
sizeof(th_v));
906 fd = DetectIPRepGenerateCategoriesDummy2();
910 fd = DetectIPRepGenerateNetworksDummy3();
915 "iprep:src,BadHosts,isnotset; sid:1; rev:1;)");
936void IPRepRegisterTests(
void)
948 UtRegisterTest(
"DetectIPRepTest11 -- isnotset", DetectIPRepTest11);
#define PKT_HOST_DST_LOOKED_UP
#define PKT_HOST_SRC_LOOKED_UP
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
DetectEngineCtx * DetectEngineCtxInit(void)
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Data structures and function prototypes for keeping state for the detection engine.
int DetectU8Match(const uint8_t parg, const DetectUintData_u8 *du8)
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
void DetectIPRepFree(DetectEngineCtx *, void *)
void DetectIPRepRegister(void)
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
SigTableElmt * sigmatch_table
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
#define SIGMATCH_IPONLY_COMPAT
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define PASS
Pass the test.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Host * HostLookupHostFromHash(Address *a)
look up a host in the hash
void HostShutdown(void)
shutdown the flow engine
void HostInitConfig(bool quiet)
initialize the configuration
void HostRelease(Host *h)
#define HostReference(dst_h_ptr, h)
int SRepLoadCatFileFromFD(FILE *fp)
int8_t SRepCIDRGetIPRepDst(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
int8_t SRepCIDRGetIPRepSrc(SRepCIDRTree *cidr_ctx, Packet *p, uint8_t cat, uint32_t version)
int SRepInit(DetectEngineCtx *de_ctx)
init reputation
void SRepResetVersion(void)
int SRepLoadFileFromFD(SRepCIDRTree *cidr_ctx, FILE *fp)
main detection engine ctx
SRepCIDRTree * srepCIDR_ctx
uint8_t rep[SREP_MAX_CATS]
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
void(* Free)(DetectEngineCtx *, void *)
void(* RegisterTests)(void)
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
Per thread variable structure.
#define SC_ATOMIC_GET(name)
Get the value from the atomic variable.
#define SCLogError(...)
Macro used to log ERROR messages.
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.
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
uint32_t UTHSetIPv4Address(const char *str)
return the uint32_t for a ipv4 address string
#define DEBUG_VALIDATE_BUG_ON(exp)