From 0225ab3828dce70e22030df6dddece7a5b9bcf66 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 27 Jul 2018 14:16:41 +0200 Subject: [PATCH] common: introduce flags and var swapping macros --- src/suricata-common.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/suricata-common.h b/src/suricata-common.h index 70337fba6f..859f312530 100644 --- a/src/suricata-common.h +++ b/src/suricata-common.h @@ -376,6 +376,25 @@ #define SCNtohl(x) (uint32_t)ntohl((x)) #define SCNtohs(x) (uint16_t)ntohs((x)) +/* swap flags if one of them is set, otherwise do nothing. */ +#define SWAP_FLAGS(flags, a, b) \ + do { \ + if (((flags) & ((a)|(b))) == (a)) { \ + (flags) &= ~(a); \ + (flags) |= (b); \ + } else if (((flags) & ((a)|(b))) == (b)) { \ + (flags) &= ~(b); \ + (flags) |= (a); \ + } \ + } while(0) + +#define SWAP_VARS(type, a, b) \ + do { \ + type t = (a); \ + (a) = (b); \ + (b) = t; \ + } while (0) + typedef enum PacketProfileDetectId_ { PROF_DETECT_SETUP, PROF_DETECT_GETSGH,