Formatting and comment updates in flow files

Some reformatting to meet coding standards.

Added a few comments to make it more clear where p->flow gets set.
pull/628/head
Ken Steele 12 years ago
parent 72a147b6f1
commit c1b9f0e1f4

@ -1,4 +1,4 @@
/* 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
@ -43,7 +43,8 @@
#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) {
@ -55,7 +56,8 @@ static FlowBit *FlowBitGet(Flow *f, uint16_t 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));
@ -79,7 +81,8 @@ static void FlowBitAdd(Flow *f, uint16_t idx) {
}
}
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;
@ -100,7 +103,8 @@ static void FlowBitRemove(Flow *f, uint16_t idx) {
#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);
@ -111,7 +115,8 @@ void FlowBitSet(Flow *f, uint16_t 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);
@ -122,7 +127,8 @@ void FlowBitUnset(Flow *f, uint16_t 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);
@ -135,7 +141,8 @@ void FlowBitToggle(Flow *f, uint16_t idx) {
FLOWLOCK_UNLOCK(f);
}
int FlowBitIsset(Flow *f, uint16_t idx) {
int FlowBitIsset(Flow *f, uint16_t idx)
{
int r = 0;
FLOWLOCK_RDLOCK(f);
@ -148,7 +155,8 @@ int FlowBitIsset(Flow *f, uint16_t idx) {
return r;
}
int FlowBitIsnotset(Flow *f, uint16_t idx) {
int FlowBitIsnotset(Flow *f, uint16_t idx)
{
int r = 0;
FLOWLOCK_RDLOCK(f);
@ -161,7 +169,8 @@ int FlowBitIsnotset(Flow *f, uint16_t idx) {
return r;
}
void FlowBitFree(FlowBit *fb) {
void FlowBitFree(FlowBit *fb)
{
if (fb == NULL)
return;
@ -183,7 +192,8 @@ void FlowBitFree(FlowBit *fb) {
/* TESTS */
#ifdef UNITTESTS
static int FlowBitTest01 (void) {
static int FlowBitTest01 (void)
{
int ret = 0;
Flow f;
@ -199,7 +209,8 @@ static int FlowBitTest01 (void) {
return ret;
}
static int FlowBitTest02 (void) {
static int FlowBitTest02 (void)
{
int ret = 0;
Flow f;
@ -213,7 +224,8 @@ static int FlowBitTest02 (void) {
return ret;
}
static int FlowBitTest03 (void) {
static int FlowBitTest03 (void)
{
int ret = 0;
Flow f;
@ -241,7 +253,8 @@ end:
return ret;
}
static int FlowBitTest04 (void) {
static int FlowBitTest04 (void)
{
int ret = 0;
Flow f;
@ -260,7 +273,8 @@ static int FlowBitTest04 (void) {
return ret;
}
static int FlowBitTest05 (void) {
static int FlowBitTest05 (void)
{
int ret = 0;
Flow f;
@ -279,7 +293,8 @@ static int FlowBitTest05 (void) {
return ret;
}
static int FlowBitTest06 (void) {
static int FlowBitTest06 (void)
{
int ret = 0;
Flow f;
@ -298,7 +313,8 @@ static int FlowBitTest06 (void) {
return ret;
}
static int FlowBitTest07 (void) {
static int FlowBitTest07 (void)
{
int ret = 0;
Flow f;
@ -317,7 +333,8 @@ static int FlowBitTest07 (void) {
return ret;
}
static int FlowBitTest08 (void) {
static int FlowBitTest08 (void)
{
int ret = 0;
Flow f;
@ -346,7 +363,8 @@ end:
return ret;
}
static int FlowBitTest09 (void) {
static int FlowBitTest09 (void)
{
int ret = 0;
Flow f;
@ -375,7 +393,8 @@ end:
return ret;
}
static int FlowBitTest10 (void) {
static int FlowBitTest10 (void)
{
int ret = 0;
Flow f;
@ -404,7 +423,8 @@ end:
return ret;
}
static int FlowBitTest11 (void) {
static int FlowBitTest11 (void)
{
int ret = 0;
Flow f;
@ -435,7 +455,8 @@ end:
#endif /* UNITTESTS */
void FlowBitRegisterTests(void) {
void FlowBitRegisterTests(void)
{
#ifdef UNITTESTS
UtRegisterTest("FlowBitTest01", FlowBitTest01, 1);
UtRegisterTest("FlowBitTest02", FlowBitTest02, 1);

@ -86,7 +86,8 @@ static SCSpinlock flow_hash_count_lock;
#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
@ -96,7 +97,8 @@ void FlowHashDebugInit(void) {
}
}
void FlowHashDebugPrint(uint32_t ts) {
void FlowHashDebugPrint(uint32_t ts)
{
#ifdef FLOW_DEBUG_STATS
if (flow_hash_count_fp == NULL)
return;
@ -121,7 +123,8 @@ void FlowHashDebugPrint(uint32_t ts) {
#endif
}
void FlowHashDebugDeinit(void) {
void FlowHashDebugDeinit(void)
{
#ifdef FLOW_DEBUG_STATS
struct timeval ts;
memset(&ts, 0, sizeof(ts));
@ -204,7 +207,8 @@ typedef struct FlowHashKey6_ {
*
* 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) {
@ -342,7 +346,8 @@ static inline uint32_t FlowGetKey(Packet *p) {
* \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
@ -381,7 +386,8 @@ static inline int FlowCompareICMPv4(Flow *f, Packet *p) {
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 {
@ -399,7 +405,8 @@ static inline int FlowCompare(Flow *f, Packet *p) {
* \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;
@ -417,10 +424,10 @@ static inline int FlowCreateCheck(Packet *p) {
*
* \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;
}
@ -476,9 +483,11 @@ static Flow *FlowGetNew(Packet *p) {
* 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;
@ -506,10 +515,11 @@ Flow *FlowGetFlowFromHash (Packet *p)
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);
@ -543,10 +553,11 @@ Flow *FlowGetFlowFromHash (Packet *p)
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);
@ -572,6 +583,7 @@ Flow *FlowGetFlowFromHash (Packet *p)
fb->head->hprev = f;
fb->head = f;
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* found our flow, lock & return */
@ -583,8 +595,9 @@ Flow *FlowGetFlowFromHash (Packet *p)
}
}
/* lock & return */
/* Point the Packet at the Flow */
FlowReference(&p->flow, f);
/* lock & return */
FLOWLOCK_WRLOCK(f);
FBLOCK_UNLOCK(fb);
FlowHashCountUpdate;
@ -603,7 +616,8 @@ Flow *FlowGetFlowFromHash (Packet *p)
*
* \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;
@ -650,7 +664,7 @@ static Flow *FlowGetUsedFlow(void) {
f->fb = NULL;
FBLOCK_UNLOCK(fb);
FlowClearMemory (f, f->protomap);
FlowClearMemory(f, f->protomap);
FLOWLOCK_UNLOCK(f);

@ -1,4 +1,4 @@
/* 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
@ -88,8 +88,8 @@ void FlowFree(Flow *f)
* \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;

@ -833,8 +833,8 @@ int FlowSetProtoEmergencyTimeout(uint8_t proto, uint32_t emerg_new_timeout,
* \retval On success it returns 1 and on failure 0.
*/
static int FlowTest01 (void) {
static int FlowTest01 (void)
{
uint8_t proto_map;
FlowInitFlowProto();
@ -872,7 +872,7 @@ static int FlowTest01 (void) {
/*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
@ -881,8 +881,8 @@ void test(void *f){}
* \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);
@ -914,8 +914,8 @@ static int FlowTest02 (void) {
* \retval On success it returns 1 and on failure 0.
*/
static int FlowTest07 (void) {
static int FlowTest07 (void)
{
int result = 0;
FlowInitConfig(FLOW_QUIET);
@ -961,8 +961,8 @@ static int FlowTest07 (void) {
* \retval On success it returns 1 and on failure 0.
*/
static int FlowTest08 (void) {
static int FlowTest08 (void)
{
int result = 0;
FlowInitConfig(FLOW_QUIET);
@ -1008,8 +1008,8 @@ static int FlowTest08 (void) {
* \retval On success it returns 1 and on failure 0.
*/
static int FlowTest09 (void) {
static int FlowTest09 (void)
{
int result = 0;
FlowInitConfig(FLOW_QUIET);
@ -1052,7 +1052,8 @@ static int FlowTest09 (void) {
/**
* \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);

Loading…
Cancel
Save