summaryrefslogtreecommitdiff
path: root/nuttx/net
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-21 16:00:20 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2009-03-21 16:00:20 +0000
commit6f33910a3b092e057e3e066603837784cd41b4e2 (patch)
tree9eb3a98ea84ce5b3f1c417eee5da66aa6f3747de /nuttx/net
parent8c195a6502ab171dde27aa23ba9251079e18d3ac (diff)
downloadpx4-nuttx-6f33910a3b092e057e3e066603837784cd41b4e2.tar.gz
px4-nuttx-6f33910a3b092e057e3e066603837784cd41b4e2.tar.bz2
px4-nuttx-6f33910a3b092e057e3e066603837784cd41b4e2.zip
Expose more ARP APIs
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@1633 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/net')
-rw-r--r--nuttx/net/netdev_ioctl.c7
-rw-r--r--nuttx/net/uip/Make.defs6
-rw-r--r--nuttx/net/uip/uip_arp.c149
-rw-r--r--nuttx/net/uip/uip_arptab.c253
4 files changed, 271 insertions, 144 deletions
diff --git a/nuttx/net/netdev_ioctl.c b/nuttx/net/netdev_ioctl.c
index 950d4e21d..f690b335e 100644
--- a/nuttx/net/netdev_ioctl.c
+++ b/nuttx/net/netdev_ioctl.c
@@ -253,6 +253,13 @@ int netdev_ioctl(int sockfd, int cmd, struct ifreq *req)
err = ENOSYS;
goto errout;
+#ifdef CONFIG_NET_ARPIOCTLS
+ case SIOCSARP: /* Set a ARP mapping */
+ case SIOCDARP: /* Delete an ARP mapping */
+ case SIOCGARP: /* Get an ARP mapping */
+# error "IOCTL Commands not implemented"
+#endif
+
default:
err = EINVAL;
goto errout;
diff --git a/nuttx/net/uip/Make.defs b/nuttx/net/uip/Make.defs
index 234e6a9bc..e67c73243 100644
--- a/nuttx/net/uip/Make.defs
+++ b/nuttx/net/uip/Make.defs
@@ -1,7 +1,7 @@
############################################################################
# Make.defs
#
-# Copyright (C) 2007 Gregory Nutt. All rights reserved.
+# Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <spudmonkey@racsa.co.cr>
#
# Redistribution and use in source and binary forms, with or without
@@ -40,8 +40,8 @@ ifeq ($(CONFIG_NET),y)
# Common IP source files
-UIP_CSRCS += uip_initialize.c uip_setipid.c uip_arp.c uip_input.c uip_send.c \
- uip_poll.c uip_chksum.c uip_callback.c
+UIP_CSRCS += uip_initialize.c uip_setipid.c uip_arp.c uip_arptab.c uip_input.c \
+ uip_send.c uip_poll.c uip_chksum.c uip_callback.c
ifeq ($(CONFIG_NET_IPv6),y)
UIP_CSRCS += uip_neighbor.c
diff --git a/nuttx/net/uip/uip_arp.c b/nuttx/net/uip/uip_arp.c
index 47ac8ba7f..2f2c729d3 100644
--- a/nuttx/net/uip/uip_arp.c
+++ b/nuttx/net/uip/uip_arp.c
@@ -115,13 +115,6 @@ struct ethip_hdr
uint16 eh_ipoption[2]; /* (optional) */
};
-struct arp_entry
-{
- in_addr_t at_ipaddr;
- struct ether_addr at_ethaddr;
- uint8 at_time;
-};
-
/****************************************************************************
* Private Data
****************************************************************************/
@@ -152,11 +145,6 @@ static const uint16 g_broadcast_ipaddr[2] = {0xffff, 0xffff};
static const ubyte g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e};
#endif
-/* The table of known address mappings */
-
-static struct arp_entry g_arptable[CONFIG_NET_ARPTAB_SIZE];
-static uint8 g_arptime;
-
/****************************************************************************
* Private Functions
****************************************************************************/
@@ -183,122 +171,10 @@ static void uip_arp_dump(struct arp_hdr *arp)
# define uip_arp_dump(arp)
#endif
-static void uip_arp_update(uint16 *pipaddr, uint8 *ethaddr)
-{
- struct arp_entry *tabptr = NULL;
- in_addr_t ipaddr = uip_ip4addr_conv(pipaddr);
- int i;
-
- /* Walk through the ARP mapping table and try to find an entry to
- * update. If none is found, the IP -> MAC address mapping is
- * inserted in the ARP table.
- */
-
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- tabptr = &g_arptable[i];
-
- /* Only check those entries that are actually in use. */
-
- if (tabptr->at_ipaddr != 0)
- {
- /* Check if the source IP address of the incoming packet matches
- * the IP address in this ARP table entry.
- */
-
- if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr))
- {
- /* An old entry found, update this and return. */
- memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN);
- tabptr->at_time = g_arptime;
-
- return;
- }
- }
- }
-
- /* If we get here, no existing ARP table entry was found, so we
- create one. */
-
- /* First, we try to find an unused entry in the ARP table. */
-
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- tabptr = &g_arptable[i];
- if (tabptr->at_ipaddr == 0)
- {
- break;
- }
- }
-
- /* If no unused entry is found, we try to find the oldest entry and
- * throw it away.
- */
-
- if (i == CONFIG_NET_ARPTAB_SIZE)
- {
- uint8 tmpage = 0;
- int j = 0;
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- tabptr = &g_arptable[i];
- if (g_arptime - tabptr->at_time > tmpage)
- {
- tmpage = g_arptime - tabptr->at_time;
- j = i;
- }
- }
- i = j;
- tabptr = &g_arptable[i];
- }
-
- /* Now, i is the ARP table entry which we will fill with the new
- * information.
- */
-
- tabptr->at_ipaddr = ipaddr;
- memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN);
- tabptr->at_time = g_arptime;
-}
-
/****************************************************************************
* Public Functions
****************************************************************************/
-/* Initialize the ARP module. */
-
-void uip_arp_init(void)
-{
- int i;
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- memset(&g_arptable[i].at_ipaddr, 0, sizeof(in_addr_t));
- }
-}
-
-/* Periodic ARP processing function.
- *
- * This function performs periodic timer processing in the ARP module
- * and should be called at regular intervals. The recommended interval
- * is 10 seconds between the calls.
- */
-
-void uip_arp_timer(void)
-{
- struct arp_entry *tabptr;
- int i;
-
- ++g_arptime;
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- tabptr = &g_arptable[i];
- if (tabptr->at_ipaddr != 0 && g_arptime - tabptr->at_time >= UIP_ARP_MAXAGE)
- {
- tabptr->at_ipaddr = 0;
- }
- }
-}
-
/* ARP processing for incoming ARP packets.
*
* This function should be called by the device driver when an ARP
@@ -410,13 +286,12 @@ void uip_arp_arpin(struct uip_driver_s *dev)
void uip_arp_out(struct uip_driver_s *dev)
{
- struct arp_entry *tabptr = NULL;
- struct arp_hdr *parp = ARPBUF;
- struct uip_eth_hdr *peth = ETHBUF;
- struct ethip_hdr *pip = IPBUF;
- in_addr_t ipaddr;
- in_addr_t destipaddr;
- int i;
+ const struct arp_entry *tabptr = NULL;
+ struct arp_hdr *parp = ARPBUF;
+ struct uip_eth_hdr *peth = ETHBUF;
+ struct ethip_hdr *pip = IPBUF;
+ in_addr_t ipaddr;
+ in_addr_t destipaddr;
/* Find the destination IP address in the ARP table and construct
* the Ethernet header. If the destination IP addres isn't on the
@@ -478,16 +353,8 @@ void uip_arp_out(struct uip_driver_s *dev)
/* Check if we already have this destination address in the ARP table */
- for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
- {
- tabptr = &g_arptable[i];
- if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr))
- {
- break;
- }
- }
-
- if (i == CONFIG_NET_ARPTAB_SIZE)
+ tabptr = uip_arp_find(ipaddr);
+ if (!tabptr)
{
nvdbg("ARP request for IP %04lx\n", (long)ipaddr);
diff --git a/nuttx/net/uip/uip_arptab.c b/nuttx/net/uip/uip_arptab.c
new file mode 100644
index 000000000..9c0ad6c4d
--- /dev/null
+++ b/nuttx/net/uip/uip_arptab.c
@@ -0,0 +1,253 @@
+/****************************************************************************
+ * net/uip/uip_arptab.c
+ * Implementation of the ARP Address Resolution Protocol.
+ *
+ * Copyright (C) 2007-2009 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <spudmonkey@racsa.co.cr>
+ *
+ * Based originally on uIP which also has a BSD style license:
+ *
+ * Author: Adam Dunkels <adam@dunkels.com>
+ * Copyright (c) 2001-2003, Adam Dunkels.
+ * All rights reserved.
+ *
+ * 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. The name of the author may not be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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>
+#ifdef CONFIG_NET
+
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include <string.h>
+#include <debug.h>
+
+#include <netinet/in.h>
+#include <net/ethernet.h>
+#include <net/uip/uip-arch.h>
+#include <net/uip/uip-arp.h>
+
+/****************************************************************************
+ * Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* The table of known address mappings */
+
+static struct arp_entry g_arptable[CONFIG_NET_ARPTAB_SIZE];
+static uint8 g_arptime;
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: uip_arp_init
+ *
+ * Description:
+ * Initialize the ARP module. This function must be called before any of
+ * the other ARP functions.
+ *
+ ****************************************************************************/
+
+void uip_arp_init(void)
+{
+ int i;
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ memset(&g_arptable[i].at_ipaddr, 0, sizeof(in_addr_t));
+ }
+}
+
+/****************************************************************************
+ * Name: uip_arp_timer
+ *
+ * Description:
+ * This function performs periodic timer processing in the ARP module
+ * and should be called at regular intervals. The recommended interval
+ * is 10 seconds between the calls. It is responsible for flushing old
+ * entries in the ARP table.
+ *
+ ****************************************************************************/
+
+void uip_arp_timer(void)
+{
+ struct arp_entry *tabptr;
+ int i;
+
+ ++g_arptime;
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ tabptr = &g_arptable[i];
+ if (tabptr->at_ipaddr != 0 && g_arptime - tabptr->at_time >= UIP_ARP_MAXAGE)
+ {
+ tabptr->at_ipaddr = 0;
+ }
+ }
+}
+
+/****************************************************************************
+ * Name: uip_arp_update
+ *
+ * Description:
+ * Add the IP/HW address mapping to the ARP table -OR- change the IP
+ * address of an existing association.
+ *
+ * Input parameters:
+ * pipaddr - Refers to an IP address uint16[2]
+ * ethaddr - Refers to a HW address uint8[IFHWADDRLEN]
+ *
+ * Assumptions
+ * Interrupts are disabled
+ *
+ ****************************************************************************/
+
+void uip_arp_update(uint16 *pipaddr, uint8 *ethaddr)
+{
+ struct arp_entry *tabptr = NULL;
+ in_addr_t ipaddr = uip_ip4addr_conv(pipaddr);
+ int i;
+
+ /* Walk through the ARP mapping table and try to find an entry to
+ * update. If none is found, the IP -> MAC address mapping is
+ * inserted in the ARP table.
+ */
+
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ tabptr = &g_arptable[i];
+
+ /* Only check those entries that are actually in use. */
+
+ if (tabptr->at_ipaddr != 0)
+ {
+ /* Check if the source IP address of the incoming packet matches
+ * the IP address in this ARP table entry.
+ */
+
+ if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr))
+ {
+ /* An old entry found, update this and return. */
+
+ memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN);
+ tabptr->at_time = g_arptime;
+ return;
+ }
+ }
+ }
+
+ /* If we get here, no existing ARP table entry was found, so we create one. */
+
+ /* First, we try to find an unused entry in the ARP table. */
+
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ tabptr = &g_arptable[i];
+ if (tabptr->at_ipaddr == 0)
+ {
+ break;
+ }
+ }
+
+ /* If no unused entry is found, we try to find the oldest entry and
+ * throw it away.
+ */
+
+ if (i == CONFIG_NET_ARPTAB_SIZE)
+ {
+ uint8 tmpage = 0;
+ int j = 0;
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ tabptr = &g_arptable[i];
+ if (g_arptime - tabptr->at_time > tmpage)
+ {
+ tmpage = g_arptime - tabptr->at_time;
+ j = i;
+ }
+ }
+ i = j;
+ tabptr = &g_arptable[i];
+ }
+
+ /* Now, i is the ARP table entry which we will fill with the new
+ * information.
+ */
+
+ tabptr->at_ipaddr = ipaddr;
+ memcpy(tabptr->at_ethaddr.ether_addr_octet, ethaddr, ETHER_ADDR_LEN);
+ tabptr->at_time = g_arptime;
+}
+
+/****************************************************************************
+ * Name: uip_arp_find
+ *
+ * Description:
+ * Find the ARP entry corresponding to this IP address.
+ *
+ * Input parameters:
+ * ipaddr - Refers to an IP addressin network order
+ *
+ * Assumptions
+ * Interrupts are disabled; Returned value will become unstable when
+ * interrupts are re-enabled or if any other uIP APIs are called.
+ *
+ ****************************************************************************/
+
+struct arp_entry *uip_arp_find(in_addr_t ipaddr)
+{
+ struct arp_entry *tabptr;
+ int i;
+
+ for (i = 0; i < CONFIG_NET_ARPTAB_SIZE; ++i)
+ {
+ tabptr = &g_arptable[i];
+ if (uip_ipaddr_cmp(ipaddr, tabptr->at_ipaddr))
+ {
+ return tabptr;
+ }
+ }
+ return NULL;
+}
+
+#endif /* CONFIG_NET */