summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorGregory Nutt <gnutt@nuttx.org>2015-02-03 08:01:55 -0600
committerGregory Nutt <gnutt@nuttx.org>2015-02-03 08:01:55 -0600
commitd2dd063179ec9ab25b0db59573aa5231ba82ad93 (patch)
treee1daaf9acdcc41cfff736d7d56babbe1c59045d2 /apps
parent5facd80a972df125a152f2ac2493441c18985b51 (diff)
downloadpx4-nuttx-d2dd063179ec9ab25b0db59573aa5231ba82ad93.tar.gz
px4-nuttx-d2dd063179ec9ab25b0db59573aa5231ba82ad93.tar.bz2
px4-nuttx-d2dd063179ec9ab25b0db59573aa5231ba82ad93.zip
Add netlib and application hooks for ICMPv6 auto-configuration (still incomplete
Diffstat (limited to 'apps')
-rw-r--r--apps/examples/nettest/nettest.c11
-rw-r--r--apps/examples/udp/target.c11
-rw-r--r--apps/include/netutils/netlib.h6
-rw-r--r--apps/netutils/dhcpc/Kconfig2
-rw-r--r--apps/netutils/dhcpd/Kconfig1
-rw-r--r--apps/netutils/netlib/Makefile3
-rw-r--r--apps/netutils/netlib/netlib_autoconfig.c111
-rw-r--r--apps/nshlib/Kconfig20
-rw-r--r--apps/nshlib/nsh_netinit.c21
9 files changed, 164 insertions, 22 deletions
diff --git a/apps/examples/nettest/nettest.c b/apps/examples/nettest/nettest.c
index c42f688c6..e4c9a1db3 100644
--- a/apps/examples/nettest/nettest.c
+++ b/apps/examples/nettest/nettest.c
@@ -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 */
diff --git a/apps/examples/udp/target.c b/apps/examples/udp/target.c
index 711fe0d02..2d80ac0dc 100644
--- a/apps/examples/udp/target.c
+++ b/apps/examples/udp/target.c
@@ -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 */
diff --git a/apps/include/netutils/netlib.h b/apps/include/netutils/netlib.h
index 882de51f5..ffd45b442 100644
--- a/apps/include/netutils/netlib.h
+++ b/apps/include/netutils/netlib.h
@@ -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,
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 <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 */
diff --git a/apps/nshlib/Kconfig b/apps/nshlib/Kconfig
index 3805ffff4..8bcd5eda7 100644
--- a/apps/nshlib/Kconfig
+++ b/apps/nshlib/Kconfig
@@ -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"
diff --git a/apps/nshlib/nsh_netinit.c b/apps/nshlib/nsh_netinit.c
index d2ea3520f..c2b8bf952 100644
--- a/apps/nshlib/nsh_netinit.c
+++ b/apps/nshlib/nsh_netinit.c
@@ -132,14 +132,9 @@ static sem_t g_notify_sem;
#endif
#ifdef CONFIG_NET_IPv6
- /* Host IPv6 address */
+#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 */