Go to the documentation of this file.
68 #define MODULE_NAME "JsonFrameLog"
83 #if 0 // TODO see if this is useful in some way
84 static inline bool NeedsAsHex(uint8_t c)
104 static void PayloadAsHex(
const uint8_t *data, uint32_t data_len,
char *
str,
size_t str_len)
107 for (uint32_t i = 0; i < data_len; i++) {
108 if (NeedsAsHex(data[i])) {
110 snprintf(hex_str,
sizeof(hex_str),
"%s%02X", !hex ?
"|" :
" ", data[i]);
115 snprintf(p_str,
sizeof(p_str),
"%s%c", hex ?
"|" :
"", data[i]);
132 static int FrameJsonStreamDataCallback(
133 void *cb_data,
const uint8_t *input,
const uint32_t input_len,
const uint64_t input_offset)
138 uint32_t write_size = input_len;
142 const uint64_t data_re = input_offset + input_len;
146 if (input_offset >= frame_re) {
150 if (data_re >= frame_re) {
151 const uint64_t to_write = frame_re - input_offset;
152 if (to_write < (uint64_t)write_size) {
153 write_size = (uint32_t)to_write;
158 if (input_offset > cbd->
last_re) {
160 cbd->
payload,
"[%" PRIu64
" bytes missing]", input_offset - cbd->
last_re);
163 if (write_size > 0) {
165 if (written < write_size)
168 cbd->
last_re = input_offset + write_size;
178 MemBufferReset(buffer);
182 bool complete =
false;
192 ssn, stream, FrameJsonStreamDataCallback, &cbd,
frame->
offset, &unused,
false);
207 jb_set_string(jb,
"payload_printable", (
char *)printable_buf);
208 jb_set_bool(jb,
"complete", complete);
212 static void FrameAddPayloadUDP(JsonBuilder *js,
const Packet *p,
const Frame *
frame)
231 const uint32_t data_len = frame_len;
233 const uint32_t log_data_len =
MIN(data_len, 256);
234 jb_set_base64(js,
"payload", data, log_data_len);
236 uint8_t printable_buf[log_data_len + 1];
239 printable_buf[log_data_len] =
'\0';
240 jb_set_string(js,
"payload_printable", (
char *)printable_buf);
242 char pretty_buf[data_len * 4 + 1];
243 pretty_buf[0] =
'\0';
244 PayloadAsHex(data, data_len, pretty_buf, data_len * 4 + 1);
245 jb_set_string(js,
"payload_hex", pretty_buf);
259 jb_open_object(jb,
"frame");
261 jb_set_string(jb,
"type",
"stream");
265 jb_set_uint(jb,
"id",
frame->
id);
266 jb_set_string(jb,
"direction",
PKT_IS_TOSERVER(p) ?
"toserver" :
"toclient");
268 if (ipproto == IPPROTO_TCP) {
275 jb_set_uint(jb,
"length",
len);
277 jb_set_uint(jb,
"length",
frame->
len);
279 FrameAddPayloadTCP(f, f->
protoctx, stream,
frame, jb, buffer);
281 jb_set_uint(jb,
"length",
frame->
len);
282 FrameAddPayloadUDP(jb, p,
frame);
297 frames = &frames_container->
toserver;
299 frames = &frames_container->
toclient;
302 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
332 if (frames_container == NULL)
335 if (p->
proto == IPPROTO_UDP) {
336 return FrameJsonUdp(
tv, aft, p, p->
flow, frames_container);
351 frames = &frames_container->
toserver;
357 frames = &frames_container->
toclient;
363 for (uint32_t idx = 0; idx < frames->
cnt; idx++) {
374 if (!eof && ((
frame->
len == -1) || (win < frame->
len)) && win < 2500) {
375 SCLogDebug(
"frame id %" PRIi64
" len %" PRIi64
", win %" PRIi64
376 ", skipping logging",
403 return FrameJson(
tv, aft, p);
412 if (p->
proto == IPPROTO_TCP) {
425 if (frames_container == NULL)
430 frames = &frames_container->
toserver;
432 frames = &frames_container->
toclient;
434 return (frames->
cnt != 0);
439 static TmEcode JsonFrameLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
445 if (initdata == NULL) {
446 SCLogDebug(
"Error getting context for EveLogFrame. \"initdata\" argument NULL");
492 static void JsonFrameLogDeInitCtxSub(
OutputCtx *output_ctx)
494 SCLogDebug(
"cleaning up sub output_ctx %p", output_ctx);
498 if (json_output_ctx != NULL) {
520 if (
unlikely(json_output_ctx == NULL)) {
524 uint32_t payload_buffer_size = 4096;
527 if (payload_buffer_value != NULL) {
530 SCLogError(
"Error parsing payload-buffer-size \"%s\"", payload_buffer_value);
533 payload_buffer_size = value;
538 json_output_ctx->
eve_ctx = ajt;
541 output_ctx->
data = json_output_ctx;
542 output_ctx->
DeInit = JsonFrameLogDeInitCtxSub;
546 result.
ctx = output_ctx;
551 if (json_output_ctx != NULL) {
554 if (output_ctx != NULL) {
564 JsonFrameLogInitCtxSub, JsonFrameLogger, JsonFrameLogCondition, JsonFrameLogThreadInit,
565 JsonFrameLogThreadDeinit);
#define PKT_IS_TOCLIENT(p)
#define PKT_IS_PSEUDOPKT(p)
return 1 if the packet is a pseudo packet
#define FLOW_PKT_LAST_PSEUDO
void OutputRegisterPacketSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a packet output sub-module.
OutputJsonThreadCtx * ctx
struct FrameJsonOutputCtx_ FrameJsonOutputCtx
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
const char * AppProtoToString(AppProto alproto)
Maps the ALPROTO_*, to its string equivalent.
#define FLOW_TC_APP_UPDATED
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
Frame * FrameGetByIndex(Frames *frames, const uint32_t idx)
const JsonAddrInfo json_addr_info_zero
#define APP_LAYER_PARSER_EOF_TS
void PrintStringsToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32_t dst_buf_size, const uint8_t *src_buf, const uint32_t src_buf_len)
uint64_t StreamTcpGetUsable(const TcpStream *stream, const bool eof)
AppLayerParserState * alparser
#define PKT_IS_TOSERVER(p)
const char * AppLayerParserGetFrameNameById(uint8_t ipproto, AppProto alproto, const uint8_t id)
size_t strlcat(char *, const char *src, size_t siz)
#define FRAME_FLAG_TX_ID_SET
#define STREAM_BASE_OFFSET(stream)
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Per thread variable structure.
#define JB_SET_TRUE(jb, key)
FrameJsonOutputCtx * json_output_ctx
uint32_t payload_buffer_size
FramesContainer * AppLayerFramesGetContainer(Flow *f)
#define APP_LAYER_PARSER_EOF_TC
MemBuffer * payload_buffer
void JsonFrameLogRegister(void)
void(* DeInit)(struct OutputCtx_ *)
void MemBufferFree(MemBuffer *buffer)
#define FLOW_TS_APP_UPDATED
void FrameConfigEnableAll(void)
#define JB_SET_FALSE(jb, key)
int ParseSizeStringU32(const char *size, uint32_t *res)
#define FRAME_STREAM_TYPE
#define SCLogError(...)
Macro used to log ERROR messages.
#define FRAME_FLAG_LOGGED
void FrameJsonLogOneFrame(const uint8_t ipproto, const Frame *frame, Flow *f, const TcpStream *stream, const Packet *p, JsonBuilder *jb, MemBuffer *buffer)
log a single frame
struct JsonFrameLogThread_ JsonFrameLogThread
uint64_t StreamDataRightEdge(const TcpStream *stream, const bool eof)
#define STREAMTCP_FLAG_APP_LAYER_DISABLED
uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
Write a raw buffer to the MemBuffer dst.
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddrInfo *addr)
#define STREAM_APP_PROGRESS(stream)
uint16_t AppLayerParserStateIssetFlag(AppLayerParserState *pstate, uint16_t flag)
AppProto alproto
application level protocol
int StreamReassembleLog(const TcpSession *ssn, const TcpStream *stream, StreamReassembleRawFunc Callback, void *cb_data, const uint64_t progress_in, uint64_t *progress_out, const bool eof)
#define DEBUG_VALIDATE_BUG_ON(exp)
MemBuffer * MemBufferCreateNew(uint32_t size)
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.