change the netmask to uint8_t for the ip handling part of the radix tree and also use 255 instead of -1 to indicate the absence of a netblock

remotes/origin/master-1.0.x
Anoop Saldanha 16 years ago committed by Victor Julien
parent 3f91af89a2
commit 96614c60f2

@ -672,8 +672,8 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
Frag *frag, *prev = NULL; Frag *frag, *prev = NULL;
Packet *rp = NULL; Packet *rp = NULL;
int offset = 0; int offset = 0;
int hlen; int hlen = 0;
int len; int len = 0;
/* Lock the tracker. */ /* Lock the tracker. */
mutex_lock(&tracker->lock); mutex_lock(&tracker->lock);
@ -683,7 +683,6 @@ Defrag4Reassemble(ThreadVars *tv, DefragContext *dc, DefragTracker *tracker,
return NULL; return NULL;
/* Check that we have all the data. */ /* Check that we have all the data. */
len = 0;
TAILQ_FOREACH(frag, &tracker->frags, next) { TAILQ_FOREACH(frag, &tracker->frags, next) {
if (frag == TAILQ_FIRST(&tracker->frags)) { if (frag == TAILQ_FIRST(&tracker->frags)) {
/* First frag should have an offset of 0. */ /* First frag should have an offset of 0. */

@ -30,7 +30,7 @@
*/ */
static SCRadixPrefix *SCRadixCreatePrefix(uint8_t *key_stream, static SCRadixPrefix *SCRadixCreatePrefix(uint8_t *key_stream,
uint16_t key_bitlen, void *user, uint16_t key_bitlen, void *user,
int netmask) uint8_t netmask)
{ {
SCRadixPrefix *prefix = NULL; SCRadixPrefix *prefix = NULL;
@ -183,13 +183,13 @@ void SCRadixReleaseRadixTree(SCRadixTree *tree)
* \param tree Pointer to the Radix tree * \param tree Pointer to the Radix tree
* \param user Pointer to the user data that has to be associated with * \param user Pointer to the user data that has to be associated with
* this key * 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 * not adding an IP netblock
* *
* \retval node Pointer to the newly created node * \retval node Pointer to the newly created node
*/ */
static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen, 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 *node = NULL;
SCRadixNode *new_node = NULL; SCRadixNode *new_node = NULL;
@ -312,7 +312,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
return node; return node;
node->prefix = SCRadixCreatePrefix(prefix->stream, prefix->bitlen, NULL, node->prefix = SCRadixCreatePrefix(prefix->stream, prefix->bitlen, NULL,
-1); 255);
return node; return node;
} }
@ -380,7 +380,7 @@ static SCRadixNode *SCRadixAddKey(uint8_t *key_stream, uint16_t key_bitlen,
node->parent = inter_node; node->parent = inter_node;
} }
if (netmask != -1) { if (netmask != 255) {
node = new_node; node = new_node;
parent = new_node->parent; parent = new_node->parent;
while (parent != NULL && netmask < (parent->bit + 1)) { 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, SCRadixNode *SCRadixAddKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen,
SCRadixTree *tree, void *user) 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; return node;
} }
@ -450,7 +450,7 @@ SCRadixNode *SCRadixAddKeyGeneric(uint8_t *key_stream, uint16_t key_bitlen,
SCRadixNode *SCRadixAddKeyIPV4(uint8_t *key_stream, SCRadixTree *tree, SCRadixNode *SCRadixAddKeyIPV4(uint8_t *key_stream, SCRadixTree *tree,
void *user) void *user)
{ {
SCRadixNode *node = SCRadixAddKey(key_stream, 32, tree, user, -1); SCRadixNode *node = SCRadixAddKey(key_stream, 32, tree, user, 255);
return node; return node;
} }
@ -469,7 +469,7 @@ SCRadixNode *SCRadixAddKeyIPV4(uint8_t *key_stream, SCRadixTree *tree,
SCRadixNode *SCRadixAddKeyIPV6(uint8_t *key_stream, SCRadixTree *tree, SCRadixNode *SCRadixAddKeyIPV6(uint8_t *key_stream, SCRadixTree *tree,
void *user) void *user)
{ {
SCRadixNode *node = SCRadixAddKey(key_stream, 128, tree, user, -1); SCRadixNode *node = SCRadixAddKey(key_stream, 128, tree, user, 255);
return node; return node;
} }
@ -487,7 +487,7 @@ SCRadixNode *SCRadixAddKeyIPV6(uint8_t *key_stream, SCRadixTree *tree,
* \retval node Pointer to the newly created node * \retval node Pointer to the newly created node
*/ */
SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *key_stream, SCRadixTree *tree, 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); 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 * \retval node Pointer to the newly created node
*/ */
SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *key_stream, SCRadixTree *tree, 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); 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) if (node == NULL)
return; return;
if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, -1)) == NULL) if ( (prefix = SCRadixCreatePrefix(key_stream, key_bitlen, NULL, 255)) == NULL)
return; return;
while (node->bit < prefix->bitlen) { while (node->bit < prefix->bitlen) {
@ -651,7 +651,6 @@ void SCRadixRemoveKeyIPV6(uint8_t *key_stream, SCRadixTree *tree)
return SCRadixRemoveKey(key_stream, 128, tree); return SCRadixRemoveKey(key_stream, 128, tree);
} }
/** /**
* \brief Checks if an IP prefix falls under a netblock, in the path to the root * \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() * 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) if (tree->head == NULL)
return 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; return NULL;
while (node->bit < prefix->bitlen) { while (node->bit < prefix->bitlen) {

@ -18,8 +18,8 @@ typedef struct SCRadixPrefix_ {
uint8_t *stream; uint8_t *stream;
/* if this is a prefix that holds a netblock, this field holds the /* if this is a prefix that holds a netblock, this field holds the
* netmask, -1 otherwise */ * netmask, 255 otherwise */
int netmask; uint8_t netmask;
/* any user data that has to be associated with this key */ /* any user data that has to be associated with this key */
void *user; void *user;
@ -34,7 +34,7 @@ typedef struct SCRadixNode_ {
uint16_t bit; uint16_t bit;
/* holds a list of netmaks that come under this node in the tree */ /* 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 */ /* total no of netmasks that are registered under this node */
int netmask_cnt; int netmask_cnt;
@ -67,8 +67,10 @@ void SCRadixReleaseRadixTree(SCRadixTree *);
SCRadixNode *SCRadixAddKeyGeneric(uint8_t *, uint16_t, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyGeneric(uint8_t *, uint16_t, SCRadixTree *, void *);
SCRadixNode *SCRadixAddKeyIPV4(uint8_t *, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV4(uint8_t *, SCRadixTree *, void *);
SCRadixNode *SCRadixAddKeyIPV6(uint8_t *, SCRadixTree *, void *); SCRadixNode *SCRadixAddKeyIPV6(uint8_t *, SCRadixTree *, void *);
SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *, SCRadixTree *, void *, int); SCRadixNode *SCRadixAddKeyIPV4Netblock(uint8_t *, SCRadixTree *, void *,
SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *, SCRadixTree *, void *, int); uint8_t);
SCRadixNode *SCRadixAddKeyIPV6Netblock(uint8_t *, SCRadixTree *, void *,
uint8_t);
void SCRadixRemoveKeyGeneric(uint8_t *, uint16_t, SCRadixTree *); void SCRadixRemoveKeyGeneric(uint8_t *, uint16_t, SCRadixTree *);
void SCRadixRemoveKeyIPV4(uint8_t *, SCRadixTree *); void SCRadixRemoveKeyIPV4(uint8_t *, SCRadixTree *);

Loading…
Cancel
Save