DHCPD no longer calls directly into the OS, but uses network IOCTL commands to modify the ARP table.

This commit is contained in:
Gregory Nutt 2016-02-08 12:07:47 -06:00
parent 3f95e05bc2
commit 85b5341d7b
2 changed files with 19 additions and 23 deletions

View File

@ -1545,4 +1545,7 @@
(2016-02-02).
* apps/netutils/netlib: Add utility functions to support accesses
to the ARP table (2016-02-08).
* apps/netutils/dhcpd: DHCPD no longer calls directly into the
OS but uses the new network IOCTL commands to modify the ARP
table (2016-02-08).

View File

@ -55,9 +55,6 @@
# include <nuttx/config.h> /* NuttX configuration */
# include <debug.h> /* For ndbg, vdbg */
# include <nuttx/compiler.h> /* For CONFIG_CPP_HAVE_WARNING */
# include <arch/irq.h> /* For irqstore() and friends -- REVISIT */
# include <nuttx/net/net.h> /* For net_lock() and friends */
# include <nuttx/net/arp.h> /* For low-level ARP interfaces -- REVISIT */
# include <apps/netutils/dhcpd.h> /* Advertised DHCPD APIs */
#endif
@ -75,6 +72,8 @@
#include <netinet/in.h>
#include <arpa/inet.h>
#include <apps/netutils/netlib.h>
/****************************************************************************
* Private Data
****************************************************************************/
@ -278,16 +277,6 @@ static const uint8_t g_magiccookie[4] = {99, 130, 83, 99};
static const uint8_t g_anyipaddr[4] = {0, 0, 0, 0};
static struct dhcpd_state_s g_state;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
#ifndef CONFIG_NETUTILS_DHCPD_HOST
/* This is an internal OS interface and should be called from this file */
void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
@ -297,20 +286,24 @@ void arp_update(FAR uint16_t *pipaddr, FAR uint8_t *ethaddr);
****************************************************************************/
#ifndef CONFIG_NETUTILS_DHCPD_HOST
static inline void dhcpd_arpupdate(uint16_t *pipaddr, uint8_t *phwaddr)
static inline void dhcpd_arpupdate(FAR uint8_t *ipaddr, FAR uint8_t *hwaddr)
{
net_lock_t flags;
struct sockaddr_in inaddr;
/* Disable interrupts and update the ARP table -- very non-portable hack.
* REVISIT -- switch to the SIOCSARP ioctl call if/when it is implemented.
/* Put the protocol address in a standard form. ipaddr is assume to be in
* network order by the memcpy.
*/
flags = net_lock();
arp_update(pipaddr, phwaddr);
net_unlock(flags);
inaddr.sin_family = AF_INET;
inaddr.sin_port = INADDR_ANY;
memcpy(&inaddr.sin_addr.s_addr, hwaddr, sizeof(in_addr_t));
/* Update the ARP table */
(void)netlib_set_arpmapping(&inaddr, hwaddr);
}
#else
# define dhcpd_arpupdate(pipaddr,phwaddr)
# define dhcpd_arpupdate(ipaddr,hwaddr)
#endif
/****************************************************************************
@ -956,7 +949,7 @@ static int dhcpd_sendpacket(int bbroadcast)
}
else if (memcmp(g_state.ds_outpacket.ciaddr, g_anyipaddr, 4) != 0)
{
dhcpd_arpupdate((uint16_t*)g_state.ds_outpacket.ciaddr, g_state.ds_outpacket.chaddr);
dhcpd_arpupdate(g_state.ds_outpacket.ciaddr, g_state.ds_outpacket.chaddr);
memcpy(&ipaddr, g_state.ds_outpacket.ciaddr, 4);
}
else if (g_state.ds_outpacket.flags & HTONS(BOOTP_BROADCAST))
@ -965,7 +958,7 @@ static int dhcpd_sendpacket(int bbroadcast)
}
else
{
dhcpd_arpupdate((uint16_t*)g_state.ds_outpacket.yiaddr, g_state.ds_outpacket.chaddr);
dhcpd_arpupdate(g_state.ds_outpacket.yiaddr, g_state.ds_outpacket.chaddr);
memcpy(&ipaddr, g_state.ds_outpacket.yiaddr, 4);
}
#endif