From be3800fc91148fbb4a884e2004766c8bd2b95f9b Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Thu, 26 Aug 2021 17:07:41 +0900 Subject: [PATCH] libc/netdb: Separate IPv4 and IPv6 cache size limit Some domains have a lot of IPv6 addresses. Because of that, it is not possible to get the IPv4 address with getaddrinfo. This change separate IPv4 and IPv6 cache size limit to enable to get both IP addresses. --- libs/libc/netdb/Kconfig | 23 +++++++++++++++++++---- libs/libc/netdb/lib_dnscache.c | 1 + libs/libc/netdb/lib_dnsquery.c | 6 ++++-- libs/libc/netdb/lib_netdb.h | 11 +++++++++-- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/libs/libc/netdb/Kconfig b/libs/libc/netdb/Kconfig index a8cffa7759f14..9161a72b048da 100644 --- a/libs/libc/netdb/Kconfig +++ b/libs/libc/netdb/Kconfig @@ -33,15 +33,30 @@ config NETDB_BUFSIZE depends on LIBC_NETDB default 256 -config NETDB_MAX_IPADDR - int "Max number of IP addresses per host" +if NET_IPv4 + +config NETDB_MAX_IPv4ADDR + int "Max number of IPv4 addresses per host" depends on LIBC_NETDB - default 2 if NET_IPv4 && NET_IPv6 default 1 ---help--- - This setting determines the maximum number of IP addresses + This setting determines the maximum number of IPv4 addresses stored to the name resolution cache for a given host. +endif # NET_IPv4 + +if NET_IPv6 + +config NETDB_MAX_IPv6ADDR + int "Max number of IPv6 addresses per host" + depends on LIBC_NETDB + default 1 + ---help--- + This setting determines the maximum number of IPv6 addresses + stored to the name resolution cache for a given host. + +endif # NET_IPv6 + menuconfig NETDB_HOSTFILE bool "Network host file support" default n diff --git a/libs/libc/netdb/lib_dnscache.c b/libs/libc/netdb/lib_dnscache.c index bb1ee03aa15d6..1260185103959 100644 --- a/libs/libc/netdb/lib_dnscache.c +++ b/libs/libc/netdb/lib_dnscache.c @@ -32,6 +32,7 @@ #include #include "netdb/lib_dns.h" +#include "netdb/lib_netdb.h" #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 diff --git a/libs/libc/netdb/lib_dnsquery.c b/libs/libc/netdb/lib_dnsquery.c index ba414f4c53f66..a01e79db7901b 100644 --- a/libs/libc/netdb/lib_dnsquery.c +++ b/libs/libc/netdb/lib_dnsquery.c @@ -669,7 +669,8 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, /* Obtain the IPv6 response */ ret = dns_recv_response(sd, &query->addr[next], - *query->naddr - next, &qdata->qinfo, + CONFIG_NETDB_MAX_IPv6ADDR, + &qdata->qinfo, &query->ttl, qdata->buffer); if (ret >= 0) { @@ -718,7 +719,8 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr, } ret = dns_recv_response(sd, &query->addr[next], - *query->naddr - next, &qdata->qinfo, + CONFIG_NETDB_MAX_IPv4ADDR, + &qdata->qinfo, &query->ttl, qdata->buffer); if (ret >= 0) { diff --git a/libs/libc/netdb/lib_netdb.h b/libs/libc/netdb/lib_netdb.h index 72dcf91ec4d2b..b4d4a0a60ecf7 100644 --- a/libs/libc/netdb/lib_netdb.h +++ b/libs/libc/netdb/lib_netdb.h @@ -56,10 +56,17 @@ # define CONFIG_NETDB_BUFSIZE 128 #endif -#ifndef CONFIG_NETDB_MAX_IPADDR -# define CONFIG_NETDB_MAX_IPADDR 1 +#ifndef CONFIG_NETDB_MAX_IPv4ADDR +# define CONFIG_NETDB_MAX_IPv4ADDR 1 #endif +#ifndef CONFIG_NETDB_MAX_IPv6ADDR +# define CONFIG_NETDB_MAX_IPv6ADDR 1 +#endif + +#define CONFIG_NETDB_MAX_IPADDR (CONFIG_NETDB_MAX_IPv4ADDR + \ + CONFIG_NETDB_MAX_IPv6ADDR) + /**************************************************************************** * Public Types ****************************************************************************/