|
|
|
@ -76,7 +76,7 @@ static XBit *HostBitGet(Host *h, uint16_t idx)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* add a flowbit to the flow */
|
|
|
|
|
static void HostBitAdd(Host *h, uint16_t idx)
|
|
|
|
|
static void HostBitAdd(Host *h, uint16_t idx, uint32_t expire)
|
|
|
|
|
{
|
|
|
|
|
XBit *fb = HostBitGet(h, idx);
|
|
|
|
|
if (fb == NULL) {
|
|
|
|
@ -87,10 +87,15 @@ static void HostBitAdd(Host *h, uint16_t idx)
|
|
|
|
|
fb->type = DETECT_XBITS;
|
|
|
|
|
fb->idx = idx;
|
|
|
|
|
fb->next = NULL;
|
|
|
|
|
fb->expire = expire;
|
|
|
|
|
|
|
|
|
|
GenericVar *gv = HostGetStorageById(h, host_bit_id);
|
|
|
|
|
GenericVarAppend(&gv, (GenericVar *)fb);
|
|
|
|
|
HostSetStorageById(h, host_bit_id, gv);
|
|
|
|
|
|
|
|
|
|
// bit already set, lets update it's time
|
|
|
|
|
} else {
|
|
|
|
|
fb->expire = expire;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -107,11 +112,11 @@ static void HostBitRemove(Host *h, uint16_t idx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostBitSet(Host *h, uint16_t idx)
|
|
|
|
|
void HostBitSet(Host *h, uint16_t idx, uint32_t expire)
|
|
|
|
|
{
|
|
|
|
|
XBit *fb = HostBitGet(h, idx);
|
|
|
|
|
if (fb == NULL) {
|
|
|
|
|
HostBitAdd(h, idx);
|
|
|
|
|
HostBitAdd(h, idx, expire);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -123,37 +128,41 @@ void HostBitUnset(Host *h, uint16_t idx)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void HostBitToggle(Host *h, uint16_t idx)
|
|
|
|
|
void HostBitToggle(Host *h, uint16_t idx, uint32_t expire)
|
|
|
|
|
{
|
|
|
|
|
XBit *fb = HostBitGet(h, idx);
|
|
|
|
|
if (fb != NULL) {
|
|
|
|
|
HostBitRemove(h, idx);
|
|
|
|
|
} else {
|
|
|
|
|
HostBitAdd(h, idx);
|
|
|
|
|
HostBitAdd(h, idx, expire);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int HostBitIsset(Host *h, uint16_t idx)
|
|
|
|
|
int HostBitIsset(Host *h, uint16_t idx, uint32_t ts)
|
|
|
|
|
{
|
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h, idx);
|
|
|
|
|
if (fb != NULL) {
|
|
|
|
|
r = 1;
|
|
|
|
|
if (fb->expire < ts) {
|
|
|
|
|
HostBitRemove(h,idx);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return r;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int HostBitIsnotset(Host *h, uint16_t idx)
|
|
|
|
|
int HostBitIsnotset(Host *h, uint16_t idx, uint32_t ts)
|
|
|
|
|
{
|
|
|
|
|
int r = 0;
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h, idx);
|
|
|
|
|
if (fb == NULL) {
|
|
|
|
|
r = 1;
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
if (fb->expire < ts) {
|
|
|
|
|
HostBitRemove(h,idx);
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* TESTS */
|
|
|
|
@ -167,7 +176,7 @@ static int HostBitTest01 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 0, 0);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,0);
|
|
|
|
|
if (fb != NULL)
|
|
|
|
@ -207,7 +216,7 @@ static int HostBitTest03 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 0, 30);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,0);
|
|
|
|
|
if (fb == NULL) {
|
|
|
|
@ -240,10 +249,10 @@ static int HostBitTest04 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 30);
|
|
|
|
|
HostBitAdd(h, 1, 30);
|
|
|
|
|
HostBitAdd(h, 2, 30);
|
|
|
|
|
HostBitAdd(h, 3, 30);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,0);
|
|
|
|
|
if (fb != NULL)
|
|
|
|
@ -264,10 +273,10 @@ static int HostBitTest05 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 30);
|
|
|
|
|
HostBitAdd(h, 1, 30);
|
|
|
|
|
HostBitAdd(h, 2, 30);
|
|
|
|
|
HostBitAdd(h, 3, 30);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,1);
|
|
|
|
|
if (fb != NULL)
|
|
|
|
@ -288,10 +297,10 @@ static int HostBitTest06 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,2);
|
|
|
|
|
if (fb != NULL)
|
|
|
|
@ -312,10 +321,10 @@ static int HostBitTest07 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,3);
|
|
|
|
|
if (fb != NULL)
|
|
|
|
@ -336,10 +345,10 @@ static int HostBitTest08 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,0);
|
|
|
|
|
if (fb == NULL)
|
|
|
|
@ -369,10 +378,10 @@ static int HostBitTest09 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,1);
|
|
|
|
|
if (fb == NULL)
|
|
|
|
@ -402,10 +411,10 @@ static int HostBitTest10 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,2);
|
|
|
|
|
if (fb == NULL)
|
|
|
|
@ -435,10 +444,10 @@ static int HostBitTest11 (void)
|
|
|
|
|
if (h == NULL)
|
|
|
|
|
goto end;
|
|
|
|
|
|
|
|
|
|
HostBitAdd(h, 0);
|
|
|
|
|
HostBitAdd(h, 1);
|
|
|
|
|
HostBitAdd(h, 2);
|
|
|
|
|
HostBitAdd(h, 3);
|
|
|
|
|
HostBitAdd(h, 0, 90);
|
|
|
|
|
HostBitAdd(h, 1, 90);
|
|
|
|
|
HostBitAdd(h, 2, 90);
|
|
|
|
|
HostBitAdd(h, 3, 90);
|
|
|
|
|
|
|
|
|
|
XBit *fb = HostBitGet(h,3);
|
|
|
|
|
if (fb == NULL)
|
|
|
|
|