From 2218a3716e79de28faaddb37f4019832cda6bb30 Mon Sep 17 00:00:00 2001 From: Victor Julien Date: Fri, 10 Jun 2022 08:01:15 +0200 Subject: [PATCH] file: clean up file flags handling --- src/flow.h | 3 +++ src/util-file.c | 33 ++++++++++++++++++++++----------- src/util-file.h | 1 + 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/flow.h b/src/flow.h index 8bbe6e600a..a4ecf78358 100644 --- a/src/flow.h +++ b/src/flow.h @@ -139,6 +139,9 @@ typedef struct AppLayerParserState_ AppLayerParserState; #define FLOWFILE_NO_SIZE_TS BIT_U16(10) #define FLOWFILE_NO_SIZE_TC BIT_U16(11) +/** store all files in the flow */ +#define FLOWFILE_STORE BIT_U16(12) + #define FLOWFILE_NONE_TS (FLOWFILE_NO_MAGIC_TS | \ FLOWFILE_NO_STORE_TS | \ FLOWFILE_NO_MD5_TS | \ diff --git a/src/util-file.c b/src/util-file.c index ce291feb68..fec4771763 100644 --- a/src/util-file.c +++ b/src/util-file.c @@ -230,54 +230,65 @@ void FileForceHashParseCfg(ConfNode *conf) } } -uint16_t FileFlowToFlags(const Flow *flow, uint8_t direction) +uint16_t FileFlowFlagsToFlags(const uint16_t flow_file_flags, uint8_t direction) { uint16_t flags = 0; if (direction == STREAM_TOSERVER) { - if (flow->file_flags & FLOWFILE_NO_STORE_TS) { + if ((flow_file_flags & (FLOWFILE_NO_STORE_TS | FLOWFILE_STORE)) == FLOWFILE_NO_STORE_TS) { flags |= FILE_NOSTORE; } - if (flow->file_flags & FLOWFILE_NO_MAGIC_TS) { + if (flow_file_flags & FLOWFILE_NO_MAGIC_TS) { flags |= FILE_NOMAGIC; } - if (flow->file_flags & FLOWFILE_NO_MD5_TS) { + if (flow_file_flags & FLOWFILE_NO_MD5_TS) { flags |= FILE_NOMD5; } - if (flow->file_flags & FLOWFILE_NO_SHA1_TS) { + if (flow_file_flags & FLOWFILE_NO_SHA1_TS) { flags |= FILE_NOSHA1; } - if (flow->file_flags & FLOWFILE_NO_SHA256_TS) { + if (flow_file_flags & FLOWFILE_NO_SHA256_TS) { flags |= FILE_NOSHA256; } } else { - if (flow->file_flags & FLOWFILE_NO_STORE_TC) { + if ((flow_file_flags & (FLOWFILE_NO_STORE_TC | FLOWFILE_STORE)) == FLOWFILE_NO_STORE_TC) { flags |= FILE_NOSTORE; } - if (flow->file_flags & FLOWFILE_NO_MAGIC_TC) { + if (flow_file_flags & FLOWFILE_NO_MAGIC_TC) { flags |= FILE_NOMAGIC; } - if (flow->file_flags & FLOWFILE_NO_MD5_TC) { + if (flow_file_flags & FLOWFILE_NO_MD5_TC) { flags |= FILE_NOMD5; } - if (flow->file_flags & FLOWFILE_NO_SHA1_TC) { + if (flow_file_flags & FLOWFILE_NO_SHA1_TC) { flags |= FILE_NOSHA1; } - if (flow->file_flags & FLOWFILE_NO_SHA256_TC) { + if (flow_file_flags & FLOWFILE_NO_SHA256_TC) { flags |= FILE_NOSHA256; } } + if (flow_file_flags & FLOWFILE_STORE) { + flags |= FILE_STORE; + } + DEBUG_VALIDATE_BUG_ON((flags & (FILE_STORE | FILE_NOSTORE)) == (FILE_STORE | FILE_NOSTORE)); + + SCLogDebug("direction %02x flags %02x", direction, flags); return flags; } +uint16_t FileFlowToFlags(const Flow *flow, uint8_t direction) +{ + return FileFlowFlagsToFlags(flow->file_flags, direction); +} + static int FileMagicSize(void) { /** \todo make this size configurable */ diff --git a/src/util-file.h b/src/util-file.h index b633030690..3f1cbed9d4 100644 --- a/src/util-file.h +++ b/src/util-file.h @@ -251,6 +251,7 @@ void FileTruncateAllOpenFiles(FileContainer *); uint64_t FileDataSize(const File *file); uint64_t FileTrackedSize(const File *file); +uint16_t FileFlowFlagsToFlags(const uint16_t flow_file_flags, uint8_t direction); uint16_t FileFlowToFlags(const Flow *flow, uint8_t direction); #ifdef DEBUG -- 2.47.2