diff --git a/src/defrag.c b/src/defrag.c index d01821c90e..33073da2b2 100644 --- a/src/defrag.c +++ b/src/defrag.c @@ -672,8 +672,8 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker, Frag *frag, *prev = NULL; Packet *rp = NULL; int offset = 0; - int hlen; - int len; + int hlen = 0; + int len = 0; /* Lock the tracker. */ mutex_lock(&tracker->lock); @@ -683,7 +683,6 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker, return NULL; /* Check that we have all the data. */ - len = 0; TAILQ_FOREACH(frag, &tracker->frags, next) { if (frag == TAILQ_FIRST(&tracker->frags)) { /* First frag should have an offset of 0. */ diff --git a/src/detect-ttl.c b/src/detect-ttl.c index adda8a9d49..ddcf033714 100644 --- a/src/detect-ttl.c +++ b/src/detect-ttl.c @@ -569,4 +569,4 @@ void DetectTtlRegisterTests(void) { UtRegisterTest("DetectTtlSetpTest01", DetectTtlSetpTest01, 1); UtRegisterTest("DetectTtlTestSig1", DetectTtlTestSig1, 1); #endif /* UNITTESTS */ -} \ No newline at end of file +} diff --git a/src/util-radix-tree.c b/src/util-radix-tree.c index 30d8b74977..ef785f96e5 100644 --- a/src/util-radix-tree.c +++ b/src/util-radix-tree.c @@ -30,7 +30,7 @@ */ static SCRadixPrefix *SCRadixCreatePrefix(uint8_t *key_stream, uint16_t key_bitlen, void *user, - int netmask) + uint8_t netmask) { SCRadixPrefix *prefix = NULL; @@ -183,13 +183,13 @@ void SCRadixReleaseRadixTree(SCRadixTree *tree) * \param tree Pointer to the Radix tree * \param user Pointer to the user data that has to be associated with * this key - * \param netmask The netmask if we are adding an IP netblock; -1 if we are + * \param netmask The netmask if we are adding an IP netblock; 255 if we are * not adding an IP netblock * * \retval node Pointer to the newly created node */ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, - SCRadixTree *tree, void *user, int netmask) + SCRadixTree *tree, void *user, uint8_t netmask) { SCRadixNode *node = NULL; SCRadixNode *new_node = NULL; @@ -312,7 +312,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, return node; node->prefix = SCRadixCreatePrefix(prefix->stream, prefix->bitlen, NULL, - -1); + 255); return node; } @@ -380,7 +380,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, node->parent = inter_node; } - if (netmask != -1) { + if (netmask != 255) { node = new_node; parent = new_node->parent; while (parent != NULL && netmask < (parent->bit + 1)) { @@ -431,7 +431,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, SCRadixNode *SCRadixAddKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen, SCRadixTree *tree, void *user) { - SCRadixNode *node = SCRadixAddKey(key_stream, key_bitlen, tree, user, -1); + SCRadixNode *node = SCRadixAddKey(key_stream, key_bitlen, tree, user, 255); return node; } @@ -450,7 +450,7 @@ SCRadixNode *SCRadixAddKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen, SCRadixNode *SCRadixAddKeyIPV4(uint8_t *key_stream, SCRadixTree *tree, void *user) { - SCRadixNode *node = SCRadixAddKey(key_stream, 32, tree, user, -1); + SCRadixNode *node = SCRadixAddKey(key_stream, 32, tree, user, 255); return node; } @@ -469,7 +469,7 @@ SCRadixNode *SCRadixAddKeyIPV4(uint8_t *key_stream, SCRadixTree *tree, SCRadixNode *SCRadixAddKeyIPV6(uint8_t *key_stream, SCRadixTree *tree, void *user) { - SCRadixNode *node = SCRadixAddKey(key_stream, 128, tree, user, -1); + SCRadixNode *node = SCRadixAddKey(key_stream, 128, tree, user, 255); return node; } @@ -487,7 +487,7 @@ SCRadixNode *SCRadixAddKeyIPV6(uint8_t *key_stream, SCRadixTree *tree, * \retval node Pointer to the newly created node */ SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *key_stream, SCRadixTree *tree, - void *user, int netmask) + void *user, uint8_t netmask) { SCRadixNode *node = SCRadixAddKey(key_stream, 32, tree, user, netmask); @@ -507,7 +507,7 @@ SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *key_stream, SCRadixTree *tree, * \retval node Pointer to the newly created node */ SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *key_stream, SCRadixTree *tree, - void *user, int netmask) + void *user, uint8_t netmask) { SCRadixNode *node = SCRadixAddKey(key_stream, 128, tree, user, netmask); @@ -538,7 +538,7 @@ static void SCRadixRemoveKey(uint8_t *key_stream, uint16_t key_bitlen, if (node == NULL) return; - if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, -1)) == NULL) + if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, 255)) == NULL) return; while (node->bit < prefix->bitlen) { @@ -651,7 +651,6 @@ void SCRadixRemoveKeyIPV6(uint8_t *key_stream, SCRadixTree *tree) return SCRadixRemoveKey(key_stream, 128, tree); } - /** * \brief Checks if an IP prefix falls under a netblock, in the path to the root * of the tree, from the node. Used internally by SCRadixFindKey() @@ -738,7 +737,7 @@ static SCRadixNode *SCRadixFindKey(uint8_t *key_stream, uint16_t key_bitlen, if (tree->head == NULL) return NULL; - if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, -1)) == NULL) + if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, 255)) == NULL) return NULL; while (node->bit < prefix->bitlen) { diff --git a/src/util-radix-tree.h b/src/util-radix-tree.h index 675803a6e7..5207554fe5 100644 --- a/src/util-radix-tree.h +++ b/src/util-radix-tree.h @@ -18,8 +18,8 @@ typedef struct SCRadixPrefix_ { uint8_t *stream; /* if this is a prefix that holds a netblock, this field holds the - * netmask, -1 otherwise */ - int netmask; + * netmask, 255 otherwise */ + uint8_t netmask; /* any user data that has to be associated with this key */ void *user; @@ -34,7 +34,7 @@ typedef struct SCRadixNode_ { uint16_t bit; /* holds a list of netmaks that come under this node in the tree */ - int *netmasks; + uint8_t *netmasks; /* total no of netmasks that are registered under this node */ int netmask_cnt; @@ -67,8 +67,10 @@ void SCRadixReleaseRadixTree(SCRadixTree *); SCRadixNode *SCRadixAddKeyGeneric(uint8_t *, uint16_t, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV4(uint8_t *, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV6(uint8_t *, SCRadixTree *, void *); -SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *, SCRadixTree *, void *, int); -SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *, SCRadixTree *, void *, int); +SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *, SCRadixTree *, void *, + uint8_t); +SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *, SCRadixTree *, void *, + uint8_t); void SCRadixRemoveKeyGeneric(uint8_t *, uint16_t, SCRadixTree *); void SCRadixRemoveKeyIPV4(uint8_t *, SCRadixTree *);