From 4addf6c30812c1869e8786af07efe173f4f76add Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 1 Apr 2020 17:20:13 +0800 Subject: [PATCH] libc/netdb: query IPv6 first than IPv4 since some host have multiple IPv4 address, the dns cache may fill in all Ipv4 address and refuse to accept any IPv6 address if we query IPv4 first Signed-off-by: Xiang Xiao Change-Id: I229a7a524fb9daa7498c66913a2de61f11d6fb43 --- libs/libc/netdb/lib_dnsquery.c | 58 +++++++++++++++++----------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c index c27784af784..dd07768d60a 100644 --- a/libs/libc/netdb/lib_dnsquery.c +++ b/libs/libc/netdb/lib_dnsquery.c @@ -581,35 +581,6 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, for (retries = 0; retries < CONFIG_NETDB_DNSCLIENT_RETRIES; retries++) { -#ifdef CONFIG_NET_IPv4 - /* Send the IPv4 query */ - - ret = dns_send_query(query->sd, query->hostname, - (FAR union dns_addr_u *)addr, - DNS_RECTYPE_A, &qinfo); - if (ret < 0) - { - nerr("ERROR: IPv4 dns_send_query failed: %d\n", ret); - query->result = ret; - } - else - { - /* Obtain the IPv4 response */ - - ret = dns_recv_response(query->sd, &query->addr[next], - *query->naddr - next, &qinfo); - if (ret >= 0) - { - next += ret; - } - else - { - nerr("ERROR: IPv4 dns_recv_response failed: %d\n", ret); - query->result = ret; - } - } -#endif /* CONFIG_NET_IPv4 */ - #ifdef CONFIG_NET_IPv6 /* Send the IPv6 query */ @@ -639,6 +610,35 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, } #endif +#ifdef CONFIG_NET_IPv4 + /* Send the IPv4 query */ + + ret = dns_send_query(query->sd, query->hostname, + (FAR union dns_addr_u *)addr, + DNS_RECTYPE_A, &qinfo); + if (ret < 0) + { + nerr("ERROR: IPv4 dns_send_query failed: %d\n", ret); + query->result = ret; + } + else + { + /* Obtain the IPv4 response */ + + ret = dns_recv_response(query->sd, &query->addr[next], + *query->naddr - next, &qinfo); + if (ret >= 0) + { + next += ret; + } + else + { + nerr("ERROR: IPv4 dns_recv_response failed: %d\n", ret); + query->result = ret; + } + } +#endif /* CONFIG_NET_IPv4 */ + if (next > 0) { #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0