From d00f012fe39de8e7aadeb7654d912b4d09786dae Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 14 Jan 2024 12:32:44 +0800 Subject: [PATCH] dns_server: no retry when upstream server return no results with RCODE=NOERROR --- src/dns_server.c | 8 ++++++-- src/tlog.c | 3 +-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/dns_server.c b/src/dns_server.c index e6ec9dbbd1..50dc47abd9 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -3746,9 +3746,13 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d } if (has_result == 0 && request->rcode == DNS_RC_NOERROR) { - tlog(TLOG_DEBUG, "no result, %s qtype: %d, rcode: %d, id: %d, retry", domain, request->qtype, + /* When queries A and AAAA from CloudFlare DNS at the same time and there is a retry, + * CloudFlare DNS may return the sent request packet. I don’t know the reason. + * Maybe retry should be considered? + */ + tlog(TLOG_DEBUG, "no result, %s qtype: %d, rcode: %d, id: %d", domain, request->qtype, packet->head.rcode, packet->head.id); - return -1; + return 0; } return 0; diff --git a/src/tlog.c b/src/tlog.c index 22bf1f6e1c..e61ff026ee 100644 --- a/src/tlog.c +++ b/src/tlog.c @@ -666,7 +666,7 @@ int tlog_stdout_with_color(tlog_level level, const char *buff, int bufflen) } if (color != NULL) { - fprintf(stdout, "%s%.*s\033[0m\n", color, bufflen - 2, buff); + fprintf(stdout, "%s%.*s\033[0m\n", color, bufflen - 1, buff); } else { fprintf(stdout, "%s", buff); } @@ -1227,7 +1227,6 @@ static int _tlog_write_screen(struct tlog_log *log, struct tlog_loginfo *info, c } if (info == NULL) { - return write(STDOUT_FILENO, buff, bufflen);; }