else
HostLock(p->host_src);
- HostBitToggle(p->host_src, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ HostBitToggle(p->host_src, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
HostUnlock(p->host_src);
break;
case DETECT_XBITS_TRACK_IPDST:
else
HostLock(p->host_dst);
- HostBitToggle(p->host_dst, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ HostBitToggle(p->host_dst, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
HostUnlock(p->host_dst);
break;
}
} else
HostLock(p->host_src);
- HostBitSet(p->host_src, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ HostBitSet(p->host_src, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
HostUnlock(p->host_src);
break;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- HostBitSet(p->host_dst, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ HostBitSet(p->host_dst, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
HostUnlock(p->host_dst);
break;
}
} else
HostLock(p->host_src);
- r = HostBitIsset(p->host_src, fd->idx, SCTIME_SECS(p->ts));
+ r = HostBitIsset(p->host_src, fd->idx, p->ts);
HostUnlock(p->host_src);
return r;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- r = HostBitIsset(p->host_dst, fd->idx, SCTIME_SECS(p->ts));
+ r = HostBitIsset(p->host_dst, fd->idx, p->ts);
HostUnlock(p->host_dst);
return r;
}
} else
HostLock(p->host_src);
- r = HostBitIsnotset(p->host_src, fd->idx, SCTIME_SECS(p->ts));
+ r = HostBitIsnotset(p->host_src, fd->idx, p->ts);
HostUnlock(p->host_src);
return r;
case DETECT_XBITS_TRACK_IPDST:
} else
HostLock(p->host_dst);
- r = HostBitIsnotset(p->host_dst, fd->idx, SCTIME_SECS(p->ts));
+ r = HostBitIsnotset(p->host_dst, fd->idx, p->ts);
HostUnlock(p->host_dst);
return r;
}
if (pair == NULL)
return 0;
- IPPairBitToggle(pair, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ IPPairBitToggle(pair, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
IPPairRelease(pair);
return 1;
}
if (pair == NULL)
return 0;
- IPPairBitSet(pair, fd->idx, SCTIME_SECS(p->ts) + fd->expire);
+ IPPairBitSet(pair, fd->idx, SCTIME_ADD_SECS(p->ts, fd->expire));
IPPairRelease(pair);
return 1;
}
if (pair == NULL)
return 0;
- r = IPPairBitIsset(pair, fd->idx, SCTIME_SECS(p->ts));
+ r = IPPairBitIsset(pair, fd->idx, p->ts);
IPPairRelease(pair);
return r;
}
if (pair == NULL)
return 1;
- r = IPPairBitIsnotset(pair, fd->idx, SCTIME_SECS(p->ts));
+ r = IPPairBitIsnotset(pair, fd->idx, p->ts);
IPPairRelease(pair);
return r;
}
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS) {
XBit *xb = (XBit *)gv;
- if (xb->expire > (uint32_t)SCTIME_SECS(ts))
+ if (SCTIME_CMP_GT(xb->expire, ts))
return 0;
}
}
}
/* add a flowbit to the flow */
-static void HostBitAdd(Host *h, uint32_t idx, uint32_t expire)
+static void HostBitAdd(Host *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = HostBitGet(h, idx);
if (fb == NULL) {
}
}
-void HostBitSet(Host *h, uint32_t idx, uint32_t expire)
+void HostBitSet(Host *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = HostBitGet(h, idx);
if (fb == NULL) {
}
}
-void HostBitToggle(Host *h, uint32_t idx, uint32_t expire)
+void HostBitToggle(Host *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = HostBitGet(h, idx);
if (fb != NULL) {
}
}
-int HostBitIsset(Host *h, uint32_t idx, uint32_t ts)
+int HostBitIsset(Host *h, uint32_t idx, SCTime_t ts)
{
XBit *fb = HostBitGet(h, idx);
if (fb != NULL) {
- if (fb->expire < ts) {
+ if (SCTIME_CMP_LT(fb->expire, ts)) {
HostBitRemove(h,idx);
return 0;
}
return 0;
}
-int HostBitIsnotset(Host *h, uint32_t idx, uint32_t ts)
+int HostBitIsnotset(Host *h, uint32_t idx, SCTime_t ts)
{
XBit *fb = HostBitGet(h, idx);
if (fb == NULL) {
return 1;
}
- if (fb->expire < ts) {
+ if (SCTIME_CMP_LT(fb->expire, ts)) {
HostBitRemove(h,idx);
return 1;
}
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 0);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(0));
XBit *fb = HostBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 30);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(30));
XBit *fb = HostBitGet(h,0);
if (fb == NULL) {
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 30);
- HostBitAdd(h, 1, 30);
- HostBitAdd(h, 2, 30);
- HostBitAdd(h, 3, 30);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(30));
XBit *fb = HostBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 30);
- HostBitAdd(h, 1, 30);
- HostBitAdd(h, 2, 30);
- HostBitAdd(h, 3, 30);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(30));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(30));
XBit *fb = HostBitGet(h,1);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,2);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,3);
if (fb != NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,0);
if (fb == NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,1);
if (fb == NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,2);
if (fb == NULL)
if (h == NULL)
goto end;
- HostBitAdd(h, 0, 90);
- HostBitAdd(h, 1, 90);
- HostBitAdd(h, 2, 90);
- HostBitAdd(h, 3, 90);
+ HostBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ HostBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = HostBitGet(h,3);
if (fb == NULL)
int HostHasHostBits(Host *host);
int HostBitsTimedoutCheck(Host *h, SCTime_t ts);
-void HostBitSet(Host *, uint32_t, uint32_t);
+void HostBitSet(Host *, uint32_t, SCTime_t);
void HostBitUnset(Host *, uint32_t);
-void HostBitToggle(Host *, uint32_t, uint32_t);
-int HostBitIsset(Host *, uint32_t, uint32_t);
-int HostBitIsnotset(Host *, uint32_t, uint32_t);
+void HostBitToggle(Host *, uint32_t, SCTime_t);
+int HostBitIsset(Host *, uint32_t, SCTime_t);
+int HostBitIsnotset(Host *, uint32_t, SCTime_t);
int HostBitList(Host *, XBit **);
#endif /* SURICATA_HOST_BIT_H */
for ( ; gv != NULL; gv = gv->next) {
if (gv->type == DETECT_XBITS) {
XBit *xb = (XBit *)gv;
- if (xb->expire > (uint32_t)SCTIME_SECS(ts))
+ if (SCTIME_CMP_GT(xb->expire, ts))
return 0;
}
}
}
/* add a flowbit to the flow */
-static void IPPairBitAdd(IPPair *h, uint32_t idx, uint32_t expire)
+static void IPPairBitAdd(IPPair *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
}
}
-void IPPairBitSet(IPPair *h, uint32_t idx, uint32_t expire)
+void IPPairBitSet(IPPair *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
}
}
-void IPPairBitToggle(IPPair *h, uint32_t idx, uint32_t expire)
+void IPPairBitToggle(IPPair *h, uint32_t idx, SCTime_t expire)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb != NULL) {
}
}
-int IPPairBitIsset(IPPair *h, uint32_t idx, uint32_t ts)
+int IPPairBitIsset(IPPair *h, uint32_t idx, SCTime_t ts)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb != NULL) {
- if (fb->expire < ts) {
+ if (SCTIME_CMP_LT(fb->expire, ts)) {
IPPairBitRemove(h, idx);
return 0;
}
return 0;
}
-int IPPairBitIsnotset(IPPair *h, uint32_t idx, uint32_t ts)
+int IPPairBitIsnotset(IPPair *h, uint32_t idx, SCTime_t ts)
{
XBit *fb = IPPairBitGet(h, idx);
if (fb == NULL) {
return 1;
}
- if (fb->expire < ts) {
+ if (SCTIME_CMP_LT(fb->expire, ts)) {
IPPairBitRemove(h, idx);
return 1;
}
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0, 0);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(0));
XBit *fb = IPPairBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0, 30);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(30));
XBit *fb = IPPairBitGet(h,0);
if (fb == NULL) {
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,30);
- IPPairBitAdd(h, 1,30);
- IPPairBitAdd(h, 2,30);
- IPPairBitAdd(h, 3,30);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(30));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(30));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(30));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(30));
XBit *fb = IPPairBitGet(h,0);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,1);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,2);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,3);
if (fb != NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,0);
if (fb == NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,1);
if (fb == NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,2);
if (fb == NULL)
if (h == NULL)
goto end;
- IPPairBitAdd(h, 0,90);
- IPPairBitAdd(h, 1,90);
- IPPairBitAdd(h, 2,90);
- IPPairBitAdd(h, 3,90);
+ IPPairBitAdd(h, 0, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 1, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 2, SCTIME_FROM_SECS(90));
+ IPPairBitAdd(h, 3, SCTIME_FROM_SECS(90));
XBit *fb = IPPairBitGet(h,3);
if (fb == NULL)
int IPPairHasBits(IPPair *host);
int IPPairBitsTimedoutCheck(IPPair *h, SCTime_t ts);
-void IPPairBitSet(IPPair *, uint32_t, uint32_t);
+void IPPairBitSet(IPPair *, uint32_t, SCTime_t);
void IPPairBitUnset(IPPair *, uint32_t);
-void IPPairBitToggle(IPPair *, uint32_t, uint32_t);
-int IPPairBitIsset(IPPair *, uint32_t, uint32_t);
-int IPPairBitIsnotset(IPPair *, uint32_t, uint32_t);
+void IPPairBitToggle(IPPair *, uint32_t, SCTime_t);
+int IPPairBitIsset(IPPair *, uint32_t, SCTime_t);
+int IPPairBitIsnotset(IPPair *, uint32_t, SCTime_t);
#endif /* SURICATA_IPPAIR_BIT_H */
HostRelease(host);
return TM_ECODE_FAILED;
}
- HostBitSet(host, idx, (uint32_t)(SCTIME_SECS(current_time) + expire));
+ HostBitSet(host, idx, SCTIME_ADD_SECS(current_time, expire));
HostRelease(host);
json_object_set_new(answer, "message", json_string("hostbit added"));
struct Bit {
uint32_t id;
- uint32_t expire;
+ SCTime_t expire;
} bits[256];
memset(&bits, 0, sizeof(bits));
int i = 0, use = 0;
json_t *bitobject = json_object();
if (bitobject == NULL)
continue;
- uint32_t expire = 0;
- if ((uint32_t)SCTIME_SECS(ts) < bits[i].expire)
- expire = bits[i].expire - (uint32_t)SCTIME_SECS(ts);
+ uint64_t expire = 0;
+ if (SCTIME_CMP_LT(ts, bits[i].expire))
+ expire = SCTIME_SECS(bits[i].expire) - SCTIME_SECS(ts);
const char *name = VarNameStoreLookupById(bits[i].id, VAR_TYPE_HOST_BIT);
if (name == NULL)
continue;
json_object_set_new(bitobject, "name", json_string(name));
- SCLogDebug("xbit %s expire %u", name, expire);
+ SCLogDebug("xbit %s expire %" PRIu64, name, expire);
json_object_set_new(bitobject, "expire", json_integer(expire));
json_array_append_new(jarray, bitobject);
}
xb->type = DETECT_XBITS;
xb->idx = idx;
xb->next = NULL;
- xb->expire = 0; // not used by tx bits
+ SCTIME_INIT(xb->expire); // not used by tx bits
GenericVarAppend(&txd->txbits, (GenericVar *)xb);
return 1;
uint8_t pad[2];
uint32_t idx; /* name idx */
GenericVar *next;
- uint32_t expire;
+ SCTime_t expire;
} XBit;
void XBitFree(XBit *);