From: Victor Julien Date: Thu, 28 Mar 2024 10:30:15 +0000 (+0100) Subject: decode/udp: add and use PacketIsUDP inline func X-Git-Tag: suricata-8.0.0-beta1~1382 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c3036bea80209545cf0c95e1c89caa076f19d7a;p=thirdparty%2Fsuricata.git decode/udp: add and use PacketIsUDP inline func Replace PKT_IS_UDP macro with PacketIsUDP inline function. For better readability and type checking. Ticket: #5517. --- diff --git a/src/alert-debuglog.c b/src/alert-debuglog.c index a9973cdb0b..600187f564 100644 --- a/src/alert-debuglog.c +++ b/src/alert-debuglog.c @@ -186,7 +186,7 @@ static TmEcode AlertDebugLogger(ThreadVars *tv, const Packet *p, void *thread_da "DST IP: %s\n" "PROTO: %" PRIu32 "\n", srcip, dstip, p->proto); - if (PacketIsTCP(p) || PKT_IS_UDP(p)) { + if (PacketIsTCP(p) || PacketIsUDP(p)) { MemBufferWriteString(aft->buffer, "SRC PORT: %" PRIu32 "\n" "DST PORT: %" PRIu32 "\n", p->sp, p->dp); diff --git a/src/decode-geneve.c b/src/decode-geneve.c index 2aec534659..21ac947caf 100644 --- a/src/decode-geneve.c +++ b/src/decode-geneve.c @@ -305,11 +305,11 @@ static int DecodeGeneveTest01(void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top == NULL); Packet *tp = PacketDequeueNoLock(&tv.decode_pq); - FAIL_IF_NOT(PKT_IS_UDP(tp)); + FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 546); FlowShutdown(); @@ -347,11 +347,11 @@ static int DecodeGeneveTest02(void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top == NULL); Packet *tp = PacketDequeueNoLock(&tv.decode_pq); - FAIL_IF_NOT(PKT_IS_UDP(tp)); + FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); FlowShutdown(); @@ -394,11 +394,11 @@ static int DecodeGeneveTest03(void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top == NULL); Packet *tp = PacketDequeueNoLock(&tv.decode_pq); - FAIL_IF_NOT(PKT_IS_UDP(tp)); + FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); FlowShutdown(); @@ -438,7 +438,7 @@ static int DecodeGeneveTest04(void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ DecodeGeneveConfigPorts(GENEVE_DEFAULT_PORT_S); /* Reset Geneve port list for future calls */ @@ -478,7 +478,7 @@ static int DecodeGeneveTest05(void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_geneve, sizeof(raw_geneve)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top != NULL); /* Geneve packet should not have been processed */ FlowShutdown(); diff --git a/src/decode-vxlan.c b/src/decode-vxlan.c index 5d06eb73c5..a8473de052 100644 --- a/src/decode-vxlan.c +++ b/src/decode-vxlan.c @@ -218,11 +218,11 @@ static int DecodeVXLANtest01 (void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_vxlan, sizeof(raw_vxlan)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top == NULL); Packet *tp = PacketDequeueNoLock(&tv.decode_pq); - FAIL_IF_NOT(PKT_IS_UDP(tp)); + FAIL_IF_NOT(PacketIsUDP(tp)); FAIL_IF_NOT(tp->sp == 53); FlowShutdown(); @@ -257,7 +257,7 @@ static int DecodeVXLANtest02 (void) FlowInitConfig(FLOW_QUIET); DecodeUDP(&tv, &dtv, p, raw_vxlan, sizeof(raw_vxlan)); - FAIL_IF_NOT(PKT_IS_UDP(p)); + FAIL_IF_NOT(PacketIsUDP(p)); FAIL_IF(tv.decode_pq.top != NULL); DecodeVXLANConfigPorts(VXLAN_DEFAULT_PORT_S); /* reset */ diff --git a/src/decode.h b/src/decode.h index 92f6fdd1ca..6e52ddcd59 100644 --- a/src/decode.h +++ b/src/decode.h @@ -764,6 +764,11 @@ static inline bool PacketIsTCP(const Packet *p) return PKT_IS_TCP(p); } +static inline bool PacketIsUDP(const Packet *p) +{ + return PKT_IS_UDP(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 082dedd820..a19234c4b6 100644 --- a/src/detect-csum.c +++ b/src/detect-csum.c @@ -507,7 +507,7 @@ static int DetectUDPV4CsumMatch(DetectEngineThreadCtx *det_ctx, { const DetectCsumData *cd = (const DetectCsumData *)ctx; - if (!PacketIsIPv4(p) || !PKT_IS_UDP(p) || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p) || + if (!PacketIsIPv4(p) || !PacketIsUDP(p) || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p) || p->udph->uh_sum == 0) return 0; @@ -597,7 +597,7 @@ static int DetectUDPV6CsumMatch(DetectEngineThreadCtx *det_ctx, { const DetectCsumData *cd = (const DetectCsumData *)ctx; - if (!PacketIsIPv6(p) || !PKT_IS_UDP(p) || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p)) + if (!PacketIsIPv6(p) || !PacketIsUDP(p) || p->proto != IPPROTO_UDP || PKT_IS_PSEUDOPKT(p)) return 0; if (p->flags & PKT_IGNORE_CHECKSUM) { diff --git a/src/detect-rpc.c b/src/detect-rpc.c index fcea1644dd..e604e2c99a 100644 --- a/src/detect-rpc.c +++ b/src/detect-rpc.c @@ -103,7 +103,7 @@ static int DetectRpcMatch (DetectEngineThreadCtx *det_ctx, Packet *p, return 0; } rpcmsg += 4; - } else if (PKT_IS_UDP(p)) { + } else if (PacketIsUDP(p)) { /* if Rpc msg too small */ if (p->payload_len < 24) { SCLogDebug("UDP packet to small for the rpc msg (%u)", p->payload_len); diff --git a/src/detect-udphdr.c b/src/detect-udphdr.c index f123db7103..79d43b7632 100644 --- a/src/detect-udphdr.c +++ b/src/detect-udphdr.c @@ -99,7 +99,7 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx, InspectionBuffer *buffer = InspectionBufferGet(det_ctx, list_id); if (buffer->inspect == NULL) { - if (!PKT_IS_UDP(p)) { + if (!PacketIsUDP(p)) { return NULL; } if (((uint8_t *)p->udph + (ptrdiff_t)UDP_HEADER_LEN) > diff --git a/src/flow-hash.c b/src/flow-hash.c index da1cc51cd8..c9ba024e01 100644 --- a/src/flow-hash.c +++ b/src/flow-hash.c @@ -192,7 +192,7 @@ static inline uint32_t FlowGetHash(const Packet *p) uint32_t hash = 0; if (PacketIsIPv4(p)) { - if (PacketIsTCP(p) || PKT_IS_UDP(p)) { + if (PacketIsTCP(p) || PacketIsUDP(p)) { FlowHashKey4 fhk = { .pad[0] = 0 }; int ai = (p->src.addr_data32[0] > p->dst.addr_data32[0]); diff --git a/src/flow-util.c b/src/flow-util.c index c43448eaf6..bfacc4dcf7 100644 --- a/src/flow-util.c +++ b/src/flow-util.c @@ -173,7 +173,7 @@ void FlowInit(Flow *f, const Packet *p) if (PacketIsTCP(p)) { SET_TCP_SRC_PORT(p,&f->sp); SET_TCP_DST_PORT(p,&f->dp); - } else if (PKT_IS_UDP(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)) { diff --git a/src/log-tlsstore.c b/src/log-tlsstore.c index f54723aeac..f0ccfaaaff 100644 --- a/src/log-tlsstore.c +++ b/src/log-tlsstore.c @@ -173,7 +173,7 @@ static void LogTlsLogPem(LogTlsStoreLogThread *aft, const Packet *p, SSLState *s goto end_fwrite_fpmeta; if (fprintf(fpmeta, "PROTO: %" PRIu32 "\n", p->proto) < 0) goto end_fwrite_fpmeta; - if (PacketIsTCP(p) || PKT_IS_UDP(p)) { + if (PacketIsTCP(p) || PacketIsUDP(p)) { if (fprintf(fpmeta, "SRC PORT: %" PRIu16 "\n", sp) < 0) goto end_fwrite_fpmeta; if (fprintf(fpmeta, "DST PORT: %" PRIu16 "\n", dp) < 0) diff --git a/src/output-json-drop.c b/src/output-json-drop.c index b4b77deb4b..19b9d3a900 100644 --- a/src/output-json-drop.c +++ b/src/output-json-drop.c @@ -139,7 +139,7 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p) } break; case IPPROTO_UDP: - if (PKT_IS_UDP(p)) { + if (PacketIsUDP(p)) { jb_set_uint(js, "udplen", UDP_GET_LEN(p)); } break; diff --git a/src/source-af-packet.c b/src/source-af-packet.c index d4454ec3fd..2018fe9eba 100644 --- a/src/source-af-packet.c +++ b/src/source-af-packet.c @@ -2181,7 +2181,7 @@ static int AFPBypassCallback(Packet *p) { SCLogDebug("Calling af_packet callback function"); /* Only bypass TCP and UDP */ - if (!(PacketIsTCP(p) || PKT_IS_UDP(p))) { + if (!(PacketIsTCP(p) || PacketIsUDP(p))) { return 0; } @@ -2335,7 +2335,7 @@ static int AFPXDPBypassCallback(Packet *p) { SCLogDebug("Calling af_packet callback function"); /* Only bypass TCP and UDP */ - if (!(PacketIsTCP(p) || PKT_IS_UDP(p))) { + if (!(PacketIsTCP(p) || PacketIsUDP(p))) { return 0; } diff --git a/src/source-napatech.c b/src/source-napatech.c index b2ddc8b0d3..69eaec2111 100644 --- a/src/source-napatech.c +++ b/src/source-napatech.c @@ -464,7 +464,7 @@ static int ProgramFlow(Packet *p, int inline_mode) /* Only bypass TCP and UDP */ if (PacketIsTCP(p)) { SC_ATOMIC_ADD(flow_callback_tcp_pkts, 1); - } else if PKT_IS_UDP (p) { + } else if PacketIsUDP (p) { SC_ATOMIC_ADD(flow_callback_udp_pkts, 1); } else { SC_ATOMIC_ADD(flow_callback_unhandled_pkts, 1); diff --git a/src/source-pfring.c b/src/source-pfring.c index c1878489e3..bb22981a6e 100644 --- a/src/source-pfring.c +++ b/src/source-pfring.c @@ -305,7 +305,7 @@ static int PfringBypassCallback(Packet *p) hw_filtering_rule r; /* Only bypass TCP and UDP */ - if (!(PacketIsTCP(p) || PKT_IS_UDP(p))) { + if (!(PacketIsTCP(p) || PacketIsUDP(p))) { return 0; } diff --git a/src/util-checksum.c b/src/util-checksum.c index ae3e8dd6d1..4f19c6dae2 100644 --- a/src/util-checksum.c +++ b/src/util-checksum.c @@ -35,7 +35,7 @@ int ReCalculateChecksum(Packet *p) p->tcph->th_sum = 0; p->tcph->th_sum = TCPChecksum( ip4h->s_ip_addrs, (uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)), 0); - } else if (PKT_IS_UDP(p)) { + } else if (PacketIsUDP(p)) { p->udph->uh_sum = 0; p->udph->uh_sum = UDPV4Checksum( ip4h->s_ip_addrs, (uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN), 0); @@ -49,7 +49,7 @@ int ReCalculateChecksum(Packet *p) p->tcph->th_sum = 0; p->tcph->th_sum = TCPV6Checksum( ip6h->s_ip6_addrs, (uint16_t *)p->tcph, (p->payload_len + TCP_GET_HLEN(p)), 0); - } else if (PKT_IS_UDP(p)) { + } else if (PacketIsUDP(p)) { p->udph->uh_sum = 0; p->udph->uh_sum = UDPV6Checksum( ip6h->s_ip6_addrs, (uint16_t *)p->udph, (p->payload_len + UDP_HEADER_LEN), 0);