2015-02-03 00:54:48 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* net/icmpv6/icmpv6_autoconfig.c
|
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2015-02-03 00:54:48 +01:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-02-03 00:54:48 +01:00
|
|
|
*
|
2020-05-17 16:47:40 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2015-02-03 00:54:48 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2015-02-03 20:25:28 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
2015-02-03 00:54:48 +01:00
|
|
|
#include <errno.h>
|
2015-02-03 20:25:28 +01:00
|
|
|
#include <debug.h>
|
2015-02-03 00:54:48 +01:00
|
|
|
|
2019-07-06 15:02:51 +02:00
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
2016-11-03 19:17:02 +01:00
|
|
|
#include <nuttx/semaphore.h>
|
2015-02-03 20:25:28 +01:00
|
|
|
#include <nuttx/net/net.h>
|
|
|
|
#include <nuttx/net/netdev.h>
|
|
|
|
|
|
|
|
#include "devif/devif.h"
|
2015-02-03 22:40:56 +01:00
|
|
|
#include "netdev/netdev.h"
|
2017-08-07 19:50:50 +02:00
|
|
|
#include "inet/inet.h"
|
2015-02-03 00:54:48 +01:00
|
|
|
#include "icmpv6/icmpv6.h"
|
|
|
|
|
2015-02-03 23:19:08 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
|
|
|
|
2015-02-03 20:25:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/* This structure holds the state of the send operation until it can be
|
2018-06-23 22:09:06 +02:00
|
|
|
* operated upon by the event handler.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct icmpv6_router_s
|
|
|
|
{
|
|
|
|
FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */
|
|
|
|
sem_t snd_sem; /* Used to wake up the waiting thread */
|
|
|
|
volatile bool snd_sent; /* True: if request sent */
|
2015-02-04 23:13:27 +01:00
|
|
|
bool snd_advertise; /* True: Send Neighbor Advertisement */
|
2015-02-03 20:25:28 +01:00
|
|
|
uint8_t snd_ifname[IFNAMSIZ]; /* Interface name */
|
2015-05-27 20:49:39 +02:00
|
|
|
int16_t snd_result; /* Result of the send */
|
2015-02-03 20:25:28 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-05-27 20:49:39 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: icmpv6_router_terminate
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
static void icmpv6_router_terminate(FAR struct icmpv6_router_s *state,
|
|
|
|
int result)
|
|
|
|
{
|
|
|
|
/* Don't allow any further call backs. */
|
|
|
|
|
|
|
|
state->snd_sent = true;
|
|
|
|
state->snd_result = (int16_t)result;
|
|
|
|
state->snd_cb->flags = 0;
|
|
|
|
state->snd_cb->priv = NULL;
|
|
|
|
state->snd_cb->event = NULL;
|
|
|
|
|
|
|
|
/* Wake up the waiting thread */
|
|
|
|
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_post(&state->snd_sem);
|
2015-05-27 20:49:39 +02:00
|
|
|
}
|
|
|
|
|
2015-02-03 20:25:28 +01:00
|
|
|
/****************************************************************************
|
2017-08-29 22:08:04 +02:00
|
|
|
* Name: icmpv6_router_eventhandler
|
2015-02-03 20:25:28 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-29 22:08:04 +02:00
|
|
|
static uint16_t icmpv6_router_eventhandler(FAR struct net_driver_s *dev,
|
|
|
|
FAR void *pvconn,
|
|
|
|
FAR void *priv, uint16_t flags)
|
2015-02-03 20:25:28 +01:00
|
|
|
{
|
|
|
|
FAR struct icmpv6_router_s *state = (FAR struct icmpv6_router_s *)priv;
|
|
|
|
|
2016-06-20 19:59:15 +02:00
|
|
|
ninfo("flags: %04x sent: %d\n", flags, state->snd_sent);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
if (state)
|
|
|
|
{
|
2015-05-27 20:49:39 +02:00
|
|
|
/* Check if the network is still up */
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2015-05-27 20:49:39 +02:00
|
|
|
if ((flags & NETDEV_DOWN) != 0)
|
2015-02-03 20:25:28 +01:00
|
|
|
{
|
2016-06-20 20:44:38 +02:00
|
|
|
nerr("ERROR: Interface is down\n");
|
2015-05-27 20:49:39 +02:00
|
|
|
icmpv6_router_terminate(state, -ENETUNREACH);
|
2015-02-03 20:25:28 +01:00
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if the outgoing packet is available. It may have been claimed
|
2020-05-17 16:47:40 +02:00
|
|
|
* by a send event handler serving a different thread -OR- if the
|
|
|
|
* output buffer currently contains unprocessed incoming data. In
|
|
|
|
* these cases we will just have to wait for the next polling cycle.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
2015-05-27 20:49:39 +02:00
|
|
|
else if (dev->d_sndlen > 0 || (flags & ICMPv6_NEWDATA) != 0)
|
2015-02-03 20:25:28 +01:00
|
|
|
{
|
|
|
|
/* Another thread has beat us sending data or the buffer is busy,
|
|
|
|
* Check for a timeout. If not timed out, wait for the next
|
|
|
|
* polling cycle and check again.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* REVISIT: No timeout. Just wait for the next polling cycle */
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
2018-11-09 22:41:23 +01:00
|
|
|
/* It looks like we are good to send the data.
|
|
|
|
*
|
|
|
|
* Copy the packet data into the device packet buffer and send it.
|
|
|
|
*/
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2015-02-04 23:13:27 +01:00
|
|
|
if (state->snd_advertise)
|
|
|
|
{
|
|
|
|
/* Send the ICMPv6 Neighbor Advertisement message */
|
|
|
|
|
|
|
|
icmpv6_advertise(dev, g_ipv6_allnodes);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Send the ICMPv6 Router Solicitation message */
|
|
|
|
|
|
|
|
icmpv6_rsolicit(dev);
|
|
|
|
}
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2018-11-09 22:41:23 +01:00
|
|
|
IFF_SET_IPv6(dev->d_flags);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
/* Don't allow any further call backs. */
|
|
|
|
|
2015-05-27 20:49:39 +02:00
|
|
|
icmpv6_router_terminate(state, OK);
|
2015-02-03 20:25:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-02-04 23:13:27 +01:00
|
|
|
* Name: icmpv6_send_message
|
2015-02-03 20:25:28 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Send an ICMPv6 Router Solicitation to resolve an IPv6 address.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2015-02-04 23:13:27 +01:00
|
|
|
* dev - The device to use to send the solicitation
|
|
|
|
* advertise - True: Send the Neighbor Advertisement message
|
2015-02-03 20:25:28 +01:00
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Zero (OK) is returned on success; On error a negated errno value is
|
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* The network is locked.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-09-20 20:45:05 +02:00
|
|
|
static int icmpv6_send_message(FAR struct net_driver_s *dev, bool advertise)
|
2015-02-03 20:25:28 +01:00
|
|
|
{
|
|
|
|
struct icmpv6_router_s state;
|
|
|
|
int ret;
|
|
|
|
|
2018-06-23 23:03:01 +02:00
|
|
|
/* Initialize the state structure with the network locked.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* This semaphore is used for signaling and, hence, should not have
|
2016-11-03 19:17:02 +01:00
|
|
|
* priority inheritance enabled.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
nxsem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
2020-05-17 15:56:21 +02:00
|
|
|
nxsem_set_protocol(&state.snd_sem, SEM_PRIO_NONE);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
/* Remember the routing device name */
|
|
|
|
|
|
|
|
strncpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname,
|
|
|
|
IFNAMSIZ);
|
|
|
|
|
|
|
|
/* Allocate resources to receive a callback. This and the following
|
|
|
|
* initialization is performed with the network lock because we don't
|
|
|
|
* want anything to happen until we are ready.
|
|
|
|
*/
|
|
|
|
|
2019-09-20 20:45:05 +02:00
|
|
|
state.snd_cb = devif_callback_alloc(dev, &dev->d_conncb);
|
2015-02-03 20:25:28 +01:00
|
|
|
if (!state.snd_cb)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed to allocate a cllback\n");
|
2015-02-03 20:25:28 +01:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto errout_with_semaphore;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Arm the callback */
|
|
|
|
|
|
|
|
state.snd_sent = false;
|
2015-05-27 20:49:39 +02:00
|
|
|
state.snd_result = -EBUSY;
|
2015-02-04 23:13:27 +01:00
|
|
|
state.snd_advertise = advertise;
|
2015-05-27 20:49:39 +02:00
|
|
|
state.snd_cb->flags = (ICMPv6_POLL | NETDEV_DOWN);
|
2015-02-03 20:25:28 +01:00
|
|
|
state.snd_cb->priv = (FAR void *)&state;
|
2017-08-29 22:08:04 +02:00
|
|
|
state.snd_cb->event = icmpv6_router_eventhandler;
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
/* Notify the device driver that new TX data is available. */
|
|
|
|
|
2018-11-09 18:22:58 +01:00
|
|
|
netdev_txnotify_dev(dev);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2018-06-23 23:03:01 +02:00
|
|
|
/* Wait for the send to complete or an error to occur
|
|
|
|
* net_lockedwait will also terminate if a signal is received.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
net_lockedwait(&state.snd_sem);
|
2015-02-03 20:25:28 +01:00
|
|
|
}
|
|
|
|
while (!state.snd_sent);
|
|
|
|
|
2015-05-27 20:49:39 +02:00
|
|
|
ret = state.snd_result;
|
2019-09-20 20:45:05 +02:00
|
|
|
devif_dev_callback_free(dev, state.snd_cb);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
errout_with_semaphore:
|
2017-10-03 23:35:24 +02:00
|
|
|
nxsem_destroy(&state.snd_sem);
|
2015-02-03 20:25:28 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-02-03 00:54:48 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: icmpv6_autoconfig
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Perform IPv6 auto-configuration to assign an IPv6 address to this
|
|
|
|
* device.
|
|
|
|
*
|
2015-02-03 13:04:54 +01:00
|
|
|
* Stateless auto-configuration exploits several other features in IPv6,
|
|
|
|
* including link-local addresses, multi-casting, the Neighbor Discovery
|
|
|
|
* protocol, and the ability to generate the interface identifier of an
|
2018-10-20 14:35:39 +02:00
|
|
|
* address from the underlying link layer address. The general idea is
|
|
|
|
* to have a device generate a temporary address until it can determine
|
2015-02-03 13:04:54 +01:00
|
|
|
* the characteristics of the network it is on, and then create a permanent
|
|
|
|
* address it can use based on that information.
|
|
|
|
*
|
2018-03-13 16:52:27 +01:00
|
|
|
* Input Parameters:
|
2019-03-19 16:43:32 +01:00
|
|
|
* dev - The device driver structure to assign the address to
|
|
|
|
* psock - A pointer to a NuttX-specific, internal socket structure
|
2015-02-03 00:54:48 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2015-02-03 00:54:48 +01:00
|
|
|
* Zero (OK) is returned on success; A negated errno value is returned on
|
|
|
|
* any failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2019-09-20 20:45:05 +02:00
|
|
|
int icmpv6_autoconfig(FAR struct net_driver_s *dev)
|
2015-02-03 00:54:48 +01:00
|
|
|
{
|
2015-02-03 20:25:28 +01:00
|
|
|
struct icmpv6_rnotify_s notify;
|
|
|
|
net_ipv6addr_t lladdr;
|
|
|
|
int retries;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Sanity checks */
|
|
|
|
|
|
|
|
DEBUGASSERT(dev);
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Auto-configuring %s\n", dev->d_ifname);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2018-11-10 14:13:54 +01:00
|
|
|
/* Lock the network.
|
|
|
|
*
|
|
|
|
* NOTE: Normally it is required that the network be in the "down" state
|
|
|
|
* when re-configuring the network interface. This is thought not to be
|
|
|
|
* a problem here because.
|
|
|
|
*
|
|
|
|
* 1. The ICMPv6 logic here runs with the network locked so there can be
|
|
|
|
* no outgoing packets with bad source IP addresses from any
|
|
|
|
* asynchronous network activity using the device being reconfigured.
|
|
|
|
* 2. Incoming packets depend only upon the MAC filtering. Network
|
|
|
|
* drivers do not use the IP address; they filter incoming packets
|
|
|
|
* using only the MAC address which is not being changed here.
|
|
|
|
*/
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_lock();
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2015-02-03 13:04:54 +01:00
|
|
|
/* IPv6 Stateless Autoconfiguration
|
2020-01-11 16:40:32 +01:00
|
|
|
* Reference:
|
|
|
|
* http://www.tcpipguide.com/free/t_IPv6AutoconfigurationandRenumbering.htm
|
2015-02-03 13:04:54 +01:00
|
|
|
*
|
|
|
|
* The following is a summary of the steps a device takes when using
|
|
|
|
* stateless auto-configuration:
|
|
|
|
*
|
|
|
|
* 1. Link-Local Address Generation: The device generates a link-local
|
|
|
|
* address. Recall that this is one of the two types of local-use IPv6
|
|
|
|
* addresses. Link-local addresses have "1111 1110 10" for the first
|
|
|
|
* ten bits. The generated address uses those ten bits followed by 54
|
|
|
|
* zeroes and then the 64 bit interface identifier. Typically this
|
2018-10-20 14:35:39 +02:00
|
|
|
* will be derived from the link layer (MAC) address.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
2018-11-09 22:28:58 +01:00
|
|
|
icmpv6_linkipaddr(dev, lladdr);
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("lladdr=%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x\n",
|
2020-05-17 16:47:40 +02:00
|
|
|
ntohs(lladdr[0]), ntohs(lladdr[1]),
|
|
|
|
ntohs(lladdr[2]), ntohs(lladdr[3]),
|
|
|
|
ntohs(lladdr[4]), ntohs(lladdr[5]),
|
|
|
|
ntohs(lladdr[6]), ntohs(lladdr[7]));
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2015-02-03 20:25:28 +01:00
|
|
|
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
2018-11-10 14:13:54 +01:00
|
|
|
/* 2. Link-Local Address Uniqueness Test: The node tests to ensure that
|
2015-02-03 13:04:54 +01:00
|
|
|
* the address it generated isn't for some reason already in use on the
|
2020-05-17 16:47:40 +02:00
|
|
|
* local network. (This is very unlikely to be an issue if the link-
|
|
|
|
* local address came from a MAC address but more likely if it was
|
|
|
|
* based on a generated token.) It sends a Neighbor Solicitation
|
|
|
|
* message using the Neighbor Discovery (ND) protocol. It then listens
|
|
|
|
* for a Neighbor Advertisement in response that indicates that another
|
|
|
|
* device is already using its link-local address; if so, either a new
|
|
|
|
* address must be generated, or auto-configuration fails and another
|
|
|
|
* method must be employed.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
ret = icmpv6_neighbor(lladdr);
|
2018-11-10 14:13:54 +01:00
|
|
|
if (ret >= 0)
|
2015-02-03 20:25:28 +01:00
|
|
|
{
|
|
|
|
/* Hmmm... someone else responded to our Neighbor Solicitation. We
|
2018-11-10 14:13:54 +01:00
|
|
|
* have no back-up plan in place. Just bail.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: IP conflict\n");
|
2018-11-10 14:13:54 +01:00
|
|
|
|
|
|
|
net_unlock();
|
2015-02-03 20:25:28 +01:00
|
|
|
return -EEXIST;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* 3. Link-Local Address Assignment: Assuming the uniqueness test passes,
|
2015-02-03 13:04:54 +01:00
|
|
|
* the device assigns the link-local address to its IP interface. This
|
|
|
|
* address can be used for communication on the local network, but not
|
|
|
|
* on the wider Internet (since link-local addresses are not routed).
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
net_ipv6addr_copy(dev->d_ipv6addr, lladdr);
|
|
|
|
|
|
|
|
/* 4. Router Contact: The node next attempts to contact a local router for
|
2015-02-03 13:04:54 +01:00
|
|
|
* more information on continuing the configuration. This is done either
|
|
|
|
* by listening for Router Advertisement messages sent periodically by
|
|
|
|
* routers, or by sending a specific Router Solicitation to ask a router
|
|
|
|
* for information on what to do next.
|
2015-02-03 20:25:28 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
for (retries = 0; retries < CONFIG_ICMPv6_AUTOCONF_MAXTRIES; retries++)
|
|
|
|
{
|
|
|
|
/* Set up the Router Advertisement BEFORE we send the Router
|
|
|
|
* Solicitation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
icmpv6_rwait_setup(dev, ¬ify);
|
|
|
|
|
|
|
|
/* Send the ICMPv6 Router solicitation message */
|
|
|
|
|
2019-09-20 20:45:05 +02:00
|
|
|
ret = icmpv6_send_message(dev, false);
|
2015-02-03 20:25:28 +01:00
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
nerr("ERROR: Failed send router solicitation: %d\n", ret);
|
2015-02-03 20:25:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait to receive the Router Advertisement message */
|
|
|
|
|
2020-01-04 11:37:46 +01:00
|
|
|
ret = icmpv6_rwait(¬ify, CONFIG_ICMPv6_AUTOCONF_DELAYMSEC);
|
2015-02-03 20:25:28 +01:00
|
|
|
if (ret != -ETIMEDOUT)
|
|
|
|
{
|
|
|
|
/* ETIMEDOUT is the only expected failure. We will retry on that
|
|
|
|
* case only.
|
|
|
|
*/
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
ninfo("Timed out... retrying %d\n", retries + 1);
|
2015-02-03 20:25:28 +01:00
|
|
|
}
|
|
|
|
|
2018-11-10 14:13:54 +01:00
|
|
|
/* Check for failures. */
|
2015-02-03 20:25:28 +01:00
|
|
|
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2019-09-20 20:51:37 +02:00
|
|
|
int senderr;
|
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
nerr("ERROR: Failed to get the router advertisement: "
|
|
|
|
"%d (retries=%d)\n",
|
2015-02-03 20:25:28 +01:00
|
|
|
ret, retries);
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2015-02-04 23:13:27 +01:00
|
|
|
/* Claim the link local address as ours by sending the ICMPv6 Neighbor
|
|
|
|
* Advertisement message.
|
|
|
|
*/
|
|
|
|
|
2019-09-20 20:51:37 +02:00
|
|
|
senderr = icmpv6_send_message(dev, true);
|
|
|
|
if (senderr < 0)
|
2015-02-04 23:13:27 +01:00
|
|
|
{
|
2019-09-20 20:51:37 +02:00
|
|
|
nerr("ERROR: Failed send neighbor advertisement: %d\n", senderr);
|
2015-02-04 23:13:27 +01:00
|
|
|
}
|
|
|
|
|
2015-02-06 15:11:09 +01:00
|
|
|
/* No off-link communications; No router address. */
|
|
|
|
|
2018-06-23 20:53:27 +02:00
|
|
|
net_ipv6addr_copy(dev->d_ipv6draddr, g_ipv6_unspecaddr);
|
2015-02-06 15:11:09 +01:00
|
|
|
|
2015-02-05 12:43:57 +01:00
|
|
|
/* Set a netmask for the local link address */
|
|
|
|
|
|
|
|
net_ipv6addr_copy(dev->d_ipv6netmask, g_ipv6_llnetmask);
|
2015-02-03 20:25:28 +01:00
|
|
|
}
|
|
|
|
|
2020-05-17 16:47:40 +02:00
|
|
|
/* 5. Router Direction: The router provides direction to the node on how
|
|
|
|
* to proceed with the auto-configuration. It may tell the node that on
|
|
|
|
* this network "stateful" auto-configuration is in use, and tell it
|
|
|
|
* the address of a DHCP server to use. Alternately, it will tell the
|
|
|
|
* host how to determine its global Internet address.
|
2015-02-03 22:40:56 +01:00
|
|
|
*
|
|
|
|
* 6. Global Address Configuration: Assuming that stateless auto-
|
2015-02-03 13:04:54 +01:00
|
|
|
* configuration is in use on the network, the host will configure
|
|
|
|
* itself with its globally-unique Internet address. This address is
|
|
|
|
* generally formed from a network prefix provided to the host by the
|
|
|
|
* router, combined with the device's identifier as generated in the
|
|
|
|
* first step.
|
|
|
|
*/
|
2015-02-03 20:25:28 +01:00
|
|
|
|
2018-11-10 14:13:54 +01:00
|
|
|
/* On success, the new address was already set (in icmpv_rnotify()). */
|
2015-02-03 22:40:56 +01:00
|
|
|
|
2016-12-03 23:28:19 +01:00
|
|
|
net_unlock();
|
2018-11-10 14:13:54 +01:00
|
|
|
return ret;
|
2015-02-03 00:54:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|