]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
app-layer: get sbconfg with files
authorVictor Julien <vjulien@oisf.net>
Sat, 21 Jan 2023 21:45:36 +0000 (22:45 +0100)
committerVictor Julien <vjulien@oisf.net>
Mon, 23 Jan 2023 08:19:54 +0000 (09:19 +0100)
18 files changed:
rust/src/applayer.rs
rust/src/http2/http2.rs
rust/src/nfs/nfs.rs
rust/src/smb/files.rs
src/app-layer-ftp.c
src/app-layer-htp.c
src/app-layer-parser.c
src/app-layer-parser.h
src/app-layer-register.h
src/app-layer-smtp.c
src/detect-engine-file.c
src/detect-engine-state.c
src/detect-file-data.c
src/detect-filemagic.c
src/detect-filename.c
src/detect-filestore.c
src/output-json-alert.c
src/output-tx.c

index e5be48944f1e0c1bc1d1d65ad42559b06ca10df4..d7dbfe6ab90e50cd2f356df16e4bc22344a288ca 100644 (file)
@@ -24,6 +24,7 @@ use crate::applayer;
 use std::os::raw::{c_void,c_char,c_int};
 use crate::core::SC;
 use std::ffi::CStr;
+use crate::core::StreamingBufferConfig;
 
 // Make the AppLayerEvent derive macro available to users importing
 // AppLayerEvent from this module.
@@ -383,6 +384,20 @@ macro_rules! cast_pointer {
     ($ptr:ident, $ty:ty) => ( &mut *($ptr as *mut $ty) );
 }
 
+/// helper for the GetTxFilesFn. Not meant to be embedded as the config
+/// pointer is passed around in the API.
+#[allow(non_snake_case)]
+#[repr(C)]
+pub struct AppLayerGetFileState {
+    pub fc: *mut FileContainer,
+    pub cfg: *const StreamingBufferConfig,
+}
+impl AppLayerGetFileState {
+    pub fn err() -> AppLayerGetFileState {
+        AppLayerGetFileState { fc: std::ptr::null_mut(), cfg: std::ptr::null() }
+    }
+}
+
 pub type ParseFn      = unsafe extern "C" fn (flow: *const Flow,
                                        state: *mut c_void,
                                        pstate: *mut c_void,
@@ -399,7 +414,7 @@ pub type GetEventInfoFn     = unsafe extern "C" fn (*const c_char, *mut c_int, *
 pub type GetEventInfoByIdFn = unsafe extern "C" fn (c_int, *mut *const c_char, *mut AppLayerEventType) -> i8;
 pub type LocalStorageNewFn  = extern "C" fn () -> *mut c_void;
 pub type LocalStorageFreeFn = extern "C" fn (*mut c_void);
-pub type GetTxFilesFn       = unsafe extern "C" fn (*mut c_void, u8) -> *mut FileContainer;
+pub type GetTxFilesFn       = unsafe extern "C" fn (*mut c_void, *mut c_void, u8) -> AppLayerGetFileState;
 pub type GetTxIteratorFn    = unsafe extern "C" fn (ipproto: u8, alproto: AppProto,
                                              state: *mut c_void,
                                              min_tx_id: u64,
index 83eb492caca616d0a60d543a7f059a562931cce2..ba4ae1f746ff684604b1399243a827c0aa846e13 100644 (file)
@@ -1210,14 +1210,15 @@ pub unsafe extern "C" fn rs_http2_tx_get_alstate_progress(
 
 #[no_mangle]
 pub unsafe extern "C" fn rs_http2_getfiles(
+    _state: *mut std::os::raw::c_void,
     tx: *mut std::os::raw::c_void, direction: u8,
-) -> *mut FileContainer {
+) -> AppLayerGetFileState {
     let tx = cast_pointer!(tx, HTTP2Transaction);
-    if direction == Direction::ToClient.into() {
-        &mut tx.files.files_tc as *mut FileContainer
-    } else {
-        &mut tx.files.files_ts as *mut FileContainer
+    let (files, _flags) = tx.files.get(direction.into());
+    if let Some(sfcm) = { SURICATA_HTTP2_FILE_CONFIG } {
+        return AppLayerGetFileState { fc: files, cfg: sfcm.files_sbcfg }
     }
+    AppLayerGetFileState::err()
 }
 
 // Parser name as a C style string.
index 9961561bd639fc08c15af08d9f8961f9f4febb4f..8190a48b6f757b43c2f4f424e68363185758c31b 100644 (file)
@@ -158,14 +158,15 @@ impl NFSTransactionFile {
 }
 
 #[no_mangle]
-pub unsafe extern "C" fn rs_nfs_gettxfiles(tx_ptr: *mut std::ffi::c_void, direction: u8) -> * mut FileContainer {
-    let tx = cast_pointer!(tx_ptr, NFSTransaction);
+pub unsafe extern "C" fn rs_nfs_gettxfiles(_state: *mut std::ffi::c_void, tx: *mut std::ffi::c_void, direction: u8) -> AppLayerGetFileState {
+    let tx = cast_pointer!(tx, NFSTransaction);
     if let Some(NFSTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
         let (files, _flags) = tdf.files.get(direction.into());
-        files
-    } else {
-        std::ptr::null_mut()
+        if let Some(sfcm) = { SURICATA_NFS_FILE_CONFIG } {
+            return AppLayerGetFileState { fc: files, cfg: sfcm.files_sbcfg }
+        }
     }
+    AppLayerGetFileState::err()
 }
 
 #[derive(Debug)]
index 938ffaffab598d3f80003d54e88c7dc1040b367c..955e867aef6ff83b24767474265a8e0e0c0931d1 100644 (file)
@@ -225,13 +225,15 @@ impl SMBState {
     }
 }
 
+use crate::applayer::AppLayerGetFileState;
 #[no_mangle]
-pub unsafe extern "C" fn rs_smb_gettxfiles(tx_ptr: *mut std::ffi::c_void, direction: u8) -> * mut FileContainer {
-    let tx = cast_pointer!(tx_ptr, SMBTransaction);
+pub unsafe extern "C" fn rs_smb_gettxfiles(_state: *mut std::ffi::c_void, tx: *mut std::ffi::c_void, direction: u8) -> AppLayerGetFileState {
+    let tx = cast_pointer!(tx, SMBTransaction);
     if let Some(SMBTransactionTypeData::FILE(ref mut tdf)) = tx.type_data {
         let (files, _flags) = tdf.files.get(direction.into());
-        files
-    } else {
-        std::ptr::null_mut()
+        if let Some(sfcm) = { SURICATA_SMB_FILE_CONFIG } {
+            return AppLayerGetFileState { fc: files, cfg: sfcm.files_sbcfg }
+        }
     }
+    AppLayerGetFileState::err()
 }
index 45e124bd28a401a214ee25cfc7cbe8bb92f54c0e..bdd5a85a9183629c01fa02e99a4fe60b8c34aa8f 100644 (file)
@@ -1284,14 +1284,15 @@ static int FTPDataGetAlstateProgress(void *tx, uint8_t direction)
         return FTPDATA_STATE_FINISHED;
 }
 
-static FileContainer *FTPDataStateGetTxFiles(void *tx, uint8_t direction)
+static AppLayerGetFileState FTPDataStateGetTxFiles(void *_state, void *tx, uint8_t direction)
 {
     FtpDataState *ftpdata_state = (FtpDataState *)tx;
+    AppLayerGetFileState files = { .fc = NULL, .cfg = &sbcfg };
 
-    if (direction != ftpdata_state->direction)
-        SCReturnPtr(NULL, "FileContainer");
+    if (direction == ftpdata_state->direction)
+        files.fc = ftpdata_state->files;
 
-    SCReturnPtr(ftpdata_state->files, "FileContainer");
+    return files;
 }
 
 static void FTPSetMpmState(void)
index c2facb228c17975502c8a49f5f543172eb5dd051..dd39508f8d586d4fd9b7f335d9d08570ddd8abe2 100644 (file)
@@ -3021,18 +3021,22 @@ void AppLayerHtpPrintStats(void)
  *  \param direction flow direction
  *  \retval files files ptr
  */
-static FileContainer *HTPGetTxFiles(void *txv, uint8_t direction)
+static AppLayerGetFileState HTPGetTxFiles(void *state, void *txv, uint8_t direction)
 {
+    AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
+    HtpState *s = state;
     htp_tx_t *tx = (htp_tx_t *)txv;
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     if (tx_ud) {
         if (direction & STREAM_TOCLIENT) {
-            SCReturnPtr(&tx_ud->files_tc, "FileContainer");
+            files.fc = &tx_ud->files_tc;
+            files.cfg = &s->cfg->response.sbcfg;
         } else {
-            SCReturnPtr(&tx_ud->files_ts, "FileContainer");
+            files.fc = &tx_ud->files_ts;
+            files.cfg = &s->cfg->request.sbcfg;
         }
     }
-    SCReturnPtr(NULL, "FileContainer");
+    return files;
 }
 
 static int HTPStateGetAlstateProgress(void *tx, uint8_t direction)
@@ -6962,7 +6966,8 @@ libhtp:\n\
     void *tx_ptr = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, http_state, 0);
     FAIL_IF_NULL(tx_ptr);
 
-    FileContainer *ffc = HTPGetTxFiles(tx_ptr, STREAM_TOCLIENT);
+    AppLayerGetFileState files = HTPGetTxFiles(http_state, tx_ptr, STREAM_TOCLIENT);
+    FileContainer *ffc = files.fc;
     FAIL_IF_NULL(ffc);
 
     File *ptr = ffc->head;
index 11d27034559d65a8b547f3b4fb9dc469a588b0df..cb91d69c908a980f39b9ca2d09477207f1b02475 100644 (file)
@@ -95,7 +95,7 @@ typedef struct AppLayerParserProtoCtx_
 
     /** get FileContainer reference from the TX. MUST return a non-NULL reference if the TX
      *  has or may have files in the requested direction at some point. */
-    FileContainer *(*GetTxFiles)(void *, uint8_t);
+    AppLayerGetFileState (*GetTxFiles)(void *, void *, uint8_t);
 
     int (*StateGetProgress)(void *alstate, uint8_t direction);
     uint64_t (*StateGetTxCnt)(void *alstate);
@@ -455,8 +455,8 @@ void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto alproto,
     SCReturn;
 }
 
-void AppLayerParserRegisterGetTxFilesFunc(
-        uint8_t ipproto, AppProto alproto, FileContainer *(*GetTxFiles)(void *, uint8_t))
+void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto,
+        AppLayerGetFileState (*GetTxFiles)(void *, void *, uint8_t))
 {
     SCEnter();
 
@@ -887,28 +887,28 @@ AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alp
     SCReturnPtr(ptr, "AppLayerDecoderEvents *");
 }
 
-FileContainer *AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
+AppLayerGetFileState AppLayerParserGetTxFiles(
+        const Flow *f, void *state, void *tx, const uint8_t direction)
 {
     SCEnter();
 
-    FileContainer *ptr = NULL;
-
     if (alp_ctx.ctxs[f->protomap][f->alproto].GetTxFiles != NULL) {
-        ptr = alp_ctx.ctxs[f->protomap][f->alproto].GetTxFiles(tx, direction);
+        return alp_ctx.ctxs[f->protomap][f->alproto].GetTxFiles(state, tx, direction);
     }
 
-    SCReturnPtr(ptr, "FileContainer *");
+    AppLayerGetFileState files = { .fc = NULL, .cfg = NULL };
+    return files;
 }
 
 static void AppLayerParserFileTxHousekeeping(
         const Flow *f, void *tx, const uint8_t pkt_dir, const bool trunc)
 {
-    FileContainer *fc = AppLayerParserGetTxFiles(f, tx, pkt_dir);
-    if (fc) {
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, FlowGetAppState(f), tx, pkt_dir);
+    if (files.fc) {
         if (trunc) {
-            FileTruncateAllOpenFiles(fc);
+            FileTruncateAllOpenFiles(files.fc);
         }
-        FilePrune(fc);
+        FilePrune(files.fc);
     }
 }
 
index 71ab593ceb88056f6d925ed2c1a667c01650f305..902a1a949ae8bad35d268429d09a8d128b3169df 100644 (file)
@@ -177,8 +177,8 @@ void AppLayerParserRegisterLocalStorageFunc(uint8_t ipproto, AppProto proto,
         void *(*LocalStorageAlloc)(void), void (*LocalStorageFree)(void *));
 // void AppLayerParserRegisterGetEventsFunc(uint8_t ipproto, AppProto proto,
 //     AppLayerDecoderEvents *(*StateGetEvents)(void *) __attribute__((nonnull)));
-void AppLayerParserRegisterGetTxFilesFunc(
-        uint8_t ipproto, AppProto alproto, FileContainer *(*GetTxFiles)(void *, uint8_t));
+void AppLayerParserRegisterGetTxFilesFunc(uint8_t ipproto, AppProto alproto,
+        AppLayerGetFileState (*GetTxFiles)(void *, void *, uint8_t));
 void AppLayerParserRegisterLoggerFuncs(uint8_t ipproto, AppProto alproto,
                          LoggerId (*StateGetTxLogged)(void *, void *),
                          void (*StateSetTxLogged)(void *, void *, LoggerId));
@@ -241,7 +241,8 @@ void AppLayerParserSetTransactionInspectId(const Flow *f, AppLayerParserState *p
 AppLayerDecoderEvents *AppLayerParserGetDecoderEvents(AppLayerParserState *pstate);
 void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents);
 AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx);
-FileContainer *AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction);
+AppLayerGetFileState AppLayerParserGetTxFiles(
+        const Flow *f, void *state, void *tx, const uint8_t direction);
 int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
                         void *alstate, uint8_t direction);
 uint64_t AppLayerParserGetTxCnt(const Flow *, void *alstate);
index beffe2a31841ef37b796dbe446c626515bfa3e6c..4fcbe6cf8b6cfbf4e615820b4dd5c70037c347f3 100644 (file)
@@ -59,7 +59,7 @@ typedef struct AppLayerParser {
     void *(*LocalStorageAlloc)(void);
     void (*LocalStorageFree)(void *);
 
-    FileContainer *(*GetTxFiles)(void *, uint8_t);
+    AppLayerGetFileState (*GetTxFiles)(void *, void *, uint8_t);
 
     AppLayerGetTxIterTuple (*GetTxIterator)(const uint8_t ipproto,
             const AppProto alproto, void *alstate, uint64_t min_tx_id,
index 6fab7cb77ae3333888f9c363f474d59ca81c2f64..40f173f72c82e3306c17972c8cfdf5c6763d49ed 100644 (file)
@@ -1691,16 +1691,15 @@ static int SMTPStateGetAlstateProgress(void *vtx, uint8_t direction)
     return tx->done;
 }
 
-static FileContainer *SMTPGetTxFiles(void *txv, uint8_t direction)
+static AppLayerGetFileState SMTPGetTxFiles(void *state, void *txv, uint8_t direction)
 {
+    AppLayerGetFileState files = { .fc = NULL, .cfg = &smtp_config.sbcfg };
     SMTPTransaction *tx = (SMTPTransaction *)txv;
 
-    if (direction & STREAM_TOCLIENT) {
-        SCReturnPtr(NULL, "FileContainer");
-    } else {
-        SCLogDebug("tx->files_ts %p", &tx->files_ts);
-        SCReturnPtr(&tx->files_ts, "FileContainer");
+    if (direction & STREAM_TOSERVER) {
+        files.fc = &tx->files_ts;
     }
+    return files;
 }
 
 static AppLayerTxData *SMTPGetTxData(void *vtx)
index 8d0fd32b41aaf4cd736834a72783bf2dd046126c..0ce8c7a0d587e7543301182350665d7391cd7fa1 100644 (file)
@@ -182,13 +182,14 @@ static uint8_t DetectFileInspect(DetectEngineThreadCtx *det_ctx, Flow *f, const
  */
 uint8_t DetectFileInspectGeneric(DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
         const struct DetectEngineAppInspectionEngine_ *engine, const Signature *s, Flow *f,
-        uint8_t flags, void *_alstate, void *tx, uint64_t tx_id)
+        uint8_t flags, void *alstate, void *tx, uint64_t tx_id)
 {
     SCEnter();
-    DEBUG_VALIDATE_BUG_ON(f->alstate != _alstate);
+    DEBUG_VALIDATE_BUG_ON(f->alstate != alstate);
 
     const uint8_t direction = flags & (STREAM_TOSERVER|STREAM_TOCLIENT);
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, tx, direction);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, alstate, tx, direction);
+    FileContainer *ffc = files.fc;
     SCLogDebug("tx %p tx_id %" PRIu64 " ffc %p ffc->head %p sid %u", tx, tx_id, ffc,
             ffc ? ffc->head : NULL, s->id);
     if (ffc == NULL) {
index b600180fafa823d32cc8d40801bddf9913dc0e3f..db7cfc0ace0c0a9240de71ed3012afd5596eb236 100644 (file)
@@ -720,10 +720,11 @@ static int DeStateSigTest03(void)
     SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
     FAIL_IF(!(PacketAlertCheck(p, 1)));
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
 
-    File *file = files->head;
+    File *file = fc->head;
     FAIL_IF_NULL(file);
 
     FAIL_IF(!(file->flags & FILE_STORE));
@@ -799,9 +800,10 @@ static int DeStateSigTest04(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
 
     FAIL_IF(file->flags & FILE_STORE);
@@ -873,9 +875,10 @@ static int DeStateSigTest05(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF(http_state->state_data.file_flags & FLOWFILE_NO_STORE_TS);
 
@@ -958,9 +961,10 @@ static int DeStateSigTest06(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     /* detect will have set FLOWFILE_NO_STORE_TS, but it won't have had
      * an opportunity to be applied to the file itself yet */
@@ -1045,9 +1049,10 @@ static int DeStateSigTest07(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF(file->flags & FILE_STORE);
 
@@ -1143,9 +1148,10 @@ static int DeStateSigTest08(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF(file->flags & FILE_STORE);
 
@@ -1169,9 +1175,10 @@ static int DeStateSigTest08(void)
     tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    file = files->head;
+    files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    fc = files.fc;
+    FAIL_IF_NULL(fc);
+    file = fc->head;
     FAIL_IF_NULL(file);
     file = file->next;
     FAIL_IF_NULL(file);
@@ -1269,9 +1276,10 @@ static int DeStateSigTest09(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF_NOT(file->flags & FILE_STORE);
 
@@ -1295,9 +1303,10 @@ static int DeStateSigTest09(void)
     tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    file = files->head;
+    files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    fc = files.fc;
+    FAIL_IF_NULL(fc);
+    file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF_NOT(file->flags & FILE_STORE);
 
@@ -1393,9 +1402,10 @@ static int DeStateSigTest10(void)
     HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    FileContainer *files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    File *file = files->head;
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    FileContainer *fc = files.fc;
+    FAIL_IF_NULL(fc);
+    File *file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF_NOT(file->flags & FILE_STORE);
 
@@ -1419,9 +1429,10 @@ static int DeStateSigTest10(void)
     tx_ud = htp_tx_get_user_data(tx);
     FAIL_IF_NULL(tx_ud);
 
-    files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
-    FAIL_IF_NULL(files);
-    file = files->head;
+    files = AppLayerParserGetTxFiles(p->flow, http_state, tx, STREAM_TOSERVER);
+    fc = files.fc;
+    FAIL_IF_NULL(fc);
+    file = fc->head;
     FAIL_IF_NULL(file);
     FAIL_IF_NOT(file->flags & FILE_STORE);
 
index 88394b7f5b60fdacedf49c983b4a675b64fd5691..d905357aa64bc5a00c4cfab90d5803eb8d4fc864 100644 (file)
@@ -598,7 +598,8 @@ static uint8_t DetectEngineInspectFiledata(DetectEngineCtx *de_ctx, DetectEngine
         transforms = engine->v2.transforms;
     }
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc == NULL) {
         return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES;
     }
@@ -660,7 +661,8 @@ static void PrefilterTxFiledata(DetectEngineThreadCtx *det_ctx, const void *pect
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, f->alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc != NULL) {
         int local_file_id = 0;
         for (File *file = ffc->head; file != NULL; file = file->next) {
index 33fc7ee34f1bb54473b02ee73bfa5536a54fe0c2..5e96a648498f1829d8012883d20b0fe3a720927b 100644 (file)
@@ -484,7 +484,8 @@ static uint8_t DetectEngineInspectFilemagic(DetectEngineCtx *de_ctx, DetectEngin
         transforms = engine->v2.transforms;
     }
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc == NULL) {
         return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES;
     }
@@ -542,7 +543,8 @@ static void PrefilterTxFilemagic(DetectEngineThreadCtx *det_ctx, const void *pec
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, f->alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc != NULL) {
         int local_file_id = 0;
         for (File *file = ffc->head; file != NULL; file = file->next) {
index 06d5cab2c5a13fcaac587e635de0135cc021809b..ad09abed40f0990ac53f119b21c148a7107d53c7 100644 (file)
@@ -380,7 +380,8 @@ static uint8_t DetectEngineInspectFilename(DetectEngineCtx *de_ctx, DetectEngine
         transforms = engine->v2.transforms;
     }
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc == NULL) {
         return DETECT_ENGINE_INSPECT_SIG_CANT_MATCH_FILES;
     }
@@ -438,7 +439,8 @@ static void PrefilterTxFilename(DetectEngineThreadCtx *det_ctx, const void *pect
     const MpmCtx *mpm_ctx = ctx->mpm_ctx;
     const int list_id = ctx->list_id;
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, txv, flags);
+    AppLayerGetFileState files = AppLayerParserGetTxFiles(f, f->alstate, txv, flags);
+    FileContainer *ffc = files.fc;
     if (ffc != NULL) {
         int local_file_id = 0;
         for (File *file = ffc->head; file != NULL; file = file->next) {
index 9a57469a42d08b6814aaf53d68e289a2c0bb4762..9fe533c6180e3e49490c25abc28ea35dfc3d5659 100644 (file)
@@ -216,14 +216,16 @@ static int DetectFilestorePostMatch(DetectEngineThreadCtx *det_ctx,
 
     const uint8_t flags = STREAM_FLAGS_FOR_PACKET(p);
     for (uint16_t u = 0; u < det_ctx->filestore_cnt; u++) {
-        AppLayerParserSetStreamDepthFlag(p->flow->proto, p->flow->alproto, FlowGetAppState(p->flow),
-                det_ctx->filestore[u].tx_id, flags);
+        void *alstate = FlowGetAppState(p->flow);
+        AppLayerParserSetStreamDepthFlag(
+                p->flow->proto, p->flow->alproto, alstate, det_ctx->filestore[u].tx_id, flags);
 
-        void *txv = AppLayerParserGetTx(p->flow->proto, p->flow->alproto, FlowGetAppState(p->flow),
-                det_ctx->filestore[u].tx_id);
+        void *txv = AppLayerParserGetTx(
+                p->flow->proto, p->flow->alproto, alstate, det_ctx->filestore[u].tx_id);
         DEBUG_VALIDATE_BUG_ON(txv == NULL);
         if (txv) {
-            FileContainer *ffc_tx = AppLayerParserGetTxFiles(p->flow, txv, flags);
+            AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, alstate, txv, flags);
+            FileContainer *ffc_tx = files.fc;
             DEBUG_VALIDATE_BUG_ON(ffc_tx == NULL);
             if (ffc_tx) {
                 SCLogDebug("u %u txv %p ffc_tx %p file_id %u", u, txv, ffc_tx,
index d4f55088b3fa7c033aae8398a46556e080458b1a..20e0a5df484f509d5db8b58d8884e2f89cb7317e 100644 (file)
@@ -604,7 +604,9 @@ static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id
     if (p->flow->alstate != NULL) {
         void *tx = AppLayerParserGetTx(p->flow->proto, p->flow->alproto, p->flow->alstate, tx_id);
         if (tx) {
-            ffc = AppLayerParserGetTxFiles(p->flow, tx, direction);
+            AppLayerGetFileState files =
+                    AppLayerParserGetTxFiles(p->flow, p->flow->alstate, tx, direction);
+            ffc = files.fc;
         }
     }
     if (ffc != NULL) {
index cc7d348b66a30ad27b4e6ccfd1f2593f2cd19dcb..1fd4a1a2a98d05b7fe617be563f09c24daefe9ac 100644 (file)
@@ -168,8 +168,12 @@ static inline void OutputTxLogFiles(ThreadVars *tv, OutputFileLoggerThreadData *
             opposing_dir == STREAM_TOSERVER ? "TOSERVER" : "TOCLIENT", packet_dir_ready,
             opposing_dir_ready);
 
-    FileContainer *ffc = AppLayerParserGetTxFiles(f, tx, packet_dir);
-    FileContainer *ffc_opposing = AppLayerParserGetTxFiles(f, tx, opposing_dir);
+    AppLayerGetFileState app_files =
+            AppLayerParserGetTxFiles(f, FlowGetAppState(f), tx, packet_dir);
+    FileContainer *ffc = app_files.fc;
+    AppLayerGetFileState app_files_opposing =
+            AppLayerParserGetTxFiles(f, FlowGetAppState(f), tx, opposing_dir);
+    FileContainer *ffc_opposing = app_files_opposing.fc;
 
     /* see if opposing side is finished: if no file support in this direction, of is not
      * files and tx is done for opposing dir. */