From d1c7e1816fe5ac220ffcfcc8e817fdf92b8387fc 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. --- .../lm3s6965-ek/configs/qemu-flat/defconfig | 1 - .../lm3s6965-ek/configs/qemu-nxflat/defconfig | 1 - .../configs/qemu-protected/defconfig | 1 - boards/sim/sim/sim/configs/matter/defconfig | 1 - boards/sim/sim/sim/configs/usbdev/defconfig | 1 - 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 +++++++-- 9 files changed, 33 insertions(+), 13 deletions(-) diff --git a/boards/arm/tiva/lm3s6965-ek/configs/qemu-flat/defconfig b/boards/arm/tiva/lm3s6965-ek/configs/qemu-flat/defconfig index 5443a0484d..490f0f9c68 100644 --- a/boards/arm/tiva/lm3s6965-ek/configs/qemu-flat/defconfig +++ b/boards/arm/tiva/lm3s6965-ek/configs/qemu-flat/defconfig @@ -44,7 +44,6 @@ CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSSERVER_NOADDR=y -CONFIG_NETDB_MAX_IPADDR=2 CONFIG_NETINIT_DHCPC=y CONFIG_NETINIT_NOMAC=y CONFIG_NETUTILS_NETCAT=y diff --git a/boards/arm/tiva/lm3s6965-ek/configs/qemu-nxflat/defconfig b/boards/arm/tiva/lm3s6965-ek/configs/qemu-nxflat/defconfig index 8a387b7da2..508340f149 100644 --- a/boards/arm/tiva/lm3s6965-ek/configs/qemu-nxflat/defconfig +++ b/boards/arm/tiva/lm3s6965-ek/configs/qemu-nxflat/defconfig @@ -25,7 +25,6 @@ CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSSERVER_NOADDR=y -CONFIG_NETDB_MAX_IPADDR=2 CONFIG_NETUTILS_NETCAT=y CONFIG_NETUTILS_TELNETD=y CONFIG_NETUTILS_TFTPC=y diff --git a/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig b/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig index 3b157590f2..32ca54f0cc 100644 --- a/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig +++ b/boards/arm/tiva/lm3s6965-ek/configs/qemu-protected/defconfig @@ -47,7 +47,6 @@ CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSSERVER_NOADDR=y -CONFIG_NETDB_MAX_IPADDR=2 CONFIG_NETINIT_DHCPC=y CONFIG_NETINIT_NOMAC=y CONFIG_NETUTILS_NETCAT=y diff --git a/boards/sim/sim/sim/configs/matter/defconfig b/boards/sim/sim/sim/configs/matter/defconfig index 04635b4d24..63a2557185 100644 --- a/boards/sim/sim/sim/configs/matter/defconfig +++ b/boards/sim/sim/sim/configs/matter/defconfig @@ -58,7 +58,6 @@ CONFIG_MATTER=y CONFIG_NET=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x771d1d1d -CONFIG_NETDB_MAX_IPADDR=1 CONFIG_NETDEV_HPWORK_THREAD=y CONFIG_NETINIT_IPADDR=0x0a000102 CONFIG_NETLINK_ROUTE=y diff --git a/boards/sim/sim/sim/configs/usbdev/defconfig b/boards/sim/sim/sim/configs/usbdev/defconfig index 76f0e07598..6e56a1f7d3 100644 --- a/boards/sim/sim/sim/configs/usbdev/defconfig +++ b/boards/sim/sim/sim/configs/usbdev/defconfig @@ -45,7 +45,6 @@ CONFIG_LIBUV=y CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=1024 CONFIG_NETDB_DNSSERVER_IPv4ADDR=0xDF050505 -CONFIG_NETDB_MAX_IPADDR=1 CONFIG_NETDEV_PHY_IOCTL=y CONFIG_NETDOWN_NOTIFIER=y CONFIG_NETINIT_DRIPADDR=0x0a000101 diff --git a/libs/libc/netdb/Kconfig b/libs/libc/netdb/Kconfig index a8cffa7759..9161a72b04 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 bb1ee03aa1..1260185103 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 ba414f4c53..a01e79db79 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 72dcf91ec4..b4d4a0a60e 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 ****************************************************************************/