logging: convert tcp data logging to non-thread module

pull/2245/head
Jason Ish 9 years ago committed by Victor Julien
parent 4d8b8ca046
commit 7a8e8343e5

@ -61,18 +61,13 @@ static void LogTcpDataLogDeInitCtx(OutputCtx *);
int LogTcpDataLogger(ThreadVars *tv, void *thread_data, const Flow *f, const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t flags);
void TmModuleLogTcpDataLogRegister (void) {
tmm_modules[TMM_LOGTCPDATALOG].name = MODULE_NAME;
tmm_modules[TMM_LOGTCPDATALOG].ThreadInit = LogTcpDataLogThreadInit;
tmm_modules[TMM_LOGTCPDATALOG].ThreadExitPrintStats = LogTcpDataLogExitPrintStats;
tmm_modules[TMM_LOGTCPDATALOG].ThreadDeinit = LogTcpDataLogThreadDeinit;
tmm_modules[TMM_LOGTCPDATALOG].RegisterTests = NULL;
tmm_modules[TMM_LOGTCPDATALOG].cap_flags = 0;
tmm_modules[TMM_LOGTCPDATALOG].flags = TM_FLAG_LOGAPI_TM;
OutputRegisterStreamingModule(MODULE_NAME, "tcp-data", LogTcpDataLogInitCtx,
LogTcpDataLogger, STREAMING_TCP_DATA);
OutputRegisterStreamingModule(MODULE_NAME, "http-body-data", LogTcpDataLogInitCtx,
LogTcpDataLogger, STREAMING_HTTP_BODIES);
LogTcpDataLogger, STREAMING_TCP_DATA, LogTcpDataLogThreadInit,
LogTcpDataLogThreadDeinit, LogTcpDataLogExitPrintStats);
OutputRegisterStreamingModule(MODULE_NAME, "http-body-data",
LogTcpDataLogInitCtx, LogTcpDataLogger, STREAMING_HTTP_BODIES,
LogTcpDataLogThreadInit, LogTcpDataLogThreadDeinit,
LogTcpDataLogExitPrintStats);
}
typedef struct LogTcpDataFileCtx_ {

@ -55,16 +55,23 @@ typedef struct OutputStreamingLogger_ {
const char *name;
TmmId module_id;
enum OutputStreamingType type;
ThreadInitFunc ThreadInit;
ThreadDeinitFunc ThreadDeinit;
ThreadExitPrintStatsFunc ThreadExitPrintStats;
} OutputStreamingLogger;
static OutputStreamingLogger *list = NULL;
int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
OutputCtx *output_ctx, enum OutputStreamingType type )
OutputCtx *output_ctx, enum OutputStreamingType type,
ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats)
{
#if 0
int module_id = TmModuleGetIdByName(name);
if (module_id < 0)
return -1;
#endif
OutputStreamingLogger *op = SCMalloc(sizeof(*op));
if (op == NULL)
@ -74,8 +81,13 @@ int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
op->LogFunc = LogFunc;
op->output_ctx = output_ctx;
op->name = name;
#if 0
op->module_id = (TmmId) module_id;
#endif
op->type = type;
op->ThreadInit = ThreadInit;
op->ThreadDeinit = ThreadDeinit;
op->ThreadExitPrintStats = ThreadExitPrintStats;
if (list == NULL)
list = op;
@ -368,16 +380,9 @@ static TmEcode OutputStreamingLogThreadInit(ThreadVars *tv, void *initdata, void
OutputStreamingLogger *logger = list;
while (logger) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name);
if (tm_module == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"TmModuleGetByName for %s failed", logger->name);
exit(EXIT_FAILURE);
}
if (tm_module->ThreadInit) {
if (logger->ThreadInit) {
void *retptr = NULL;
if (tm_module->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) {
if (logger->ThreadInit(tv, (void *)logger->output_ctx, &retptr) == TM_ECODE_OK) {
OutputLoggerThreadStore *ts = SCMalloc(sizeof(*ts));
/* todo */ BUG_ON(ts == NULL);
memset(ts, 0x00, sizeof(*ts));
@ -412,15 +417,8 @@ static TmEcode OutputStreamingLogThreadDeinit(ThreadVars *tv, void *thread_data)
OutputStreamingLogger *logger = list;
while (logger && store) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name);
if (tm_module == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"TmModuleGetByName for %s failed", logger->name);
exit(EXIT_FAILURE);
}
if (tm_module->ThreadDeinit) {
tm_module->ThreadDeinit(tv, store->thread_data);
if (logger->ThreadDeinit) {
logger->ThreadDeinit(tv, store->thread_data);
}
logger = logger->next;
@ -436,15 +434,8 @@ static void OutputStreamingLogExitPrintStats(ThreadVars *tv, void *thread_data)
OutputStreamingLogger *logger = list;
while (logger && store) {
TmModule *tm_module = TmModuleGetByName((char *)logger->name);
if (tm_module == NULL) {
SCLogError(SC_ERR_INVALID_ARGUMENT,
"TmModuleGetByName for %s failed", logger->name);
exit(EXIT_FAILURE);
}
if (tm_module->ThreadExitPrintStats) {
tm_module->ThreadExitPrintStats(tv, store->thread_data);
if (logger->ThreadExitPrintStats) {
logger->ThreadExitPrintStats(tv, store->thread_data);
}
logger = logger->next;

@ -45,8 +45,10 @@ typedef int (*StreamingLogger)(ThreadVars *, void *thread_data,
const Flow *f, const uint8_t *data, uint32_t data_len,
uint64_t tx_id, uint8_t flags);
int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc, OutputCtx *,
enum OutputStreamingType);
int OutputRegisterStreamingLogger(const char *name, StreamingLogger LogFunc,
OutputCtx *, enum OutputStreamingType, ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
void TmModuleStreamingLoggerRegister (void);

@ -587,7 +587,9 @@ error:
void
OutputRegisterStreamingModule(const char *name, const char *conf_name,
OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc,
enum OutputStreamingType stream_type)
enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats)
{
if (unlikely(StreamingLogFunc == NULL)) {
goto error;
@ -603,6 +605,9 @@ OutputRegisterStreamingModule(const char *name, const char *conf_name,
module->InitFunc = InitFunc;
module->StreamingLogFunc = StreamingLogFunc;
module->stream_type = stream_type;
module->ThreadInit = ThreadInit;
module->ThreadDeinit = ThreadDeinit;
module->ThreadExitPrintStats = ThreadExitPrintStats;
TAILQ_INSERT_TAIL(&output_modules, module, entries);
SCLogDebug("Streaming logger \"%s\" registered.", name);
@ -623,7 +628,9 @@ error:
void
OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type)
StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats)
{
if (unlikely(StreamingLogFunc == NULL)) {
goto error;
@ -640,6 +647,9 @@ OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
module->InitSubFunc = InitFunc;
module->StreamingLogFunc = StreamingLogFunc;
module->stream_type = stream_type;
module->ThreadInit = ThreadInit;
module->ThreadDeinit = ThreadDeinit;
module->ThreadExitPrintStats = ThreadExitPrintStats;
TAILQ_INSERT_TAIL(&output_modules, module, entries);
SCLogDebug("Streaming logger \"%s\" registered.", name);

@ -153,10 +153,14 @@ void OutputRegisterFlowSubModule(const char *parent_name, const char *name,
void OutputRegisterStreamingModule(const char *name, const char *conf_name,
OutputCtx *(*InitFunc)(ConfNode *), StreamingLogger StreamingLogFunc,
enum OutputStreamingType stream_type);
enum OutputStreamingType stream_type, ThreadInitFunc ThreadInit,
ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
void OutputRegisterStreamingSubModule(const char *parent_name, const char *name,
const char *conf_name, OutputCtx *(*InitFunc)(ConfNode *, OutputCtx *),
StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type);
StreamingLogger StreamingLogFunc, enum OutputStreamingType stream_type,
ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit,
ThreadExitPrintStatsFunc ThreadExitPrintStats);
void OutputRegisterStatsModule(const char *name, const char *conf_name,
OutputCtx *(*InitFunc)(ConfNode *), StatsLogger StatsLogFunc,

@ -711,7 +711,8 @@ static void SetupOutput(const char *name, OutputModule *module, OutputCtx *outpu
} else if (module->StreamingLogFunc) {
SCLogDebug("%s is a streaming logger", module->name);
OutputRegisterStreamingLogger(module->name, module->StreamingLogFunc,
output_ctx, module->stream_type);
output_ctx, module->stream_type, module->ThreadInit,
module->ThreadDeinit, module->ThreadExitPrintStats);
/* need one instance of the streaming logger module */
if (streaming_logger_module == NULL) {

@ -214,7 +214,6 @@ const char * TmModuleTmmIdToString(TmmId id)
CASE_CODE (TMM_ALERTDEBUGLOG);
CASE_CODE (TMM_RESPONDREJECT);
CASE_CODE (TMM_LOGTLSLOG);
CASE_CODE (TMM_LOGTCPDATALOG);
CASE_CODE (TMM_PCAPLOG);
CASE_CODE (TMM_DECODEIPFW);
CASE_CODE (TMM_VERDICTIPFW);

@ -44,7 +44,6 @@ typedef enum {
TMM_ALERTDEBUGLOG,
TMM_RESPONDREJECT,
TMM_LOGTLSLOG,
TMM_LOGTCPDATALOG,
TMM_OUTPUTJSON,
TMM_PCAPLOG,
TMM_DECODEIPFW,

Loading…
Cancel
Save