From: Victor Julien Date: Thu, 28 Mar 2024 10:39:32 +0000 (+0100) Subject: decode/icmpv4: add and use PacketIsICMPv4 inline func X-Git-Tag: suricata-8.0.0-beta1~1381 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1002068e39c98618c5624c6c249824408d1b1c37;p=thirdparty%2Fsuricata.git decode/icmpv4: add and use PacketIsICMPv4 inline func For better readability and type checking. Ticket: #5517. --- diff --git a/src/decode.h b/src/decode.h index 6e52ddcd59..8a7870e2e4 100644 --- a/src/decode.h +++ b/src/decode.h @@ -769,6 +769,11 @@ static inline bool PacketIsUDP(const Packet *p) return PKT_IS_UDP(p); } +static inline bool PacketIsICMPv4(const Packet *p) +{ + return PKT_IS_ICMPV4(p); +} + /** \brief Structure to hold thread specific data for all decode modules */ typedef struct DecodeThreadVars_ { diff --git a/src/detect-csum.c b/src/detect-csum.c index a19234c4b6..bd2e612593 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -686,7 +686,7 @@ static int DetectICMPV4CsumMatch(DetectEngineThreadCtx *det_ctx, { const DetectCsumData *cd = (const DetectCsumData *)ctx; - if (!PacketIsIPv4(p) || !PKT_IS_ICMPV4(p) || p->proto != IPPROTO_ICMP || PKT_IS_PSEUDOPKT(p)) + if (!PacketIsIPv4(p) || !PacketIsICMPv4(p) || p->proto != IPPROTO_ICMP || PKT_IS_PSEUDOPKT(p)) return 0; if (p->flags & PKT_IGNORE_CHECKSUM) { diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c index 8c75dae60d..09233d597e 100644 --- a/src/detect-icmp-id.c +++ b/src/detect-icmp-id.c @@ -79,7 +79,7 @@ static inline bool GetIcmpId(Packet *p, uint16_t *id) return false; uint16_t pid; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { switch (ICMPV4_GET_TYPE(p)){ case ICMP_ECHOREPLY: case ICMP_ECHO: diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index ca32d2cec7..d7fef80d9c 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -79,7 +79,7 @@ static inline bool GetIcmpSeq(Packet *p, uint16_t *seq) if (PKT_IS_PSEUDOPKT(p)) return false; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { switch (ICMPV4_GET_TYPE(p)){ case ICMP_ECHOREPLY: case ICMP_ECHO: diff --git a/src/detect-icmpv4hdr.c b/src/detect-icmpv4hdr.c index 72c9156b2e..fe029ec9fa 100644 --- a/src/detect-icmpv4hdr.c +++ b/src/detect-icmpv4hdr.c @@ -95,7 +95,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, { SCEnter(); - if (!PKT_IS_ICMPV4(p)) { + if (!PacketIsICMPv4(p)) { SCReturnPtr(NULL, "InspectionBuffer"); } diff --git a/src/detect-icode.c b/src/detect-icode.c index 1e7d1cc060..6b40c0a156 100644 --- a/src/detect-icode.c +++ b/src/detect-icode.c @@ -91,7 +91,7 @@ static int DetectICodeMatch (DetectEngineThreadCtx *det_ctx, Packet *p, return 0; uint8_t picode; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { picode = ICMPV4_GET_CODE(p); } else if (PKT_IS_ICMPV6(p)) { picode = ICMPV6_GET_CODE(p); @@ -156,7 +156,7 @@ static void PrefilterPacketICodeMatch(DetectEngineThreadCtx *det_ctx, } uint8_t picode; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { picode = ICMPV4_GET_CODE(p); } else if (PKT_IS_ICMPV6(p)) { picode = ICMPV6_GET_CODE(p); diff --git a/src/detect-itype.c b/src/detect-itype.c index 3f8da9568a..f67db70ae2 100644 --- a/src/detect-itype.c +++ b/src/detect-itype.c @@ -88,7 +88,7 @@ static int DetectITypeMatch (DetectEngineThreadCtx *det_ctx, Packet *p, return 0; uint8_t pitype; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { pitype = ICMPV4_GET_TYPE(p); } else if (PKT_IS_ICMPV6(p)) { pitype = ICMPV6_GET_TYPE(p); @@ -172,7 +172,7 @@ static void PrefilterPacketITypeMatch(DetectEngineThreadCtx *det_ctx, } uint8_t pitype; - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { pitype = ICMPV4_GET_TYPE(p); } else if (PKT_IS_ICMPV6(p)) { pitype = ICMPV6_GET_TYPE(p); diff --git a/src/detect.c b/src/detect.c index 2c46114477..f7b2b79e71 100644 --- a/src/detect.c +++ b/src/detect.c @@ -534,7 +534,7 @@ static inline void DetectRunGetRuleGroup( /* HACK: prevent the wrong sgh (or NULL) from being stored in the * flow's sgh pointers */ - if (PKT_IS_ICMPV4(p) && ICMPV4_DEST_UNREACH_IS_VALID(p)) { + if (PacketIsICMPv4(p) && ICMPV4_DEST_UNREACH_IS_VALID(p)) { ; /* no-op */ } else { /* store the found sgh (or NULL) in the flow to save us diff --git a/src/flow-hash.c b/src/flow-hash.c index c9ba024e01..4827706589 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -560,7 +560,7 @@ static inline int FlowCreateCheck(const Packet *p, const bool emerg) } } - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { if (ICMPV4_IS_ERROR_MSG(p)) { return 0; } diff --git a/src/flow-util.c b/src/flow-util.c index bfacc4dcf7..9c524b2e70 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -176,7 +176,7 @@ void FlowInit(Flow *f, const Packet *p) } else if (PacketIsUDP(p)) { SET_UDP_SRC_PORT(p,&f->sp); SET_UDP_DST_PORT(p,&f->dp); - } else if (PKT_IS_ICMPV4(p)) { + } else if (PacketIsICMPv4(p)) { f->icmp_s.type = p->icmp_s.type; f->icmp_s.code = p->icmp_s.code; FlowSetICMPv4CounterPart(f); diff --git a/src/flow.c b/src/flow.c index 8a179d2b1c..f11b024eb1 100644 --- a/src/flow.c +++ b/src/flow.c @@ -328,7 +328,7 @@ int FlowGetPacketDirection(const Flow *f, const Packet *p) */ static inline int FlowUpdateSeenFlag(const Packet *p) { - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { if (ICMPV4_IS_ERROR_MSG(p)) { return 0; } diff --git a/src/output-json-drop.c b/src/output-json-drop.c index 19b9d3a900..337bfb8d9b 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -144,10 +144,10 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p) } break; case IPPROTO_ICMP: - if (PKT_IS_ICMPV4(p)) { + if (PacketIsICMPv4(p)) { jb_set_uint(js, "icmp_id", ICMPV4_GET_ID(p)); jb_set_uint(js, "icmp_seq", ICMPV4_GET_SEQ(p)); - } else if(PKT_IS_ICMPV6(p)) { + } else if (PKT_IS_ICMPV6(p)) { jb_set_uint(js, "icmp_id", ICMPV6_GET_ID(p)); jb_set_uint(js, "icmp_seq", ICMPV6_GET_SEQ(p)); }