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 JsonBuilderMark mark = { 0, 0, 0 };
261 jb_get_mark(js, &mark);
263 bool r = rs_http2_log_json(txptr, js);
265 jb_restore_mark(js, &mark);
269 if (tx_dns == NULL) {
274 jb_get_mark(js, &mark);
277 jb_restore_mark(js, &mark);
284 void *alstate,
void *txptr, uint64_t tx_id)
295 JsonBuilderMark mark = { 0, 0, 0 };
297 jb_get_mark(jb, &mark);
299 bool r = rs_http2_log_json(txptr, jb);
301 jb_restore_mark(jb, &mark);
305 if (tx_dns == NULL) {
311 if (SCDnsTxIsRequest(tx_dns)) {
315 }
else if (SCDnsTxIsResponse(tx_dns)) {
325 jb_get_mark(jb, &mark);
329 jb_restore_mark(jb, &mark);
340 static int JsonDnsLoggerToServer(
ThreadVars *
tv,
void *thread_data,
341 const Packet *p,
Flow *f,
void *alstate,
void *txptr, uint64_t tx_id)
352 for (uint16_t i = 0; i < 0xffff; i++) {
358 jb_open_object(jb,
"dns");
359 jb_set_int(jb,
"version", 2);
373 static int JsonDnsLoggerToClient(
ThreadVars *
tv,
void *thread_data,
374 const Packet *p,
Flow *f,
void *alstate,
void *txptr, uint64_t tx_id)
391 jb_open_object(jb,
"dns");
392 jb_set_int(jb,
"version", 2);
403 void *txptr, uint64_t tx_id)
408 if (dnslog_ctx->
version == DNS_LOG_VERSION_2) {
409 if (SCDnsTxIsRequest(txptr)) {
410 return JsonDnsLoggerToServer(
tv, thread_data, p, f, alstate, txptr, tx_id);
411 }
else if (SCDnsTxIsResponse(txptr)) {
412 return JsonDnsLoggerToClient(
tv, thread_data, p, f, alstate, txptr, tx_id);
415 if (SCDnsTxIsRequest(txptr)) {
419 }
else if (SCDnsTxIsResponse(txptr)) {
442 static TmEcode LogDnsLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
450 SCLogDebug(
"Error getting context for EveLogDNS. \"initdata\" argument NULL");
484 static void LogDnsLogDeInitCtxSub(
OutputCtx *output_ctx)
486 SCLogDebug(
"cleaning up sub output_ctx %p", output_ctx);
493 const char *query_key,
const char *answer_key,
494 const char *answer_types_key)
508 if (response != NULL) {
526 dnslog_ctx->
flags |= dns_rrtype_fields[f].flags;
536 static uint8_t GetDnsLogVersion(
ConfNode *conf)
539 return DNS_LOG_VERSION_DEFAULT;
542 char *version_string = NULL;
544 if (version_node != NULL) {
545 version_string = version_node->
val;
548 if (version_string == NULL) {
549 version_string = getenv(
"SURICATA_EVE_DNS_VERSION");
552 if (version_string == NULL) {
553 return DNS_LOG_VERSION_DEFAULT;
560 SCLogWarning(
"Failed to parse EVE DNS log version of \"%s\"", version_string);
561 return DNS_LOG_VERSION_DEFAULT;
564 static uint8_t JsonDnsCheckVersion(
ConfNode *conf)
566 const uint8_t default_version = DNS_LOG_VERSION_DEFAULT;
567 const uint8_t
version = GetDnsLogVersion(conf);
568 static bool v1_deprecation_warned =
false;
569 static bool v2_deprecation_warned =
false;
573 return DNS_LOG_VERSION_3;
575 if (!v2_deprecation_warned) {
576 SCLogNotice(
"DNS EVE v2 logging has been deprecated and will be removed in "
578 v2_deprecation_warned =
true;
580 return DNS_LOG_VERSION_2;
582 if (!v1_deprecation_warned) {
583 SCLogWarning(
"DNS EVE v1 logging has been removed, will use v2");
584 v1_deprecation_warned =
true;
586 return default_version;
589 "Invalid EVE DNS version %d, will use v%d",
version, DNS_LOG_VERSION_DEFAULT);
590 return default_version;
593 return default_version;
598 dnslog_ctx->
flags = ~0ULL;
601 JsonDnsLogParseConfig(dnslog_ctx, conf,
"requests",
"responses",
"types");
608 if (strcasecmp(field->
val,
"detailed") == 0) {
610 }
else if (strcasecmp(field->
val,
"grouped") == 0) {
620 SCLogWarning(
"Empty EVE DNS format array, using defaults");
646 dnslog_ctx->
version = JsonDnsCheckVersion(conf);
654 output_ctx->
data = dnslog_ctx;
655 output_ctx->
DeInit = LogDnsLogDeInitCtxSub;
657 JsonDnsLogInitFilters(dnslog_ctx, conf);
664 result.
ctx = output_ctx;
670 #define MODULE_NAME "JsonDnsLog"
674 JsonDnsLogInitCtxSub,
ALPROTO_DNS, JsonDnsLogger, LogDnsLogThreadInit,
675 LogDnsLogThreadDeinit);
681 JsonDnsLogInitCtxSub,
ALPROTO_DOH2, JsonDoh2Logger, LogDnsLogThreadInit,
682 LogDnsLogThreadDeinit);