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.
This commit is contained in:
SPRESENSE 2021-08-26 17:07:41 +09:00 committed by Petro Karashchenko
parent 63ed723d93
commit d1c7e1816f
9 changed files with 33 additions and 13 deletions

View file

@ -44,7 +44,6 @@ CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSCLIENT_NAMESIZE=64
CONFIG_NETDB_DNSSERVER_NOADDR=y CONFIG_NETDB_DNSSERVER_NOADDR=y
CONFIG_NETDB_MAX_IPADDR=2
CONFIG_NETINIT_DHCPC=y CONFIG_NETINIT_DHCPC=y
CONFIG_NETINIT_NOMAC=y CONFIG_NETINIT_NOMAC=y
CONFIG_NETUTILS_NETCAT=y CONFIG_NETUTILS_NETCAT=y

View file

@ -25,7 +25,6 @@ CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSCLIENT_NAMESIZE=64
CONFIG_NETDB_DNSSERVER_NOADDR=y CONFIG_NETDB_DNSSERVER_NOADDR=y
CONFIG_NETDB_MAX_IPADDR=2
CONFIG_NETUTILS_NETCAT=y CONFIG_NETUTILS_NETCAT=y
CONFIG_NETUTILS_TELNETD=y CONFIG_NETUTILS_TELNETD=y
CONFIG_NETUTILS_TFTPC=y CONFIG_NETUTILS_TFTPC=y

View file

@ -47,7 +47,6 @@ CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSCLIENT_NAMESIZE=64 CONFIG_NETDB_DNSCLIENT_NAMESIZE=64
CONFIG_NETDB_DNSSERVER_NOADDR=y CONFIG_NETDB_DNSSERVER_NOADDR=y
CONFIG_NETDB_MAX_IPADDR=2
CONFIG_NETINIT_DHCPC=y CONFIG_NETINIT_DHCPC=y
CONFIG_NETINIT_NOMAC=y CONFIG_NETINIT_NOMAC=y
CONFIG_NETUTILS_NETCAT=y CONFIG_NETUTILS_NETCAT=y

View file

@ -58,7 +58,6 @@ CONFIG_MATTER=y
CONFIG_NET=y CONFIG_NET=y
CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x771d1d1d CONFIG_NETDB_DNSSERVER_IPv4ADDR=0x771d1d1d
CONFIG_NETDB_MAX_IPADDR=1
CONFIG_NETDEV_HPWORK_THREAD=y CONFIG_NETDEV_HPWORK_THREAD=y
CONFIG_NETINIT_IPADDR=0x0a000102 CONFIG_NETINIT_IPADDR=0x0a000102
CONFIG_NETLINK_ROUTE=y CONFIG_NETLINK_ROUTE=y

View file

@ -45,7 +45,6 @@ CONFIG_LIBUV=y
CONFIG_NETDB_DNSCLIENT=y CONFIG_NETDB_DNSCLIENT=y
CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=1024 CONFIG_NETDB_DNSCLIENT_MAXRESPONSE=1024
CONFIG_NETDB_DNSSERVER_IPv4ADDR=0xDF050505 CONFIG_NETDB_DNSSERVER_IPv4ADDR=0xDF050505
CONFIG_NETDB_MAX_IPADDR=1
CONFIG_NETDEV_PHY_IOCTL=y CONFIG_NETDEV_PHY_IOCTL=y
CONFIG_NETDOWN_NOTIFIER=y CONFIG_NETDOWN_NOTIFIER=y
CONFIG_NETINIT_DRIPADDR=0x0a000101 CONFIG_NETINIT_DRIPADDR=0x0a000101

View file

@ -33,15 +33,30 @@ config NETDB_BUFSIZE
depends on LIBC_NETDB depends on LIBC_NETDB
default 256 default 256
config NETDB_MAX_IPADDR if NET_IPv4
int "Max number of IP addresses per host"
config NETDB_MAX_IPv4ADDR
int "Max number of IPv4 addresses per host"
depends on LIBC_NETDB depends on LIBC_NETDB
default 2 if NET_IPv4 && NET_IPv6
default 1 default 1
---help--- ---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. 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 menuconfig NETDB_HOSTFILE
bool "Network host file support" bool "Network host file support"
default n default n

View file

@ -32,6 +32,7 @@
#include <debug.h> #include <debug.h>
#include "netdb/lib_dns.h" #include "netdb/lib_dns.h"
#include "netdb/lib_netdb.h"
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0

View file

@ -669,7 +669,8 @@ static int dns_query_callback(FAR void *arg, FAR struct sockaddr *addr,
/* Obtain the IPv6 response */ /* Obtain the IPv6 response */
ret = dns_recv_response(sd, &query->addr[next], ret = dns_recv_response(sd, &query->addr[next],
*query->naddr - next, &qdata->qinfo, CONFIG_NETDB_MAX_IPv6ADDR,
&qdata->qinfo,
&query->ttl, qdata->buffer); &query->ttl, qdata->buffer);
if (ret >= 0) 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], ret = dns_recv_response(sd, &query->addr[next],
*query->naddr - next, &qdata->qinfo, CONFIG_NETDB_MAX_IPv4ADDR,
&qdata->qinfo,
&query->ttl, qdata->buffer); &query->ttl, qdata->buffer);
if (ret >= 0) if (ret >= 0)
{ {

View file

@ -56,10 +56,17 @@
# define CONFIG_NETDB_BUFSIZE 128 # define CONFIG_NETDB_BUFSIZE 128
#endif #endif
#ifndef CONFIG_NETDB_MAX_IPADDR #ifndef CONFIG_NETDB_MAX_IPv4ADDR
# define CONFIG_NETDB_MAX_IPADDR 1 # define CONFIG_NETDB_MAX_IPv4ADDR 1
#endif #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 * Public Types
****************************************************************************/ ****************************************************************************/