Go to the documentation of this file.
34 #define DEFAULT_LOG_FILENAME "tcp-data.log"
36 #define MODULE_NAME "LogTcpDataLog"
38 #define OUTPUT_BUFFER_SIZE 65535
42 static void LogTcpDataLogDeInitCtx(
OutputCtx *);
69 static int LogTcpDataLoggerDir(
ThreadVars *
tv,
void *thread_data,
const Flow *f,
70 const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t
flags)
75 const char *mode =
"a";
80 if (data && data_len) {
81 char srcip[46] =
"", dstip[46] =
"";
83 PrintInet(AF_INET, (
const void *)&f->
src.addr_data32[0], srcip,
sizeof(srcip));
84 PrintInet(AF_INET, (
const void *)&f->
dst.addr_data32[0], dstip,
sizeof(dstip));
86 PrintInet(AF_INET6, (
const void *)f->
src.addr_data32, srcip,
sizeof(srcip));
87 PrintInet(AF_INET6, (
const void *)f->
dst.addr_data32, dstip,
sizeof(dstip));
94 snprintf(tx,
sizeof(tx),
"%"PRIu64, tx_id);
97 snprintf(name,
sizeof(name),
"%s/%s/%s_%u-%s_%u-%s-%s.data",
100 srcip, f->
sp, dstip, f->
dp, tx,
103 FILE *fp = fopen(name, mode);
107 fwrite(data, data_len, 1, fp);
114 static int LogTcpDataLoggerFile(
ThreadVars *
tv,
void *thread_data,
const Flow *f,
115 const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t
flags)
121 if (data && data_len) {
122 MemBufferReset(aft->
buffer);
124 char srcip[46] =
"", dstip[46] =
"";
126 PrintInet(AF_INET, (
const void *)&f->
src.addr_data32[0], srcip,
sizeof(srcip));
127 PrintInet(AF_INET, (
const void *)&f->
dst.addr_data32[0], dstip,
sizeof(dstip));
129 PrintInet(AF_INET6, (
const void *)f->
src.addr_data32, srcip,
sizeof(srcip));
130 PrintInet(AF_INET6, (
const void *)f->
dst.addr_data32, dstip,
sizeof(dstip));
134 snprintf(name,
sizeof(name),
"%s_%u-%s_%u-%s:",
135 srcip, f->
sp, dstip, f->
dp,
139 aft->
buffer->
size, (uint8_t *)name,strlen(name));
152 const uint8_t *data, uint32_t data_len, uint64_t tx_id, uint8_t
flags)
159 LogTcpDataLoggerDir(
tv, thread_data, f, data, data_len, tx_id,
flags);
161 LogTcpDataLoggerFile(
tv, thread_data, f, data, data_len, tx_id,
flags);
174 SCLogDebug(
"Error getting context. \"initdata\" argument NULL");
180 if (aft->
buffer == NULL) {
214 char filename[PATH_MAX] =
"";
215 char dirname[32] =
"";
219 if(file_ctx == NULL) {
225 if (
unlikely(tcpdatalog_ctx == NULL)) {
230 tcpdatalog_ctx->
file_ctx = file_ctx;
234 if (strcmp(conf->
name,
"tcp-data") == 0) {
236 snprintf(filename,
sizeof(filename),
"%s.log", conf->
name);
237 strlcpy(dirname,
"tcp",
sizeof(dirname));
238 }
else if (strcmp(conf->
name,
"http-body-data") == 0) {
240 snprintf(filename,
sizeof(filename),
"%s.log", conf->
name);
241 strlcpy(dirname,
"http",
sizeof(dirname));
249 if (strcmp(logtype,
"file") == 0) {
250 tcpdatalog_ctx->
file = 1;
251 }
else if (strcmp(logtype,
"dir") == 0) {
252 tcpdatalog_ctx->
dir = 1;
253 }
else if (strcmp(logtype,
"both") == 0) {
254 tcpdatalog_ctx->
file = 1;
255 tcpdatalog_ctx->
dir = 1;
258 tcpdatalog_ctx->
file = 1;
259 tcpdatalog_ctx->
dir = 0;
262 if (tcpdatalog_ctx->
file == 1) {
271 if (tcpdatalog_ctx->
dir == 1) {
273 char dirfull[PATH_MAX];
276 snprintf(dirfull, PATH_MAX,
"%s/%s", tcpdatalog_ctx->
log_dir, dirname);
278 SCLogInfo(
"using directory %s", dirfull);
289 output_ctx->
data = tcpdatalog_ctx;
290 output_ctx->
DeInit = LogTcpDataLogDeInitCtx;
292 SCLogDebug(
"Streaming log output initialized");
293 result.
ctx = output_ctx;
300 SCLogError(
"Syntax error in custom http log format string.");
305 static void LogTcpDataLogDeInitCtx(
OutputCtx *output_ctx)
void OutputRegisterStreamingModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, SCStreamingLogger StreamingLogFunc, enum SCOutputStreamingType stream_type, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a streaming data output module.
#define DEFAULT_LOG_FILENAME
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
#define OUTPUT_BUFFER_SIZE
enum SCOutputStreamingType type
int(* Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp)
TmEcode LogTcpDataLogThreadInit(ThreadVars *, const void *, void **)
#define OUTPUT_STREAMING_FLAG_TRANSACTION
void LogTcpDataLogRegister(void)
int SCConfLogOpenGeneric(ConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
open a generic output "log file", which may be a regular file or a socket
size_t strlcpy(char *dst, const char *src, size_t siz)
void PrintRawDataToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32_t dst_buf_size, const uint8_t *src_buf, uint32_t src_buf_len)
Per thread variable structure.
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)
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
void PrintRawUriBuf(char *retbuf, uint32_t *offset, uint32_t retbuflen, uint8_t *buf, size_t buflen)
OutputInitResult LogTcpDataLogInitCtx(ConfNode *conf)
Create a new http log LogFileCtx.
#define OUTPUT_STREAMING_FLAG_OPEN
void(* DeInit)(struct OutputCtx_ *)
LogTcpDataFileCtx * tcpdatalog_ctx
void MemBufferFree(MemBuffer *buffer)
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
const char * ConfigGetLogDirectory(void)
#define OUTPUT_STREAMING_FLAG_TOSERVER
#define SCLogError(...)
Macro used to log ERROR messages.
struct LogTcpDataFileCtx_ LogTcpDataFileCtx
TmEcode LogTcpDataLogThreadDeinit(ThreadVars *, void *)
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
#define MEMBUFFER_BUFFER(mem_buffer)
Get the MemBuffers underlying buffer.
#define MEMBUFFER_OFFSET(mem_buffer)
Get the MemBuffers current offset.
MemBuffer * MemBufferCreateNew(uint32_t size)
struct LogTcpDataLogThread_ LogTcpDataLogThread
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.