SCReturnPtr(ptr, "AppLayerDecoderEvents *");
}
-FileContainer *AppLayerParserGetFiles(uint8_t ipproto, AppProto alproto,
- void *alstate, uint8_t direction)
+FileContainer *AppLayerParserGetFiles(const Flow *f, const uint8_t direction)
{
SCEnter();
FileContainer *ptr = NULL;
- if (alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
- StateGetFiles != NULL)
+ if (alp_ctx.ctxs[f->protomap][f->alproto].StateGetFiles != NULL)
{
- ptr = alp_ctx.ctxs[FlowGetProtoMapping(ipproto)][alproto].
- StateGetFiles(alstate, direction);
+ ptr = alp_ctx.ctxs[f->protomap][f->alproto].
+ StateGetFiles(f->alstate, direction);
}
SCReturnPtr(ptr, "FileContainer *");
SCFree(s);
}
-static uint64_t TestProtocolGetTxCnt(void *state)
+static uint64_t TestGetTxCnt(void *state)
{
/* single tx */
return 1;
}
+static void TestStateTransactionFree(void *state, uint64_t tx_id)
+{
+ /* do nothing */
+}
+
+static void *TestGetTx(void *state, uint64_t tx_id)
+{
+ TestState *test_state = (TestState *)state;
+ return test_state;
+}
+
void AppLayerParserRegisterProtocolUnittests(uint8_t ipproto, AppProto alproto,
void (*RegisterUnittests)(void))
{
TestProtocolParser);
AppLayerParserRegisterStateFuncs(IPPROTO_TCP, ALPROTO_TEST,
TestProtocolStateAlloc, TestProtocolStateFree);
- AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TEST, TestProtocolGetTxCnt);
+ AppLayerParserRegisterTxFreeFunc(IPPROTO_TCP, ALPROTO_TEST, TestStateTransactionFree);
+ AppLayerParserRegisterGetTx(IPPROTO_TCP, ALPROTO_TEST, TestGetTx);
+ AppLayerParserRegisterGetTxCnt(IPPROTO_TCP, ALPROTO_TEST, TestGetTxCnt);
f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
if (f == NULL)
TestProtocolParser);
AppLayerParserRegisterStateFuncs(IPPROTO_UDP, ALPROTO_TEST,
TestProtocolStateAlloc, TestProtocolStateFree);
- AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TEST, TestProtocolGetTxCnt);
+ AppLayerParserRegisterTxFreeFunc(IPPROTO_UDP, ALPROTO_TEST, TestStateTransactionFree);
+ AppLayerParserRegisterGetTx(IPPROTO_UDP, ALPROTO_TEST, TestGetTx);
+ AppLayerParserRegisterGetTxCnt(IPPROTO_UDP, ALPROTO_TEST, TestGetTxCnt);
f = UTHBuildFlow(AF_INET, "1.2.3.4", "4.3.2.1", 20, 40);
if (f == NULL)
AppLayerDecoderEvents *AppLayerParserGetDecoderEvents(AppLayerParserState *pstate);
void AppLayerParserSetDecoderEvents(AppLayerParserState *pstate, AppLayerDecoderEvents *devents);
AppLayerDecoderEvents *AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx);
-FileContainer *AppLayerParserGetFiles(uint8_t ipproto, AppProto alproto,
- void *alstate, uint8_t direction);
+FileContainer *AppLayerParserGetFiles(const Flow *f, const uint8_t direction);
int AppLayerParserGetStateProgress(uint8_t ipproto, AppProto alproto,
void *alstate, uint8_t direction);
uint64_t AppLayerParserGetTxCnt(const Flow *, void *alstate);
#include "util-unittest.h"
#include "util-unittest-helper.h"
#include "util-profiling.h"
+#include "util-validate.h"
/**
int DetectFileInspectGeneric(ThreadVars *tv,
DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx,
const Signature *s, const SigMatchData *smd,
- Flow *f, uint8_t flags, void *alstate, void *tx, uint64_t tx_id)
+ Flow *f, uint8_t flags, void *_alstate, void *tx, uint64_t tx_id)
{
SCEnter();
-
- if (alstate == NULL) {
- SCReturnInt(DETECT_ENGINE_INSPECT_SIG_NO_MATCH);
- }
+ DEBUG_VALIDATE_BUG_ON(f->alstate != _alstate);
const uint8_t direction = flags & (STREAM_TOSERVER|STREAM_TOCLIENT);
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, direction);
if (ffc == NULL || ffc->head == NULL) {
SCReturnInt(DETECT_ENGINE_INSPECT_SIG_NO_MATCH);
}
SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
FAIL_IF(!(PacketAlertCheck(p, 1)));
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- FileContainer *files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ FileContainer *files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
File *file = files->head;
FAIL_IF_NULL(file);
FAIL_IF_NULL(http_state);
FAIL_IF_NULL(http_state->files_ts);
- files = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, STREAM_TOSERVER);
+ files = AppLayerParserGetFiles(p->flow, STREAM_TOSERVER);
FAIL_IF_NULL(files);
file = files->head;
FAIL_IF_NULL(file);
transforms = engine->v2.transforms;
}
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
if (ffc == NULL) {
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
}
const MpmCtx *mpm_ctx = ctx->mpm_ctx;
const int list_id = ctx->list_id;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
int local_file_id = 0;
if (ffc != NULL) {
File *file = ffc->head;
transforms = engine->v2.transforms;
}
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
if (ffc == NULL) {
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
}
const MpmCtx *mpm_ctx = ctx->mpm_ctx;
const int list_id = ctx->list_id;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
int local_file_id = 0;
if (ffc != NULL) {
File *file = ffc->head;
transforms = engine->v2.transforms;
}
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
if (ffc == NULL) {
return DETECT_ENGINE_INSPECT_SIG_NO_MATCH;
}
const MpmCtx *mpm_ctx = ctx->mpm_ctx;
const int list_id = ctx->list_id;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto,
- f->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(f, flags);
int local_file_id = 0;
if (ffc != NULL) {
File *file = ffc->head;
flags);
}
- FileContainer *ffc = AppLayerParserGetFiles(p->flow->proto, p->flow->alproto,
- p->flow->alstate, flags);
+ FileContainer *ffc = AppLayerParserGetFiles(p->flow, flags);
/* filestore for single files only */
if (s->filestore_ctx == NULL) {
{
if (p->flow && p->flow->alstate) {
Flow *f = p->flow;
- FileContainer *fc = AppLayerParserGetFiles(p->proto, f->alproto,
- f->alstate, PKT_IS_TOSERVER(p) ? STREAM_TOSERVER : STREAM_TOCLIENT);
+ FileContainer *fc = AppLayerParserGetFiles(f,
+ PKT_IS_TOSERVER(p) ? STREAM_TOSERVER : STREAM_TOCLIENT);
if (fc != NULL) {
FilePrune(fc);
}
(p->flowflags & FLOW_PKT_TOCLIENT));
const bool file_trunc = StreamTcpReassembleDepthReached(p);
- FileContainer *ffc_ts = AppLayerParserGetFiles(p->proto, f->alproto,
- f->alstate, STREAM_TOSERVER);
- FileContainer *ffc_tc = AppLayerParserGetFiles(p->proto, f->alproto,
- f->alstate, STREAM_TOCLIENT);
+ FileContainer *ffc_ts = AppLayerParserGetFiles(f, STREAM_TOSERVER);
+ FileContainer *ffc_tc = AppLayerParserGetFiles(f, STREAM_TOCLIENT);
OutputFileLogFfc(tv, op_thread_data, p, ffc_ts, file_close_ts, file_trunc, STREAM_TOSERVER);
OutputFileLogFfc(tv, op_thread_data, p, ffc_tc, file_close_tc, file_trunc, STREAM_TOCLIENT);
(p->flowflags & FLOW_PKT_TOCLIENT));
const bool file_trunc = StreamTcpReassembleDepthReached(p);
- FileContainer *ffc_ts = AppLayerParserGetFiles(p->proto, f->alproto,
- f->alstate, STREAM_TOSERVER);
- FileContainer *ffc_tc = AppLayerParserGetFiles(p->proto, f->alproto,
- f->alstate, STREAM_TOCLIENT);
+ FileContainer *ffc_ts = AppLayerParserGetFiles(f, STREAM_TOSERVER);
+ FileContainer *ffc_tc = AppLayerParserGetFiles(f, STREAM_TOCLIENT);
SCLogDebug("ffc_ts %p", ffc_ts);
OutputFiledataLogFfc(tv, store, p, ffc_ts, STREAM_TOSERVER, file_close_ts, file_trunc, STREAM_TOSERVER);
SCLogDebug("ffc_tc %p", ffc_tc);
else
f->file_flags |= FLOWFILE_NO_STORE_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
/* if we're already storing, we'll continue */
else
f->file_flags |= FLOWFILE_NO_MAGIC_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
SCLogDebug("disabling magic for file %p from direction %s",
else
f->file_flags |= FLOWFILE_NO_MD5_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
SCLogDebug("disabling md5 for file %p from direction %s",
else
f->file_flags |= FLOWFILE_NO_SHA1_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
SCLogDebug("disabling sha1 for file %p from direction %s",
else
f->file_flags |= FLOWFILE_NO_SHA256_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
SCLogDebug("disabling sha256 for file %p from direction %s",
else
f->file_flags |= FLOWFILE_NO_SIZE_TC;
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, f->alstate, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
SCLogDebug("disabling size tracking for file %p from direction %s",
SCEnter();
- FileContainer *ffc = AppLayerParserGetFiles(f->proto, f->alproto, f->alstate, direction);
+ FileContainer *ffc = AppLayerParserGetFiles(f, direction);
if (ffc != NULL) {
for (ptr = ffc->head; ptr != NULL; ptr = ptr->next) {
if (ptr->txid == tx_id) {