ippair: implement xbits expiration

pull/1422/head
Victor Julien 11 years ago
parent fbdcffabc2
commit ca1f3e68d4

@ -104,7 +104,7 @@ static int DetectIPPairbitMatchToggle (Packet *p, const DetectXbitsData *fd)
if (pair == NULL)
return 0;
IPPairBitToggle(pair,fd->idx);
IPPairBitToggle(pair,fd->idx,p->ts.tv_sec + fd->expire);
IPPairRelease(pair);
return 1;
}
@ -127,7 +127,7 @@ static int DetectIPPairbitMatchSet (Packet *p, const DetectXbitsData *fd)
if (pair == NULL)
return 0;
IPPairBitSet(pair,fd->idx);
IPPairBitSet(pair, fd->idx, p->ts.tv_sec + fd->expire);
IPPairRelease(pair);
return 1;
}
@ -139,7 +139,7 @@ static int DetectIPPairbitMatchIsset (Packet *p, const DetectXbitsData *fd)
if (pair == NULL)
return 0;
r = IPPairBitIsset(pair,fd->idx);
r = IPPairBitIsset(pair,fd->idx,p->ts.tv_sec);
IPPairRelease(pair);
return r;
}
@ -151,7 +151,7 @@ static int DetectIPPairbitMatchIsnotset (Packet *p, const DetectXbitsData *fd)
if (pair == NULL)
return 1;
r = IPPairBitIsnotset(pair,fd->idx);
r = IPPairBitIsnotset(pair,fd->idx,p->ts.tv_sec);
IPPairRelease(pair);
return r;
}

@ -76,7 +76,7 @@ static XBit *IPPairBitGet(IPPair *h, uint16_t idx)
}
/* add a flowbit to the flow */
static void IPPairBitAdd(IPPair *h, uint16_t idx)
static void IPPairBitAdd(IPPair *h, uint16_t idx, uint32_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
@ -87,10 +87,15 @@ static void IPPairBitAdd(IPPair *h, uint16_t idx)
fb->type = DETECT_XBITS;
fb->idx = idx;
fb->next = NULL;
fb->expire = expire;
GenericVar *gv = IPPairGetStorageById(h, ippair_bit_id);
GenericVarAppend(&gv, (GenericVar *)fb);
IPPairSetStorageById(h, ippair_bit_id, gv);
// bit already set, lets update it's timer
} else {
fb->expire = expire;
}
}
@ -107,11 +112,11 @@ static void IPPairBitRemove(IPPair *h, uint16_t idx)
}
}
void IPPairBitSet(IPPair *h, uint16_t idx)
void IPPairBitSet(IPPair *h, uint16_t idx, uint32_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
IPPairBitAdd(h, idx);
IPPairBitAdd(h, idx, expire);
}
}
@ -123,37 +128,43 @@ void IPPairBitUnset(IPPair *h, uint16_t idx)
}
}
void IPPairBitToggle(IPPair *h, uint16_t idx)
void IPPairBitToggle(IPPair *h, uint16_t idx, uint32_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb != NULL) {
IPPairBitRemove(h, idx);
} else {
IPPairBitAdd(h, idx);
IPPairBitAdd(h, idx, expire);
}
}
int IPPairBitIsset(IPPair *h, uint16_t idx)
int IPPairBitIsset(IPPair *h, uint16_t idx, uint32_t ts)
{
int r = 0;
XBit *fb = IPPairBitGet(h, idx);
if (fb != NULL) {
r = 1;
if (fb->expire < ts) {
IPPairBitRemove(h, idx);
return 0;
}
return 1;
}
return r;
return 0;
}
int IPPairBitIsnotset(IPPair *h, uint16_t idx)
int IPPairBitIsnotset(IPPair *h, uint16_t idx, uint32_t ts)
{
int r = 0;
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
r = 1;
return 1;
}
if (fb->expire < ts) {
IPPairBitRemove(h, idx);
return 1;
}
return r;
return 0;
}
@ -168,7 +179,7 @@ static int IPPairBitTest01 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 0, 0);
XBit *fb = IPPairBitGet(h,0);
if (fb != NULL)
@ -208,7 +219,7 @@ static int IPPairBitTest03 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 0, 30);
XBit *fb = IPPairBitGet(h,0);
if (fb == NULL) {
@ -241,10 +252,10 @@ static int IPPairBitTest04 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,30);
IPPairBitAdd(h, 1,30);
IPPairBitAdd(h, 2,30);
IPPairBitAdd(h, 3,30);
XBit *fb = IPPairBitGet(h,0);
if (fb != NULL)
@ -265,10 +276,10 @@ static int IPPairBitTest05 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,1);
if (fb != NULL)
@ -289,10 +300,10 @@ static int IPPairBitTest06 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,2);
if (fb != NULL)
@ -313,10 +324,10 @@ static int IPPairBitTest07 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,3);
if (fb != NULL)
@ -337,10 +348,10 @@ static int IPPairBitTest08 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,0);
if (fb == NULL)
@ -370,10 +381,10 @@ static int IPPairBitTest09 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,1);
if (fb == NULL)
@ -403,10 +414,10 @@ static int IPPairBitTest10 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,2);
if (fb == NULL)
@ -436,10 +447,10 @@ static int IPPairBitTest11 (void)
if (h == NULL)
goto end;
IPPairBitAdd(h, 0);
IPPairBitAdd(h, 1);
IPPairBitAdd(h, 2);
IPPairBitAdd(h, 3);
IPPairBitAdd(h, 0,90);
IPPairBitAdd(h, 1,90);
IPPairBitAdd(h, 2,90);
IPPairBitAdd(h, 3,90);
XBit *fb = IPPairBitGet(h,3);
if (fb == NULL)

@ -32,10 +32,10 @@ void IPPairBitRegisterTests(void);
int IPPairHasIPPairBits(IPPair *host);
void IPPairBitSet(IPPair *, uint16_t);
void IPPairBitSet(IPPair *, uint16_t, uint32_t);
void IPPairBitUnset(IPPair *, uint16_t);
void IPPairBitToggle(IPPair *, uint16_t);
int IPPairBitIsset(IPPair *, uint16_t);
int IPPairBitIsnotset(IPPair *, uint16_t);
void IPPairBitToggle(IPPair *, uint16_t, uint32_t);
int IPPairBitIsset(IPPair *, uint16_t, uint32_t);
int IPPairBitIsnotset(IPPair *, uint16_t, uint32_t);
#endif /* __IPPAIR_BIT_H__ */

Loading…
Cancel
Save