From: Victor Julien Date: Thu, 28 Mar 2024 11:23:26 +0000 (+0100) Subject: decode/icmpv6: add and use PacketIsICMPv6 inline func X-Git-Tag: suricata-8.0.0-beta1~1379 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2137bbbf9a4a4f28b3681e3e1afdec077cbcbacd;p=thirdparty%2Fsuricata.git decode/icmpv6: add and use PacketIsICMPv6 inline func For better readability and type checking. Ticket: #5517. --- diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index c7af860a59..d40b1a8e9d 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -606,7 +606,7 @@ static int ICMPV6ParamProbTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); /* ICMPv6 not processed at all? */ FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0 || @@ -659,7 +659,7 @@ static int ICMPV6PktTooBigTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); /* Note: it has an embedded ipv6 packet but no protocol after ipv6 * (IPPROTO_NONE) */ @@ -715,7 +715,7 @@ static int ICMPV6TimeExceedTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */ FAIL_IF(ICMPV6_GET_TYPE(p) != 3 || ICMPV6_GET_CODE(p) != 0 || @@ -771,7 +771,7 @@ static int ICMPV6DestUnreachTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); /* Note: it has an embedded ipv6 packet but no protocol after ipv6 (IPPROTO_NONE) */ FAIL_IF(ICMPV6_GET_TYPE(p) != 1 || ICMPV6_GET_CODE(p) != 0 || @@ -815,7 +815,7 @@ static int ICMPV6EchoReqTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p)); @@ -859,7 +859,7 @@ static int ICMPV6EchoRepTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); SCLogDebug("type: %u code %u ID: %u seq: %u", ICMPV6_GET_TYPE(p), ICMPV6_GET_CODE(p),ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p)); @@ -910,7 +910,7 @@ static int ICMPV6ParamProbTest02(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0); FAIL_IF(!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_UNKNOWN_VER)); @@ -951,7 +951,7 @@ static int ICMPV6PktTooBigTest02(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); FAIL_IF(!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)); PacketRecycle(p); @@ -1507,7 +1507,7 @@ static int ICMPV6CalculateValidChecksumWithFCS(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6 + 14, sizeof(raw_ipv6) - 14); - FAIL_IF(!PKT_IS_ICMPV6(p)); + FAIL_IF(!PacketIsICMPv6(p)); const IPV6Hdr *ip6h = PacketGetIPv6(p); uint16_t icmpv6_len = IPV6_GET_RAW_PLEN(ip6h) - diff --git a/src/decode.h b/src/decode.h index 8a7870e2e4..f547de9575 100644 --- a/src/decode.h +++ b/src/decode.h @@ -774,6 +774,11 @@ static inline bool PacketIsICMPv4(const Packet *p) return PKT_IS_ICMPV4(p); } +static inline bool PacketIsICMPv6(const Packet *p) +{ + return PKT_IS_ICMPV6(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 806d9c3450..9f1817aa68 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -775,7 +775,7 @@ static int DetectICMPV6CsumMatch(DetectEngineThreadCtx *det_ctx, { const DetectCsumData *cd = (const DetectCsumData *)ctx; - if (!PacketIsIPv6(p) || !PKT_IS_ICMPV6(p) || p->proto != IPPROTO_ICMPV6 || + if (!PacketIsIPv6(p) || !PacketIsICMPv6(p) || p->proto != IPPROTO_ICMPV6 || PKT_IS_PSEUDOPKT(p) || (GET_PKT_LEN(p) - ((uint8_t *)p->icmpv6h - GET_PKT_DATA(p))) <= 0) { return 0; diff --git a/src/detect-icmp-id.c b/src/detect-icmp-id.c index 09233d597e..8b3cb0d1a6 100644 --- a/src/detect-icmp-id.c +++ b/src/detect-icmp-id.c @@ -99,7 +99,7 @@ static inline bool GetIcmpId(Packet *p, uint16_t *id) SCLogDebug("Packet has no id field"); return false; } - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { switch (ICMPV6_GET_TYPE(p)) { case ICMP6_ECHO_REQUEST: case ICMP6_ECHO_REPLY: diff --git a/src/detect-icmp-seq.c b/src/detect-icmp-seq.c index d7fef80d9c..a6e5860f6c 100644 --- a/src/detect-icmp-seq.c +++ b/src/detect-icmp-seq.c @@ -99,7 +99,7 @@ static inline bool GetIcmpSeq(Packet *p, uint16_t *seq) SCLogDebug("Packet has no seq field"); return false; } - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { switch (ICMPV6_GET_TYPE(p)) { case ICMP6_ECHO_REQUEST: diff --git a/src/detect-icmpv6-mtu.c b/src/detect-icmpv6-mtu.c index f84e484e90..c90762244b 100644 --- a/src/detect-icmpv6-mtu.c +++ b/src/detect-icmpv6-mtu.c @@ -64,7 +64,7 @@ void DetectICMPv6mtuRegister(void) // returns 0 on no mtu, and 1 if mtu static inline int DetectICMPv6mtuGetValue(Packet *p, uint32_t *picmpv6mtu) { - if (!(PKT_IS_ICMPV6(p)) || PKT_IS_PSEUDOPKT(p)) + if (!(PacketIsICMPv6(p)) || PKT_IS_PSEUDOPKT(p)) return 0; if (ICMPV6_GET_CODE(p) != 0) return 0; diff --git a/src/detect-icmpv6hdr.c b/src/detect-icmpv6hdr.c index 18bd2bee37..97e0ba6692 100644 --- a/src/detect-icmpv6hdr.c +++ b/src/detect-icmpv6hdr.c @@ -105,7 +105,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); if (buffer->inspect == NULL) { uint32_t hlen = ICMPV6_HEADER_LEN; - if (!PKT_IS_ICMPV6(p)) { + if (!PacketIsICMPv6(p)) { // DETECT_PROTO_IPV6 does not prefilter return NULL; } diff --git a/src/detect-icode.c b/src/detect-icode.c index 6b40c0a156..88c9ece000 100644 --- a/src/detect-icode.c +++ b/src/detect-icode.c @@ -93,7 +93,7 @@ static int DetectICodeMatch (DetectEngineThreadCtx *det_ctx, Packet *p, uint8_t picode; if (PacketIsICMPv4(p)) { picode = ICMPV4_GET_CODE(p); - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { picode = ICMPV6_GET_CODE(p); } else { /* Packet not ICMPv4 nor ICMPv6 */ @@ -158,7 +158,7 @@ static void PrefilterPacketICodeMatch(DetectEngineThreadCtx *det_ctx, uint8_t picode; if (PacketIsICMPv4(p)) { picode = ICMPV4_GET_CODE(p); - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { picode = ICMPV6_GET_CODE(p); } else { /* Packet not ICMPv4 nor ICMPv6 */ diff --git a/src/detect-itype.c b/src/detect-itype.c index f67db70ae2..cd314beb05 100644 --- a/src/detect-itype.c +++ b/src/detect-itype.c @@ -90,7 +90,7 @@ static int DetectITypeMatch (DetectEngineThreadCtx *det_ctx, Packet *p, uint8_t pitype; if (PacketIsICMPv4(p)) { pitype = ICMPV4_GET_TYPE(p); - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { pitype = ICMPV6_GET_TYPE(p); } else { /* Packet not ICMPv4 nor ICMPv6 */ @@ -174,7 +174,7 @@ static void PrefilterPacketITypeMatch(DetectEngineThreadCtx *det_ctx, uint8_t pitype; if (PacketIsICMPv4(p)) { pitype = ICMPV4_GET_TYPE(p); - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { pitype = ICMPV6_GET_TYPE(p); } else { /* Packet not ICMPv4 nor ICMPv6 */ diff --git a/src/flow-util.c b/src/flow-util.c index 826d3ef791..3cce866b3e 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -180,7 +180,7 @@ void FlowInit(Flow *f, const Packet *p) f->icmp_s.type = p->icmp_s.type; f->icmp_s.code = p->icmp_s.code; FlowSetICMPv4CounterPart(f); - } else if (PKT_IS_ICMPV6(p)) { + } else if (PacketIsICMPv6(p)) { f->icmp_s.type = p->icmp_s.type; f->icmp_s.code = p->icmp_s.code; FlowSetICMPv6CounterPart(f); diff --git a/src/output-json-drop.c b/src/output-json-drop.c index 337bfb8d9b..a56856d4f0 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -147,7 +147,7 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *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 (PacketIsICMPv6(p)) { jb_set_uint(js, "icmp_id", ICMPV6_GET_ID(p)); jb_set_uint(js, "icmp_seq", ICMPV6_GET_SEQ(p)); } diff --git a/src/source-dpdk.c b/src/source-dpdk.c index a6fa875fb2..50242b79c3 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -366,7 +366,7 @@ static void DPDKReleasePacket(Packet *p) if ((p->dpdk_v.copy_mode == DPDK_COPY_MODE_TAP || (p->dpdk_v.copy_mode == DPDK_COPY_MODE_IPS && !PacketCheckAction(p, ACTION_DROP))) #if defined(RTE_LIBRTE_I40E_PMD) || defined(RTE_LIBRTE_IXGBE_PMD) || defined(RTE_LIBRTE_ICE_PMD) - && !(PKT_IS_ICMPV6(p) && p->icmpv6h->type == 143) + && !(PacketIsICMPv6(p) && p->icmpv6h->type == 143) #endif ) { BUG_ON(PKT_IS_PSEUDOPKT(p));