flow: convert flow_id to uint64 as no signdess is necessary

pull/13383/head
Lukas Sismis 6 months ago committed by Victor Julien
parent a90f0c96b5
commit 5dcd0a36f9

@ -1030,7 +1030,7 @@ static inline bool FlowCompareKey(Flow *f, FlowKey *key)
* \param flow_id Flow ID of the flow to look for
* \retval f *LOCKED* flow or NULL
*/
Flow *FlowGetExistingFlowFromFlowId(int64_t flow_id)
Flow *FlowGetExistingFlowFromFlowId(uint64_t flow_id)
{
uint32_t hash = flow_id & 0x0000FFFF;
FlowBucket *fb = &flow_hash[hash % flow_config.hash_size];

@ -82,7 +82,7 @@ typedef struct FlowBucket_ {
Flow *FlowGetFlowFromHash(ThreadVars *tv, FlowLookupStruct *tctx, Packet *, Flow **);
Flow *FlowGetFromFlowKey(FlowKey *key, struct timespec *ttime, const uint32_t hash);
Flow *FlowGetExistingFlowFromFlowId(int64_t flow_id);
Flow *FlowGetExistingFlowFromFlowId(uint64_t flow_id);
uint32_t FlowKeyGetHash(FlowKey *flow_key);
uint32_t FlowGetIpPairProtoHash(const Packet *p);

@ -246,7 +246,7 @@ static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
uint64_t bytes_todst = fc->todstbytecnt;
bool update = fc->BypassUpdate(f, fc->bypass_data, SCTIME_SECS(ts));
if (update) {
SCLogDebug("Updated flow: %"PRId64"", FlowGetId(f));
SCLogDebug("Updated flow: %" PRIu64 "", FlowGetId(f));
pkts_tosrc = fc->tosrcpktcnt - pkts_tosrc;
bytes_tosrc = fc->tosrcbytecnt - bytes_tosrc;
pkts_todst = fc->todstpktcnt - pkts_todst;
@ -259,7 +259,7 @@ static inline bool FlowBypassedTimeout(Flow *f, SCTime_t ts, FlowTimeoutCounters
counters->bypassed_bytes += bytes_tosrc + bytes_todst;
return false;
}
SCLogDebug("No new packet, dead flow %" PRId64 "", FlowGetId(f));
SCLogDebug("No new packet, dead flow %" PRIu64 "", FlowGetId(f));
if (f->livedev) {
if (FLOW_IS_IPV4(f)) {
LiveDevSubBypassStats(f->livedev, 1, AF_INET);

@ -634,14 +634,12 @@ static inline void FlowDeReference(Flow **d)
}
/** \brief create a flow id that is as unique as possible
* \retval flow_id signed 64bit id
* \note signed because of the signedness of json_integer_t in
* the json output
* \retval flow_id unsigned 64bit id
*/
static inline int64_t FlowGetId(const Flow *f)
static inline uint64_t FlowGetId(const Flow *f)
{
int64_t id = (uint64_t)(SCTIME_SECS(f->startts) & 0x0000FFFF) << 48 |
(uint64_t)(SCTIME_USECS(f->startts) & 0x0000FFFF) << 32 | (int64_t)f->flow_hash;
uint64_t id = (uint64_t)(SCTIME_SECS(f->startts) & 0xFFFF) << 48 |
(uint64_t)(SCTIME_USECS(f->startts) & 0xFFFF) << 32 | (uint64_t)f->flow_hash;
/* reduce to 51 bits as JavaScript and even JSON often seem to
* max out there. */
id &= 0x7ffffffffffffLL;

@ -702,7 +702,7 @@ void CreateEveFlowId(SCJsonBuilder *js, const Flow *f)
if (f == NULL) {
return;
}
int64_t flow_id = FlowGetId(f);
uint64_t flow_id = FlowGetId(f);
SCJbSetUint(js, "flow_id", flow_id);
if (f->parent_id) {
SCJbSetUint(js, "parent_id", f->parent_id);

@ -654,7 +654,7 @@ bool EBPFBypassUpdate(Flow *f, void *data, time_t tsec)
bool activity = EBPFBypassCheckHalfFlow(f, fc, eb, eb->key[0], 0);
activity |= EBPFBypassCheckHalfFlow(f, fc, eb, eb->key[1], 1);
if (!activity) {
SCLogDebug("Delete entry: %u (%ld)", FLOW_IS_IPV6(f), FlowGetId(f));
SCLogDebug("Delete entry: %u (%" PRIu64 ")", FLOW_IS_IPV6(f), FlowGetId(f));
/* delete the entries if no time update */
EBPFDeleteKey(eb->mapfd, eb->key[0]);
EBPFDeleteKey(eb->mapfd, eb->key[1]);

@ -67,7 +67,7 @@ static int LuaFlowId(lua_State *luastate)
Flow *f = s->f;
int64_t id = FlowGetId(f);
int64_t id = (int64_t)FlowGetId(f);
lua_pushinteger(luastate, id);
return 1;
}

Loading…
Cancel
Save