From: Victor Julien Date: Fri, 22 Mar 2024 08:36:51 +0000 (+0100) Subject: decode: implement IP_GET_IPPROTO as inline func X-Git-Tag: suricata-8.0.0-beta1~1411 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=61df76a57d33733ed53a1c57cb272eeb5b2df581;p=thirdparty%2Fsuricata.git decode: implement IP_GET_IPPROTO as inline func For better readability and type checking. Ticket: #5517. --- diff --git a/src/decode.h b/src/decode.h index c0b1b67709..cf8981a2db 100644 --- a/src/decode.h +++ b/src/decode.h @@ -254,11 +254,6 @@ typedef uint16_t Port; #define IPH_IS_VALID(p) (PKT_IS_IPV4((p)) || PKT_IS_IPV6((p))) -/* Retrieve proto regardless of IP version */ -#define IP_GET_IPPROTO(p) \ - (p->proto ? p->proto : \ - (PKT_IS_IPV4((p))? IPV4_GET_IPPROTO((p)) : (PKT_IS_IPV6((p))? IPV6_GET_L4PROTO((p)) : 0))) - /* structure to store the sids/gids/etc the detection engine * found in this packet */ typedef struct PacketAlert_ { @@ -680,6 +675,21 @@ typedef struct Packet_ extern uint32_t default_packet_size; #define SIZE_OF_PACKET (default_packet_size + sizeof(Packet)) +/* Retrieve proto regardless of IP version */ +static inline uint8_t IP_GET_IPPROTO(const Packet *p) +{ + if (p->proto != 0) { + return p->proto; + } + if (PKT_IS_IPV4(p)) { + return IPV4_GET_IPPROTO(p); + } else if (PKT_IS_IPV6(p)) { + return IPV6_GET_L4PROTO(p); + } else { + return 0; + } +} + /** \brief Structure to hold thread specific data for all decode modules */ typedef struct DecodeThreadVars_ {