Skip to content

Commit

Permalink
Merge branch 'pymumu:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
PikuZheng committed May 7, 2024
2 parents 553e924 + 5276ba5 commit 59fcfb7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
8 changes: 7 additions & 1 deletion src/dns_client.c
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,13 @@ static int _dns_client_recv(struct dns_server_info *server_info, unsigned char *
_dns_replied_check_remove(query, from, from_len);
atomic_inc(&query->dns_request_sent);
if (ret == DNS_CLIENT_ACTION_RETRY) {
/* retry immdiately */
/*
* retry immdiately
* The socket needs to be re-created to avoid being limited, such as 1.1.1.1
*/
pthread_mutex_lock(&client.server_list_lock);
_dns_client_close_socket(server_info);
pthread_mutex_unlock(&client.server_list_lock);
_dns_client_retry_dns_query(query);
}
} else {
Expand Down
13 changes: 9 additions & 4 deletions src/dns_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -3760,7 +3760,8 @@ static int _dns_server_process_answer_A_IP(struct dns_request *request, char *cn

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

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

/* add this ip to request */
if (_dns_ip_address_check_add(request, cname, paddr, DNS_T_AAAA, 0, NULL) != 0) {
return -1;
/* skip result */
return -2;
}

snprintf(ip, sizeof(ip), "[%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x:%.2x%.2x]", paddr[0],
Expand Down Expand Up @@ -4130,6 +4132,7 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d
if (ret == -1) {
break;
} else if (ret == -2) {
is_skip = 1;
continue;
}
request->rcode = packet->head.rcode;
Expand Down Expand Up @@ -4181,13 +4184,15 @@ static int _dns_server_process_answer(struct dns_request *request, const char *d
request->rcode = packet->head.rcode;
}

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

if (is_rcode_set == 0 && has_result == 1) {
if (is_rcode_set == 0 && has_result == 1 && is_skip == 0) {
/* need retry for some server. */
return DNS_CLIENT_ACTION_MAY_RETRY;
}

Expand Down

0 comments on commit 59fcfb7

Please sign in to comment.