forked from nuttx/nuttx-update
ICMPv6: Adds basic logic to support verification that we have the IPv6 address in the Neighbor Table. This feature is important because otherwise the first packet sent to a remote peer will fail (it will be replaced with a Neighbor Solicitation).
This commit is contained in:
parent
4ce94a7e95
commit
a07a764d42
20 changed files with 933 additions and 108 deletions
|
@ -600,6 +600,11 @@ CONFIG_NET_SOLINGER=y
|
|||
#
|
||||
# CONFIG_NET_PKT is not set
|
||||
|
||||
#
|
||||
# Unix Domain Socket Support
|
||||
#
|
||||
# CONFIG_NET_LOCAL is not set
|
||||
|
||||
#
|
||||
# TCP/IP Networking
|
||||
#
|
||||
|
@ -622,6 +627,7 @@ CONFIG_NET_UDP_CHECKSUMS=y
|
|||
CONFIG_NET_UDP_CONNS=8
|
||||
CONFIG_NET_BROADCAST=y
|
||||
# CONFIG_NET_RXAVAIL is not set
|
||||
# CONFIG_NET_UDP_READAHEAD is not set
|
||||
|
||||
#
|
||||
# ICMPv6 Networking Support
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/****************************************************************************
|
||||
* net/arp/arp.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
|
|
|
@ -112,7 +112,7 @@ void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify)
|
|||
* Function: arp_wait_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel any wait set after arp_wait_setup is called but before arm_wait()
|
||||
* Cancel any wait set after arp_wait_setup is called but before arp_wait()
|
||||
* is called (arp_wait() will automatically cancel the wait).
|
||||
*
|
||||
* Assumptions:
|
||||
|
|
|
@ -114,11 +114,6 @@
|
|||
* OUT: Cleared (only) by the socket layer logic to indicate
|
||||
* that the reply was processed, suppressing further
|
||||
* attempts to process the reply.
|
||||
*
|
||||
* ICMPv6_ADVERTISE IN: An ICMPv6 Neighbor Advertisement has been received.
|
||||
* Used to support ICMPv6 Neighbor Discovery Protocol.
|
||||
* OUT: Cleared (only) by the socket layer logic to indicate
|
||||
* that the reply was processed.
|
||||
*/
|
||||
|
||||
#define TCP_ACKDATA (1 << 0)
|
||||
|
@ -142,7 +137,6 @@
|
|||
#define TCP_TIMEDOUT (1 << 9)
|
||||
#define ICMP_ECHOREPLY (1 << 10)
|
||||
#define ICMPv6_ECHOREPLY ICMP_ECHOREPLY
|
||||
#define ICMPv6_ADVERTISE (1 << 11)
|
||||
|
||||
#define TCP_CONN_EVENTS (TCP_CLOSE | TCP_ABORT | TCP_CONNECTED | TCP_TIMEDOUT)
|
||||
|
||||
|
@ -217,12 +211,6 @@ extern uint8_t g_reassembly_timer;
|
|||
extern struct devif_callback_s *g_icmp_echocallback;
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6) && defined(CONFIG_NET_ICMPv6_PING)
|
||||
/* List of applications waiting for ICMPv6 ECHO REPLY */
|
||||
|
||||
extern struct devif_callback_s *g_icmpv6_echocallback;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
|
|
@ -129,7 +129,7 @@ static inline int devif_poll_icmp(FAR struct net_driver_s *dev,
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_NET_ICMPv6_NEIGHBOR)
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
static inline int devif_poll_icmpv6(FAR struct net_driver_s *dev,
|
||||
devif_poll_callback_t callback)
|
||||
{
|
||||
|
@ -141,7 +141,7 @@ static inline int devif_poll_icmpv6(FAR struct net_driver_s *dev,
|
|||
|
||||
return callback(dev);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_PING || CONFIG_NET_NET_ICMPv6_NEIGHBOR*/
|
||||
#endif /* CONFIG_NET_ICMPv6_PING || CONFIG_NET_ICMPv6_NEIGHBOR*/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: devif_poll_igmp
|
||||
|
@ -374,7 +374,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
|
|||
|
||||
if (!bstop)
|
||||
#endif
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_NET_ICMPv6_NEIGHBOR)
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
{
|
||||
/* Traverse all of the tasks waiting to send an ICMPv6 ECHO request. */
|
||||
|
||||
|
|
|
@ -43,14 +43,14 @@ ifeq ($(CONFIG_NET_ICMPv6_PING),y)
|
|||
NET_CSRCS += icmpv6_ping.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_NET_ICMPv6_NEIGHBOR),y)
|
||||
NET_CSRCS += icmpv6_neighbor.c
|
||||
ifeq ($(CONFIG_NET_ICMPv6_NEIGHBOR),y)
|
||||
NET_CSRCS += icmpv6_neighbor.c icmpv6_notify.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_ICMPv6_PING),y)
|
||||
NET_CSRCS += icmpv6_poll.c
|
||||
else
|
||||
ifeq ($(CONFIG_NET_NET_ICMPv6_NEIGHBOR),y)
|
||||
ifeq ($(CONFIG_NET_ICMPv6_NEIGHBOR),y)
|
||||
NET_CSRCS += icmpv6_poll.c
|
||||
endif
|
||||
endif
|
||||
|
|
|
@ -43,6 +43,7 @@
|
|||
#include <nuttx/config.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/net/ip.h>
|
||||
|
||||
|
@ -52,30 +53,35 @@
|
|||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Allocate a new ICMPv6 data callback */
|
||||
|
||||
#define icmpv6_callback_alloc() devif_callback_alloc(&g_icmpv6_conn.list)
|
||||
#define icmpv6_callback_free(cb) devif_callback_free(cb, &g_icmpv6_conn.list)
|
||||
|
||||
/****************************************************************************
|
||||
* Public Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_IPv6_NEIGHBOR
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
/* For symmetry with other protocols, a "connection" structure is
|
||||
* provided. But it is a singleton for the case of ARP packet transfers.
|
||||
*/
|
||||
|
||||
struct icmpv6_conn_s
|
||||
{
|
||||
FAR struct devif_callback_s *list; /* ARP callbacks */
|
||||
FAR struct devif_callback_s *list; /* ARP callbacks */
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6_NEIGHBOR
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
/* Used to notify a thread waiting for a particular ARP response */
|
||||
|
||||
struct icmpv6_notify_s
|
||||
{
|
||||
FAR struct icmpv6_notify_s *nt_flink; /* Supports singly linked list */
|
||||
in_addr_t nt_ipaddr; /* Waited for IP address in the mapping */
|
||||
sem_t nt_sem; /* Will wake up the waiter */
|
||||
int nt_result; /* The result of the wait */
|
||||
net_ipv6addr_t nt_ipaddr; /* Waited for IP address in the mapping */
|
||||
sem_t nt_sem; /* Will wake up the waiter */
|
||||
int nt_result; /* The result of the wait */
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -91,10 +97,19 @@ extern "C"
|
|||
# define EXTERN extern
|
||||
#endif
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
/* This is the singleton "connection" structure for TX polls and echo replies */
|
||||
|
||||
EXTERN struct icmpv6_conn_s g_icmpv6_conn;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
struct timespec; /* Forward reference */
|
||||
struct net_driver_s; /* Forward reference */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_input
|
||||
*
|
||||
|
@ -136,7 +151,7 @@ void icmpv6_input(FAR struct net_driver_s *dev);
|
|||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success and the IP address mapping can now be
|
||||
* found in the ARP table. On error a negated errno value is returned:
|
||||
* found in the Neighbor Table. On error a negated errno value is returned:
|
||||
*
|
||||
* -ETIMEDOUT: The number or retry counts has been exceed.
|
||||
* -EHOSTUNREACH: Could not find a route to the host
|
||||
|
@ -146,8 +161,8 @@ void icmpv6_input(FAR struct net_driver_s *dev);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_NET_ICMPv6_NEIGHBOR
|
||||
int icmpv6_neighbor(net_ipv6addr_t ipaddr);
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
int icmpv6_neighbor(const net_ipv6addr_t ipaddr);
|
||||
#else
|
||||
# define icmpv6_neighbor(i) (0)
|
||||
#endif
|
||||
|
@ -169,7 +184,7 @@ int icmpv6_neighbor(net_ipv6addr_t ipaddr);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_NET_ICMPv6_NEIGHBOR)
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
void icmpv6_poll(FAR struct net_driver_s *dev);
|
||||
#endif
|
||||
|
||||
|
@ -196,5 +211,87 @@ void icmpv6_solicit(FAR struct net_driver_s *dev,
|
|||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait_setup
|
||||
*
|
||||
* Description:
|
||||
* Called BEFORE an Neighbor Solicitation is sent. This function sets up
|
||||
* the Neighbor Advertisement timeout before the the Neighbor Solicitation
|
||||
* is sent so that there is no race condition when icmpv6_wait() is called.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from icmpv6_neighbor() and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
void icmpv6_wait_setup(const net_ipv6addr_t ipaddr,
|
||||
FAR struct icmpv6_notify_s *notify);
|
||||
#else
|
||||
# define icmpv6_wait_setup(i,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel any wait set after icmpv6_wait_setup is called but before
|
||||
* icmpv6_wait()is called (icmpv6_wait() will automatically cancel the
|
||||
* wait).
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may execute in the interrupt context when called from
|
||||
* icmpv6_wait().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify);
|
||||
#else
|
||||
# define icmpv6_wait_cancel(n) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a Neighbor Solicitation is sent. This function
|
||||
* will sleep until either: (1) the matching Neighbor Advertisement is
|
||||
* received, or (2) a timeout occurs.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from icmpv6_neighbor() and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
int icmpv6_wait(FAR struct icmpv6_notify_s *notify,
|
||||
FAR struct timespec *timeout);
|
||||
#else
|
||||
# define icmpv6_wait(n,t) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_notify
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a Neighbor Advertisement is received in order to
|
||||
* wake-up any threads that may be waiting for this particular Neighbor
|
||||
* Advertisement.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver indirectly through
|
||||
* icmpv6_icmpv6in() and may be execute from the interrupt level.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
void icmpv6_notify(net_ipv6addr_t ipaddr);
|
||||
#else
|
||||
# define icmpv6_notify(i)
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6 */
|
||||
#endif /* __NET_ICMPv6_ICMPv6_H */
|
||||
|
|
|
@ -80,12 +80,10 @@
|
|||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_PING
|
||||
FAR struct devif_callback_s *g_icmpv6_echocallback = NULL;
|
||||
#endif
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
/* This is the singleton "connection" structure for TX polls and echo replies */
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
FAR struct devif_callback_s *g_icmpv6_neighborcallback = NULL;
|
||||
struct icmpv6_conn_s g_icmpv6_conn;
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -259,17 +257,9 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
(FAR struct neighbor_addr_s *)adv->tgtlladdr);
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
/* Is there logic waiting for the Neighbor Advertisement? */
|
||||
/* Then notify any logic waiting for the Neighbor Advertisement */
|
||||
|
||||
if (g_icmpv6_neighborcallback)
|
||||
{
|
||||
/* Dispatch the Neighbor Advertisement reply to the
|
||||
* waiting thread.
|
||||
*/
|
||||
|
||||
(void)devif_callback_execute(dev, icmp, ICMPv6_ADVERTISE,
|
||||
g_icmpv6_neighborcallback);
|
||||
}
|
||||
icmpv6_notify(icmp->srcipaddr);
|
||||
#endif
|
||||
|
||||
/* We consumed the packet but we don't send anything in
|
||||
|
@ -298,18 +288,18 @@ void icmpv6_input(FAR struct net_driver_s *dev)
|
|||
icmp->chksum = ~icmpv6_chksum(dev);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_PING
|
||||
/* If an ICMPv6 echo reply is received then there should also be
|
||||
* a thread waiting to received the echo response.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_PING
|
||||
else if (icmp->type == ICMPv6_ECHO_REPLY && g_icmpv6_echocallback)
|
||||
else if (icmp->type == ICMPv6_ECHO_REPLY)
|
||||
{
|
||||
uint16_t flags = ICMPv6_ECHOREPLY;
|
||||
|
||||
/* Dispatch the ECHO reply to the waiting thread */
|
||||
|
||||
flags = devif_callback_execute(dev, icmp, flags, g_icmpv6_echocallback);
|
||||
flags = devif_callback_execute(dev, icmp, flags, g_icmpv6_conn.list);
|
||||
|
||||
/* If the ECHO reply was not handled, then drop the packet */
|
||||
|
||||
|
|
408
net/icmpv6/icmpv6_neighbor.c
Normal file
408
net/icmpv6/icmpv6_neighbor.c
Normal file
|
@ -0,0 +1,408 @@
|
|||
/****************************************************************************
|
||||
* net/icmpv6/icmpv6_neighbor.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>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/netdev.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/icmpv6.h>
|
||||
|
||||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "neighbor/neighbor.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_ICMPv6_NEIGHBOR_DELAYSEC \
|
||||
(CONFIG_ICMPv6_NEIGHBOR_DELAYMSEC / 1000)
|
||||
#define CONFIG_ICMPv6_NEIGHBOR_DELAYNSEC \
|
||||
((CONFIG_ICMPv6_NEIGHBOR_DELAYMSEC - 1000*CONFIG_ICMPv6_NEIGHBOR_DELAYSEC) * 1000000)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/* This structure holds the state of the send operation until it can be
|
||||
* operated upon from the interrupt level.
|
||||
*/
|
||||
|
||||
struct icmpv6_neighbor_s
|
||||
{
|
||||
FAR struct devif_callback_s *snd_cb; /* Reference to callback instance */
|
||||
sem_t snd_sem; /* Used to wake up the waiting thread */
|
||||
uint8_t snd_retries; /* Retry count */
|
||||
volatile bool snd_sent; /* True: if request sent */
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
uint8_t snd_ifname[IFNAMSIZ]; /* Interface name */
|
||||
#endif
|
||||
net_ipv6addr_t snd_ipaddr; /* The IPv6 address to be queried */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_neighbor_interrupt
|
||||
****************************************************************************/
|
||||
|
||||
static uint16_t icmpv6_neighbor_interrupt(FAR struct net_driver_s *dev,
|
||||
FAR void *pvconn,
|
||||
FAR void *priv, uint16_t flags)
|
||||
{
|
||||
FAR struct icmpv6_neighbor_s *state = (FAR struct icmpv6_neighbor_s *)priv;
|
||||
|
||||
nllvdbg("flags: %04x sent: %d\n", flags, state->snd_sent);
|
||||
|
||||
if (state)
|
||||
{
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
/* Is this the device that we need to route this request? */
|
||||
|
||||
if (strncmp((FAR const char *)dev->d_ifname,
|
||||
(FAR const char *)state->snd_ifname, IFNAMSIZ) != 0)
|
||||
{
|
||||
/* No... pass on this one and wait for the device that we want */
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* Check if the outgoing packet is available. It may have been claimed
|
||||
* by a send interrupt 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.
|
||||
*/
|
||||
|
||||
if (dev->d_sndlen > 0 || (flags & PKT_NEWDATA) != 0)
|
||||
{
|
||||
/* 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;
|
||||
}
|
||||
|
||||
/* It looks like we are good to send the data */
|
||||
/* Copy the packet data into the device packet buffer and send it */
|
||||
|
||||
icmpv6_solicit(dev, state->snd_ipaddr);
|
||||
|
||||
/* Make sure no additional Neighbor Solicitation overwrites this one. This
|
||||
* flag will be cleared in icmpv6_out().
|
||||
*/
|
||||
|
||||
IFF_SET_NOARP(dev->d_flags);
|
||||
|
||||
/* Don't allow any further call backs. */
|
||||
|
||||
state->snd_sent = true;
|
||||
state->snd_cb->flags = 0;
|
||||
state->snd_cb->priv = NULL;
|
||||
state->snd_cb->event = NULL;
|
||||
|
||||
/* Wake up the waiting thread */
|
||||
|
||||
sem_post(&state->snd_sem);
|
||||
}
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: icmpv6_neighbor
|
||||
*
|
||||
* Description:
|
||||
* The icmpv6_solicit() call may be to send an ICMPv6 Neighbor
|
||||
* Solicitation to resolve an IPv6 address. This function first checks if
|
||||
* the IPv6 address is already in the Neighbor Table. If so, then it
|
||||
* returns success immediately.
|
||||
*
|
||||
* If the requested IPv6 address in not in the Neighbor Table, then this
|
||||
* function will send the Neighbor Solicitation, delay, then check if the
|
||||
* IP address is now in the Neighbor able. It will repeat this sequence
|
||||
* until either (1) the IPv6 address mapping is now in the Neighbor table,
|
||||
* or (2) a configurable number of timeouts occur without receiving the
|
||||
* ICMPv6 Neighbor Advertisement.
|
||||
*
|
||||
* Parameters:
|
||||
* ipaddr The IPv6 address to be queried.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) is returned on success and the IP address mapping can now be
|
||||
* found in the Neighbor Table. On error a negated errno value is returned:
|
||||
*
|
||||
* -ETIMEDOUT: The number or retry counts has been exceed.
|
||||
* -EHOSTUNREACH: Could not find a route to the host
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the normal tasking context.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int icmpv6_neighbor(const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
struct icmpv6_notify_s notify;
|
||||
struct timespec delay;
|
||||
struct icmpv6_neighbor_s state;
|
||||
FAR const uint16_t *lookup;
|
||||
net_lock_t save;
|
||||
int ret;
|
||||
|
||||
/* First check if destination is a local broadcast or a multicast address.
|
||||
*
|
||||
* - IPv6 multicast addresses are have the high-order octet of the
|
||||
* addresses=0xff (ff00::/8.)
|
||||
*/
|
||||
|
||||
if (net_ipv6addr_cmp(ipaddr, g_ipv6_allzeroaddr) ||
|
||||
(ipaddr[0] & NTOHS(0xff00)) == NTOHS(0xff00))
|
||||
{
|
||||
/* We don't need to send the Neighbor Solicitation */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/* Get the device that can route this request */
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
dev = netdev_findby_ipv6addr(g_ipv6_allzeroaddr, ipaddr);
|
||||
#else
|
||||
dev = netdev_findby_ipv6addr(ipaddr);
|
||||
#endif
|
||||
if (!dev)
|
||||
{
|
||||
ndbg("ERROR: Unreachable: %08lx\n", (unsigned long)ipaddr);
|
||||
ret = -EHOSTUNREACH;
|
||||
goto errout;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NET_MULTILINK
|
||||
/* If we are supporting multiple network devices and using different
|
||||
* link level protocols then we can get here for other link protocols
|
||||
* as well. Continue and send the Neighbor Solicitation request only
|
||||
* if this device uses the Ethernet data link protocol.
|
||||
*
|
||||
* REVISIT: Other link layer protocols may require Neighbor Discovery
|
||||
* as well (but not SLIP which is the only other option at the moment).
|
||||
*/
|
||||
|
||||
if (dev->d_lltype != NET_LL_ETHERNET)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Check if the destination address is on the local network. */
|
||||
|
||||
if (net_ipv6addr_maskcmp(ipaddr, dev->d_ipv6addr, dev->d_ipv6netmask))
|
||||
{
|
||||
/* Yes.. use the input address for the lookup */
|
||||
|
||||
lookup = ipaddr;
|
||||
}
|
||||
else
|
||||
{
|
||||
net_ipv6addr_t dripaddr;
|
||||
|
||||
/* Destination address is not on the local network */
|
||||
|
||||
#ifdef CONFIG_NET_ROUTE
|
||||
|
||||
/* We have a routing table.. find the correct router to use in
|
||||
* this case (or, as a fall-back, use the device's default router
|
||||
* address). We will use the router IP address instead of the
|
||||
* destination address when determining the MAC address.
|
||||
*/
|
||||
|
||||
netdev_ipv6_router(dev, ipaddr, dripaddr);
|
||||
#else
|
||||
/* Use the device's default router IP address instead of the
|
||||
* destination address when determining the MAC address.
|
||||
*/
|
||||
|
||||
net_ipv6addr_copy(dripaddr, dev->d_ipv6draddr);
|
||||
#endif
|
||||
|
||||
/* Use the router address for the lookup */
|
||||
|
||||
lookup = dripaddr;
|
||||
}
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
save = net_lock();
|
||||
state.snd_cb = icmpv6_callback_alloc();
|
||||
if (!state.snd_cb)
|
||||
{
|
||||
ndbg("ERROR: Failed to allocate a cllback\n");
|
||||
ret = -ENOMEM;
|
||||
goto errout_with_lock;
|
||||
}
|
||||
|
||||
/* Initialize the state structure. This is done with interrupts
|
||||
* disabled
|
||||
*/
|
||||
|
||||
(void)sem_init(&state.snd_sem, 0, 0); /* Doesn't really fail */
|
||||
state.snd_retries = 0; /* No retries yet */
|
||||
net_ipv6addr_copy(state.snd_ipaddr, lookup); /* IP address to query */
|
||||
|
||||
#ifdef CONFIG_NETDEV_MULTINIC
|
||||
/* Remember the routing device name */
|
||||
|
||||
strncpy((FAR char *)state.snd_ifname, (FAR const char *)dev->d_ifname, IFNAMSIZ);
|
||||
#endif
|
||||
|
||||
/* Now loop, testing if the address mapping is in the Neighbor Table and re-sending the ARP request if it is not.
|
||||
*/
|
||||
|
||||
ret = -ETIMEDOUT; /* Assume a timeout failure */
|
||||
|
||||
while (state.snd_retries < CONFIG_ICMPv6_NEIGHBOR_MAXTRIES)
|
||||
{
|
||||
/* Check if the address mapping is present in the Neighbor Table. This
|
||||
* is only really meaningful on the first time through the loop.
|
||||
*
|
||||
* NOTE: If the Neighbor Table is large than this could be a performance
|
||||
* issue.
|
||||
*/
|
||||
|
||||
if (neighbor_findentry(lookup) != NULL)
|
||||
{
|
||||
/* We have it! Break out with success */
|
||||
|
||||
ret = OK;
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set up the ARP response wait BEFORE we send the ARP request */
|
||||
|
||||
icmpv6_wait_setup(lookup, ¬ify);
|
||||
|
||||
/* Arm/re-arm the callback */
|
||||
|
||||
state.snd_sent = false;
|
||||
state.snd_cb->flags = ICMPv6_POLL;
|
||||
state.snd_cb->priv = (FAR void *)&state;
|
||||
state.snd_cb->event = icmpv6_neighbor_interrupt;
|
||||
|
||||
/* Notify the device driver that new TX data is available.
|
||||
* NOTES: This is in essence what netdev_ipv4_txnotify() does, which
|
||||
* is not possible to call since it expects a icmpv6_neighbor as
|
||||
* its single argument to lookup the network interface.
|
||||
*/
|
||||
|
||||
dev->d_txavail(dev);
|
||||
|
||||
/* Wait for the send to complete or an error to occur: NOTES: (1)
|
||||
* net_lockedwait will also terminate if a signal is received, (2)
|
||||
* interrupts may be disabled! They will be re-enabled while the
|
||||
* task sleeps and automatically re-enabled when the task restarts.
|
||||
*/
|
||||
|
||||
do
|
||||
{
|
||||
(void)net_lockedwait(&state.snd_sem);
|
||||
}
|
||||
while (!state.snd_sent);
|
||||
|
||||
/* Now wait for response to the ARP response to be received. The
|
||||
* optimal delay would be the work case round trip time.
|
||||
*/
|
||||
|
||||
delay.tv_sec = CONFIG_ICMPv6_NEIGHBOR_DELAYSEC;
|
||||
delay.tv_nsec = CONFIG_ICMPv6_NEIGHBOR_DELAYNSEC;
|
||||
|
||||
ret = icmpv6_wait(¬ify, &delay);
|
||||
|
||||
/* icmpv6_wait will return OK if and only if the matching ARP response
|
||||
* is received. Otherwise, it will return -ETIMEDOUT.
|
||||
*/
|
||||
|
||||
if (ret == OK)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
/* Increment the retry count */
|
||||
|
||||
state.snd_retries++;
|
||||
}
|
||||
|
||||
sem_destroy(&state.snd_sem);
|
||||
icmpv6_callback_free(state.snd_cb);
|
||||
errout_with_lock:
|
||||
net_unlock(save);
|
||||
errout:
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
256
net/icmpv6/icmpv6_notify.c
Normal file
256
net/icmpv6/icmpv6_notify.c
Normal file
|
@ -0,0 +1,256 @@
|
|||
/****************************************************************************
|
||||
* net/icmpv6/icmpv6_notify.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>
|
||||
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include "icmpv6/icmpv6.h"
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* List of tasks waiting for Neighbor Discover events */
|
||||
|
||||
static struct icmpv6_notify_s *g_icmpv6_waiters;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait_setup
|
||||
*
|
||||
* Description:
|
||||
* Called BEFORE an Neighbor Solicitation is sent. This function sets up
|
||||
* the Neighbor Advertisement timeout before the the Neighbor Solicitation
|
||||
* is sent so that there is no race condition when icmpv6_wait() is called.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from icmpv6_neighbor() and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void icmpv6_wait_setup(const net_ipv6addr_t ipaddr,
|
||||
FAR struct icmpv6_notify_s *notify)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
/* Initialize the wait structure */
|
||||
|
||||
net_ipv6addr_copy(notify->nt_ipaddr, ipaddr);
|
||||
notify->nt_result = -ETIMEDOUT;
|
||||
(void)sem_init(¬ify->nt_sem, 0, 0);
|
||||
|
||||
/* Add the wait structure to the list with interrupts disabled */
|
||||
|
||||
flags = irqsave();
|
||||
notify->nt_flink = g_icmpv6_waiters;
|
||||
g_icmpv6_waiters = notify;
|
||||
irqrestore(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel any wait set after icmpv6_wait_setup is called but before
|
||||
* icmpv6_wait()is called (icmpv6_wait() will automatically cancel the
|
||||
* wait).
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may execute in the interrupt context when called from
|
||||
* icmpv6_wait().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int icmpv6_wait_cancel(FAR struct icmpv6_notify_s *notify)
|
||||
{
|
||||
FAR struct icmpv6_notify_s *curr;
|
||||
FAR struct icmpv6_notify_s *prev;
|
||||
irqstate_t flags;
|
||||
int ret = -ENOENT;
|
||||
|
||||
/* Remove our wait structure from the list (we may no longer be at the
|
||||
* head of the list).
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
for (prev = NULL, curr = g_icmpv6_waiters;
|
||||
curr && curr != notify;
|
||||
prev = curr, curr = curr->nt_flink);
|
||||
|
||||
DEBUGASSERT(curr && curr == notify);
|
||||
if (curr)
|
||||
{
|
||||
if (prev)
|
||||
{
|
||||
prev->nt_flink = notify->nt_flink;
|
||||
}
|
||||
else
|
||||
{
|
||||
g_icmpv6_waiters = notify->nt_flink;
|
||||
}
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
(void)sem_destroy(¬ify->nt_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_wait
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a Neighbor Solicitation is sent. This function
|
||||
* will sleep until either: (1) the matching Neighbor Advertisement is
|
||||
* received, or (2) a timeout occurs.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from icmpv6_neighbor() and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int icmpv6_wait(FAR struct icmpv6_notify_s *notify,
|
||||
FAR struct timespec *timeout)
|
||||
{
|
||||
struct timespec abstime;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
/* And wait for the Neighbor Advertisement (or a timeout). Interrupts will
|
||||
* be re-enabled while we wait.
|
||||
*/
|
||||
|
||||
flags = irqsave();
|
||||
DEBUGVERIFY(clock_gettime(CLOCK_REALTIME, &abstime));
|
||||
|
||||
abstime.tv_sec += timeout->tv_sec;
|
||||
abstime.tv_nsec += timeout->tv_nsec;
|
||||
if (abstime.tv_nsec > 1000000000)
|
||||
{
|
||||
abstime.tv_sec++;
|
||||
abstime.tv_nsec -= 1000000000;
|
||||
}
|
||||
|
||||
/* REVISIT: If sem_timedwait() is awakened with signal, we will return
|
||||
* the wrong error code.
|
||||
*/
|
||||
|
||||
(void)sem_timedwait(¬ify->nt_sem, &abstime);
|
||||
ret = notify->nt_result;
|
||||
|
||||
/* Remove our wait structure from the list (we may no longer be at the
|
||||
* head of the list).
|
||||
*/
|
||||
|
||||
(void)icmpv6_wait_cancel(notify);
|
||||
|
||||
/* Re-enable interrupts and return the result of the wait */
|
||||
|
||||
irqrestore(flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: icmpv6_notify
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a Neighbor Advertisement is received in order to
|
||||
* wake-up any threads that may be waiting for this particular Neighbor
|
||||
* Advertisement.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver indirectly through
|
||||
* icmpv6_icmpv6in() and may be execute from the interrupt level.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void icmpv6_notify(net_ipv6addr_t ipaddr)
|
||||
{
|
||||
FAR struct icmpv6_notify_s *curr;
|
||||
|
||||
/* Find an entry with the matching IP address in the list of waiters */
|
||||
|
||||
for (curr = g_icmpv6_waiters; curr; curr = curr->nt_flink)
|
||||
{
|
||||
/* Does this entry match? If the result is okay, then we have
|
||||
* already notified this waiter and it has not yet taken the
|
||||
* entry from the list.
|
||||
*/
|
||||
|
||||
if (curr->nt_result != OK && curr->nt_ipaddr == ipaddr)
|
||||
{
|
||||
/* Yes.. Signal the waiting, returning success */
|
||||
|
||||
curr->nt_result = OK;
|
||||
sem_post(&curr->nt_sem);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
|
@ -74,11 +74,6 @@
|
|||
#define ICMPv6ECHOREPLY \
|
||||
((struct icmpv6_echo_reply_s *)&dev->d_buf[NET_LL_HDRLEN(dev) + IPv6_HDRLEN])
|
||||
|
||||
/* Allocate a new ICMPv6 data callback */
|
||||
|
||||
#define icmpv6_callback_alloc() devif_callback_alloc(&g_icmpv6_echocallback)
|
||||
#define icmpv6_callback_free(cb) devif_callback_free(cb, &g_icmpv6_echocallback)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
@ -405,18 +400,18 @@ int icmpv6_ping(net_ipv6addr_t addr, uint16_t id, uint16_t seqno,
|
|||
struct icmpv6_ping_s state;
|
||||
net_lock_t save;
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_SEND
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
int ret;
|
||||
|
||||
/* Make sure that the IP address mapping is in the Neighbor Table */
|
||||
|
||||
ret = neighbor_send(addr);
|
||||
ret = icmpv6_neighbor(addr);
|
||||
if (ret < 0)
|
||||
{
|
||||
ndbg("ERROR: Not reachable\n");
|
||||
return -ENETUNREACH;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Initialize the state structure */
|
||||
|
||||
|
|
|
@ -38,8 +38,9 @@
|
|||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_NET_ICMPv6_NEIGHBOR)
|
||||
#if defined(CONFIG_NET_ICMPv6_PING) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
|
||||
#include <semaphore.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
|
@ -88,8 +89,6 @@
|
|||
|
||||
void icmpv6_poll(FAR struct net_driver_s *dev)
|
||||
{
|
||||
uint16_t flags;
|
||||
|
||||
/* Setup for the application callback */
|
||||
|
||||
dev->d_appdata = &dev->d_buf[NET_LL_HDRLEN(dev) + IPICMPv6_HDRLEN];
|
||||
|
@ -98,30 +97,7 @@ void icmpv6_poll(FAR struct net_driver_s *dev)
|
|||
|
||||
/* Perform the application callback */
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_PING
|
||||
#ifdef CONFIG_NET_NET_ICMPv6_NEIGHBOR
|
||||
flags = ICMPv6_POLL;
|
||||
#endif
|
||||
if (g_icmpv6_echocallback)
|
||||
{
|
||||
flags = devif_callback_execute(dev, NULL, ICMPv6_POLL,
|
||||
g_icmpv6_echocallback);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_PING */
|
||||
|
||||
#ifdef CONFIG_NET_NET_ICMPv6_NEIGHBOR
|
||||
if (
|
||||
#ifdef CONFIG_NET_ICMPv6_PING
|
||||
flags != 0 &&
|
||||
#endif
|
||||
g_icmpv6_neighborcallback)
|
||||
{
|
||||
flags = devif_callback_execute(dev, NULL, ICMPv6_POLL,
|
||||
g_icmpv6_neighborcallback);
|
||||
}
|
||||
#endif /* CONFIG_NET_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
UNUSED(flags);
|
||||
(void)devif_callback_execute(dev, NULL, ICMPv6_POLL, g_icmpv6_conn.list);
|
||||
}
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6_PING || CONFIG_NET_NET_ICMPv6_NEIGHBOR */
|
||||
#endif /* CONFIG_NET_ICMPv6_PING || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
|
|
@ -138,7 +138,7 @@ void neighbor_initialize(void);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct neighbor_entry *neighbor_findentry(net_ipv6addr_t ipaddr);
|
||||
FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_add
|
||||
|
@ -174,7 +174,7 @@ void neighbor_add(FAR net_ipv6addr_t ipaddr, FAR struct neighbor_addr_s *addr);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct neighbor_addr_s *neighbor_lookup(net_ipv6addr_t ipaddr);
|
||||
FAR const struct neighbor_addr_s *neighbor_lookup(const net_ipv6addr_t ipaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_update
|
||||
|
@ -192,7 +192,7 @@ FAR const struct neighbor_addr_s *neighbor_lookup(net_ipv6addr_t ipaddr);
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_update(net_ipv6addr_t ipaddr);
|
||||
void neighbor_update(const net_ipv6addr_t ipaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: neighbor_periodic
|
||||
|
|
|
@ -68,7 +68,7 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR struct neighbor_entry *neighbor_findentry(net_ipv6addr_t ipaddr)
|
||||
FAR struct neighbor_entry *neighbor_findentry(const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR const struct neighbor_addr_s *neighbor_lookup(net_ipv6addr_t ipaddr)
|
||||
FAR const struct neighbor_addr_s *neighbor_lookup(const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
FAR struct neighbor_entry *neighbor;
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@
|
|||
*
|
||||
****************************************************************************/
|
||||
|
||||
void neighbor_update(net_ipv6addr_t ipaddr)
|
||||
void neighbor_update(const net_ipv6addr_t ipaddr)
|
||||
{
|
||||
struct neighbor_entry *neighbor;
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@
|
|||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "arp/arp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "neighbor/neighbor.h"
|
||||
#include "tcp/tcp.h"
|
||||
#include "socket/socket.h"
|
||||
|
@ -283,7 +284,7 @@ static inline bool sendfile_addrcheck(FAR struct tcp_conn_s *conn)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
#if !defined(CONFIG_NET_ICMPv6_SEND)
|
||||
#if !defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
return (neighbor_findentry(conn->u.ipv6.raddr) != NULL);
|
||||
#else
|
||||
return true;
|
||||
|
@ -588,7 +589,7 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset,
|
|||
size_t count)
|
||||
{
|
||||
FAR struct socket *psock = sockfd_socket(outfd);
|
||||
FAR struct tcp_conn_s *conn = (FAR struct tcp_conn_s*)psock->s_conn;
|
||||
FAR struct tcp_conn_s *conn;
|
||||
struct sendfile_s state;
|
||||
net_lock_t save;
|
||||
int err;
|
||||
|
@ -611,17 +612,44 @@ ssize_t net_sendfile(int outfd, struct file *infile, off_t *offset,
|
|||
goto errout;
|
||||
}
|
||||
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
/* Make sure that we have the IP address mapping */
|
||||
|
||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
if (psock->s_domain == PF_INET)
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ARP_SEND */
|
||||
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the Neighbor Table */
|
||||
|
||||
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Did we successfully get the address mapping? */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
ndbg("ERROR: Not reachable\n");
|
||||
err = ENETUNREACH;
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Set the socket state to sending */
|
||||
|
||||
|
|
|
@ -72,6 +72,7 @@
|
|||
#include "socket/socket.h"
|
||||
#include "netdev/netdev.h"
|
||||
#include "arp/arp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "neighbor/neighbor.h"
|
||||
#include "tcp/tcp.h"
|
||||
#include "devif/devif.h"
|
||||
|
@ -297,7 +298,7 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
#if !defined(CONFIG_NET_ICMPv6_SEND)
|
||||
#if !defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
return (neighbor_findentry(conn->u.ipv6.raddr) != NULL);
|
||||
#else
|
||||
return true;
|
||||
|
@ -938,19 +939,44 @@ ssize_t psock_tcp_send(FAR struct socket *psock, FAR const void *buf,
|
|||
goto errout;
|
||||
}
|
||||
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
/* Make sure that we have the IP address mapping */
|
||||
|
||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
if (psock->s_domain == PF_INET)
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ARP_SEND */
|
||||
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the Neighbor Table */
|
||||
|
||||
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Did we successfully get the address mapping? */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
ndbg("ERROR: Not reachable\n");
|
||||
err = ENETUNREACH;
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Dump the incoming buffer */
|
||||
|
||||
|
|
|
@ -61,6 +61,7 @@
|
|||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "arp/arp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "neighbor/neighbor.h"
|
||||
#include "tcp/tcp.h"
|
||||
#include "socket/socket.h"
|
||||
|
@ -249,7 +250,7 @@ static inline bool psock_send_addrchck(FAR struct tcp_conn_s *conn)
|
|||
else
|
||||
#endif
|
||||
{
|
||||
#if !defined(CONFIG_NET_ICMPv6_SEND)
|
||||
#if !defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
return (neighbor_findentry(conn->u.ipv6.raddr) != NULL);
|
||||
#else
|
||||
return true;
|
||||
|
@ -727,18 +728,44 @@ ssize_t psock_tcp_send(FAR struct socket *psock,
|
|||
goto errout;
|
||||
}
|
||||
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
/* Make sure that we have the IP address mapping */
|
||||
|
||||
conn = (FAR struct tcp_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
if (psock->s_domain == PF_INET)
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
|
||||
ret = arp_send(conn->u.ipv4.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ARP_SEND */
|
||||
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
else
|
||||
#endif
|
||||
{
|
||||
/* Make sure that the IP address mapping is in the Neighbor Table */
|
||||
|
||||
ret = icmpv6_neighbor(conn->u.ipv6.raddr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Did we successfully get the address mapping? */
|
||||
|
||||
if (ret < 0)
|
||||
{
|
||||
ndbg("ERROR: Not reachable\n");
|
||||
err = ENETUNREACH;
|
||||
goto errout;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Set the socket state to sending */
|
||||
|
||||
|
|
|
@ -53,6 +53,7 @@
|
|||
#include "netdev/netdev.h"
|
||||
#include "devif/devif.h"
|
||||
#include "arp/arp.h"
|
||||
#include "icmpv6/icmpv6.h"
|
||||
#include "socket/socket.h"
|
||||
#include "udp/udp.h"
|
||||
|
||||
|
@ -382,19 +383,44 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
net_lock_t save;
|
||||
int ret;
|
||||
|
||||
#if defined(CONFIG_NET_ARP_SEND) || defined(CONFIG_NET_ICMPv6_NEIGHBOR)
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
FAR const struct sockaddr_in *into;
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
if (psock->s_domain == PF_INET)
|
||||
#endif
|
||||
{
|
||||
FAR const struct sockaddr_in *into;
|
||||
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
/* Make sure that the IP address mapping is in the ARP table */
|
||||
|
||||
into = (FAR const struct sockaddr_in *)to;
|
||||
ret = arp_send(into->sin_addr.s_addr);
|
||||
}
|
||||
#endif /* CONFIG_NET_ARP_SEND */
|
||||
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_NEIGHBOR
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
else
|
||||
#endif
|
||||
{
|
||||
FAR const struct sockaddr_in6 *into;
|
||||
|
||||
/* Make sure that the IP address mapping is in the Neighbor Table */
|
||||
|
||||
into = (FAR const struct sockaddr_in6 *)to;
|
||||
ret = icmpv6_neighbor(into->sin6_addr.s6_addr16);
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Did we successfully get the address mapping? */
|
||||
|
||||
into = (FAR const struct sockaddr_in *)to;
|
||||
ret = arp_send(into->sin_addr.s_addr);
|
||||
if (ret < 0)
|
||||
{
|
||||
ndbg("ERROR: Not reachable\n");
|
||||
return -ENETUNREACH;
|
||||
}
|
||||
#endif
|
||||
#endif /* CONFIG_NET_ARP_SEND || CONFIG_NET_ICMPv6_NEIGHBOR */
|
||||
|
||||
/* Set the socket state to sending */
|
||||
|
||||
|
@ -428,6 +454,8 @@ ssize_t psock_udp_sendto(FAR struct socket *psock, FAR const void *buf,
|
|||
/* Setup the UDP socket */
|
||||
|
||||
conn = (FAR struct udp_conn_s *)psock->s_conn;
|
||||
DEBUGASSERT(conn);
|
||||
|
||||
ret = udp_connect(conn, to);
|
||||
if (ret < 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue