Skip to content

Commit

Permalink
libc/netdb: Separate IPv4 and IPv6 cache size limit
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SPRESENSE committed Sep 2, 2024
1 parent 32801d3 commit eed50fd
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 13 deletions.
1 change: 0 additions & 1 deletion boards/arm/tiva/lm3s6965-ek/configs/qemu-flat/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion boards/arm/tiva/lm3s6965-ek/configs/qemu-nxflat/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion boards/sim/sim/sim/configs/matter/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion boards/sim/sim/sim/configs/usbdev/defconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 19 additions & 4 deletions libs/libc/netdb/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libs/libc/netdb/lib_dnscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <debug.h>

#include "netdb/lib_dns.h"
#include "netdb/lib_netdb.h"

#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0

Expand Down
6 changes: 4 additions & 2 deletions libs/libc/netdb/lib_dnsquery.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
11 changes: 9 additions & 2 deletions libs/libc/netdb/lib_netdb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
****************************************************************************/
Expand Down

0 comments on commit eed50fd

Please sign in to comment.