Skip to content

Commit 5276ba5

Browse files
committed
dns_client: Fixed the issue of retrying after DNS results are trucated.
1 parent 2f57d8d commit 5276ba5

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/dns_client.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -1888,7 +1888,13 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *
18881888
_dns_replied_check_remove(query, from, from_len);
18891889
atomic_inc(&query->dns_request_sent);
18901890
if (ret == DNS_CLIENT_ACTION_RETRY) {
1891-
/* retry immdiately */
1891+
/*
1892+
* retry immdiately
1893+
* The socket needs to be re-created to avoid being limited, such as 1.1.1.1
1894+
*/
1895+
pthread_mutex_lock(&client.server_list_lock);
1896+
_dns_client_close_socket(server_info);
1897+
pthread_mutex_unlock(&client.server_list_lock);
18921898
_dns_client_retry_dns_query(query);
18931899
}
18941900
} else {

src/dns_server.c

+9-4
Original file line numberDiff line numberDiff line change
@@ -3760,7 +3760,8 @@ static int _dns_server_process_answer_A_IP(struct dns_request *request, char *cn
37603760

37613761
/* add this ip to request */
37623762
if (_dns_ip_address_check_add(request, cname, paddr, DNS_T_A, 0, NULL) != 0) {
3763-
return -1;
3763+
/* skip result */
3764+
return -2;
37643765
}
37653766

37663767
snprintf(ip, sizeof(ip), "%d.%d.%d.%d", paddr[0], paddr[1], paddr[2], paddr[3]);
@@ -3829,7 +3830,8 @@ static int _dns_server_process_answer_AAAA_IP(struct dns_request *request, char
38293830

38303831
/* add this ip to request */
38313832
if (_dns_ip_address_check_add(request, cname, paddr, DNS_T_AAAA, 0, NULL) != 0) {
3832-
return -1;
3833+
/* skip result */
3834+
return -2;
38333835
}
38343836

38353837
snprintf(ip, sizeof(ip), "[%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x]", paddr[0],
@@ -4130,6 +4132,7 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d
41304132
if (ret == -1) {
41314133
break;
41324134
} else if (ret == -2) {
4135+
is_skip = 1;
41334136
continue;
41344137
}
41354138
request->rcode = packet->head.rcode;
@@ -4181,13 +4184,15 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d
41814184
request->rcode = packet->head.rcode;
41824185
}
41834186

4184-
if (has_result == 0 && request->rcode == DNS_RC_NOERROR && packet->head.tc == 1) {
4187+
if (has_result == 0 && request->rcode == DNS_RC_NOERROR && packet->head.tc == 1 && request->has_ip == 0 &&
4188+
request->has_soa == 0) {
41854189
tlog(TLOG_DEBUG, "result is truncated, %s qtype: %d, rcode: %d, id: %d, retry.", domain, request->qtype,
41864190
packet->head.rcode, packet->head.id);
41874191
return DNS_CLIENT_ACTION_RETRY;
41884192
}
41894193

4190-
if (is_rcode_set == 0 && has_result == 1) {
4194+
if (is_rcode_set == 0 && has_result == 1 && is_skip == 0) {
4195+
/* need retry for some server. */
41914196
return DNS_CLIENT_ACTION_MAY_RETRY;
41924197
}
41934198

0 commit comments

Comments
 (0)