mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 08:36:24 +08:00
ARP: Add IOCTL commands to manage the ARP table
This commit is contained in:
+31
-4
@@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* net/arp/arp.h
|
||||
*
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014-2016 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -420,15 +420,41 @@ FAR struct arp_entry *arp_find(in_addr_t ipaddr);
|
||||
* address of an existing association.
|
||||
*
|
||||
* Input parameters:
|
||||
* pipaddr - Refers to an IP address uint16_t[2] in network order
|
||||
* ipaddr - The IP address as an inaddr_t
|
||||
* ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the ARP table entry was successfully modified. A negated
|
||||
* errno value is returned on any error.
|
||||
*
|
||||
* Assumptions
|
||||
* Interrupts are disabled to assure exclusive access to the ARP table.
|
||||
* The network is locked to assure exclusive access to the ARP table
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
|
||||
int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arp_hdr_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_t[2] in network order
|
||||
* ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the ARP table entry was successfully modified. A negated
|
||||
* errno value is returned on any error.
|
||||
*
|
||||
* Assumptions
|
||||
* The network is locked to assure exclusive access to the ARP table
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_hdr_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arp_dump
|
||||
@@ -467,6 +493,7 @@ void arp_dump(FAR struct arp_hdr_s *arp);
|
||||
# define arp_find(i) (NULL)
|
||||
# define arp_delete(i)
|
||||
# define arp_update(i,m);
|
||||
# define arp_hdr_update(i,m);
|
||||
# define arp_dump(arp)
|
||||
|
||||
#endif /* CONFIG_NET_ARP */
|
||||
|
||||
+2
-2
@@ -132,7 +132,7 @@ void arp_arpin(FAR struct net_driver_s *dev)
|
||||
* with this host in the future.
|
||||
*/
|
||||
|
||||
arp_update(arp->ah_sipaddr, arp->ah_shwaddr);
|
||||
arp_hdr_update(arp->ah_sipaddr, arp->ah_shwaddr);
|
||||
|
||||
arp->ah_opcode = HTONS(ARP_REPLY);
|
||||
memcpy(arp->ah_dhwaddr, arp->ah_shwaddr, ETHER_ADDR_LEN);
|
||||
@@ -161,7 +161,7 @@ void arp_arpin(FAR struct net_driver_s *dev)
|
||||
{
|
||||
/* Yes... Insert the address mapping in the ARP table */
|
||||
|
||||
arp_update(arp->ah_sipaddr, arp->ah_shwaddr);
|
||||
arp_hdr_update(arp->ah_sipaddr, arp->ah_shwaddr);
|
||||
|
||||
/* Then notify any logic waiting for the ARP result */
|
||||
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ void arp_ipin(FAR struct net_driver_s *dev)
|
||||
srcipaddr = net_ip4addr_conv32(IPBUF->eh_srcipaddr);
|
||||
if (net_ipv4addr_maskcmp(srcipaddr, dev->d_ipaddr, dev->d_netmask))
|
||||
{
|
||||
arp_update(IPBUF->eh_srcipaddr, ETHBUF->src);
|
||||
arp_hdr_update(IPBUF->eh_srcipaddr, ETHBUF->src);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+36
-4
@@ -142,18 +142,21 @@ void arp_timer(void)
|
||||
* address of an existing association.
|
||||
*
|
||||
* Input parameters:
|
||||
* pipaddr - Refers to an IP address uint16_t[2]
|
||||
* ipaddr - The IP address as an inaddr_t
|
||||
* ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the ARP table entry was successfully modified. A negated
|
||||
* errno value is returned on any error.
|
||||
*
|
||||
* Assumptions
|
||||
* Interrupts are disabled
|
||||
* The network is locked to assure exclusive access to the ARP table
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr)
|
||||
int arp_update(in_addr_t ipaddr, FAR uint8_t *ethaddr)
|
||||
{
|
||||
struct arp_entry *tabptr = NULL;
|
||||
in_addr_t ipaddr = net_ip4addr_conv32(pipaddr);
|
||||
int i;
|
||||
|
||||
/* Walk through the ARP mapping table and try to find an entry to
|
||||
@@ -229,6 +232,35 @@ void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr)
|
||||
tabptr->at_time = g_arptime;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arp_hdr_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_t[2] in network order
|
||||
* ethaddr - Refers to a HW address uint8_t[IFHWADDRLEN]
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) if the ARP table entry was successfully modified. A negated
|
||||
* errno value is returned on any error.
|
||||
*
|
||||
* Assumptions
|
||||
* The network is locked to assure exclusive access to the ARP table
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void arp_hdr_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr)
|
||||
{
|
||||
in_addr_t ipaddr = net_ip4addr_conv32(pipaddr);
|
||||
|
||||
/* Update the ARP table */
|
||||
|
||||
(void)arp_update(ipaddr, ethaddr);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: arp_find
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user