]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode: implement IP_GET_IPPROTO as inline func
authorVictor Julien <vjulien@oisf.net>
Fri, 22 Mar 2024 08:36:51 +0000 (09:36 +0100)
committerVictor Julien <victor@inliniac.net>
Fri, 26 Apr 2024 18:59:44 +0000 (20:59 +0200)
For better readability and type checking.

Ticket: #5517.

src/decode.h

index c0b1b677098d2e43fac0ac702b562f201e75a96f..cf8981a2db29153eee675bbb59cba704990476ca 100644 (file)
@@ -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_
 {