]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
eve/json: handle common options in central function
authorVictor Julien <victor@inliniac.net>
Tue, 9 Oct 2018 12:08:56 +0000 (14:08 +0200)
committerVictor Julien <victor@inliniac.net>
Tue, 9 Oct 2018 15:22:01 +0000 (17:22 +0200)
16 files changed:
src/output-json-alert.c
src/output-json-dnp3.c
src/output-json-dns.c
src/output-json-drop.c
src/output-json-flow.c
src/output-json-http.c
src/output-json-ikev2.c
src/output-json-krb5.c
src/output-json-metadata.c
src/output-json-netflow.c
src/output-json-nfs.c
src/output-json-smtp.c
src/output-json-ssh.c
src/output-json-tls.c
src/output-json.c
src/output-json.h

index 081a9a1925301bfed117eebd6da17fb1194849fe..697c9603acf71ba5609ab5086396c0bd1833cad9 100644 (file)
@@ -424,9 +424,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
 
-    if (json_output_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, p->flow, js);
-    }
+    JsonAddCommonOptions(&json_output_ctx->cfg, p, p->flow, js);
 
     for (i = 0; i < p->alerts.cnt; i++) {
         const PacketAlert *pa = &p->alerts.alerts[i];
index 6b415627e31093ee7ea6fd447440745e614ac570..0e6d799ce3e82e01016e36c5fb31137340c4c17d 100644 (file)
@@ -316,9 +316,9 @@ static int JsonDNP3LoggerToServer(ThreadVars *tv, void *thread_data,
         if (unlikely(js == NULL)) {
             return TM_ECODE_OK;
         }
-        if (thread->dnp3log_ctx->cfg.include_metadata) {
-            JsonAddMetadata(p, f, js);
-        }
+
+        JsonAddCommonOptions(&thread->dnp3log_ctx->cfg, p, f, js);
+
         json_t *dnp3js = JsonDNP3LogRequest(tx);
         if (dnp3js != NULL) {
             json_object_set_new(js, "dnp3", dnp3js);
@@ -345,9 +345,9 @@ static int JsonDNP3LoggerToClient(ThreadVars *tv, void *thread_data,
         if (unlikely(js == NULL)) {
             return TM_ECODE_OK;
         }
-        if (thread->dnp3log_ctx->cfg.include_metadata) {
-            JsonAddMetadata(p, f, js);
-        }
+
+        JsonAddCommonOptions(&thread->dnp3log_ctx->cfg, p, f, js);
+
         json_t *dnp3js = JsonDNP3LogResponse(tx);
         if (dnp3js != NULL) {
             json_object_set_new(js, "dnp3", dnp3js);
index 507fb9325b2bc6bf33fdf94208e70a7e0c518d12..c963eec73aa121f830bf8da878ee5d4205a69130 100644 (file)
@@ -1029,9 +1029,8 @@ static int JsonDnsLoggerToServer(ThreadVars *tv, void *thread_data,
         if (unlikely(js == NULL)) {
             return TM_ECODE_OK;
         }
-        if (dnslog_ctx->cfg.include_metadata) {
-            JsonAddMetadata(p, f, js);
-        }
+        JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
+
         json_t *dns = rs_dns_log_json_query(txptr, i, td->dnslog_ctx->flags);
         if (unlikely(dns == NULL)) {
             json_decref(js);
@@ -1049,9 +1048,8 @@ static int JsonDnsLoggerToServer(ThreadVars *tv, void *thread_data,
         js = CreateJSONHeader(p, LOG_DIR_PACKET, "dns");
         if (unlikely(js == NULL))
             return TM_ECODE_OK;
-        if (dnslog_ctx->include_metadata) {
-            JsonAddMetadata(p, f, js);
-        }
+
+        JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
 
         LogQuery(td, js, tx, tx_id, query);
 
@@ -1078,9 +1076,7 @@ static int JsonDnsLoggerToClient(ThreadVars *tv, void *thread_data,
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
 
-    if (dnslog_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&dnslog_ctx->cfg, p, f, js);
 
 #if HAVE_RUST
     if (td->dnslog_ctx->version == DNS_VERSION_2) {
index 87382e9420cda1128084df1bc5f838461fcb58ac..48b05688d62bf49c0e26fa5e2c3b9fe020367268 100644 (file)
@@ -93,9 +93,7 @@ static int DropLogJSON (JsonDropLogThread *aft, const Packet *p)
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
 
-    if (drop_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, p->flow, js);
-    }
+    JsonAddCommonOptions(&drop_ctx->cfg, p, p->flow, js);
 
     json_t *djs = json_object();
     if (unlikely(djs == NULL)) {
index 7f28d0ef9b4ffe6ab554dc37f6b25effc8610f34..d5a34a22b266aea981dbafe8ae546c4b888104e2 100644 (file)
@@ -277,9 +277,7 @@ static void JsonFlowLogJSON(JsonFlowLogThread *aft, json_t *js, Flow *f)
 
     json_object_set_new(js, "flow", hjs);
 
-    if (flow_ctx->cfg.include_metadata) {
-        JsonAddMetadata(NULL, f, js);
-    }
+    JsonAddCommonOptions(&flow_ctx->cfg, NULL, f, js);
 
     /* TCP */
     if (f->proto == IPPROTO_TCP) {
index 6fa33a3232959c26dc3ab4d1b77a4b75cad7900a..b4898ab6565f5153765b681fbe7304001b38f1de 100644 (file)
@@ -471,9 +471,7 @@ static int JsonHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
 
-    if (jhl->httplog_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&jhl->httplog_ctx->cfg, p, f, js);
 
     SCLogDebug("got a HTTP request and now logging !!");
 
index dcce48681b842c5f65f89b06a89ea8771841bea0..b0e5ec484c3d26f5b87c61b5d2d2600dfc9387eb 100644 (file)
@@ -75,9 +75,7 @@ static int JsonIKEv2Logger(ThreadVars *tv, void *thread_data,
         return TM_ECODE_FAILED;
     }
 
-    if (thread->ikev2log_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&thread->ikev2log_ctx->cfg, p, f, js);
 
     ikev2js = rs_ikev2_log_json_response(state, ikev2tx);
     if (unlikely(ikev2js == NULL)) {
index 02424571d36266ef7334d65ae6b4e3c882d2a901..62c18114cbeeb9b2c411310dbb1138980c7681aa 100644 (file)
@@ -75,9 +75,7 @@ static int JsonKRB5Logger(ThreadVars *tv, void *thread_data,
         return TM_ECODE_FAILED;
     }
 
-    if (thread->krb5log_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&thread->krb5log_ctx->cfg, p, f, js);
 
     krb5js = rs_krb5_log_json_response(state, krb5tx);
     if (unlikely(krb5js == NULL)) {
index de918d3ea1b0f2f6fc06b721cc345784755049b4..c90e1f98f4553c7de1c9b5030f1671bb85d9bfa9 100644 (file)
@@ -71,6 +71,7 @@
 
 typedef struct MetadataJsonOutputCtx_ {
     LogFileCtx* file_ctx;
+    OutputJsonCommonSettings cfg;
 } MetadataJsonOutputCtx;
 
 typedef struct JsonMetadataLogThread_ {
@@ -86,7 +87,7 @@ static int MetadataJson(ThreadVars *tv, JsonMetadataLogThread *aft, const Packet
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
 
-    JsonAddMetadata(p, p->flow, js);
+    JsonAddCommonOptions(&aft->json_output_ctx->cfg, p, p->flow, js);
     OutputJSONBuffer(js, aft->file_ctx, &aft->json_buffer);
     json_object_del(js, "metadata");
     json_object_clear(js);
@@ -214,6 +215,7 @@ static OutputInitResult JsonMetadataLogInitCtx(ConfNode *conf)
     memset(json_output_ctx, 0, sizeof(MetadataJsonOutputCtx));
 
     json_output_ctx->file_ctx = logfile_ctx;
+    json_output_ctx->cfg.include_metadata = true;
 
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonMetadataLogDeInitCtx;
@@ -245,6 +247,9 @@ static OutputInitResult JsonMetadataLogInitCtxSub(ConfNode *conf, OutputCtx *par
     memset(json_output_ctx, 0, sizeof(MetadataJsonOutputCtx));
 
     json_output_ctx->file_ctx = ajt->file_ctx;
+    json_output_ctx->cfg = ajt->cfg;
+    /* override config setting as this logger is about metadata */
+    json_output_ctx->cfg.include_metadata = true;
 
     output_ctx->data = json_output_ctx;
     output_ctx->DeInit = JsonMetadataLogDeInitCtxSub;
index 1437f70109d08636903bd127115db90b4a1cb808..13bc7a6024093f521c225c88028a2def16b22518 100644 (file)
@@ -313,9 +313,7 @@ static int JsonNetFlowLogger(ThreadVars *tv, void *thread_data, Flow *f)
     if (unlikely(js == NULL))
         return TM_ECODE_OK;
     JsonNetFlowLogJSONToServer(jhl, js, f);
-    if (netflow_ctx->cfg.include_metadata) {
-        JsonAddMetadata(NULL, f, js);
-    }
+    JsonAddCommonOptions(&netflow_ctx->cfg, NULL, f, js);
     OutputJSONBuffer(js, jhl->flowlog_ctx->file_ctx, &jhl->buffer);
     json_object_del(js, "netflow");
     json_object_clear(js);
@@ -329,9 +327,7 @@ static int JsonNetFlowLogger(ThreadVars *tv, void *thread_data, Flow *f)
         if (unlikely(js == NULL))
             return TM_ECODE_OK;
         JsonNetFlowLogJSONToClient(jhl, js, f);
-        if (netflow_ctx->cfg.include_metadata) {
-            JsonAddMetadata(NULL, f, js);
-        }
+        JsonAddCommonOptions(&netflow_ctx->cfg, NULL, f, js);
         OutputJSONBuffer(js, jhl->flowlog_ctx->file_ctx, &jhl->buffer);
         json_object_del(js, "netflow");
         json_object_clear(js);
index 67adfdc1b2540d1ddc58181bc4649b0ac874f6bb..5274adc58190654c58e86c1646e30faf0372cb4c 100644 (file)
@@ -91,9 +91,7 @@ static int JsonNFSLogger(ThreadVars *tv, void *thread_data,
         return TM_ECODE_FAILED;
     }
 
-    if (thread->ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&thread->ctx->cfg, p, f, js);
 
     json_t *rpcjs = rs_rpc_log_json_response(tx);
     if (unlikely(rpcjs == NULL)) {
index 4bbfc93226aefdb25b55849ed1d7c01c9f924bed..b8079ab01211ce9da881cc0c96483b1f63af6d05 100644 (file)
@@ -95,9 +95,7 @@ static int JsonSmtpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Fl
     /* reset */
     MemBufferReset(jhl->buffer);
 
-    if (jhl->emaillog_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&jhl->emaillog_ctx->cfg, p, f, js);
 
     json_t *sjs = JsonSmtpDataLogger(f, state, tx, tx_id);
     if (sjs) {
index 7ed4843713dd1beb6841e04fc227d1a0d364685a..c174eabfb33928e1694765f854b85b1e63b67d0f 100644 (file)
@@ -109,9 +109,7 @@ static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p,
     if (unlikely(js == NULL))
         return 0;
 
-    if (ssh_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&ssh_ctx->cfg, p, f, js);
 
     json_t *tjs = json_object();
     if (tjs == NULL) {
index 1081034a2be4bfd65db019a89678199ce6859657..9284f79f142e372cd7994fe5b9821621f102a1f4 100644 (file)
@@ -382,9 +382,7 @@ static int JsonTlsLogger(ThreadVars *tv, void *thread_data, const Packet *p,
         return 0;
     }
 
-    if (tls_ctx->cfg.include_metadata) {
-        JsonAddMetadata(p, f, js);
-    }
+    JsonAddCommonOptions(&tls_ctx->cfg, p, f, js);
 
     json_t *tjs = json_object();
     if (tjs == NULL) {
index d4bedf6db0fb9e2f40f0dcd86a34e496231d9fff..87bcec30b65b5c4cc58b4b82bfe6282a29d77d04 100644 (file)
@@ -364,7 +364,7 @@ static void JsonAddFlowVars(const Flow *f, json_t *js_root, json_t **js_traffic)
 /**
  * \brief Add top-level metadata to the eve json object.
  */
-void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js)
+static void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js)
 {
     if ((p && p->pktvar) || (f && f->flowvar)) {
         json_t *js_vars = json_object();
@@ -385,6 +385,14 @@ void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js)
     }
 }
 
+void JsonAddCommonOptions(const OutputJsonCommonSettings *cfg,
+        const Packet *p, const Flow *f, json_t *js)
+{
+    if (cfg->include_metadata) {
+        JsonAddMetadata(p, f, js);
+    }
+}
+
 /** \brief jsonify tcp flags field
  *  Only add 'true' fields in an attempt to keep things reasonably compact.
  */
index 134bee88af7d3a4d0c10b70bd64143e65fe1daf8..140ab65cc0b5bb4f82604f3758fca464a38fce58 100644 (file)
@@ -50,7 +50,6 @@ typedef struct OutputJSONMemBufferWrapper_ {
 
 int OutputJSONMemBufferCallback(const char *str, size_t size, void *data);
 
-void JsonAddMetadata(const Packet *p, const Flow *f, json_t *js);
 void CreateJSONFlowId(json_t *js, const Flow *f);
 void JsonTcpFlags(uint8_t flags, json_t *js);
 void JsonFiveTuple(const Packet *, enum OutputJsonLogDirection, json_t *);
@@ -88,6 +87,9 @@ json_t *SCJsonBool(int val);
 json_t *SCJsonString(const char *val);
 void SCJsonDecref(json_t *js);
 
+void JsonAddCommonOptions(const OutputJsonCommonSettings *cfg,
+        const Packet *p, const Flow *f, json_t *js);
+
 #endif /* HAVE_LIBJANSSON */
 
 #endif /* __OUTPUT_JSON_H__ */