ARP: Add missing configuration option to select dumping of ARP packet headers. Move ARP dumping logic from arp_inout.c to its own file

This commit is contained in:
Gregory Nutt 2014-08-18 11:08:15 -06:00
parent 9aab8f77ea
commit 985c016150
5 changed files with 200 additions and 73 deletions

View File

@ -34,5 +34,12 @@ config NET_ARP_IPIN
Harvest IP/MAC address mappings from the ARP table
from incoming IP packets.
config NET_ARP_DUMP
bool "Dump ARP packet header"
default n
depends on DEBUG
---help---
Dump ARP packets to the SYSLOG device.
endif # NET_ARP
endmenu # ARP Configuration

View File

@ -38,6 +38,10 @@
ifneq ($(CONFIG_NET_SLIP),y)
NET_CSRCS += arp_inout.c arp_table.c arp_timer.c
ifeq ($(CONFIG_NET_ARP_DUMP),y)
NET_CSRCS += arp_dump.c
endif
# Include arp build support
DEPPATH += --dep-path arp

View File

@ -36,14 +36,76 @@
#ifndef __NET_ARP_ARP_H
#define __NET_ARP_ARP_H
/* The Address Resolution Protocol ARP is used for mapping between IP
* addresses and link level addresses such as the Ethernet MAC
* addresses. ARP uses broadcast queries to ask for the link level
* address of a known IP address and the host which is configured with
* the IP address for which the query was meant, will respond with its
* link level address.
*
* Note: This ARP implementation only supports Ethernet.
*/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
#ifndef CONFIG_DEBUG
# undef CONFIG_NET_ARP_DUMP
#endif
/* ARP Definitions **********************************************************/
#define ARP_REQUEST 1
#define ARP_REPLY 2
#define ARP_HWTYPE_ETH 1
#define RASIZE 4 /* Size of ROUTER ALERT */
/****************************************************************************
* Public Types
****************************************************************************/
/* ARP header -- Size 28 bytes */
struct arp_hdr_s
{
uint16_t ah_hwtype; /* 16-bit Hardware type (Ethernet=0x001) */
uint16_t ah_protocol; /* 16-bit Protocol type (IP=0x0800) */
uint8_t ah_hwlen; /* 8-bit Hardware address size (6) */
uint8_t ah_protolen; /* 8-bit Procotol address size (4) */
uint16_t ah_opcode; /* 16-bit Operation */
uint8_t ah_shwaddr[6]; /* 48-bit Sender hardware address */
uint16_t ah_sipaddr[2]; /* 32-bit Sender IP adress */
uint8_t ah_dhwaddr[6]; /* 48-bit Target hardware address */
uint16_t ah_dipaddr[2]; /* 32-bit Target IP address */
};
/* IP header -- Size 20 or 24 bytes */
struct arp_iphdr_s
{
uint8_t eh_vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t eh_tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t eh_len[2]; /* 16-bit Total length */
uint8_t eh_ipid[2]; /* 16-bit Identification */
uint8_t eh_ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t eh_ttl; /* 8-bit Time to Live */
uint8_t eh_proto; /* 8-bit Protocol */
uint16_t eh_ipchksum; /* 16-bit Header checksum */
uint16_t eh_srcipaddr[2]; /* 32-bit Source IP address */
uint16_t eh_destipaddr[2]; /* 32-bit Destination IP address */
uint16_t eh_ipoption[2]; /* (optional) */
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
@ -92,6 +154,26 @@ void arp_timer_initialize(void);
void arp_timer(void);
/****************************************************************************
* Name: arp_dump
*
* Description:
* Dump the contents of an ARP packet to the SYSLOG device
*
* Input Parameters:
* arp - A reference to the ARP header to be dumped.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_ARP_DUMP
void arp_dump(FAR struct arp_hdr_s *arp);
#else
# define arp_dump(arp)
#endif
#else /* CONFIG_NET_ARP */
/* If ARP is disabled, stub out all ARP interfaces */
@ -99,6 +181,7 @@ void arp_timer(void);
# define arp_reset()
# define arp_timer_initialize(void)
# define arp_timer()
# define arp_dump(arp)
#endif /* CONFIG_NET_ARP */
#endif /* __UIP-NEIGHBOR_H__ */
#endif /* __NET_ARP_ARP_H */

104
net/arp/arp_dump.c Normal file
View File

@ -0,0 +1,104 @@
/****************************************************************************
* net/arp/arp_dump.c
*
* Copyright (C) 2007-2011, 2014 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Based on uIP which also has a BSD style license:
*
* Author: Adam Dunkels <adam@dunkels.com>
* Copyright (c) 2001-2003, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <debug.h>
#include "arp/arp.h"
#ifdef CONFIG_NET_ARP_DUMP
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: arp_dump
*
* Description:
* Dump the contents of an ARP packet to the SYSLOG device
*
* Input Parameters:
* arp - A reference to the ARP header to be dumped.
*
* Returned Value:
* None
*
****************************************************************************/
void arp_dump(FAR struct arp_hdr_s *arp)
{
nlldbg(" HW type: %04x Protocol: %04x\n",
arp->ah_hwtype, arp->ah_protocol);\
nlldbg(" HW len: %02x Proto len: %02x Operation: %04x\n",
arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode);
nlldbg(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n",
arp->ah_shwaddr[0], arp->ah_shwaddr[1], arp->ah_shwaddr[2],
arp->ah_shwaddr[3], arp->ah_shwaddr[4], arp->ah_shwaddr[5],
arp->ah_sipaddr[0] & 0xff, arp->ah_sipaddr[0] >> 8,
arp->ah_sipaddr[1] & 0xff, arp->ah_sipaddr[1] >> 8);
nlldbg(" Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n",
arp->ah_dhwaddr[0], arp->ah_dhwaddr[1], arp->ah_dhwaddr[2],
arp->ah_dhwaddr[3], arp->ah_dhwaddr[4], arp->ah_dhwaddr[5],
arp->ah_dipaddr[0] & 0xff, arp->ah_dipaddr[0] >> 8,
arp->ah_dipaddr[1] & 0xff, arp->ah_dipaddr[1] >> 8);
}
#endif /* CONFIG_NET_ARP_DUMP */

View File

@ -1,5 +1,5 @@
/****************************************************************************
* net/arp/arm_inout.c
* net/arp/arp_inout.c
* Implementation of the ARP Address Resolution Protocol.
*
* Copyright (C) 2007-2011, 2014 Gregory Nutt. All rights reserved.
@ -38,16 +38,6 @@
*
****************************************************************************/
/* The Address Resolution Protocol ARP is used for mapping between IP
* addresses and link level addresses such as the Ethernet MAC
* addresses. ARP uses broadcast queries to ask for the link level
* address of a known IP address and the host which is configured with
* the IP address for which the query was meant, will respond with its
* link level address.
*
* Note: This ARP implementation only supports Ethernet.
*/
/****************************************************************************
* Included Files
****************************************************************************/
@ -79,13 +69,6 @@
* Pre-processor Definitions
****************************************************************************/
#define ARP_REQUEST 1
#define ARP_REPLY 2
#define ARP_HWTYPE_ETH 1
#define RASIZE 4 /* Size of ROUTER ALERT */
#define ETHBUF ((struct eth_hdr_s *)&dev->d_buf[0])
#define ARPBUF ((struct arp_hdr_s *)&dev->d_buf[NET_LL_HDRLEN])
#define IPBUF ((struct arp_iphdr_s *)&dev->d_buf[NET_LL_HDRLEN])
@ -94,38 +77,6 @@
* Private Types
****************************************************************************/
/* ARP header -- Size 28 bytes */
struct arp_hdr_s
{
uint16_t ah_hwtype; /* 16-bit Hardware type (Ethernet=0x001) */
uint16_t ah_protocol; /* 16-bit Protocol type (IP=0x0800) */
uint8_t ah_hwlen; /* 8-bit Hardware address size (6) */
uint8_t ah_protolen; /* 8-bit Procotol address size (4) */
uint16_t ah_opcode; /* 16-bit Operation */
uint8_t ah_shwaddr[6]; /* 48-bit Sender hardware address */
uint16_t ah_sipaddr[2]; /* 32-bit Sender IP adress */
uint8_t ah_dhwaddr[6]; /* 48-bit Target hardware address */
uint16_t ah_dipaddr[2]; /* 32-bit Target IP address */
};
/* IP header -- Size 20 or 24 bytes */
struct arp_iphdr_s
{
uint8_t eh_vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t eh_tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t eh_len[2]; /* 16-bit Total length */
uint8_t eh_ipid[2]; /* 16-bit Identification */
uint8_t eh_ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t eh_ttl; /* 8-bit Time to Live */
uint8_t eh_proto; /* 8-bit Protocol */
uint16_t eh_ipchksum; /* 16-bit Header checksum */
uint16_t eh_srcipaddr[2]; /* 32-bit Source IP address */
uint16_t eh_destipaddr[2]; /* 32-bit Destination IP address */
uint16_t eh_ipoption[2]; /* (optional) */
};
/****************************************************************************
* Private Data
****************************************************************************/
@ -160,28 +111,6 @@ static const uint8_t g_multicast_ethaddr[3] = {0x01, 0x00, 0x5e};
* Private Functions
****************************************************************************/
#if defined(CONFIG_NET_DUMPARP) && defined(CONFIG_DEBUG)
static void arp_dump(FAR struct arp_hdr_s *arp)
{
nlldbg(" HW type: %04x Protocol: %04x\n",
arp->ah_hwtype, arp->ah_protocol);\
nlldbg(" HW len: %02x Proto len: %02x Operation: %04x\n",
arp->ah_hwlen, arp->ah_protolen, arp->ah_opcode);
nlldbg(" Sender MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n",
arp->ah_shwaddr[0], arp->ah_shwaddr[1], arp->ah_shwaddr[2],
arp->ah_shwaddr[3], arp->ah_shwaddr[4], arp->ah_shwaddr[5],
arp->ah_sipaddr[0] & 0xff, arp->ah_sipaddr[0] >> 8,
arp->ah_sipaddr[1] & 0xff, arp->ah_sipaddr[1] >> 8);
nlldbg(" Dest MAC: %02x:%02x:%02x:%02x:%02x:%02x IP: %d.%d.%d.%d\n",
arp->ah_dhwaddr[0], arp->ah_dhwaddr[1], arp->ah_dhwaddr[2],
arp->ah_dhwaddr[3], arp->ah_dhwaddr[4], arp->ah_dhwaddr[5],
arp->ah_dipaddr[0] & 0xff, arp->ah_dipaddr[0] >> 8,
arp->ah_dipaddr[1] & 0xff, arp->ah_dipaddr[1] >> 8);
}
#else
# define arp_dump(arp)
#endif
/****************************************************************************
* Public Functions
****************************************************************************/