41 #define LOG_QUERIES BIT_U64(0)
42 #define LOG_ANSWERS BIT_U64(1)
44 #define LOG_A BIT_U64(2)
45 #define LOG_NS BIT_U64(3)
46 #define LOG_MD BIT_U64(4)
47 #define LOG_MF BIT_U64(5)
48 #define LOG_CNAME BIT_U64(6)
49 #define LOG_SOA BIT_U64(7)
50 #define LOG_MB BIT_U64(8)
51 #define LOG_MG BIT_U64(9)
52 #define LOG_MR BIT_U64(10)
53 #define LOG_NULL BIT_U64(11)
54 #define LOG_WKS BIT_U64(12)
55 #define LOG_PTR BIT_U64(13)
56 #define LOG_HINFO BIT_U64(14)
57 #define LOG_MINFO BIT_U64(15)
58 #define LOG_MX BIT_U64(16)
59 #define LOG_TXT BIT_U64(17)
60 #define LOG_RP BIT_U64(18)
61 #define LOG_AFSDB BIT_U64(19)
62 #define LOG_X25 BIT_U64(20)
63 #define LOG_ISDN BIT_U64(21)
64 #define LOG_RT BIT_U64(22)
65 #define LOG_NSAP BIT_U64(23)
66 #define LOG_NSAPPTR BIT_U64(24)
67 #define LOG_SIG BIT_U64(25)
68 #define LOG_KEY BIT_U64(26)
69 #define LOG_PX BIT_U64(27)
70 #define LOG_GPOS BIT_U64(28)
71 #define LOG_AAAA BIT_U64(29)
72 #define LOG_LOC BIT_U64(30)
73 #define LOG_NXT BIT_U64(31)
74 #define LOG_SRV BIT_U64(32)
75 #define LOG_ATMA BIT_U64(33)
76 #define LOG_NAPTR BIT_U64(34)
77 #define LOG_KX BIT_U64(35)
78 #define LOG_CERT BIT_U64(36)
79 #define LOG_A6 BIT_U64(37)
80 #define LOG_DNAME BIT_U64(38)
81 #define LOG_OPT BIT_U64(39)
82 #define LOG_APL BIT_U64(40)
83 #define LOG_DS BIT_U64(41)
84 #define LOG_SSHFP BIT_U64(42)
85 #define LOG_IPSECKEY BIT_U64(43)
86 #define LOG_RRSIG BIT_U64(44)
87 #define LOG_NSEC BIT_U64(45)
88 #define LOG_DNSKEY BIT_U64(46)
89 #define LOG_DHCID BIT_U64(47)
90 #define LOG_NSEC3 BIT_U64(48)
91 #define LOG_NSEC3PARAM BIT_U64(49)
92 #define LOG_TLSA BIT_U64(50)
93 #define LOG_HIP BIT_U64(51)
94 #define LOG_CDS BIT_U64(52)
95 #define LOG_CDNSKEY BIT_U64(53)
96 #define LOG_SPF BIT_U64(54)
97 #define LOG_TKEY BIT_U64(55)
98 #define LOG_TSIG BIT_U64(56)
99 #define LOG_MAILA BIT_U64(57)
100 #define LOG_ANY BIT_U64(58)
101 #define LOG_URI BIT_U64(59)
103 #define LOG_FORMAT_GROUPED BIT_U64(60)
104 #define LOG_FORMAT_DETAILED BIT_U64(61)
105 #define LOG_HTTPS BIT_U64(62)
107 #define LOG_FORMAT_ALL (LOG_FORMAT_GROUPED|LOG_FORMAT_DETAILED)
108 #define LOG_ALL_RRTYPES (~(uint64_t)(LOG_QUERIES|LOG_ANSWERS|LOG_FORMAT_DETAILED|LOG_FORMAT_GROUPED))
176 } dns_rrtype_fields[] = {
259 SCJsonBuilderMark mark = { 0, 0, 0 };
261 SCJbGetMark(js, &mark);
263 bool r = SCHttp2LogJson(txptr, js);
265 SCJbRestoreMark(js, &mark);
269 if (tx_dns == NULL) {
274 SCJbGetMark(js, &mark);
277 SCJbRestoreMark(js, &mark);
284 void *alstate,
void *txptr, uint64_t tx_id)
290 if (tx_dns == NULL) {
303 SCJsonBuilderMark mark = { 0, 0, 0 };
305 SCJbGetMark(jb, &mark);
307 bool r = SCHttp2LogJson(txptr, jb);
309 SCJbRestoreMark(jb, &mark);
315 if (SCDnsTxIsRequest(tx_dns)) {
319 }
else if (SCDnsTxIsResponse(tx_dns)) {
329 SCJbGetMark(jb, &mark);
333 SCJbRestoreMark(jb, &mark);
344 static int JsonDnsLoggerToServer(
ThreadVars *
tv,
void *thread_data,
345 const Packet *
p,
Flow *
f,
void *alstate,
void *txptr, uint64_t tx_id)
356 for (uint16_t i = 0; i < 0xffff; i++) {
362 SCJbOpenObject(jb,
"dns");
363 SCJbSetInt(jb,
"version", 2);
377 static int JsonDnsLoggerToClient(
ThreadVars *
tv,
void *thread_data,
378 const Packet *
p,
Flow *
f,
void *alstate,
void *txptr, uint64_t tx_id)
395 SCJbOpenObject(jb,
"dns");
396 SCJbSetInt(jb,
"version", 2);
407 void *txptr, uint64_t tx_id)
412 if (dnslog_ctx->
version == DNS_LOG_VERSION_2) {
413 if (SCDnsTxIsRequest(txptr)) {
414 return JsonDnsLoggerToServer(
tv, thread_data,
p,
f, alstate, txptr, tx_id);
415 }
else if (SCDnsTxIsResponse(txptr)) {
416 return JsonDnsLoggerToClient(
tv, thread_data,
p,
f, alstate, txptr, tx_id);
419 if (SCDnsTxIsRequest(txptr)) {
423 }
else if (SCDnsTxIsResponse(txptr)) {
438 if (PacketIsTCP(
p)) {
439 if (SCDnsTxIsRequest(txptr)) {
459 static TmEcode LogDnsLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
467 SCLogDebug(
"Error getting context for EveLogDNS. \"initdata\" argument NULL");
501 static void LogDnsLogDeInitCtxSub(
OutputCtx *output_ctx)
503 SCLogDebug(
"cleaning up sub output_ctx %p", output_ctx);
510 const char *query_key,
const char *answer_key,
const char *answer_types_key)
524 if (response != NULL) {
542 dnslog_ctx->
flags |= dns_rrtype_fields[
f].flags;
552 static uint8_t GetDnsLogVersion(
SCConfNode *conf)
555 return DNS_LOG_VERSION_DEFAULT;
558 char *version_string = NULL;
560 if (version_node != NULL) {
561 version_string = version_node->
val;
564 if (version_string == NULL) {
565 version_string = getenv(
"SURICATA_EVE_DNS_VERSION");
568 if (version_string == NULL) {
569 return DNS_LOG_VERSION_DEFAULT;
576 SCLogWarning(
"Failed to parse EVE DNS log version of \"%s\"", version_string);
577 return DNS_LOG_VERSION_DEFAULT;
580 static uint8_t JsonDnsCheckVersion(
SCConfNode *conf)
582 const uint8_t default_version = DNS_LOG_VERSION_DEFAULT;
583 const uint8_t
version = GetDnsLogVersion(conf);
584 static bool v1_deprecation_warned =
false;
585 static bool v2_deprecation_warned =
false;
589 return DNS_LOG_VERSION_3;
591 if (!v2_deprecation_warned) {
592 SCLogNotice(
"DNS EVE v2 logging has been deprecated and will be removed in "
594 v2_deprecation_warned =
true;
596 return DNS_LOG_VERSION_2;
598 if (!v1_deprecation_warned) {
599 SCLogWarning(
"DNS EVE v1 logging has been removed, will use v2");
600 v1_deprecation_warned =
true;
602 return default_version;
605 "Invalid EVE DNS version %d, will use v%d",
version, DNS_LOG_VERSION_DEFAULT);
606 return default_version;
609 return default_version;
614 dnslog_ctx->
flags = ~0ULL;
617 JsonDnsLogParseConfig(dnslog_ctx, conf,
"requests",
"responses",
"types");
624 if (strcasecmp(field->
val,
"detailed") == 0) {
626 }
else if (strcasecmp(field->
val,
"grouped") == 0) {
636 SCLogWarning(
"Empty EVE DNS format array, using defaults");
662 dnslog_ctx->
version = JsonDnsCheckVersion(conf);
670 output_ctx->
data = dnslog_ctx;
671 output_ctx->
DeInit = LogDnsLogDeInitCtxSub;
673 JsonDnsLogInitFilters(dnslog_ctx, conf);
680 result.
ctx = output_ctx;
686 #define MODULE_NAME "JsonDnsLog"
690 JsonDnsLogInitCtxSub,
ALPROTO_DNS, JsonDnsLogger, LogDnsLogThreadInit,
691 LogDnsLogThreadDeinit);
697 "eve-log.doh2", JsonDnsLogInitCtxSub,
ALPROTO_DOH2, HTTP2TxTypeStream, JsonDoh2Logger,
698 HTTP2ProgData, HTTP2ProgData, LogDnsLogThreadInit, LogDnsLogThreadDeinit);
700 "eve-log.doh2", JsonDnsLogInitCtxSub,
ALPROTO_DOH2, HTTP2TxTypeGlobal, JsonDoh2Logger,
701 HTTP2ProgGlobalComplete, HTTP2ProgGlobalComplete, LogDnsLogThreadInit,
702 LogDnsLogThreadDeinit);