From e2449e985855295fdbbf0ca5ffe976a9d982eb9e Mon Sep 17 00:00:00 2001 From: patacongo Date: Thu, 25 Nov 2010 20:32:51 +0000 Subject: [PATCH] Restore uip_arp_ipin() git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3131 42af7a65-404d-4744-a932-0658087f49c3 --- Documentation/NuttxPortingGuide.html | 3 +++ TODO | 8 +++----- configs/README.txt | 2 ++ include/net/uip/uip-arp.h | 10 +++++++--- net/uip/uip_arp.c | 30 +++++++++++++++++++++++++++- 5 files changed, 44 insertions(+), 9 deletions(-) diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html index a750a04a2f..9cf518cb52 100644 --- a/Documentation/NuttxPortingGuide.html +++ b/Documentation/NuttxPortingGuide.html @@ -2921,6 +2921,9 @@ build
  • CONFIG_NET_ARPTAB_SIZE: The size of the ARP table
  • +
  • + CONFIG_NET_ARP_IPIN: Harvest IP/MAC address mappings for the ARP table from incoming IP packets. +
  • CONFIG_NET_BROADCAST: Incoming UDP broadcast support
  • diff --git a/TODO b/TODO index 52ba42407e..99e5600d9f 100644 --- a/TODO +++ b/TODO @@ -214,11 +214,9 @@ o Network (net/, drivers/net) Description: Outgoing packets are dropped and overwritten by ARP packets if the destination IP has not been mapped to a MAC. Could improve send() performance by explicitly performing ARP before - sending the packet. - --- - Or by enabling arpin() logic. NOTE: From the uIP forum: "You - can use the function but it has a bug. You'll need to comment - this line: uip_len -= sizeof(struct uip_eth_hdr);" + sending the packet (or by enabling CONFIG_NET_ARP_IPIN logic. + This could, however have negative impacts on busy networks and + could require a large value for CONFIG_NET_ARPTAB_SIZE). Status: Open Priority: Medium diff --git a/configs/README.txt b/configs/README.txt index 2f393d8535..bda94884ef 100644 --- a/configs/README.txt +++ b/configs/README.txt @@ -595,6 +595,8 @@ defconfig -- This is a configuration file similar to the Linux CONFIG_NET_RECEIVE_WINDOW - The size of the advertised receiver's window CONFIG_NET_ARPTAB_SIZE - The size of the ARP table + CONFIG_NET_ARP_IPIN - Harvest IP/MAC address mappings from the ARP table + from incoming IP packets. CONFIG_NET_BROADCAST - Incoming UDP broadcast support CONFIG_NET_MULTICAST - Outgoing multi-cast address support CONFIG_NET_LLH_LEN - The link level header length diff --git a/include/net/uip/uip-arp.h b/include/net/uip/uip-arp.h index 47b5b99929..b77addde51 100644 --- a/include/net/uip/uip-arp.h +++ b/include/net/uip/uip-arp.h @@ -2,7 +2,7 @@ * include/net/uip/uip-arch.h * Macros and definitions for the ARP module. * - * Copyright (C) 2007, 2009 Gregory Nutt. All rights reserved. + * Copyright (C) 2007, 2009-2010 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Derived from uIP with has a similar BSD-styple license: @@ -114,7 +114,7 @@ extern "C" { EXTERN void uip_arp_init(void); /**************************************************************************** - * Name: uip_arp_init + * Name: uip_arp_ipin * * Description: * The uip_arp_ipin() function should be called whenever an IP packet @@ -125,7 +125,11 @@ EXTERN void uip_arp_init(void); * ****************************************************************************/ -#define uip_arp_ipin() +#ifdef CONFIG_NET_ARP_IPIN +EXTERN void uip_arp_ipin(void); +#else +# define uip_arp_ipin() +#endif /**************************************************************************** * Name: uip_arp_arpin diff --git a/net/uip/uip_arp.c b/net/uip/uip_arp.c index 270bddd640..90f1ef2d32 100644 --- a/net/uip/uip_arp.c +++ b/net/uip/uip_arp.c @@ -176,6 +176,34 @@ static void uip_arp_dump(struct arp_hdr *arp) * Public Functions ****************************************************************************/ +/* ARP processing for incoming IP packets + * + * This function should be called by the device driver when an IP packet has + * been received. The function will check if the address is in the ARP cache, + * and if so the ARP cache entry will be refreshed. If no ARP cache entry was + * found, a new one is created. + * + * This function expects an IP packet with a prepended Ethernet header in the + * d_buf[] buffer, and the length of the packet in the variable d_len. + */ + +#ifdef CONFIG_NET_ARP_IPIN +void uip_arp_ipin(void) +{ + in_addr_t srcipaddr; + + /* Only insert/update an entry if the source IP address of the incoming IP + * packet comes from a host on the local network. + */ + + srcipaddr = uip_ip4addr_conv(IPBUF->srcipaddr); + if (!uip_ipaddr_maskcmp(ipaddr, dev->d_ipaddr, dev->d_netmask)) + { + uip_arp_update(IPBUF->srcipaddr, ETHBUF->src); + } +} +#endif /* CONFIG_NET_ARP_IPIN */ + /* ARP processing for incoming ARP packets. * * This function should be called by the device driver when an ARP @@ -194,7 +222,7 @@ static void uip_arp_dump(struct arp_hdr *arp) * * This function expects an ARP packet with a prepended Ethernet * header in the d_buf[] buffer, and the length of the packet in the - * global variable d_len. + * variable d_len. */ void uip_arp_arpin(struct uip_driver_s *dev)