From bad7d2f16d1a924ffb4449cbf4972356763ec9f5 Mon Sep 17 00:00:00 2001 From: Philippe Antoine Date: Wed, 14 May 2025 20:52:02 +0200 Subject: [PATCH] detect/xbits: timeout handling precision improvement As found by -Wshorten-64-to-32 warnings Ticket: #6186 Use SCTime_t instead of u32, which increases memory usage for the structures changed here, while making it more correct. --- src/detect-hostbits.c | 16 ++++---- src/detect-xbits.c | 8 ++-- src/host-bit.c | 84 +++++++++++++++++++-------------------- src/host-bit.h | 8 ++-- src/ippair-bit.c | 84 +++++++++++++++++++-------------------- src/ippair-bit.h | 8 ++-- src/runmode-unix-socket.c | 12 +++--- src/tx-bit.c | 2 +- src/util-var.h | 2 +- 9 files changed, 112 insertions(+), 112 deletions(-) diff --git a/src/detect-hostbits.c b/src/detect-hostbits.c index 86d93da4f3..5fb050f301 100644 --- a/src/detect-hostbits.c +++ b/src/detect-hostbits.c @@ -107,7 +107,7 @@ static int DetectHostbitMatchToggle (Packet *p, const DetectXbitsData *fd) 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: @@ -119,7 +119,7 @@ static int DetectHostbitMatchToggle (Packet *p, const DetectXbitsData *fd) 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; } @@ -167,7 +167,7 @@ static int DetectHostbitMatchSet (Packet *p, const DetectXbitsData *fd) } 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: @@ -178,7 +178,7 @@ static int DetectHostbitMatchSet (Packet *p, const DetectXbitsData *fd) } 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; } @@ -197,7 +197,7 @@ static int DetectHostbitMatchIsset (Packet *p, const DetectXbitsData *fd) } 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: @@ -208,7 +208,7 @@ static int DetectHostbitMatchIsset (Packet *p, const DetectXbitsData *fd) } 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; } @@ -227,7 +227,7 @@ static int DetectHostbitMatchIsnotset (Packet *p, const DetectXbitsData *fd) } 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: @@ -238,7 +238,7 @@ static int DetectHostbitMatchIsnotset (Packet *p, const DetectXbitsData *fd) } 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; } diff --git a/src/detect-xbits.c b/src/detect-xbits.c index b4e39c292e..6bf5e5134b 100644 --- a/src/detect-xbits.c +++ b/src/detect-xbits.c @@ -94,7 +94,7 @@ static int DetectIPPairbitMatchToggle (Packet *p, const DetectXbitsData *fd) 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; } @@ -117,7 +117,7 @@ static int DetectIPPairbitMatchSet (Packet *p, const DetectXbitsData *fd) 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; } @@ -129,7 +129,7 @@ static int DetectIPPairbitMatchIsset (Packet *p, const DetectXbitsData *fd) 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; } @@ -141,7 +141,7 @@ static int DetectIPPairbitMatchIsnotset (Packet *p, const DetectXbitsData *fd) 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; } diff --git a/src/host-bit.c b/src/host-bit.c index 3b03d50efe..1940fbd13c 100644 --- a/src/host-bit.c +++ b/src/host-bit.c @@ -70,7 +70,7 @@ int HostBitsTimedoutCheck(Host *h, SCTime_t ts) 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; } } @@ -91,7 +91,7 @@ static XBit *HostBitGet(Host *h, uint32_t idx) } /* 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) { @@ -128,7 +128,7 @@ static void HostBitRemove(Host *h, uint32_t idx) } } -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) { @@ -144,7 +144,7 @@ void HostBitUnset(Host *h, uint32_t idx) } } -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) { @@ -154,11 +154,11 @@ void HostBitToggle(Host *h, uint32_t idx, uint32_t expire) } } -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; } @@ -167,14 +167,14 @@ int HostBitIsset(Host *h, uint32_t idx, uint32_t ts) 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; } @@ -211,7 +211,7 @@ static int HostBitTest01 (void) if (h == NULL) goto end; - HostBitAdd(h, 0, 0); + HostBitAdd(h, 0, SCTIME_FROM_SECS(0)); XBit *fb = HostBitGet(h,0); if (fb != NULL) @@ -251,7 +251,7 @@ static int HostBitTest03 (void) if (h == NULL) goto end; - HostBitAdd(h, 0, 30); + HostBitAdd(h, 0, SCTIME_FROM_SECS(30)); XBit *fb = HostBitGet(h,0); if (fb == NULL) { @@ -284,10 +284,10 @@ static int HostBitTest04 (void) 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) @@ -308,10 +308,10 @@ static int HostBitTest05 (void) 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) @@ -332,10 +332,10 @@ static int HostBitTest06 (void) 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) @@ -356,10 +356,10 @@ static int HostBitTest07 (void) 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) @@ -380,10 +380,10 @@ static int HostBitTest08 (void) 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) @@ -413,10 +413,10 @@ static int HostBitTest09 (void) 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) @@ -446,10 +446,10 @@ static int HostBitTest10 (void) 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) @@ -479,10 +479,10 @@ static int HostBitTest11 (void) 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) diff --git a/src/host-bit.h b/src/host-bit.h index 2c57660d50..9d279c525e 100644 --- a/src/host-bit.h +++ b/src/host-bit.h @@ -33,11 +33,11 @@ void HostBitRegisterTests(void); 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 */ diff --git a/src/ippair-bit.c b/src/ippair-bit.c index 1d3d8fa9bb..5252912223 100644 --- a/src/ippair-bit.c +++ b/src/ippair-bit.c @@ -70,7 +70,7 @@ int IPPairBitsTimedoutCheck(IPPair *h, SCTime_t ts) 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; } } @@ -91,7 +91,7 @@ static XBit *IPPairBitGet(IPPair *h, uint32_t idx) } /* 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) { @@ -128,7 +128,7 @@ static void IPPairBitRemove(IPPair *h, uint32_t idx) } } -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) { @@ -144,7 +144,7 @@ void IPPairBitUnset(IPPair *h, uint32_t idx) } } -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) { @@ -154,11 +154,11 @@ void IPPairBitToggle(IPPair *h, uint32_t idx, uint32_t expire) } } -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; } @@ -168,14 +168,14 @@ int IPPairBitIsset(IPPair *h, uint32_t idx, uint32_t ts) 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; } @@ -195,7 +195,7 @@ static int IPPairBitTest01 (void) if (h == NULL) goto end; - IPPairBitAdd(h, 0, 0); + IPPairBitAdd(h, 0, SCTIME_FROM_SECS(0)); XBit *fb = IPPairBitGet(h,0); if (fb != NULL) @@ -235,7 +235,7 @@ static int IPPairBitTest03 (void) if (h == NULL) goto end; - IPPairBitAdd(h, 0, 30); + IPPairBitAdd(h, 0, SCTIME_FROM_SECS(30)); XBit *fb = IPPairBitGet(h,0); if (fb == NULL) { @@ -268,10 +268,10 @@ static int IPPairBitTest04 (void) 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) @@ -292,10 +292,10 @@ static int IPPairBitTest05 (void) 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) @@ -316,10 +316,10 @@ static int IPPairBitTest06 (void) 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) @@ -340,10 +340,10 @@ static int IPPairBitTest07 (void) 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) @@ -364,10 +364,10 @@ static int IPPairBitTest08 (void) 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) @@ -397,10 +397,10 @@ static int IPPairBitTest09 (void) 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) @@ -430,10 +430,10 @@ static int IPPairBitTest10 (void) 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) @@ -463,10 +463,10 @@ static int IPPairBitTest11 (void) 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) diff --git a/src/ippair-bit.h b/src/ippair-bit.h index 4f363eecad..a53b596583 100644 --- a/src/ippair-bit.h +++ b/src/ippair-bit.h @@ -32,10 +32,10 @@ void IPPairBitRegisterTests(void); 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 */ diff --git a/src/runmode-unix-socket.c b/src/runmode-unix-socket.c index c07a2a475d..e45fb3ae1e 100644 --- a/src/runmode-unix-socket.c +++ b/src/runmode-unix-socket.c @@ -1298,7 +1298,7 @@ TmEcode UnixSocketHostbitAdd(json_t *cmd, json_t* answer, void *data_usused) 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")); @@ -1428,7 +1428,7 @@ TmEcode UnixSocketHostbitList(json_t *cmd, json_t* answer, void *data_unused) struct Bit { uint32_t id; - uint32_t expire; + SCTime_t expire; } bits[256]; memset(&bits, 0, sizeof(bits)); int i = 0, use = 0; @@ -1463,15 +1463,15 @@ TmEcode UnixSocketHostbitList(json_t *cmd, json_t* answer, void *data_unused) 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); } diff --git a/src/tx-bit.c b/src/tx-bit.c index b26e8b3e9a..1ffe127254 100644 --- a/src/tx-bit.c +++ b/src/tx-bit.c @@ -58,7 +58,7 @@ static int TxBitAdd(AppLayerTxData *txd, uint32_t idx) 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; diff --git a/src/util-var.h b/src/util-var.h index a67730045f..30048084aa 100644 --- a/src/util-var.h +++ b/src/util-var.h @@ -60,7 +60,7 @@ typedef struct XBit_ { uint8_t pad[2]; uint32_t idx; /* name idx */ GenericVar *next; - uint32_t expire; + SCTime_t expire; } XBit; void XBitFree(XBit *); -- 2.47.2