diff --git a/src/decode.h b/src/decode.h index 876b3cc..07c12e9 100644 --- a/src/decode.h +++ b/src/decode.h @@ -130,31 +130,31 @@ typedef struct Address_ { /* Set the TCP ports into the Ports of the Packet. * Make sure p->tcph is initialized and validated. */ -#define SET_TCP_SRC_PORT(pkt, prt) do { \ - SET_PORT(TCP_GET_SRC_PORT((pkt)), *prt); \ +#define SET_TCP_SRC_PORT(pkt, prt) do { \ + SET_PORT(TCP_GET_SRC_PORT((pkt)), *(prt)); \ } while (0) -#define SET_TCP_DST_PORT(pkt, prt) do { \ - SET_PORT(TCP_GET_DST_PORT((pkt)), *prt); \ +#define SET_TCP_DST_PORT(pkt, prt) do { \ + SET_PORT(TCP_GET_DST_PORT((pkt)), *(prt)); \ } while (0) /* Set the UDP ports into the Ports of the Packet. * Make sure p->udph is initialized and validated. */ -#define SET_UDP_SRC_PORT(pkt, prt) do { \ - SET_PORT(UDP_GET_SRC_PORT((pkt)), *prt); \ +#define SET_UDP_SRC_PORT(pkt, prt) do { \ + SET_PORT(UDP_GET_SRC_PORT((pkt)), *(prt)); \ } while (0) -#define SET_UDP_DST_PORT(pkt, prt) do { \ - SET_PORT(UDP_GET_DST_PORT((pkt)), *prt); \ +#define SET_UDP_DST_PORT(pkt, prt) do { \ + SET_PORT(UDP_GET_DST_PORT((pkt)), *(prt)); \ } while (0) /* Set the SCTP ports into the Ports of the Packet. * Make sure p->sctph is initialized and validated. */ -#define SET_SCTP_SRC_PORT(pkt, prt) do { \ - SET_PORT(SCTP_GET_SRC_PORT((pkt)), *prt); \ +#define SET_SCTP_SRC_PORT(pkt, prt) do { \ + SET_PORT(SCTP_GET_SRC_PORT((pkt)), *(prt)); \ } while (0) -#define SET_SCTP_DST_PORT(pkt, prt) do { \ - SET_PORT(SCTP_GET_DST_PORT((pkt)), *prt); \ +#define SET_SCTP_DST_PORT(pkt, prt) do { \ + SET_PORT(SCTP_GET_DST_PORT((pkt)), *(prt)); \ } while (0) @@ -171,18 +171,18 @@ typedef struct Address_ { #define GET_PKT_LEN(p) ((p)->pktlen) #define GET_PKT_DATA(p) ((((p)->ext_pkt) == NULL ) ? (p)->pkt : (p)->ext_pkt) -#define GET_PKT_DIRECT_DATA(p) (p)->pkt -#define GET_PKT_DIRECT_MAX_SIZE(p) default_packet_size - 1 +#define GET_PKT_DIRECT_DATA(p) ((p)->pkt) +#define GET_PKT_DIRECT_MAX_SIZE(p) (default_packet_size - 1) #define SET_PKT_LEN(p, len) do { \ - (p)->pktlen = len; \ + (p)->pktlen = (len); \ } while (0) /* Port is just a uint16_t */ typedef uint16_t Port; #define SET_PORT(v, p) ((p) = (v)) -#define COPY_PORT(a,b) (b) = (a) +#define COPY_PORT(a,b) ((b) = (a)) #define CMP_ADDR(a1, a2) \ (((a1)->addr_data32[3] == (a2)->addr_data32[3] && \ @@ -190,11 +190,11 @@ typedef uint16_t Port; (a1)->addr_data32[1] == (a2)->addr_data32[1] && \ (a1)->addr_data32[0] == (a2)->addr_data32[0])) #define CMP_PORT(p1, p2) \ - ((p1 == p2)) + ((p1) == (p2)) /*Given a packet pkt offset to the start of the ip header in a packet *We determine the ip version. */ -#define IP_GET_RAW_VER(pkt) (((pkt[0] & 0xf0) >> 4)) +#define IP_GET_RAW_VER(pkt) ((((pkt)[0] & 0xf0) >> 4)) #define PKT_IS_IPV4(p) (((p)->ip4h != NULL)) #define PKT_IS_IPV6(p) (((p)->ip6h != NULL)) @@ -209,7 +209,7 @@ typedef uint16_t Port; /* Retrieve proto regardless of IP version */ #define IP_GET_IPPROTO(p) \ - (PKT_IS_IPV4(p)? IPV4_GET_IPPROTO(p) : (PKT_IS_IPV6(p)? IPV6_GET_NH(p) : 0)) + (PKT_IS_IPV4((p))? IPV4_GET_IPPROTO((p)) : (PKT_IS_IPV6((p))? IPV6_GET_NH((p)) : 0)) /* structure to store the sids/gids/etc the detection engine * found in this packet */ @@ -414,11 +414,11 @@ typedef struct Packet_ #endif } Packet; -#define DEFAULT_PACKET_SIZE 1500 + ETHERNET_HEADER_LEN +#define DEFAULT_PACKET_SIZE (1500 + ETHERNET_HEADER_LEN) /* storage: maximum ip packet size + link header */ -#define MAX_PAYLOAD_SIZE IPV6_HEADER_LEN + 65536 + 28 +#define MAX_PAYLOAD_SIZE (IPV6_HEADER_LEN + 65536 + 28) intmax_t default_packet_size; -#define SIZE_OF_PACKET default_packet_size + sizeof(Packet) +#define SIZE_OF_PACKET (default_packet_size + sizeof(Packet)) typedef struct PacketQueue_ { Packet *top; @@ -496,23 +496,23 @@ typedef struct DecodeThreadVars_ * \brief Initialize a packet structure for use. */ #ifndef __SC_CUDA_SUPPORT__ -#define PACKET_INITIALIZE(p) { \ +#define PACKET_INITIALIZE(p) do { \ memset((p), 0x00, SIZE_OF_PACKET); \ - SC_ATOMIC_INIT(p->tunnel_rtv_cnt); \ - SC_ATOMIC_INIT(p->tunnel_tpr_cnt); \ + SC_ATOMIC_INIT((p)->tunnel_rtv_cnt); \ + SC_ATOMIC_INIT((p)->tunnel_tpr_cnt); \ PACKET_RESET_CHECKSUMS((p)); \ (p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \ -} +} while (0) #else -#define PACKET_INITIALIZE(p) { \ +#define PACKET_INITIALIZE(p) do { \ memset((p), 0x00, SIZE_OF_PACKET); \ - SC_ATOMIC_INIT(p->tunnel_rtv_cnt); \ - SC_ATOMIC_INIT(p->tunnel_tpr_cnt); \ + SC_ATOMIC_INIT((p)->tunnel_rtv_cnt); \ + SC_ATOMIC_INIT((p)->tunnel_tpr_cnt); \ PACKET_RESET_CHECKSUMS((p)); \ SCMutexInit(&(p)->cuda_mutex, NULL); \ SCCondInit(&(p)->cuda_cond, NULL); \ (p)->pkt = ((uint8_t *)(p)) + sizeof(Packet); \ -} +} while (0) #endif diff --git a/src/stream-tcp.c b/src/stream-tcp.c index df6ba31..36f356c 100644 --- a/src/stream-tcp.c +++ b/src/stream-tcp.c @@ -68,8 +68,8 @@ #define STREAMTCP_DEFAULT_SESSIONS 262144 #define STREAMTCP_DEFAULT_PREALLOC 32768 -#define STREAMTCP_DEFAULT_MEMCAP 32 * 1024 * 1024 /* 32mb */ -#define STREAMTCP_DEFAULT_REASSEMBLY_MEMCAP 64 * 1024 * 1024 /* 64mb */ +#define STREAMTCP_DEFAULT_MEMCAP (32 * 1024 * 1024) /* 32mb */ +#define STREAMTCP_DEFAULT_REASSEMBLY_MEMCAP (64 * 1024 * 1024) /* 64mb */ #define STREAMTCP_DEFAULT_TOSERVER_CHUNK_SIZE 2560 #define STREAMTCP_DEFAULT_TOCLIENT_CHUNK_SIZE 2560 diff --git a/src/suricata.h b/src/suricata.h index 8ee6681..dded79d 100644 --- a/src/suricata.h +++ b/src/suricata.h @@ -52,10 +52,14 @@ enum { }; /** You can use this macros to set/check if we have real drop capabilities */ -#define SET_ENGINE_MODE_IPS(engine_mode) (engine_mode = ENGINE_MODE_IPS); -#define SET_ENGINE_MODE_IDS(engine_mode) (engine_mode = ENGINE_MODE_IDS); -#define IS_ENGINE_MODE_IPS(engine_mode) (engine_mode == ENGINE_MODE_IPS) -#define IS_ENGINE_MODE_IDS(engine_mode) (engine_mode == ENGINE_MODE_IDS) +#define SET_ENGINE_MODE_IPS(engine_mode) do { \ + (engine_mode) = ENGINE_MODE_IPS; \ + } while (0) +#define SET_ENGINE_MODE_IDS(engine_mode) do { \ + (engine_mode) = ENGINE_MODE_IDS; \ + } while (0) +#define IS_ENGINE_MODE_IPS(engine_mode) ((engine_mode) == ENGINE_MODE_IPS) +#define IS_ENGINE_MODE_IDS(engine_mode) ((engine_mode) == ENGINE_MODE_IDS) /* queue's between various other threads * XXX move to the TmQueue structure later diff --git a/src/util-mem.h b/src/util-mem.h index ea2ef88..6f24146 100644 --- a/src/util-mem.h +++ b/src/util-mem.h @@ -49,20 +49,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); extern size_t global_mem; \ extern uint8_t print_mem_flag; \ \ - ptrmem = malloc(a); \ - if (ptrmem == NULL && a > 0) { \ + ptrmem = malloc((a)); \ + if (ptrmem == NULL && (a) > 0) { \ SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ + "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ } \ \ - global_mem += a; \ + global_mem += (a); \ if (print_mem_flag == 1) \ SCLogInfo("SCMalloc return at %p of size %"PRIuMAX, \ - ptrmem, (uintmax_t)a); \ + ptrmem, (uintmax_t)(a)); \ \ (void*)ptrmem; \ }) @@ -72,20 +72,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); extern size_t global_mem; \ extern uint8_t print_mem_flag; \ \ - ptrmem = realloc(x, a); \ - if (ptrmem == NULL && a > 0) { \ + ptrmem = realloc((x), (a)); \ + if (ptrmem == NULL && (a) > 0) { \ SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ + "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ } \ \ - global_mem += a; \ + global_mem += (a); \ if (print_mem_flag == 1) \ SCLogInfo("SCRealloc return at %p (old:%p) of size %"PRIuMAX, \ - ptrmem, x, (uintmax_t)a); \ + ptrmem, (x), (uintmax_t)(a)); \ \ (void*)ptrmem; \ }) @@ -95,8 +95,8 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); extern size_t global_mem; \ extern uint8_t print_mem_flag; \ \ - ptrmem = calloc(nm, a); \ - if (ptrmem == NULL && a > 0) { \ + ptrmem = calloc((nm), (a)); \ + if (ptrmem == NULL && (a) > 0) { \ SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \ "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ @@ -105,10 +105,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); } \ } \ \ - global_mem += a*nm; \ + global_mem += (a)*(nm); \ if (print_mem_flag == 1) \ - SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" nm %"PRIuMAX, \ - ptrmem, (uintmax_t)a, (uintmax_t)nm); \ + SCLogInfo("SCCalloc return at %p of size %"PRIuMAX" (nm) %"PRIuMAX, \ + ptrmem, (uintmax_t)(a), (uintmax_t)(nm)); \ \ (void*)ptrmem; \ }) @@ -117,10 +117,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); char *ptrmem = NULL; \ extern size_t global_mem; \ extern uint8_t print_mem_flag; \ + size_t len = strlen((a)); \ \ - ptrmem = strdup(a); \ + ptrmem = strdup((a)); \ if (ptrmem == NULL) { \ - size_t len = strlen(a); \ SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \ "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ @@ -140,20 +140,20 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); #define SCFree(a) ({ \ extern uint8_t print_mem_flag; \ if (print_mem_flag == 1) \ - SCLogInfo("SCFree at %p", a); \ - free(a); \ + SCLogInfo("SCFree at %p", (a)); \ + free((a)); \ }) -#else /* DBG_MEM_ALLOC */ +#else /* !DBG_MEM_ALLOC */ #define SCMalloc(a) ({ \ void *ptrmem = NULL; \ \ - ptrmem = malloc(a); \ + ptrmem = malloc((a)); \ if (ptrmem == NULL) { \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_MEM_ALLOC, "SCMalloc failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ + "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ @@ -164,11 +164,11 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); #define SCRealloc(x, a) ({ \ void *ptrmem = NULL; \ \ - ptrmem = realloc(x, a); \ + ptrmem = realloc((x), (a)); \ if (ptrmem == NULL) { \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_MEM_ALLOC, "SCRealloc failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ + "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ @@ -179,11 +179,11 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); #define SCCalloc(nm, a) ({ \ void *ptrmem = NULL; \ \ - ptrmem = calloc(nm, a); \ + ptrmem = calloc((nm), (a)); \ if (ptrmem == NULL) { \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_MEM_ALLOC, "SCCalloc failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)a); \ + "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)(a)); \ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ @@ -194,10 +194,10 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); #define SCStrdup(a) ({ \ char *ptrmem = NULL; \ \ - ptrmem = strdup(a); \ + ptrmem = strdup((a)); \ if (ptrmem == NULL) { \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ - size_t len = strlen(a); \ + size_t len = strlen((a)); \ SCLogError(SC_ERR_MEM_ALLOC, "SCStrdup failed: %s, while trying " \ "to allocate %"PRIuMAX" bytes", strerror(errno), (uintmax_t)len); \ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ @@ -217,7 +217,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); if (posix_memalign(&ptrmem, (b), (a)) != 0) { \ if (SC_ATOMIC_GET(engine_stage) == SURICATA_INIT) {\ SCLogError(SC_ERR_MEM_ALLOC, "SCMallocAligned(posix_memalign) failed: %s, while trying " \ - "to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)a, (uintmax_t)b); \ + "to allocate %"PRIuMAX" bytes, alignment %"PRIuMAX, strerror(errno), (uintmax_t)(a), (uintmax_t)(b)); \ SCLogError(SC_ERR_FATAL, "Out of memory. The engine cannot be initialized. Exiting..."); \ exit(EXIT_FAILURE); \ } \ @@ -226,7 +226,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); }) #define SCFree(a) ({ \ - free(a); \ + free((a)); \ }) /** \brief Free aligned memory @@ -236,7 +236,7 @@ SC_ATOMIC_EXTERN(unsigned int, engine_stage); * _mm_free. */ #define SCFreeAligned(a) ({ \ - free(a); \ + free((a)); \ })