From: Victor Julien Date: Fri, 27 Jul 2018 12:16:41 +0000 (+0200) Subject: common: introduce flags and var swapping macros X-Git-Tag: suricata-5.0.0-beta1~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0225ab3828dce70e22030df6dddece7a5b9bcf66;p=thirdparty%2Fsuricata.git common: introduce flags and var swapping macros --- 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,