]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Make responselog flags similar to querylog
authorPetr Menšík <pemensik@redhat.com>
Tue, 13 Jul 2021 18:12:11 +0000 (20:12 +0200)
committerMark Andrews <marka@isc.org>
Thu, 19 Sep 2024 21:44:06 +0000 (21:44 +0000)
Remove answer flag from log, log instead count of records for each
message section. Include EDNS version and few flags of response. Add
also status of result.

Still does not include body of responses rrset.

lib/ns/query.c

index ed7d35d73f944a3784a183d57c81b3a4526d274d..e80a91f1ed66ab24819dd2f62e05be2b544f9efa 100644 (file)
@@ -552,7 +552,12 @@ log_response(ns_client_t *client, dns_rcode_t rcode) {
        char typebuf[DNS_RDATATYPE_FORMATSIZE];
        char classbuf[DNS_RDATACLASS_FORMATSIZE];
        char rcodebuf[20];
+       char onbuf[ISC_NETADDR_FORMATSIZE];
+       char ecsbuf[DNS_ECS_FORMATSIZE + sizeof(" [ECS ]") - 1] = { 0 };
+       char ednsbuf[sizeof("E(65535)")] = { 0 };
        isc_buffer_t b;
+       uint16_t extflags;
+       unsigned int flags;
        int level = ISC_LOG_INFO;
 
        if (!isc_log_wouldlog(level))
@@ -564,10 +569,38 @@ log_response(ns_client_t *client, dns_rcode_t rcode) {
        dns_rdatatype_format(client->query.qtype, typebuf, sizeof(typebuf));
        isc_buffer_init(&b, rcodebuf, sizeof(rcodebuf));
        dns_rcode_totext(rcode, &b);
+       isc_buffer_putuint8(&b, 0);
+       isc_netaddr_format(&client->destaddr, onbuf, sizeof(onbuf));
 
-       ns_client_log(client, NS_LOGCATEGORY_QUERIES, NS_LOGMODULE_QUERY, level,
-                     "response: %s %s %s %.*s", namebuf, classbuf, typebuf,
-                     (int)isc_buffer_usedlength(&b), rcodebuf);
+       if (client->ednsversion >= 0) {
+               snprintf(ednsbuf, sizeof(ednsbuf), "E(%hd)",
+                        client->ednsversion);
+       }
+
+       if (HAVEECS(client)) {
+               strlcpy(ecsbuf, " [ECS ", sizeof(ecsbuf));
+               dns_ecs_format(&client->ecs, ecsbuf + 6, sizeof(ecsbuf) - 6);
+               strlcat(ecsbuf, "]", sizeof(ecsbuf));
+       }
+
+       extflags = client->extflags;
+       flags = client->message->flags;
+       ns_client_log(client, NS_LOGCATEGORY_RESPONSES, NS_LOGMODULE_QUERY,
+                     level,
+                     "response: %s %s %s %s %d %d %d %s%s%s%s%s%s%s (%s)%s",
+                     namebuf, classbuf, typebuf, rcodebuf,
+                     client->message->counts[DNS_SECTION_ANSWER],
+                     client->message->counts[DNS_SECTION_AUTHORITY],
+                     client->message->counts[DNS_SECTION_ADDITIONAL],
+                     RECURSIONOK(client) ? "+" : "-",
+                     (client->signer != NULL) ? "S" : "", ednsbuf,
+                     TCP(client) ? "T" : "",
+                     ((extflags & DNS_MESSAGEEXTFLAG_DO) != 0) ? "D" : "",
+                     ((flags & DNS_MESSAGEFLAG_CD) != 0) ? "C" : "",
+                     HAVECOOKIE(client)   ? "V"
+                     : WANTCOOKIE(client) ? "K"
+                                          : "",
+                     onbuf, ecsbuf);
 }
 
 static void
@@ -599,13 +632,13 @@ query_send(ns_client_t *client) {
                counter = ns_statscounter_failure;
        }
 
+       inc_stats(client, counter);
+       ns_client_send(client);
+
        if ((client->manager->sctx->options & NS_SERVER_LOGRESPONSES) != 0) {
                log_response(client, client->message->rcode);
        }
 
-       inc_stats(client, counter);
-       ns_client_send(client);
-
        if (!client->nodetach) {
                isc_nmhandle_detach(&client->reqhandle);
        }
@@ -636,14 +669,14 @@ query_error(ns_client_t *client, isc_result_t result, int line) {
 
        log_queryerror(client, result, line, loglevel);
 
+       ns_client_error(client, result);
+
        if (client->query.origqname != NULL &&
            (client->manager->sctx->options & NS_SERVER_LOGRESPONSES) != 0)
        {
                log_response(client, rcode);
        }
 
-       ns_client_error(client, result);
-
        if (!client->nodetach) {
                isc_nmhandle_detach(&client->reqhandle);
        }