59#define MODULE_NAME "JsonAnomalyLog"
61#define ANOMALY_EVENT_TYPE "anomaly"
62#define LOG_JSON_DECODE_TYPE BIT_U16(0)
63#define LOG_JSON_STREAM_TYPE BIT_U16(1)
64#define LOG_JSON_APPLAYER_TYPE BIT_U16(2)
65#define LOG_JSON_PACKETHDR BIT_U16(3)
67#define LOG_JSON_PACKET_TYPE (LOG_JSON_DECODE_TYPE | LOG_JSON_STREAM_TYPE)
68#define ANOMALY_DEFAULTS LOG_JSON_APPLAYER_TYPE
70#define TX_ID_UNUSED UINT64_MAX
86#define MAX_ANOMALY_LOGGERS 1
87static int anomaly_loggers = 0;
88static bool OutputAnomalyLoggerEnable(
void)
97static void OutputAnomalyLoggerDisable(
void)
110 for (
int i = 0; i < p->
events.
cnt; i++) {
113 if (is_decode && !log_decode)
115 if (!is_decode && !log_stream)
133 SCJbSetString(js,
"event", event);
136 SCJbSetUint(js,
"code", event_code);
159 SCLogDebug(
"decoder_events %p event_count %d (last logged %d) %s",
160 decoder_events, decoder_events->
cnt,
179 SCJbSetString(js,
"app_proto", alprotoname);
181 const char *event_name = NULL;
182 uint8_t event_code = decoder_events->
events[i];
189 event_code, &event_name, &event_type);
193 SCJbSetString(js,
"event", event_name);
196 SCJbSetUint(js,
"code", event_code);
199 SCJbSetString(js,
"layer", layer);
214 Flow *f,
void *state,
void *tx, uint64_t tx_id)
224 SCLogDebug(
"state %p, tx: %p, tx_id: %"PRIu64, state, tx, tx_id);
225 AnomalyAppLayerDecoderEventJson(
tv, aft, p, decoder_events,
false,
"proto_parser", tx_id);
230static inline bool AnomalyHasParserEvents(
const Packet *p)
236static inline bool AnomalyHasPacketAppLayerEvents(
const Packet *p)
248 rc = AnomalyDecodeEventJson(
tv, aft, p);
255 if (rc ==
TM_ECODE_OK && AnomalyHasPacketAppLayerEvents(p)) {
256 rc = AnomalyAppLayerDecoderEventJson(
261 if (rc ==
TM_ECODE_OK && AnomalyHasParserEvents(p)) {
265 rc = AnomalyAppLayerDecoderEventJson(
285 return AnomalyJson(
tv, aft, p);
288static bool JsonAnomalyLogCondition(
ThreadVars *
tv,
void *thread_data,
const Packet *p)
292 AnomalyHasParserEvents(p);
295static TmEcode JsonAnomalyLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
302 if (initdata == NULL) {
303 SCLogDebug(
"Error getting context for EveLogAnomaly. \"initdata\" argument NULL");
340static void JsonAnomalyLogDeInitCtxSubHelper(
OutputCtx *output_ctx)
342 SCLogDebug(
"cleaning up sub output_ctx %p", output_ctx);
346 if (json_output_ctx != NULL) {
352static void JsonAnomalyLogDeInitCtxSub(
OutputCtx *output_ctx)
354 OutputAnomalyLoggerDisable();
356 JsonAnomalyLogDeInitCtxSubHelper(output_ctx);
359static void SetFlag(
const SCConfNode *conf,
const char *
name, uint16_t flag, uint16_t *out_flags)
363 if (setting != NULL) {
374 static bool warn_no_flags =
false;
375 static bool warn_no_packet =
false;
380 if (typeconf != NULL) {
388 SCLogWarning(
"Anomaly logging configured to include packet headers, however decode "
389 "type logging has not been selected. Packet headers will not be logged.");
390 warn_no_packet =
true;
391 flags &= ~LOG_JSON_PACKETHDR;
394 if (
flags == 0 && !warn_no_flags) {
395 SCLogWarning(
"Anomaly logging has been configured; however, no logging types "
396 "have been selected. Select one or more logging types.");
397 warn_no_flags =
true;
413 if (
unlikely(json_output_ctx == NULL)) {
417 JsonAnomalyLogConf(json_output_ctx, conf);
418 json_output_ctx->
eve_ctx = ajt;
420 output_ctx->
data = json_output_ctx;
421 output_ctx->
DeInit = JsonAnomalyLogDeInitCtxSubHelper;
423 result.
ctx = output_ctx;
441 if (!OutputAnomalyLoggerEnable()) {
450 result.
ctx->
DeInit = JsonAnomalyLogDeInitCtxSub;
460 .FlushFunc = JsonAnomalyFlush,
461 .ConditionFunc = JsonAnomalyLogCondition,
462 .ThreadInitFunc = JsonAnomalyLogThreadInit,
463 .ThreadDeinitFunc = JsonAnomalyLogThreadDeinit,
464 .ThreadExitPrintStatsFunc = NULL,
468 JsonAnomalyLogInitCtxSub, &output_logger_functions);
472 JsonAnomalyLogThreadInit, JsonAnomalyLogThreadDeinit);
int AppLayerGetEventInfoById(uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
bool AppLayerParserHasDecoderEvents(AppLayerParserState *pstate)
AppLayerDecoderEvents * AppLayerParserGetDecoderEvents(AppLayerParserState *pstate)
int AppLayerParserGetEventInfoById(uint8_t ipproto, AppProto alproto, uint8_t event_id, const char **event_name, AppLayerEventType *event_type)
AppLayerDecoderEvents * AppLayerParserGetEventsByTx(uint8_t ipproto, AppProto alproto, void *tx)
enum AppLayerEventType AppLayerEventType
const char * AppLayerGetProtoName(AppProto alproto)
Given the internal protocol id, returns a string representation of the protocol.
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
int SCConfValIsTrue(const char *val)
Check if a value is true.
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
const struct DecodeEvents_ DEvents[]
#define EVENT_IS_DECODER_PACKET_ERROR(e)
#define LOG_JSON_DECODE_TYPE
struct JsonAnomalyLogThread_ JsonAnomalyLogThread
struct AnomalyJsonOutputCtx_ AnomalyJsonOutputCtx
#define LOG_JSON_PACKETHDR
#define LOG_JSON_STREAM_TYPE
#define LOG_JSON_PACKET_TYPE
#define MAX_ANOMALY_LOGGERS
void JsonAnomalyLogRegister(void)
#define ANOMALY_EVENT_TYPE
#define LOG_JSON_APPLAYER_TYPE
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
void OutputJsonFlush(OutputJsonThreadCtx *ctx)
SCJsonBuilder * CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
void EvePacket(const Packet *p, SCJsonBuilder *js, uint32_t max_length)
Jsonify a packet.
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
SCJsonBuilder * CreateEveHeaderWithTxId(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
void OutputRegisterPacketSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, OutputPacketLoggerFunctions *output_logger_functions)
Register a packet output sub-module.
void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
#define JB_SET_STRING(jb, key, val)
Data structure to store app layer decoder events.
uint8_t event_last_logged
AppProto alproto
application level protocol
AppLayerParserState * alparser
OutputJsonThreadCtx * ctx
AnomalyJsonOutputCtx * json_output_ctx
void(* DeInit)(struct OutputCtx_ *)
uint8_t events[PACKET_ENGINE_EVENT_MAX]
AppLayerDecoderEvents * app_layer_events
PacketEngineEvents events
Per thread variable structure.
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define SCLogError(...)
Macro used to log ERROR messages.
#define DEBUG_VALIDATE_BUG_ON(exp)