if (pair == NULL)
return 0;
- IPPairBitToggle(pair,fd->idx);
+ IPPairBitToggle(pair,fd->idx,p->ts.tv_sec + fd->expire);
IPPairRelease(pair);
return 1;
}
if (pair == NULL)
return 0;
- IPPairBitSet(pair,fd->idx);
+ IPPairBitSet(pair, fd->idx, p->ts.tv_sec + fd->expire);
IPPairRelease(pair);
return 1;
}
if (pair == NULL)
return 0;
- r = IPPairBitIsset(pair,fd->idx);
+ r = IPPairBitIsset(pair,fd->idx,p->ts.tv_sec);
IPPairRelease(pair);
return r;
}
if (pair == NULL)
return 1;
- r = IPPairBitIsnotset(pair,fd->idx);
+ r = IPPairBitIsnotset(pair,fd->idx,p->ts.tv_sec);
IPPairRelease(pair);
return r;
}
}
/* 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) {
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;
}
}
}
}
-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);
}
}
}
}
-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;
}
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0);
+ IPPairBitAdd(h, 0, 0);
XBit *fb = IPPairBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0);
+ IPPairBitAdd(h, 0, 30);
XBit *fb = IPPairBitGet(h,0);
if (fb == NULL) {
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)
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)
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)
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)
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)
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)
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)
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)
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__ */