From d2dd063179ec9ab25b0db59573aa5231ba82ad93 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Tue, 3 Feb 2015 08:01:55 -0600 Subject: Add netlib and application hooks for ICMPv6 auto-configuration (still incomplete --- apps/netutils/dhcpc/Kconfig | 2 +- apps/netutils/dhcpd/Kconfig | 1 + apps/netutils/netlib/Makefile | 3 + apps/netutils/netlib/netlib_autoconfig.c | 111 +++++++++++++++++++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 apps/netutils/netlib/netlib_autoconfig.c (limited to 'apps/netutils') diff --git a/apps/netutils/dhcpc/Kconfig b/apps/netutils/dhcpc/Kconfig index b4d3a1275..3249d9d38 100644 --- a/apps/netutils/dhcpc/Kconfig +++ b/apps/netutils/dhcpc/Kconfig @@ -6,7 +6,7 @@ config NETUTILS_DHCPC bool "DHCP client" default n - depends on NET && NET_UDP && NET_BROADCAST + depends on NET_UDP && NET_BROADCAST && NET_IPv4 ---help--- Enable support for the DHCP client. diff --git a/apps/netutils/dhcpd/Kconfig b/apps/netutils/dhcpd/Kconfig index 2a38b7a00..b211bf96a 100644 --- a/apps/netutils/dhcpd/Kconfig +++ b/apps/netutils/dhcpd/Kconfig @@ -6,6 +6,7 @@ config NETUTILS_DHCPD bool "DHCP server" default n + depends on NET_UDP && NET_IPv4 ---help--- Enable support for the DHCP server. diff --git a/apps/netutils/netlib/Makefile b/apps/netutils/netlib/Makefile index a9b234f56..da981fcc9 100644 --- a/apps/netutils/netlib/Makefile +++ b/apps/netutils/netlib/Makefile @@ -53,6 +53,9 @@ endif ifeq ($(CONFIG_NET_IPv6),y) CSRCS += netlib_setipv6addr.c netlib_getipv6addr.c CSRCS += netlib_setdripv6addr.c netlib_setipv6netmask.c +ifeq ($(CONFIG_NET_ICMPv6_AUTOCONF),y) +CSRCS += netlib_autoconfig.c +endif endif # These require TCP support diff --git a/apps/netutils/netlib/netlib_autoconfig.c b/apps/netutils/netlib/netlib_autoconfig.c new file mode 100644 index 000000000..f3040e2bb --- /dev/null +++ b/apps/netutils/netlib/netlib_autoconfig.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * netutils/netlib/netlib_autoconfig.c + * + * Copyright (C) 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 +#if defined(CONFIG_NET_ICMPv6_AUTOCONF) && CONFIG_NSOCKET_DESCRIPTORS > 0 + +#include +#include +#include +#include +#include + +#include +#include + +#include + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: netlib_icmpv6_autoconfiguration + * + * Description: + * Perform ICMPv6 auto-configuration in an attempt to get the IP address + * of the specified network device. + * + * Parameters: + * ifname The name of the interface to use + * + * Return: + * 0 on success; -1 on failure (with the errno variable set appropriately) + * + ****************************************************************************/ + +int netlib_icmpv6_autoconfiguration(FAR const char *ifname) +{ + int ret = ERROR; + +#if 1 /* Not yet implemented */ + +# warning Missing logic + errno = ENOSYS; + +#else + if (ifname) + { + int sockfd = socket(PF_INET6, NETLIB_SOCK_IOCTL, 0); + if (sockfd >= 0) + { + FAR struct sockaddr_in6 *inaddr; + struct lifreq req; + + /* Add the device name to the request */ + + strncpy(req.lifr_name, ifname, IFNAMSIZ); + + /* Add the INET address to the request */ + + inaddr = (FAR struct sockaddr_in6 *)&req.lifr_addr; + inaddr->sin6_family = AF_INET6; + inaddr->sin6_port = 0; + memcpy(&inaddr->sin6_addr, addr, sizeof(struct in6_addr)); + + ret = ioctl(sockfd, SIOCSLIFNETMASK, (unsigned long)((uintptr_t)&req)); + close(sockfd); + } + } +#endif + + return ret; +} + +#endif /* CONFIG_NET_ICMPv6_AUTOCONF && CONFIG_NSOCKET_DESCRIPTORS */ -- cgit v1.2.3