else
HostLock(p->host_src);
- HostBitToggle(p->host_src,fd->idx);
+ HostBitToggle(p->host_src,fd->idx,p->ts.tv_sec + fd->expire);
HostUnlock(p->host_src);
break;
case DETECT_XBITS_TRACK_IPDST:
else
HostLock(p->host_dst);
- HostBitToggle(p->host_dst,fd->idx);
+ HostBitToggle(p->host_dst,fd->idx,p->ts.tv_sec + fd->expire);
HostUnlock(p->host_dst);
break;
}
} else
HostLock(p->host_src);
- HostBitSet(p->host_src,fd->idx);
+ HostBitSet(p->host_src,fd->idx,p->ts.tv_sec + fd->expire);
HostUnlock(p->host_src);
break;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- HostBitSet(p->host_dst,fd->idx);
+ HostBitSet(p->host_dst,fd->idx, p->ts.tv_sec + fd->expire);
HostUnlock(p->host_dst);
break;
}
} else
HostLock(p->host_src);
- r = HostBitIsset(p->host_src,fd->idx);
+ r = HostBitIsset(p->host_src,fd->idx, p->ts.tv_sec);
HostUnlock(p->host_src);
return r;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- r = HostBitIsset(p->host_dst,fd->idx);
+ r = HostBitIsset(p->host_dst,fd->idx, p->ts.tv_sec);
HostUnlock(p->host_dst);
return r;
}
} else
HostLock(p->host_src);
- r = HostBitIsnotset(p->host_src,fd->idx);
+ r = HostBitIsnotset(p->host_src,fd->idx, p->ts.tv_sec);
HostUnlock(p->host_src);
return r;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- r = HostBitIsnotset(p->host_dst,fd->idx);
+ r = HostBitIsnotset(p->host_dst,fd->idx, p->ts.tv_sec);
HostUnlock(p->host_dst);
return r;
}
}
/* 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) {
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;
}
}
}
}
-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);
}
}
}
}
-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 */
if (h == NULL)
goto end;
- HostBitAdd(h, 0);
+ HostBitAdd(h, 0, 0);
XBit *fb = HostBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0);
+ HostBitAdd(h, 0, 30);
XBit *fb = HostBitGet(h,0);
if (fb == NULL) {
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)
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)
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)
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)
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)
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)
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)
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)
int HostHasHostBits(Host *host);
-void HostBitSet(Host *, uint16_t);
+void HostBitSet(Host *, uint16_t, uint32_t);
void HostBitUnset(Host *, uint16_t);
-void HostBitToggle(Host *, uint16_t);
-int HostBitIsset(Host *, uint16_t);
-int HostBitIsnotset(Host *, uint16_t);
-#endif /* __FLOW_BIT_H__ */
+void HostBitToggle(Host *, uint16_t, uint32_t);
+int HostBitIsset(Host *, uint16_t, uint32_t);
+int HostBitIsnotset(Host *, uint16_t, uint32_t);
+#endif /* __HOST_BIT_H__ */