Go to the documentation of this file.
46 static void DetectIcmpIdRegisterTests(
void);
50 static bool PrefilterIcmpIdIsPrefilterable(
const Signature *s);
71 static inline bool GetIcmpId(
Packet *
p, uint16_t *
id)
74 if (PacketIsICMPv4(
p)) {
84 SCLogDebug(
"ICMPV4_GET_ID(p) %"PRIu16
" (network byte order), "
94 }
else if (PacketIsICMPv6(
p)) {
98 SCLogDebug(
"ICMPV6_GET_ID(p) %"PRIu16
" (network byte order), "
133 if (!GetIcmpId(
p, &pid))
177 SCDetectU16Free(ptr);
188 if (!GetIcmpId(
p, &pid))
192 du16.mode =
ctx->v1.u8[0];
193 du16.arg1 =
ctx->v1.u16[1];
194 du16.arg2 =
ctx->v1.u16[2];
197 PrefilterAddSids(&det_ctx->
pmq,
ctx->sigs_array,
ctx->sigs_cnt);
207 static bool PrefilterIcmpIdIsPrefilterable(
const Signature *s)
219 static int DetectIcmpIdParseTest01 (
void)
232 static int DetectIcmpIdParseTest02 (
void)
245 static int DetectIcmpIdParseTest03 (
void)
258 static int DetectIcmpIdParseTest04 (
void)
271 static int DetectIcmpIdParseTest05 (
void)
283 static int DetectIcmpIdMatchTest01 (
void)
309 s = s->
next =
SigInit(
de_ctx,
"alert icmp any any -> any any (icmp_id:21782; sid:2;)");
319 printf(
"sid 1 did not alert, but should have: ");
322 printf(
"sid 2 alerted, but should not have: ");
345 static int DetectIcmpIdMatchTest02 (
void)
349 uint8_t raw_icmpv4[] = {
350 0x0b, 0x00, 0x8a, 0xdf, 0x00, 0x00, 0x00, 0x00,
351 0x45, 0x00, 0x00, 0x14, 0x25, 0x0c, 0x00, 0x00,
352 0xff, 0x11, 0x00, 0x00, 0x85, 0x64, 0xea, 0x5b,
353 0x51, 0xa6, 0xbb, 0x35, 0x59, 0x8a, 0x5a, 0xe2,
354 0x00, 0x14, 0x00, 0x00 };
365 memset(&ip4h, 0,
sizeof(
IPV4Hdr));
372 p->
src.addr_data32[0] = 0x01020304;
373 p->
dst.addr_data32[0] = 0x04030201;
375 ip4h.s_ip_src.s_addr =
p->
src.addr_data32[0];
376 ip4h.s_ip_dst.s_addr =
p->
dst.addr_data32[0];
398 printf(
"sid 1 alerted, but should not have: ");
415 static void DetectIcmpIdRegisterTests (
void)
417 UtRegisterTest(
"DetectIcmpIdParseTest01", DetectIcmpIdParseTest01);
418 UtRegisterTest(
"DetectIcmpIdParseTest02", DetectIcmpIdParseTest02);
419 UtRegisterTest(
"DetectIcmpIdParseTest03", DetectIcmpIdParseTest03);
420 UtRegisterTest(
"DetectIcmpIdParseTest04", DetectIcmpIdParseTest04);
421 UtRegisterTest(
"DetectIcmpIdParseTest05", DetectIcmpIdParseTest05);
422 UtRegisterTest(
"DetectIcmpIdMatchTest01", DetectIcmpIdMatchTest01);
423 UtRegisterTest(
"DetectIcmpIdMatchTest02", DetectIcmpIdMatchTest02);
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
#define SIG_MASK_REQUIRE_REAL_PKT
void PrefilterPacketU16Set(PrefilterPacketHeaderValue *v, void *smctx)
#define ICMP_INFO_REQUEST
SigTableElmt * sigmatch_table
void(* Free)(DetectEngineCtx *, void *)
Container for matching data for a signature group.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
void UTHSetIPV4Hdr(Packet *p, IPV4Hdr *ip4h)
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
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 SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
#define ICMP6_ECHO_REQUEST
struct Packet_::@32::@39 icmp_s
int(* SetupPrefilter)(DetectEngineCtx *de_ctx, struct SigGroupHead_ *sgh)
#define ICMP_ADDRESSREPLY
void FlowInitConfig(bool quiet)
initialize the configuration
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define SIGMATCH_INFO_UINT16
#define PASS
Pass the test.
void DetectIcmpIdRegister(void)
Registration function for icode: icmp_id.
SigMatch * SCSigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
Per thread variable structure.
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
void PacketFree(Packet *p)
Return a malloced packet.
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
int PrefilterSetupPacketHeader(DetectEngineCtx *de_ctx, SigGroupHead *sgh, int sm_type, SignatureMask mask, void(*Set)(PrefilterPacketHeaderValue *v, void *), bool(*Compare)(PrefilterPacketHeaderValue v, void *), void(*Match)(DetectEngineThreadCtx *det_ctx, Packet *p, const void *pectx))
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
void StatsThreadInit(StatsThreadContext *stats)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
int DetectU16Match(const uint16_t parg, const DetectUintData_u16 *du16)
bool PrefilterPacketU16Compare(PrefilterPacketHeaderValue v, void *smctx)
void FlowShutdown(void)
shutdown the flow engine
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Packet * PacketGetFromAlloc(void)
Get a malloced packet.
Structure to hold thread specific data for all decode modules.
bool(* SupportsPrefilter)(const Signature *s)
void DetectIcmpIdFree(DetectEngineCtx *, void *)
this function will free memory associated with DetectIcmpIdData
#define ICMP_TIMESTAMPREPLY
#define ICMPV6_GET_TYPE(icmp6h)
DetectEngineCtx * DetectEngineCtxInit(void)
DetectUintData_u16 DetectU16Data
void StatsThreadCleanup(StatsThreadContext *stats)
union PacketL4::L4Vars vars
void(* RegisterTests)(void)
int DecodeICMPV4(ThreadVars *tv, DecodeThreadVars *dtv, Packet *p, const uint8_t *pkt, uint32_t len)
Main ICMPv4 decoding function.
#define SIG_FLAG_REQUIRE_PACKET
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.