diff --git a/TODO b/TODO index 1a5f890746..5438686674 100644 --- a/TODO +++ b/TODO @@ -17,7 +17,7 @@ nuttx/ (8) Kernel/Protected Build (4) C++ Support (6) Binary loaders (binfmt/) - (13) Network (net/, drivers/net) + (12) Network (net/, drivers/net) (4) USB (drivers/usbdev, drivers/usbhost) (1) Other drivers (drivers/) (11) Libraries (libc/, libm/) @@ -1008,36 +1008,6 @@ o Network (net/, drivers/net) Priority: Low. I don't know of any issues now, but I am sure that someone will encounter this in the future. - Title: GLOBAL DNS ADDRESS - Description: Currently there is a single, global DNS server address. This - address resides in user space (owned by libc/netdb) but is - accessed by network code in kernel space (net/procfs). This - works in a FLAT build, not not in other build modules. - - Things would be really weird in the kernel build: There - would be a separate name server address and a separate netdb - DNS client in each process. That can't be right. - - The Linux kernel has no knowledge at all about DNS addresses. - DNS addresses are retained in /etc/resolv.conf in records - ike: - - nameserver - - The nameserver is associated with the device only through - the routing of the IP address. And this is how there can - be multiple, global DNS addresses. - - Conclusion: The logic in net/procfs needs to be re-designed - so that it does not use the DNS address. The DNS address(es) - should to applied to the device status by logic in the - implementation of the NSH ifconfig command. This would be, - unfortunately, a significant re-design since the formatting - is currently performed in net/procfs. - Status: Open - Priority: Low. I doubt that there are any multiple NIC, multiple DNS - server configurations - Title: MISSING netdb INTERFACES Description: There is no implementation for many netdb interfaces such as getaddrinfo(), freeaddrinfo(), getnameinfo(), etc. diff --git a/include/nuttx/net/dns.h b/include/nuttx/net/dns.h index f7dff02af6..921ec595bf 100644 --- a/include/nuttx/net/dns.h +++ b/include/nuttx/net/dns.h @@ -178,44 +178,35 @@ extern "C" #endif /**************************************************************************** - * Name: dns_setserver + * Name: dns_add_nameserver * * Description: - * Configure which DNS server to use for queries. Set the port number - * to zero to use the default DNS server port. + * Configure a DNS server to use for queries. Set the port number to zero + * to use the default DNS server port. * ****************************************************************************/ -int dns_setserver(FAR const struct sockaddr *addr, socklen_t addrlen); +int dns_add_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen); /**************************************************************************** - * Name: dns_getserver + * Name: dns_del_nameserver * * Description: - * Obtain the currently configured DNS server. + * Remove a DNS server so it is no longer available for further use. * ****************************************************************************/ - -int dns_getserver(FAR struct sockaddr *addr, FAR socklen_t *addrlen); +/* REVISIT: Not implemented */ /**************************************************************************** - * Name: dns_getaddr + * Name: dns_foreach_nameserver * * Description: - * Get the DNS server IPv4 address - * - * Parameters: - * ipaddr The location to return the IPv4 address - * - * Return: - * Zero (OK) is returned on success; A negated errno value is returned - * on failure. + * Traverse each nameserver entry in the resolv.conf file and perform the + * the provided callback. * ****************************************************************************/ -#ifdef CONFIG_NET_IPv4 -int dns_getaddr(FAR struct in_addr *inaddr); -#endif +int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg); #undef EXTERN #if defined(__cplusplus) diff --git a/libc/Kconfig b/libc/Kconfig index e51915d1c2..b008f05e87 100644 --- a/libc/Kconfig +++ b/libc/Kconfig @@ -533,6 +533,22 @@ config NETDB_BUFSIZE endif # NETDB_HOSTFILE +menuconfig NETDB_RESOLVCONF + bool "DNS server file support" + default n + depends on FS_READABLE + select LIBC_NETDB + ---help--- + Enable DNS server look ups in resolver file. + +if NETDB_RESOLVCONF + +config NETDB_RESOLVCONF_PATH + string "Path to host configuration file" + default "/etc/resolv.conf" + +endif # NETDB_RESOLVCONF + config NETDB_DNSCLIENT bool "DNS Name resolution" default n @@ -615,7 +631,7 @@ config NETDB_DNSSERVER_IPv4ADDR depends on NETDB_DNSSERVER_IPv4 ---help--- Default DNS server IPv4 address in host byte order. Default value - 10.0.0.0.1. This may be changed via dns_setserver(). + 10.0.0.0.1. This may be changed via dns_add_nameserver(). if NETDB_DNSSERVER_IPv6 diff --git a/libc/net/lib_inetpton.c b/libc/net/lib_inetpton.c index 96338bde11..8b5eb77dd1 100644 --- a/libc/net/lib_inetpton.c +++ b/libc/net/lib_inetpton.c @@ -372,7 +372,7 @@ static int inet_ipv6_pton(FAR const char *src, FAR void *dest) * af - The af argument specifies the family of the address. This can be * AF_INET or AF_INET6. * src - The src argument points to the string being passed in. - * dest - The dest argument points to a numstr into which the function stores + * dest - The dest argument points to memory into which the function stores * the numeric address; this must be large enough to hold the numeric * address (32 bits for AF_INET, 128 bits for AF_INET6). * diff --git a/libc/netdb/Make.defs b/libc/netdb/Make.defs index b9347eb0fc..ac7069f153 100644 --- a/libc/netdb/Make.defs +++ b/libc/netdb/Make.defs @@ -48,7 +48,7 @@ endif # Add DNS lookup support ifeq ($(CONFIG_NETDB_DNSCLIENT),y) -CSRCS += lib_dnsclient.c lib_getdnsaddr.c +CSRCS += lib_dnsclient.c lib_dnsaddserver.c lib_dnsforeach.c endif # Add the net directory to the build diff --git a/libc/netdb/lib_dns.h b/libc/netdb/lib_dns.h index e3e5d3bae5..826b4c94c3 100644 --- a/libc/netdb/lib_dns.h +++ b/libc/netdb/lib_dns.h @@ -74,6 +74,15 @@ # define CONFIG_NETDB_DNSCLIENT_LIFESEC 3600 #endif +#define DNS_MAX_LINE 80 +#define NETDB_DNS_KEYWORD "nameserver" + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +typedef CODE int (*dns_callback_t)(FAR void *arg, int af, FAR void *addr); + /**************************************************************************** * Public Function Prototypes ****************************************************************************/ @@ -156,7 +165,7 @@ int dns_find_answer(FAR const char *hostname, FAR struct sockaddr *addr, FAR socklen_t *addrlen); #endif -#undef EXTERN +o#undef EXTERN #if defined(__cplusplus) } #endif diff --git a/libc/netdb/lib_dnsclient.c b/libc/netdb/lib_dnsclient.c index c510f2f431..70f1eb4af5 100644 --- a/libc/netdb/lib_dnsclient.c +++ b/libc/netdb/lib_dnsclient.c @@ -5,7 +5,7 @@ * The uIP DNS resolver functions are used to lookup a hostname and * map it to a numerical IP address. * - * Copyright (C) 2007, 2009, 2012, 2014-2015 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Based heavily on portions of uIP: @@ -227,8 +227,8 @@ static bool dns_initialize(void) addr4.sin_port = DNS_DEFAULT_PORT; addr4.sin_addr.s_addr = HTONL(CONFIG_NETDB_DNSSERVER_IPv4ADDR); - ret = dns_setserver((FAR struct sockaddr *)&addr4, - sizeof(struct sockaddr_in)); + ret = dns_add_nameserver((FAR struct sockaddr *)&addr4, + sizeof(struct sockaddr_in)); if (ret < 0) { return false; @@ -244,8 +244,8 @@ static bool dns_initialize(void) addr6.sin6_port = DNS_DEFAULT_PORT; memcpy(addr6.sin6_addr.s6_addr, g_ipv6_hostaddr, 16); - ret = dns_setserver((FAR struct sockaddr *)&addr6, - sizeof(struct sockaddr_in6)); + ret = dns_add_nameserver((FAR struct sockaddr *)&addr6, + sizeof(struct sockaddr_in6)); if (ret < 0) { return false; @@ -877,77 +877,6 @@ int dns_query(int sd, FAR const char *hostname, FAR struct sockaddr *addr, return -ETIMEDOUT; } -/**************************************************************************** - * Name: dns_setserver - * - * Description: - * Configure which DNS server to use for queries - * - ****************************************************************************/ - -int dns_setserver(FAR const struct sockaddr *addr, socklen_t addrlen) -{ - FAR uint16_t *pport; - size_t copylen; - - DEBUGASSERT(addr != NULL); - - /* Copy the new server IP address into our private global data structure */ - -#ifdef CONFIG_NET_IPv4 - /* Check for an IPv4 address */ - - if (addr->sa_family == AF_INET) - { - /* Set up for the IPv4 address copy */ - - copylen = sizeof(struct sockaddr_in); - pport = &g_dns_server.ipv4.sin_port; - } - else -#endif - -#ifdef CONFIG_NET_IPv6 - /* Check for an IPv6 address */ - - if (addr->sa_family == AF_INET6) - { - /* Set up for the IPv6 address copy */ - - copylen = sizeof(struct sockaddr_in6); - pport = &g_dns_server.ipv6.sin6_port; - } - else -#endif - { - nvdbg("ERROR: Unsupported family: %d\n", addr->sa_family); - return -ENOSYS; - } - - /* Copy the IP address */ - - if (addrlen < copylen) - { - nvdbg("ERROR: Invalid addrlen %ld for family %d\n", - (long)addrlen, addr->sa_family); - return -EINVAL; - } - - memcpy(&g_dns_server.addr, addr, copylen); - - /* A port number of zero means to use the default DNS server port number */ - - if (*pport == 0) - { - *pport = HTONS(DNS_DEFAULT_PORT); - } - - /* We now have a valid DNS address */ - - g_dns_address = true; - return OK; -} - /**************************************************************************** * Name: dns_getserver * diff --git a/libc/netdb/lib_getdnsaddr.c b/libc/netdb/lib_getdnsaddr.c deleted file mode 100644 index a6e6c4335a..0000000000 --- a/libc/netdb/lib_getdnsaddr.c +++ /dev/null @@ -1,98 +0,0 @@ -/**************************************************************************** - * libc/netdb/lib_dnsgetaddr.c - * - * Copyright (C) 2007-2009, 2011, 2015 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in - * the documentation and/or other materials provided with the - * distribution. - * 3. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS - * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************/ - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#include - -#include -#include -#include - -#include - -#include - -#include - -#if defined(CONFIG_NET_IPv4) && defined(CONFIG_NETDB_DNSCLIENT) - -/**************************************************************************** - * Public Functions - ****************************************************************************/ - -/**************************************************************************** - * Name: dns_getaddr - * - * Description: - * Get the DNS server IPv4 address - * - * Parameters: - * ipaddr The location to return the IPv4 address - * - * Return: - * Zero (OK) is returned on success; A negated errno value is returned - * on failure. - * - ****************************************************************************/ - -int dns_getaddr(FAR struct in_addr *inaddr) -{ - struct sockaddr_in addr; - socklen_t addrlen; - int ret = -EINVAL; - - if (inaddr) - { - addrlen = sizeof(struct sockaddr_in); - ret = dns_getserver((FAR struct sockaddr *)&addr, &addrlen); - if (ret >= 0) - { - /* Sanity check */ - - DEBUGASSERT(addr.sin_family == AF_INET && - addrlen == sizeof(struct sockaddr_in)); - memcpy(inaddr, &addr.sin_addr, sizeof(struct in_addr)); - } - } - - return ret; -} - -#endif /* CONFIG_NET_IPv4 && CONFIG_NETDB_DNSCLIENT */ diff --git a/net/procfs/netdev_statistics.c b/net/procfs/netdev_statistics.c index 16cfb440d9..80154c91fa 100644 --- a/net/procfs/netdev_statistics.c +++ b/net/procfs/netdev_statistics.c @@ -47,7 +47,6 @@ #include #include -#include #include "netdev/netdev.h" #include "utils/utils.h" @@ -246,17 +245,6 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) addr.s_addr = dev->d_netmask; len += snprintf(&netfile->line[len], NET_LINELEN - len, "Mask:%s\n", inet_ntoa(addr)); - -#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) - /* Show the IPv4 DNS address */ - /* REVISIT: DNS client is global, not per device, and resides in the - * application space and is not generally accessible from kernel space. - */ - - dns_getaddr(&addr); - len += snprintf(&netfile->line[len], NET_LINELEN - len, - "\tDNSaddr:%s\n", inet_ntoa(addr)); -#endif #endif #ifdef CONFIG_NET_IPv6 @@ -279,11 +267,6 @@ static int netprocfs_ipaddresses(FAR struct netprocfs_file_s *netfile) len += snprintf(&netfile->line[len], NET_LINELEN - len, "\tinet6 DRaddr:%s/%d\n", addrstr, preflen); } - -#if defined(CONFIG_BUILD_FLAT) && defined(CONFIG_NETDB_DNSCLIENT) - /* Show the IPv6 DNS address */ -# warning Missing logic -#endif #endif len += snprintf(&netfile->line[len], NET_LINELEN - len, "\n");