2007-11-01 07:27:55 +08:00
|
|
|
/****************************************************************************
|
2014-08-19 01:36:39 +08:00
|
|
|
* net/arp/arp_ipin.c
|
2007-08-27 07:12:17 +08:00
|
|
|
*
|
2014-05-31 02:13:06 +08:00
|
|
|
* Copyright (C) 2007-2011, 2014 Gregory Nutt. All rights reserved.
|
2011-12-16 06:21:32 +08:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-08-27 07:12:17 +08:00
|
|
|
*
|
2007-11-01 07:27:55 +08:00
|
|
|
* Based on uIP which also has a BSD style license:
|
2007-08-27 07:12:17 +08:00
|
|
|
*
|
2007-11-01 07:27:55 +08:00
|
|
|
* Author: Adam Dunkels <adam@dunkels.com>
|
|
|
|
* Copyright (c) 2001-2003, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
2007-08-27 07:12:17 +08:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
2007-11-01 07:27:55 +08:00
|
|
|
*
|
2007-08-27 07:12:17 +08:00
|
|
|
* 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.
|
2007-11-01 07:27:55 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-11-06 07:04:16 +08:00
|
|
|
#include <nuttx/config.h>
|
2007-11-05 06:59:30 +08:00
|
|
|
|
2007-09-17 06:12:04 +08:00
|
|
|
#include <netinet/in.h>
|
2011-03-12 23:36:28 +08:00
|
|
|
|
2014-06-24 23:28:44 +08:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-05-31 02:13:06 +08:00
|
|
|
#include <nuttx/net/arp.h>
|
2007-08-27 07:12:17 +08:00
|
|
|
|
2014-07-07 01:05:28 +08:00
|
|
|
#include "arp/arp.h"
|
2014-06-26 23:32:39 +08:00
|
|
|
|
2014-08-19 01:36:39 +08:00
|
|
|
#ifdef CONFIG_NET_ARP_IPIN
|
2011-03-12 23:36:28 +08:00
|
|
|
|
2007-11-01 07:27:55 +08:00
|
|
|
/****************************************************************************
|
2009-12-15 22:53:45 +08:00
|
|
|
* Pre-processor Definitions
|
2007-11-01 07:27:55 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2014-08-19 01:36:39 +08:00
|
|
|
#define ETHBUF ((struct eth_hdr_s *)&dev->d_buf[0])
|
2014-11-15 23:13:50 +08:00
|
|
|
#define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[ETH_HDRLEN])
|
2010-07-13 10:29:09 +08:00
|
|
|
|
2007-11-01 07:27:55 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-07 01:05:28 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: arp_ipin
|
2010-11-26 04:32:51 +08:00
|
|
|
*
|
2014-07-07 01:05:28 +08:00
|
|
|
* Description:
|
|
|
|
* The arp_ipin() function should be called by Ethernet device drivers
|
|
|
|
* whenever an IP packet arrives from the network. 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.
|
2010-11-26 04:32:51 +08:00
|
|
|
*
|
2014-07-07 01:05:28 +08:00
|
|
|
* This function expects that an IP packet with an Ethernet header is
|
|
|
|
* present in the d_buf buffer and that the length of the packet is in the
|
|
|
|
* d_len field.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-11-26 04:32:51 +08:00
|
|
|
|
2014-07-07 01:05:28 +08:00
|
|
|
void arp_ipin(FAR struct net_driver_s *dev)
|
2010-11-26 04:32:51 +08:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2014-06-30 03:20:00 +08:00
|
|
|
srcipaddr = net_ip4addr_conv32(IPBUF->eh_srcipaddr);
|
2015-01-16 02:19:44 +08:00
|
|
|
if (net_ipv4addr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask))
|
2010-11-26 04:32:51 +08:00
|
|
|
{
|
2016-02-09 01:17:22 +08:00
|
|
|
arp_hdr_update(IPBUF->eh_srcipaddr, ETHBUF->src);
|
2010-11-26 04:32:51 +08:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 06:45:45 +08:00
|
|
|
|
2014-08-19 01:36:39 +08:00
|
|
|
#endif /* CONFIG_NET_ARP_IPIN */
|