ARP: Add signal logic so that we do not have to wait so long with the network responses to ARP requests quickly
This commit is contained in:
parent
4bba611dc6
commit
9662f1750c
12
TODO
12
TODO
@ -873,7 +873,8 @@ o Network (net/, drivers/net)
|
||||
Or should it remain in the backlog with a status indication so that accept()
|
||||
can fail when it encounteres the invalid connection?
|
||||
Status: Open
|
||||
Priority: Medium. Important on slow applications that will not accept connections promptly.
|
||||
Priority: Medium. Important on slow applications that will not accept
|
||||
connections promptly.
|
||||
|
||||
o USB (drivers/usbdev, drivers/usbhost)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
@ -2275,9 +2276,12 @@ o Network Utilities (apps/netutils/)
|
||||
Title: THE ARP ISSUES AGAIN
|
||||
Description: The first GET received by THTTPD is not responded to. Refreshing the page
|
||||
from the browser solves the problem and THTTPD works fine after thatg. I
|
||||
believe that this is the duplicate of another bug: "Outgoing [uIP] packets are dropped
|
||||
and overwritten by ARP packets if the destination IP has not been mapped to a MAC."
|
||||
Status: Open
|
||||
believe that this is the duplicate of another bug: "Outgoing
|
||||
[uIP] packets are dropped and overwritten by ARP packets if the
|
||||
destination IP has not been mapped to a MAC."
|
||||
Status: Probably closed. The basic ARP issue has been fixed (if
|
||||
CONFIG_NET_ARP_SEND is enable), but this has not been verifie
|
||||
with THTTPD.
|
||||
Priority: Medium
|
||||
|
||||
Title: THTTPD WARNINGS
|
||||
|
@ -43,7 +43,7 @@ NET_CSRCS += arp_ipin.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_ARP_SEND),y)
|
||||
NET_CSRCS += arp_send.c arp_poll.c
|
||||
NET_CSRCS += arp_send.c arp_poll.c arp_notify.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_NET_ARP_DUMP),y)
|
||||
|
115
net/arp/arp.h
115
net/arp/arp.h
@ -155,6 +155,18 @@ struct arp_conn_s
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
/* Used to notify a thread waiting for a particular ARP response */
|
||||
|
||||
struct arp_notify_s
|
||||
{
|
||||
FAR struct arp_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 */
|
||||
};
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
@ -262,6 +274,8 @@ void arp_format(FAR struct net_driver_s *dev, in_addr_t ipaddr);
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
int arp_send(in_addr_t ipaddr);
|
||||
#else
|
||||
# define arp_send(i) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -279,6 +293,87 @@ int arp_send(in_addr_t ipaddr);
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
int arp_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback);
|
||||
#else
|
||||
# define arp_poll(d,c) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait_setup
|
||||
*
|
||||
* Description:
|
||||
* Called BEFORE an ARP request is sent. This function sets up the ARP
|
||||
* response timeout before the the ARP request is sent so that there is
|
||||
* no race condition when arp_wait() is called.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from ARP send and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify);
|
||||
#else
|
||||
# define arp_wait_setup(i,n)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel any wait set after arp_wait_setup is called but before arm_wait()
|
||||
* is called (arp_wait() will automatically cancel the wait).
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may execute in the interrupt context when called from
|
||||
* arp_wait().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
int arp_wait_cancel(FAR struct arp_notify_s *notify);
|
||||
#else
|
||||
# define arp_wait_cancel(n) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a ARP request is sent. This function will sleep
|
||||
* until either: (1) the matching ARP response is received, or (2) a
|
||||
* timeout occurs.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from ARP send and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
struct timespec;
|
||||
int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout);
|
||||
#else
|
||||
# define arp_wait(n,t) (0)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_notify
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a ARP response is received in order to wake-up
|
||||
* any threads that may be waiting for this particular ARP response.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver indirectly through
|
||||
* arp_arpin() and may be execute from the interrupt level.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
void arp_notify(in_addr_t ipaddr);
|
||||
#else
|
||||
# define arp_notify(i)
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
@ -357,17 +452,27 @@ void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
|
||||
#ifdef CONFIG_NET_ARP_DUMP
|
||||
void arp_dump(FAR struct arp_hdr_s *arp);
|
||||
#else
|
||||
# define arp_dump(arp)
|
||||
# define arp_dump(arp)
|
||||
#endif
|
||||
|
||||
#else /* CONFIG_NET_ARP */
|
||||
|
||||
/* If ARP is disabled, stub out all ARP interfaces */
|
||||
|
||||
# define arp_reset()
|
||||
# define arp_timer_initialize(void)
|
||||
# define arp_timer()
|
||||
# define arp_dump(arp)
|
||||
# define arp_reset()
|
||||
# define arp_timer_initialize()
|
||||
# define arp_timer()
|
||||
# define arp_format(d,i);
|
||||
# define arp_send(i) (0)
|
||||
# define arp_poll(d,c) (0)
|
||||
# define arp_wait_setup(i,n)
|
||||
# define arp_wait_cancel(n) (0)
|
||||
# define arp_wait(n,t) (0)
|
||||
# define arp_notify(i)
|
||||
# define arp_find(i) (NULL)
|
||||
# define arp_delete(i)
|
||||
# define arp_update(i,m);
|
||||
# define arp_dump(arp)
|
||||
|
||||
#endif /* CONFIG_NET_ARP */
|
||||
#endif /* __NET_ARP_ARP_H */
|
||||
|
@ -159,7 +159,13 @@ void arp_arpin(FAR struct net_driver_s *dev)
|
||||
|
||||
if (net_ipaddr_cmp(ipaddr, dev->d_ipaddr))
|
||||
{
|
||||
/* Yes... Insert the address mapping in the ARP table */
|
||||
|
||||
arp_update(parp->ah_sipaddr, parp->ah_shwaddr);
|
||||
|
||||
/* Then notify any logic waiting for the ARP result */
|
||||
|
||||
arp_notify(net_ip4addr_conv32(parp->ah_sipaddr));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
251
net/arp/arp_notify.c
Normal file
251
net/arp/arp_notify.c
Normal file
@ -0,0 +1,251 @@
|
||||
/****************************************************************************
|
||||
* net/arp/arp_notify.c
|
||||
*
|
||||
* Copyright (C) 2014 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 <time.h>
|
||||
#include <semaphore.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
|
||||
#include <arch/irq.h>
|
||||
|
||||
#include "arp/arp.h"
|
||||
|
||||
#ifdef CONFIG_NET_ARP_SEND
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
/* List of tasks waiting for ARP events */
|
||||
|
||||
static struct arp_notify_s *g_arp_waiters;
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_send_interrupt
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait_setup
|
||||
*
|
||||
* Description:
|
||||
* Called BEFORE an ARP request is sent. This function sets up the ARP
|
||||
* response timeout before the the ARP request is sent so that there is
|
||||
* no race condition when arp_wait() is called.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from ARP send and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_wait_setup(in_addr_t ipaddr, FAR struct arp_notify_s *notify)
|
||||
{
|
||||
irqstate_t flags;
|
||||
|
||||
/* Initialize the wait structure */
|
||||
|
||||
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_arp_waiters;
|
||||
g_arp_waiters = notify;
|
||||
irqrestore(flags);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait_cancel
|
||||
*
|
||||
* Description:
|
||||
* Cancel any wait set after arp_wait_setup is called but before arm_wait()
|
||||
* is called (arp_wait() will automatically cancel the wait).
|
||||
*
|
||||
* Assumptions:
|
||||
* This function may execute in the interrupt context when called from
|
||||
* arp_wait().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int arp_wait_cancel(FAR struct arp_notify_s *notify)
|
||||
{
|
||||
FAR struct arp_notify_s *curr;
|
||||
FAR struct arp_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_arp_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_arp_waiters = notify->nt_flink;
|
||||
}
|
||||
|
||||
ret = OK;
|
||||
}
|
||||
|
||||
irqrestore(flags);
|
||||
(void)sem_destroy(¬ify->nt_sem);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_wait
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a ARP request is sent. This function will sleep
|
||||
* until either: (1) the matching ARP response is received, or (2) a
|
||||
* timeout occurs.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from ARP send and executes in the normal
|
||||
* tasking environment.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int arp_wait(FAR struct arp_notify_s *notify, FAR struct timespec *timeout)
|
||||
{
|
||||
struct timespec abstime;
|
||||
irqstate_t flags;
|
||||
int ret;
|
||||
|
||||
/* And wait for the ARP response (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;
|
||||
}
|
||||
|
||||
(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)arp_wait_cancel(notify);
|
||||
|
||||
/* Re-enable interrupts and return the result of the wait */
|
||||
|
||||
irqrestore(flags);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: arp_notify
|
||||
*
|
||||
* Description:
|
||||
* Called each time that a ARP response is received in order to wake-up
|
||||
* any threads that may be waiting for this particular ARP response.
|
||||
*
|
||||
* Assumptions:
|
||||
* This function is called from the MAC device driver indirectly through
|
||||
* arp_arpin() and may be execute from the interrupt level.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_notify(in_addr_t ipaddr)
|
||||
{
|
||||
FAR struct arp_notify_s *curr;
|
||||
|
||||
/* Find an entry with the matching IP address in the list of waiters */
|
||||
|
||||
for (curr = g_arp_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_ARP_SEND */
|
@ -41,6 +41,7 @@
|
||||
|
||||
#include <unistd.h>
|
||||
#include <semaphore.h>
|
||||
#include <time.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
@ -61,6 +62,11 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define CONFIG_ARP_SEND_DELAYSEC \
|
||||
(CONFIG_ARP_SEND_DELAYMSEC / 1000)
|
||||
#define CONFIG_ARP_SEND_DELAYNSEC \
|
||||
((CONFIG_ARP_SEND_DELAYMSEC - 1000*CONFIG_ARP_SEND_DELAYSEC) / 1000000)
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -179,6 +185,8 @@ static uint16_t arp_send_interrupt(FAR struct net_driver_s *dev,
|
||||
int arp_send(in_addr_t ipaddr)
|
||||
{
|
||||
FAR struct net_driver_s *dev;
|
||||
struct arp_notify_s notify;
|
||||
struct timespec delay;
|
||||
struct arp_send_s state;
|
||||
net_lock_t save;
|
||||
int ret;
|
||||
@ -228,7 +236,12 @@ int arp_send(in_addr_t ipaddr)
|
||||
|
||||
while (state.snd_retries < CONFIG_ARP_SEND_MAXTRIES)
|
||||
{
|
||||
/* Check if the address mapping is present in the ARP table */
|
||||
/* Check if the address mapping is present in the ARP table. This
|
||||
* is only really meaningful on the first time through the loop.
|
||||
*
|
||||
* NOTE: If the ARP table is large than this could be a performance
|
||||
* issue.
|
||||
*/
|
||||
|
||||
if (arp_find(ipaddr))
|
||||
{
|
||||
@ -238,46 +251,58 @@ int arp_send(in_addr_t ipaddr)
|
||||
break;
|
||||
}
|
||||
|
||||
/* Set up the ARP response wait BEFORE we send the ARP request */
|
||||
|
||||
arp_wait_setup(ipaddr, ¬ify);
|
||||
|
||||
/* Arm/re-arm the callback */
|
||||
|
||||
state.snd_sent = false;
|
||||
state.snd_cb->flags = PKT_POLL;
|
||||
state.snd_cb->priv = (FAR void *)&state;
|
||||
state.snd_cb->event = arp_send_interrupt;
|
||||
state.snd_sent = false;
|
||||
state.snd_cb->flags = PKT_POLL;
|
||||
state.snd_cb->priv = (FAR void *)&state;
|
||||
state.snd_cb->event = arp_send_interrupt;
|
||||
|
||||
/* Notify the device driver that new TX data is available.
|
||||
* NOTES: This is in essence what netdev_txnotify() does, which
|
||||
* is not possible to call since it expects a net_ipaddr_t as
|
||||
* its single argument to lookup the network interface.
|
||||
*/
|
||||
/* Notify the device driver that new TX data is available.
|
||||
* NOTES: This is in essence what netdev_txnotify() does, which
|
||||
* is not possible to call since it expects a net_ipaddr_t as
|
||||
* its single argument to lookup the network interface.
|
||||
*/
|
||||
|
||||
dev->d_txavail(dev);
|
||||
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.
|
||||
*/
|
||||
/* 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);
|
||||
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.
|
||||
*
|
||||
* REVISIT: We would get better performance if there were signalling
|
||||
* from the arp_in() logic when the ARP response were received. But
|
||||
* this should be okay for testing purposes.
|
||||
*/
|
||||
/* Now wait for response to the ARP response to be received. The
|
||||
* optimal delay would be the work case round trip time.
|
||||
*/
|
||||
|
||||
usleep(1000*CONFIG_ARP_SEND_DELAYMSEC);
|
||||
delay.tv_sec = CONFIG_ARP_SEND_DELAYSEC;
|
||||
delay.tv_nsec = CONFIG_ARP_SEND_DELAYNSEC;
|
||||
|
||||
/* Increment the retry count */
|
||||
ret = arp_wait(¬ify, &delay);
|
||||
|
||||
state.snd_retries++;
|
||||
/* arp_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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user