2007-11-01 00:27:55 +01:00
|
|
|
/****************************************************************************
|
2014-08-18 19:36:39 +02:00
|
|
|
* net/arp/arp_ipin.c
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2014-05-30 20:13:06 +02:00
|
|
|
* Copyright (C) 2007-2011, 2014 Gregory Nutt. All rights reserved.
|
2011-12-15 23:21:32 +01:00
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-01 00:27:55 +01:00
|
|
|
* Based on uIP which also has a BSD style license:
|
2007-08-27 01:12:17 +02:00
|
|
|
*
|
2007-11-01 00:27:55 +01:00
|
|
|
* Author: Adam Dunkels <adam@dunkels.com>
|
|
|
|
* Copyright (c) 2001-2003, Adam Dunkels.
|
|
|
|
* All rights reserved.
|
2007-08-27 01:12:17 +02: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 00:27:55 +01:00
|
|
|
*
|
2007-08-27 01:12:17 +02: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 00:27:55 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2007-11-06 00:04:16 +01:00
|
|
|
#include <nuttx/config.h>
|
2007-11-04 23:59:30 +01:00
|
|
|
|
2007-09-17 00:12:04 +02:00
|
|
|
#include <netinet/in.h>
|
2011-03-12 16:36:28 +01:00
|
|
|
|
2014-06-24 17:28:44 +02:00
|
|
|
#include <nuttx/net/netdev.h>
|
2014-05-30 20:13:06 +02:00
|
|
|
#include <nuttx/net/arp.h>
|
2007-08-27 01:12:17 +02:00
|
|
|
|
2014-07-06 19:05:28 +02:00
|
|
|
#include "arp/arp.h"
|
2014-06-26 17:32:39 +02:00
|
|
|
|
2014-08-18 19:36:39 +02:00
|
|
|
#ifdef CONFIG_NET_ARP_IPIN
|
2011-03-12 16:36:28 +01:00
|
|
|
|
2007-11-01 00:27:55 +01:00
|
|
|
/****************************************************************************
|
2009-12-15 15:53:45 +01:00
|
|
|
* Pre-processor Definitions
|
2007-11-01 00:27:55 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2022-01-17 23:09:14 +01:00
|
|
|
#define ETHBUF ((FAR struct eth_hdr_s *)&dev->d_buf[0])
|
|
|
|
#define IPBUF ((FAR struct arp_iphdr_s *)&dev->d_buf[ETH_HDRLEN])
|
2010-07-13 04:29:09 +02:00
|
|
|
|
2007-11-01 00:27:55 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-07-06 19:05:28 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: arp_ipin
|
2010-11-25 21:32:51 +01:00
|
|
|
*
|
2014-07-06 19:05:28 +02: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
|
2021-02-19 15:01:46 +01:00
|
|
|
* will be refreshed. If no ARP cache entry was found, a new one is
|
|
|
|
* created.
|
2010-11-25 21:32:51 +01:00
|
|
|
*
|
2014-07-06 19:05:28 +02: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-25 21:32:51 +01:00
|
|
|
|
2014-07-06 19:05:28 +02:00
|
|
|
void arp_ipin(FAR struct net_driver_s *dev)
|
2010-11-25 21:32:51 +01: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-29 21:20:00 +02:00
|
|
|
srcipaddr = net_ip4addr_conv32(IPBUF->eh_srcipaddr);
|
2015-01-15 19:19:44 +01:00
|
|
|
if (net_ipv4addr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask))
|
2010-11-25 21:32:51 +01:00
|
|
|
{
|
2021-11-18 06:29:25 +01:00
|
|
|
arp_hdr_update(dev, IPBUF->eh_srcipaddr, ETHBUF->src);
|
2010-11-25 21:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
2007-09-16 00:45:45 +02:00
|
|
|
|
2014-08-18 19:36:39 +02:00
|
|
|
#endif /* CONFIG_NET_ARP_IPIN */
|