From 60e3a109e4db56230068f0f70ad5f6c843c886dc Mon Sep 17 00:00:00 2001 From: Nick Peng Date: Sun, 12 Feb 2023 16:00:19 +0800 Subject: [PATCH] dns_client: fix bootstrap DNS soa host issue. --- src/dns_client.c | 14 ++++++++------ src/dns_server.c | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/dns_client.c b/src/dns_client.c index 177ab5b..a441316 100644 --- a/src/dns_client.c +++ b/src/dns_client.c @@ -3625,6 +3625,7 @@ static int _dns_client_pending_server_resolve(const char *domain, dns_rtcode_t r if (rtcode == DNS_RC_NOERROR) { pending->has_v4 = 1; pending->ping_time_v4 = ping_time; + pending->has_soa = 0; safe_strncpy(pending->ipv4, ip, DNS_HOSTNAME_LEN); } } else if (addr_type == DNS_T_AAAA) { @@ -3632,6 +3633,7 @@ static int _dns_client_pending_server_resolve(const char *domain, dns_rtcode_t r if (rtcode == DNS_RC_NOERROR) { pending->has_v6 = 1; pending->ping_time_v6 = ping_time; + pending->has_soa = 0; safe_strncpy(pending->ipv6, ip, DNS_HOSTNAME_LEN); } } else { @@ -3754,12 +3756,6 @@ static void _dns_client_add_pending_servers(void) dnsserver_ip = pending->ipv6; } - if (pending->has_soa) { - tlog(TLOG_WARN, "add pending DNS server %s failed, no such host.", pending->host); - _dns_client_server_pending_remove(pending); - continue; - } - if (dnsserver_ip && dnsserver_ip[0]) { if (_dns_client_add_pendings(pending, dnsserver_ip) == 0) { add_success = 1; @@ -3771,6 +3767,12 @@ static void _dns_client_add_pending_servers(void) continue; } + if (pending->has_soa && dnsserver_ip == NULL) { + tlog(TLOG_WARN, "add pending DNS server %s failed, no such host.", pending->host); + _dns_client_server_pending_remove(pending); + continue; + } + if (pending->retry_cnt - 1 > DNS_PENDING_SERVER_RETRY || add_success) { if (add_success == 0) { tlog(TLOG_WARN, "add pending DNS server %s failed.", pending->host); diff --git a/src/dns_server.c b/src/dns_server.c index 3ce4b97..87d9165 100644 --- a/src/dns_server.c +++ b/src/dns_server.c @@ -1305,7 +1305,7 @@ static int _dns_result_callback_nxdomain(struct dns_request *request) return 0; } - return request->result_callback(request->domain, DNS_RC_NXDOMAIN, request->qtype, ip, ping_time, request->user_ptr); + return request->result_callback(request->domain, request->rcode, request->qtype, ip, ping_time, request->user_ptr); } static int _dns_result_callback(struct dns_server_post_context *context)