Add netlib and application hooks for ICMPv6 auto-configuration (still incomplete
This commit is contained in:
parent
3b60c71103
commit
5499189417
@ -61,6 +61,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||
#ifndef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Our host IPv6 address */
|
||||
|
||||
static const uint16_t g_ipv6_hostaddr[8] =
|
||||
@ -74,6 +75,7 @@ static const uint16_t g_ipv6_hostaddr[8] =
|
||||
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_7),
|
||||
HTONS(CONFIG_EXAMPLES_NETTEST_IPv6ADDR_8),
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Default routine IPv6 address */
|
||||
|
||||
@ -138,10 +140,17 @@ int nettest_main(int argc, char *argv[])
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_NETTEST_IPv6
|
||||
/* Set up our host address */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Perform ICMPv6 auto-configuration */
|
||||
|
||||
netlib_icmpv6_autoconfiguration("eth0");
|
||||
|
||||
#else
|
||||
/* Set up our fixed host address */
|
||||
|
||||
netlib_set_ipv6addr("eth0",
|
||||
(FAR const struct in6_addr *)g_ipv6_hostaddr);
|
||||
#endif
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
|
@ -58,6 +58,7 @@
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Our host IPv6 address */
|
||||
|
||||
static const uint16_t g_ipv6_hostaddr[8] =
|
||||
@ -71,6 +72,7 @@ static const uint16_t g_ipv6_hostaddr[8] =
|
||||
HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_7),
|
||||
HTONS(CONFIG_EXAMPLES_UDP_IPv6ADDR_8),
|
||||
};
|
||||
#endif
|
||||
|
||||
/* Default routine IPv6 address */
|
||||
|
||||
@ -116,10 +118,17 @@ int udp_main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
#ifdef CONFIG_EXAMPLES_UDP_IPv6
|
||||
/* Set up our host address */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Perform ICMPv6 auto-configuration */
|
||||
|
||||
netlib_icmpv6_autoconfiguration("eth0");
|
||||
|
||||
#else
|
||||
/* Set up our fixed host address */
|
||||
|
||||
netlib_set_ipv6addr("eth0",
|
||||
(FAR const struct in6_addr *)g_ipv6_hostaddr);
|
||||
#endif
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
|
@ -126,6 +126,12 @@ int netlib_set_dripv6addr(FAR const char *ifname, FAR const struct in6_addr *add
|
||||
int netlib_set_ipv6netmask(FAR const char *ifname, FAR const struct in6_addr *addr);
|
||||
#endif
|
||||
|
||||
/* ICMPv6 Autoconfiguration */
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
int netlib_icmpv6_autoconfiguration(FAR const char *ifname);
|
||||
#endif
|
||||
|
||||
/* HTTP support */
|
||||
|
||||
int netlib_parsehttpurl(FAR const char *url, uint16_t *port,
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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.
|
||||
|
||||
|
@ -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
|
||||
|
111
netutils/netlib/netlib_autoconfig.c
Normal file
111
netutils/netlib/netlib_autoconfig.c
Normal file
@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
* netutils/netlib/netlib_autoconfig.c
|
||||
*
|
||||
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* 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 <nuttx/config.h>
|
||||
#if defined(CONFIG_NET_ICMPv6_AUTOCONF) && CONFIG_NSOCKET_DESCRIPTORS > 0
|
||||
|
||||
#include <sys/socket.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <apps/netutils/netlib.h>
|
||||
|
||||
/****************************************************************************
|
||||
* 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 */
|
@ -931,7 +931,7 @@ config NSH_NETMASK
|
||||
endif # NET_IPv4
|
||||
|
||||
if NET_IPv6
|
||||
if !NSH_DHCPC
|
||||
if !NET_ICMPv6_AUTOCONF
|
||||
|
||||
comment "Target IPv6 address"
|
||||
|
||||
@ -940,7 +940,7 @@ config NSH_IPv6ADDR_1
|
||||
default 0xfc00
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the first of the 8-values. The default for
|
||||
@ -951,7 +951,7 @@ config NSH_IPv6ADDR_2
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the second of the 8-values. The default for
|
||||
@ -962,7 +962,7 @@ config NSH_IPv6ADDR_3
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the third of the 8-values. The default for
|
||||
@ -973,7 +973,7 @@ config NSH_IPv6ADDR_4
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the fourth of the 8-values. The default for
|
||||
@ -984,7 +984,7 @@ config NSH_IPv6ADDR_5
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the fifth of the 8-values. The default for
|
||||
@ -995,7 +995,7 @@ config NSH_IPv6ADDR_6
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the sixth of the 8-values. The default for
|
||||
@ -1006,7 +1006,7 @@ config NSH_IPv6ADDR_7
|
||||
default 0x0000
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the seventh of the 8-values. The default for
|
||||
@ -1017,13 +1017,13 @@ config NSH_IPv6ADDR_8
|
||||
default 0x0002
|
||||
range 0x0 0xffff
|
||||
---help---
|
||||
If NSH_DHCPC is NOT set, then the static IP address must be
|
||||
If NET_ICMPv6_AUTOCONF is NOT set, then the static IP address must be
|
||||
provided. This is a 16-bit integer value in host order. Each of the
|
||||
eight values forming the full IP address must be specified
|
||||
individually. This is the last of the 8-values. The default for
|
||||
all eight values is fc00::2.
|
||||
|
||||
endif # !NSH_DHCPC
|
||||
endif # !NET_ICMPv6_AUTOCONF
|
||||
|
||||
comment "Router IPv6 address"
|
||||
|
||||
|
@ -132,14 +132,9 @@ static sem_t g_notify_sem;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
#ifndef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Host IPv6 address */
|
||||
|
||||
#ifdef CONFIG_NSH_DHCPC
|
||||
static const uint16_t g_ipv6_hostaddr[8] =
|
||||
{
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
#else
|
||||
static const uint16_t g_ipv6_hostaddr[8] =
|
||||
{
|
||||
HTONS(CONFIG_NSH_IPv6ADDR_1),
|
||||
@ -151,7 +146,7 @@ static const uint16_t g_ipv6_hostaddr[8] =
|
||||
HTONS(CONFIG_NSH_IPv6ADDR_7),
|
||||
HTONS(CONFIG_NSH_IPv6ADDR_8),
|
||||
};
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||
|
||||
/* Default routine IPv6 address */
|
||||
|
||||
@ -260,10 +255,18 @@ static void nsh_netinit_configure(void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
/* Set up our host address */
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Perform ICMPv6 auto-configuration */
|
||||
|
||||
netlib_icmpv6_autoconfiguration(NET_DEVNAME);
|
||||
|
||||
#else
|
||||
|
||||
/* Set up our fixed host address */
|
||||
|
||||
netlib_set_ipv6addr(NET_DEVNAME,
|
||||
(FAR const struct in6_addr *)g_ipv6_hostaddr);
|
||||
#endif
|
||||
|
||||
/* Set up the default router address */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user