From: Victor Julien Date: Thu, 28 Mar 2024 10:55:07 +0000 (+0100) Subject: decode/icmpv6: switch ptr checks to PKT_IS_ICMPV6 X-Git-Tag: suricata-8.0.0-beta1~1380 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3a1e60745e9f4988207ecc7d12f4b0d10555e935;p=thirdparty%2Fsuricata.git decode/icmpv6: switch ptr checks to PKT_IS_ICMPV6 For better readability and type checking. Ticket: #5517. --- diff --git a/src/decode-icmpv6.c b/src/decode-icmpv6.c index 8286bda535..c7af860a59 100644 --- a/src/decode-icmpv6.c +++ b/src/decode-icmpv6.c @@ -606,8 +606,7 @@ static int ICMPV6ParamProbTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF(p->icmpv6h == NULL); + FAIL_IF(!PKT_IS_ICMPV6(p)); /* ICMPv6 not processed at all? */ FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0 || @@ -660,8 +659,7 @@ static int ICMPV6PktTooBigTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF(p->icmpv6h == NULL); + FAIL_IF(!PKT_IS_ICMPV6(p)); /* Note: it has an embedded ipv6 packet but no protocol after ipv6 * (IPPROTO_NONE) */ @@ -717,8 +715,7 @@ static int ICMPV6TimeExceedTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(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 || @@ -774,8 +771,7 @@ static int ICMPV6DestUnreachTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(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 || @@ -819,8 +815,7 @@ static int ICMPV6EchoReqTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(p)); SCLogDebug("ID: %u seq: %u", ICMPV6_GET_ID(p), ICMPV6_GET_SEQ(p)); @@ -864,8 +859,7 @@ static int ICMPV6EchoRepTest01(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(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)); @@ -916,8 +910,7 @@ static int ICMPV6ParamProbTest02(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(p)); FAIL_IF(ICMPV6_GET_TYPE(p) != 4 || ICMPV6_GET_CODE(p) != 0); FAIL_IF(!ENGINE_ISSET_EVENT(p, ICMPV6_IPV6_UNKNOWN_VER)); @@ -958,8 +951,7 @@ static int ICMPV6PktTooBigTest02(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6, sizeof(raw_ipv6)); - - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(p)); FAIL_IF(!ENGINE_ISSET_EVENT(p, ICMPV6_UNKNOWN_CODE)); PacketRecycle(p); @@ -1515,7 +1507,7 @@ static int ICMPV6CalculateValidChecksumWithFCS(void) FlowInitConfig(FLOW_QUIET); DecodeIPV6(&tv, &dtv, p, raw_ipv6 + 14, sizeof(raw_ipv6) - 14); - FAIL_IF_NULL(p->icmpv6h); + FAIL_IF(!PKT_IS_ICMPV6(p)); const IPV6Hdr *ip6h = PacketGetIPv6(p); uint16_t icmpv6_len = IPV6_GET_RAW_PLEN(ip6h) - diff --git a/src/detect-csum.c b/src/detect-csum.c index bd2e612593..806d9c3450 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) || p->icmpv6h == NULL || p->proto != IPPROTO_ICMPV6 || + if (!PacketIsIPv6(p) || !PKT_IS_ICMPV6(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-icmpv6hdr.c b/src/detect-icmpv6hdr.c index 0d990e1108..18bd2bee37 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 (p->icmpv6h == NULL) { + if (!PKT_IS_ICMPV6(p)) { // DETECT_PROTO_IPV6 does not prefilter return NULL; } diff --git a/src/flow-util.c b/src/flow-util.c index 9c524b2e70..826d3ef791 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 (p->icmpv6h != NULL) { + } else if (PKT_IS_ICMPV6(p)) { f->icmp_s.type = p->icmp_s.type; f->icmp_s.code = p->icmp_s.code; FlowSetICMPv6CounterPart(f);