]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rust/dns: add dns to dns alerts
authorJason Ish <ish@unx.ca>
Wed, 23 Jan 2019 20:08:21 +0000 (14:08 -0600)
committerVictor Julien <victor@inliniac.net>
Fri, 8 Feb 2019 06:21:14 +0000 (07:21 +0100)
src/output-json-alert.c
src/output-json-dns.c
src/output-json-dns.h

index 697c9603acf71ba5609ab5086396c0bd1833cad9..16db84b00e207da7c8577dc445df729a3b6ac346 100644 (file)
@@ -189,29 +189,26 @@ static void AlertJsonDnp3(const Flow *f, const uint64_t tx_id, json_t *js)
 
 static void AlertJsonDns(const Flow *f, const uint64_t tx_id, json_t *js)
 {
-#ifndef HAVE_RUST
     DNSState *dns_state = (DNSState *)FlowGetAppState(f);
     if (dns_state) {
-        DNSTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_DNS,
-                                                 dns_state, tx_id);
-        if (tx) {
+        void *txptr = AppLayerParserGetTx(f->proto, ALPROTO_DNS,
+                                          dns_state, tx_id);
+        if (txptr) {
             json_t *dnsjs = json_object();
             if (unlikely(dnsjs == NULL)) {
                 return;
             }
-
-            json_t *qjs = JsonDNSLogQuery(tx, tx_id);
+            json_t *qjs = JsonDNSLogQuery(txptr, tx_id);
             if (qjs != NULL) {
                 json_object_set_new(dnsjs, "query", qjs);
             }
-            json_t *ajs = JsonDNSLogAnswer(tx, tx_id);
+            json_t *ajs = JsonDNSLogAnswer(txptr, tx_id);
             if (ajs != NULL) {
                 json_object_set_new(dnsjs, "answer", ajs);
             }
             json_object_set_new(js, "dns", dnsjs);
         }
     }
-#endif
     return;
 }
 
index 02dc438fb3992c60c0b1b58e2e9c036226513c62..5de09758ffa4e6b6c15ffe5c90e7b1df9e5c671a 100644 (file)
@@ -444,23 +444,6 @@ static json_t *OutputQuery(DNSTransaction *tx, uint64_t tx_id, DNSQueryEntry *en
     return djs;
 }
 
-json_t *JsonDNSLogQuery(DNSTransaction *tx, uint64_t tx_id)
-{
-    DNSQueryEntry *entry = NULL;
-    json_t *queryjs = json_array();
-    if (queryjs == NULL)
-        return NULL;
-
-    TAILQ_FOREACH(entry, &tx->query_list, next) {
-        json_t *qjs = OutputQuery(tx, tx_id, entry);
-        if (qjs != NULL) {
-            json_array_append_new(queryjs, qjs);
-        }
-    }
-
-    return queryjs;
-}
-
 static void LogQuery(LogDnsLogThread *aft, json_t *js, DNSTransaction *tx,
         uint64_t tx_id, DNSQueryEntry *entry)
 {
@@ -485,6 +468,34 @@ static void LogQuery(LogDnsLogThread *aft, json_t *js, DNSTransaction *tx,
 }
 #endif
 
+json_t *JsonDNSLogQuery(void *txptr, uint64_t tx_id)
+{
+    json_t *queryjs = json_array();
+    if (queryjs == NULL)
+        return NULL;
+
+#ifdef HAVE_RUST
+    for (uint16_t i = 0; i < UINT16_MAX; i++) {
+        json_t *dns = rs_dns_log_json_query((void *)txptr, i, LOG_ALL_RRTYPES);
+        if (unlikely(dns == NULL)) {
+            break;
+        }
+        json_array_append_new(queryjs, dns);
+    }
+#else
+    DNSTransaction *tx = txptr;
+    DNSQueryEntry *entry = NULL;
+    TAILQ_FOREACH(entry, &tx->query_list, next) {
+        json_t *qjs = OutputQuery(tx, tx_id, entry);
+        if (qjs != NULL) {
+            json_array_append_new(queryjs, qjs);
+        }
+    }
+#endif
+
+    return queryjs;
+}
+
 #ifndef HAVE_RUST
 
 static json_t *DnsParseSshFpType(DNSAnswerEntry *entry, uint8_t *ptr)
@@ -917,20 +928,21 @@ static void OutputAnswerV2(LogDnsLogThread *aft, json_t *djs,
         OutputJSONBuffer(djs, aft->dnslog_ctx->file_ctx, &aft->buffer);
     }
 }
+#endif
 
-json_t *JsonDNSLogAnswer(DNSTransaction *tx, uint64_t tx_id)
+json_t *JsonDNSLogAnswer(void *txptr, uint64_t tx_id)
 {
+#ifdef HAVE_RUST
+    return rs_dns_log_json_answer(txptr, LOG_ALL_RRTYPES);
+#else
+    DNSTransaction *tx = txptr;
     DNSAnswerEntry *entry = TAILQ_FIRST(&tx->answer_list);
-    json_t *js = NULL;
-
     if (entry) {
-        js = BuildAnswer(tx, tx_id, LOG_FORMAT_DETAILED, DNS_VERSION_2);
+        return BuildAnswer(tx, tx_id, LOG_FORMAT_DETAILED, DNS_VERSION_2);
     }
-
-    return js;
-}
-
+    return NULL;
 #endif
+}
 
 #ifndef HAVE_RUST
 static void OutputFailure(LogDnsLogThread *aft, json_t *djs,
index 1d3bddff733ac5eded967d9018cc81b8d64e795b..9ad89fc1a197e02505b7b42b60bc791eff96b1f3 100644 (file)
@@ -29,8 +29,8 @@ void JsonDnsLogRegister(void);
 #ifdef HAVE_LIBJANSSON
 #include "app-layer-dns-common.h"
 
-json_t *JsonDNSLogQuery(DNSTransaction *tx, uint64_t tx_id) __attribute__((nonnull));
-json_t *JsonDNSLogAnswer(DNSTransaction *tx, uint64_t tx_id) __attribute__((nonnull));
+json_t *JsonDNSLogQuery(void *txptr, uint64_t tx_id) __attribute__((nonnull));
+json_t *JsonDNSLogAnswer(void *txptr, uint64_t tx_id) __attribute__((nonnull));
 #endif
 
 #endif /* __OUTPUT_JSON_DNS_H__ */