]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
decode: factorize macro code
authorEric Leblond <eric@regit.org>
Mon, 24 Jun 2013 07:52:31 +0000 (09:52 +0200)
committerVictor Julien <victor@inliniac.net>
Thu, 27 Jun 2013 08:30:51 +0000 (10:30 +0200)
PACKET_* are now wrapper to the newly introduced PACKET_SET_ACTION
macro.

src/decode.h

index b3f493bd8bb2765c8f950e9ccf8c1ab42b043c7e..c747eb2914ee1c19810a80c497db3d9bf47eb96c 100644 (file)
@@ -706,47 +706,26 @@ typedef struct DecodeThreadVars_
 /* macro's for setting the action
  * handle the case of a root packet
  * for tunnels */
-#define PACKET_ALERT(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = ACTION_ALERT) : \
-     ((p)->action = ACTION_ALERT)); \
-} while (0)
 
-#define PACKET_ACCEPT(p) do { \
+#define PACKET_SET_ACTION(p, a) do { \
     ((p)->root ? \
-     ((p)->root->action = ACTION_ACCEPT) : \
-     ((p)->action = ACTION_ACCEPT)); \
+     ((p)->root->action = a) : \
+     ((p)->action = a)); \
 } while (0)
 
-#define PACKET_DROP(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = ACTION_DROP) : \
-     ((p)->action = ACTION_DROP)); \
-} while (0)
+#define PACKET_ALERT(p) PACKET_SET_ACTION(p, ACTION_ALERT)
 
-#define PACKET_REJECT(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = (ACTION_REJECT|ACTION_DROP)) : \
-     ((p)->action = (ACTION_REJECT|ACTION_DROP))); \
-} while (0)
+#define PACKET_ACCEPT(p) PACKET_SET_ACTION(p, ACTION_ACCEPT)
 
-#define PACKET_REJECT_DST(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = (ACTION_REJECT_DST|ACTION_DROP)) : \
-     ((p)->action = (ACTION_REJECT_DST|ACTION_DROP))); \
-} while (0)
+#define PACKET_DROP(p) PACKET_SET_ACTION(p, ACTION_DROP)
 
-#define PACKET_REJECT_BOTH(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = (ACTION_REJECT_BOTH|ACTION_DROP)) : \
-     ((p)->action = (ACTION_REJECT_BOTH|ACTION_DROP))); \
-} while (0)
+#define PACKET_REJECT(p) PACKET_SET_ACTION(p, (ACTION_REJECT|ACTION_DROP))
 
-#define PACKET_PASS(p) do { \
-    ((p)->root ? \
-     ((p)->root->action = ACTION_PASS) : \
-     ((p)->action = ACTION_PASS)); \
-} while (0)
+#define PACKET_REJECT_DST(p) PACKET_SET_ACTION(p, (ACTION_REJECT_DST|ACTION_DROP))
+
+#define PACKET_REJECT_BOTH(p) PACKET_SET_ACTION(p, (ACTION_REJECT_BOTH|ACTION_DROP))
+
+#define PACKET_PASS(p) PACKET_SET_ACTION(p, ACTION_PASS)
 
 #define PACKET_TEST_ACTION(p, a) \
     ((p)->root ? \