Some reformatting to meet coding standards.
Added a few comments to make it more clear where p->flow gets set.
-/* Copyright (C) 2007-2010 Open Information Security Foundation
+/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
#include "util-unittest.h"
/* get the flowbit with idx from the flow */
-static FlowBit *FlowBitGet(Flow *f, uint16_t idx) {
+static FlowBit *FlowBitGet(Flow *f, uint16_t idx)
+{
GenericVar *gv = f->flowvar;
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_FLOWBITS && gv->idx == idx) {
}
/* add a flowbit to the flow */
-static void FlowBitAdd(Flow *f, uint16_t idx) {
+static void FlowBitAdd(Flow *f, uint16_t idx)
+{
FlowBit *fb = FlowBitGet(f, idx);
if (fb == NULL) {
fb = SCMalloc(sizeof(FlowBit));
}
}
-static void FlowBitRemove(Flow *f, uint16_t idx) {
+static void FlowBitRemove(Flow *f, uint16_t idx)
+{
FlowBit *fb = FlowBitGet(f, idx);
if (fb == NULL)
return;
#endif /* FLOWBITS_STATS */
}
-void FlowBitSet(Flow *f, uint16_t idx) {
+void FlowBitSet(Flow *f, uint16_t idx)
+{
FLOWLOCK_WRLOCK(f);
FlowBit *fb = FlowBitGet(f, idx);
FLOWLOCK_UNLOCK(f);
}
-void FlowBitUnset(Flow *f, uint16_t idx) {
+void FlowBitUnset(Flow *f, uint16_t idx)
+{
FLOWLOCK_WRLOCK(f);
FlowBit *fb = FlowBitGet(f, idx);
FLOWLOCK_UNLOCK(f);
}
-void FlowBitToggle(Flow *f, uint16_t idx) {
+void FlowBitToggle(Flow *f, uint16_t idx)
+{
FLOWLOCK_WRLOCK(f);
FlowBit *fb = FlowBitGet(f, idx);
FLOWLOCK_UNLOCK(f);
}
-int FlowBitIsset(Flow *f, uint16_t idx) {
+int FlowBitIsset(Flow *f, uint16_t idx)
+{
int r = 0;
FLOWLOCK_RDLOCK(f);
return r;
}
-int FlowBitIsnotset(Flow *f, uint16_t idx) {
+int FlowBitIsnotset(Flow *f, uint16_t idx)
+{
int r = 0;
FLOWLOCK_RDLOCK(f);
return r;
}
-void FlowBitFree(FlowBit *fb) {
+void FlowBitFree(FlowBit *fb)
+{
if (fb == NULL)
return;
/* TESTS */
#ifdef UNITTESTS
-static int FlowBitTest01 (void) {
+static int FlowBitTest01 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest02 (void) {
+static int FlowBitTest02 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest03 (void) {
+static int FlowBitTest03 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest04 (void) {
+static int FlowBitTest04 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest05 (void) {
+static int FlowBitTest05 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest06 (void) {
+static int FlowBitTest06 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest07 (void) {
+static int FlowBitTest07 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest08 (void) {
+static int FlowBitTest08 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest09 (void) {
+static int FlowBitTest09 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest10 (void) {
+static int FlowBitTest10 (void)
+{
int ret = 0;
Flow f;
return ret;
}
-static int FlowBitTest11 (void) {
+static int FlowBitTest11 (void)
+{
int ret = 0;
Flow f;
#endif /* UNITTESTS */
-void FlowBitRegisterTests(void) {
+void FlowBitRegisterTests(void)
+{
#ifdef UNITTESTS
UtRegisterTest("FlowBitTest01", FlowBitTest01, 1);
UtRegisterTest("FlowBitTest02", FlowBitTest02, 1);
#define FlowHashCountInit uint64_t _flow_hash_counter = 0
#define FlowHashCountIncr _flow_hash_counter++;
-void FlowHashDebugInit(void) {
+void FlowHashDebugInit(void)
+{
#ifdef FLOW_DEBUG_STATS
SCSpinInit(&flow_hash_count_lock, 0);
#endif
}
}
-void FlowHashDebugPrint(uint32_t ts) {
+void FlowHashDebugPrint(uint32_t ts)
+{
#ifdef FLOW_DEBUG_STATS
if (flow_hash_count_fp == NULL)
return;
#endif
}
-void FlowHashDebugDeinit(void) {
+void FlowHashDebugDeinit(void)
+{
#ifdef FLOW_DEBUG_STATS
struct timeval ts;
memset(&ts, 0, sizeof(ts));
*
* For ICMP we only consider UNREACHABLE errors atm.
*/
-static inline uint32_t FlowGetKey(Packet *p) {
+static inline uint32_t FlowGetKey(Packet *p)
+{
uint32_t key;
if (p->ip4h != NULL) {
* \retval 1 match
* \retval 0 no match
*/
-static inline int FlowCompareICMPv4(Flow *f, Packet *p) {
+static inline int FlowCompareICMPv4(Flow *f, Packet *p)
+{
if (ICMPV4_DEST_UNREACH_IS_VALID(p)) {
/* first check the direction of the flow, in other words, the client ->
* server direction as it's most likely the ICMP error will be a
return 0;
}
-static inline int FlowCompare(Flow *f, Packet *p) {
+static inline int FlowCompare(Flow *f, Packet *p)
+{
if (p->proto == IPPROTO_ICMP) {
return FlowCompareICMPv4(f, p);
} else {
* \retval 1 true
* \retval 0 false
*/
-static inline int FlowCreateCheck(Packet *p) {
+static inline int FlowCreateCheck(Packet *p)
+{
if (PKT_IS_ICMPV4(p)) {
if (ICMPV4_IS_ERROR_MSG(p)) {
return 0;
*
* \retval f *LOCKED* flow on succes, NULL on error.
*/
-static Flow *FlowGetNew(Packet *p) {
+static Flow *FlowGetNew(Packet *p)
+{
Flow *f = NULL;
-
if (FlowCreateCheck(p) == 0) {
return NULL;
}
* the queue. FlowDequeue() will alloc new flows as long as we stay within our
* memcap limit.
*
+ * The p->flow pointer is updated to point to the flow.
+ *
* returns a *LOCKED* flow or NULL
*/
-Flow *FlowGetFlowFromHash (Packet *p)
+Flow *FlowGetFlowFromHash(Packet *p)
{
Flow *f = NULL;
FlowHashCountInit;
fb->head = f;
fb->tail = f;
+ /* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* got one, now lock, initialize and return */
- FlowInit(f,p);
+ FlowInit(f, p);
f->fb = fb;
FBLOCK_UNLOCK(fb);
f->hprev = pf;
+ /* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* initialize and return */
- FlowInit(f,p);
+ FlowInit(f, p);
f->fb = fb;
FBLOCK_UNLOCK(fb);
fb->head->hprev = f;
fb->head = f;
+ /* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* found our flow, lock & return */
}
}
- /* lock & return */
+ /* Point the Packet at the Flow */
FlowReference(&p->flow, f);
+ /* lock & return */
FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
*
* \retval f flow or NULL
*/
-static Flow *FlowGetUsedFlow(void) {
+static Flow *FlowGetUsedFlow(void)
+{
uint32_t idx = SC_ATOMIC_GET(flow_prune_idx) % flow_config.hash_size;
uint32_t cnt = flow_config.hash_size;
f->fb = NULL;
FBLOCK_UNLOCK(fb);
- FlowClearMemory (f, f->protomap);
+ FlowClearMemory(f, f->protomap);
FLOWLOCK_UNLOCK(f);
-/* Copyright (C) 2007-2012 Open Information Security Foundation
+/* Copyright (C) 2007-2013 Open Information Security Foundation
*
* You can copy, redistribute or modify this Program under the terms of
* the GNU General Public License version 2 as published by the Free
* \param proto protocol which is needed to be mapped
*/
-uint8_t FlowGetProtoMapping(uint8_t proto) {
-
+uint8_t FlowGetProtoMapping(uint8_t proto)
+{
switch (proto) {
case IPPROTO_TCP:
return FLOW_PROTO_TCP;
* \retval On success it returns 1 and on failure 0.
*/
-static int FlowTest01 (void) {
-
+static int FlowTest01 (void)
+{
uint8_t proto_map;
FlowInitFlowProto();
/*Test function for the unit test FlowTest02*/
-void test(void *f){}
+void test(void *f) {}
/**
* \test Test the setting of the per protocol free function to free the
* \retval On success it returns 1 and on failure 0.
*/
-static int FlowTest02 (void) {
-
+static int FlowTest02 (void)
+{
FlowSetProtoFreeFunc(IPPROTO_DCCP, test);
FlowSetProtoFreeFunc(IPPROTO_TCP, test);
FlowSetProtoFreeFunc(IPPROTO_UDP, test);
* \retval On success it returns 1 and on failure 0.
*/
-static int FlowTest07 (void) {
-
+static int FlowTest07 (void)
+{
int result = 0;
FlowInitConfig(FLOW_QUIET);
* \retval On success it returns 1 and on failure 0.
*/
-static int FlowTest08 (void) {
-
+static int FlowTest08 (void)
+{
int result = 0;
FlowInitConfig(FLOW_QUIET);
* \retval On success it returns 1 and on failure 0.
*/
-static int FlowTest09 (void) {
-
+static int FlowTest09 (void)
+{
int result = 0;
FlowInitConfig(FLOW_QUIET);
/**
* \brief Function to register the Flow Unitests.
*/
-void FlowRegisterTests (void) {
+void FlowRegisterTests (void)
+{
#ifdef UNITTESTS
UtRegisterTest("FlowTest01 -- Protocol Specific Timeouts", FlowTest01, 1);
UtRegisterTest("FlowTest02 -- Setting Protocol Specific Free Function", FlowTest02, 1);