Networking: Break out Ethernet definitions into a separate file; add IPv6 multicast addresses as common globals, Ethernet drivers need to filter link-local, all nodes Ethernet address
This commit is contained in:
parent
72645e184d
commit
24d800398e
@ -3527,6 +3527,16 @@ static void stm32_ipv6multicast(FAR struct stm32_ethmac_s *priv)
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
(void)stm32_addmac(dev, mac);
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Add the IPv6 all link-local nodes Ethernet address. This is the
|
||||
* address that we expect to receive ICMPv6 Router Advertisement
|
||||
* packets.
|
||||
*/
|
||||
|
||||
(void)stm32_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6 */
|
||||
|
||||
|
@ -3985,6 +3985,16 @@ static void tiva_ipv6multicast(FAR struct tiva_ethmac_s *priv)
|
||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||
|
||||
(void)tiva_addmac(dev, mac);
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* Add the IPv6 all link-local nodes Ethernet address. This is the
|
||||
* address that we expect to receive ICMPv6 Router Advertisement
|
||||
* packets.
|
||||
*/
|
||||
|
||||
(void)tiva_addmac(dev, g_ipv6_ethallnodes.ether_addr_octet);
|
||||
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||
}
|
||||
#endif /* CONFIG_NET_ICMPv6 */
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
* include/nuttx/net/arp.h
|
||||
* Macros and definitions for the ARP module.
|
||||
*
|
||||
* Copyright (C) 2007, 2009-2012 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Derived from uIP with has a similar BSD-styple license:
|
||||
@ -54,37 +54,16 @@
|
||||
#include <net/ethernet.h>
|
||||
|
||||
#include <nuttx/net/netconfig.h>
|
||||
#include <nuttx/net/ethernet.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Recognized values of the type bytes in the Ethernet header */
|
||||
|
||||
#define ETHTYPE_ARP 0x0806 /* Address resolution protocol */
|
||||
#define ETHTYPE_IP 0x0800 /* IP protocol */
|
||||
#define ETHTYPE_IP6 0x86dd /* IP protocol version 6 */
|
||||
|
||||
/* Size of the Ethernet header */
|
||||
|
||||
#define ETH_HDRLEN 14 /* Minimum size: 2*6 + 2 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The Ethernet header -- 14 bytes. The first two fields are type 'struct
|
||||
* ether_addr but are represented as a simple byte array here because
|
||||
* some compilers refuse to pack 6 byte structures.
|
||||
*/
|
||||
|
||||
struct eth_hdr_s
|
||||
{
|
||||
uint8_t dest[6]; /* Ethernet destination address (6 bytes) */
|
||||
uint8_t src[6]; /* Ethernet source address (6 bytes) */
|
||||
uint16_t type; /* Type code (2 bytes) */
|
||||
};
|
||||
|
||||
/* One entry in the ARP table (volatile!) */
|
||||
|
||||
struct arp_entry
|
||||
|
111
include/nuttx/net/ethernet.h
Normal file
111
include/nuttx/net/ethernet.h
Normal file
@ -0,0 +1,111 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/net/ethernt.h
|
||||
* Macros and definitions for the Ethernet link layer.
|
||||
*
|
||||
* Copyright (C) 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Derived from uIP with has a similar BSD-styple 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_NET_ETHERNET_H
|
||||
#define __INCLUDE_NUTTX_NET_ETHERNET_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
#include <stdint.h>
|
||||
#include <net/ethernet.h>
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Recognized values of the type bytes in the Ethernet header */
|
||||
|
||||
#define ETHTYPE_ARP 0x0806 /* Address resolution protocol */
|
||||
#define ETHTYPE_IP 0x0800 /* IP protocol */
|
||||
#define ETHTYPE_IP6 0x86dd /* IP protocol version 6 */
|
||||
|
||||
/* Size of the Ethernet header */
|
||||
|
||||
#define ETH_HDRLEN 14 /* Minimum size: 2*6 + 2 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* The Ethernet header -- 14 bytes. The first two fields are type 'struct
|
||||
* ether_addr but are represented as a simple byte array here because
|
||||
* some compilers refuse to pack 6 byte structures.
|
||||
*/
|
||||
|
||||
struct eth_hdr_s
|
||||
{
|
||||
uint8_t dest[6]; /* Ethernet destination address (6 bytes) */
|
||||
uint8_t src[6]; /* Ethernet source address (6 bytes) */
|
||||
uint16_t type; /* Type code (2 bytes) */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
EXTERN const struct ether_addr g_ipv6_ethallnodes; /* All link local nodes */
|
||||
EXTERN const struct ether_addr g_ipv6_ethallrouters; /* All link local routers */
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_ETHERNET */
|
||||
#endif /* __INCLUDE_NUTTX_NET_ETHERNET_H */
|
@ -209,6 +209,29 @@ struct ipv6_stats_s
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/* Well-known IP addresses */
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
EXTERN const in_addr_t g_ipv4_alloneaddr;
|
||||
EXTERN const in_addr_t g_ipv4_allzeroaddr;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
EXTERN const net_ipv6addr_t g_ipv6_alloneaddr;
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allzeroaddr;
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allnodes; /* All link local nodes */
|
||||
EXTERN const net_ipv6addr_t g_ipv6_allrouters; /* All link local routers */
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
@ -398,4 +421,9 @@ bool net_ipv6addr_maskcmp(const net_ipv6addr_t addr1,
|
||||
(in_addr_t)(dest) = (in_addr_t)(src) & (in_addr_t)(mask); \
|
||||
} while (0)
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __INCLUDE_NUTTX_NET_IP_H */
|
||||
|
@ -184,18 +184,6 @@ struct devif_callback_s
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
/* Well-known addresses */
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
extern const in_addr_t g_ipv4_alloneaddr;
|
||||
extern const in_addr_t g_ipv4_allzeroaddr;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
extern const net_ipv6addr_t g_ipv6_alloneaddr;
|
||||
extern const net_ipv6addr_t g_ipv6_allzeroaddr;
|
||||
#endif
|
||||
|
||||
/* Increasing number used for the IP ID field. */
|
||||
|
||||
extern uint16_t g_ipid;
|
||||
|
@ -70,21 +70,69 @@ struct net_stats_s g_netstats;
|
||||
uint16_t g_ipid;
|
||||
|
||||
#ifdef CONFIG_NET_IPv4
|
||||
|
||||
const in_addr_t g_ipv4_alloneaddr = 0xffffffff;
|
||||
const in_addr_t g_ipv4_allzeroaddr = 0x00000000;
|
||||
|
||||
/* Reassembly timer (units: deci-seconds) */
|
||||
|
||||
#ifdef CONFIG_NET_TCP_REASSEMBLY
|
||||
|
||||
uint8_t g_reassembly_timer;
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_NET_TCP_REASSEMBLY */
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
#ifdef CONFIG_NET_IPv6
|
||||
|
||||
const net_ipv6addr_t g_ipv6_alloneaddr =
|
||||
{0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff};
|
||||
{
|
||||
0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff, 0xffff
|
||||
};
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allzeroaddr =
|
||||
{0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000};
|
||||
{
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_ICMPv6_AUTOCONF
|
||||
/* IPv6 Multi-cast IP address */
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allnodes = /* All link local nodes */
|
||||
{
|
||||
HTONS(0xff02),
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
HTONS(0x0001)
|
||||
};
|
||||
|
||||
const net_ipv6addr_t g_ipv6_allrouters = /* All link local routers */
|
||||
{
|
||||
HTONS(0xff02),
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
HTONS(0x0002)
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_ETHERNET
|
||||
|
||||
/* IPv6 Multi-cast Ethernet addresses. Formed from the 16-bit prefix:
|
||||
*
|
||||
* 0x33:0x33:xx:xx:xx:xx:
|
||||
*
|
||||
* and the last 32-bits of the IPv6 IP address
|
||||
*/
|
||||
|
||||
const struct ether_addr g_ipv6_ethallnodes = /* All link local nodes */
|
||||
{
|
||||
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x01 }
|
||||
};
|
||||
|
||||
const struct ether_addr g_ipv6_ethallrouters = /* All link local routers */
|
||||
{
|
||||
{ 0x33, 0x33, 0x00, 0x00, 0x00, 0x02 }
|
||||
};
|
||||
|
||||
#endif /* CONFIG_NET_ETHERNET */
|
||||
#endif /* CONFIG_NET_ICMPv6_AUTOCONF */
|
||||
#endif /* CONFIG_NET_IPv4 */
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -108,13 +108,11 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
||||
icmp->proto = IP_PROTO_ICMP6; /* Next header */
|
||||
icmp->ttl = 255; /* Hop limit */
|
||||
|
||||
/* Set the multicast destination IP address to the IPv7 all routers
|
||||
* address: ff02::2
|
||||
/* Set the multicast destination IP address to the IPv6 all link-
|
||||
* loocal routers address: ff02::2
|
||||
*/
|
||||
|
||||
icmp->destipaddr[0] = HTONS(0xff02);
|
||||
memset(&icmp->destipaddr[1], 0, 6*sizeof(uint16_t));
|
||||
icmp->destipaddr[7] = HTONS(0x0002);
|
||||
net_ipv6addr_copy(icmp->destipaddr, g_ipv6_allrouters);
|
||||
|
||||
/* Add our link local IPv6 address as the source address */
|
||||
|
||||
@ -139,7 +137,7 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
||||
* REVISIT: What if the link layer is not Ethernet?
|
||||
*/
|
||||
|
||||
memcpy(sol->srclladdr, &dev->d_mac, IFHWADDRLEN);
|
||||
memcpy(sol->srclladdr, dev->d_mac.ether_addr_octet, sizeof(net_ipv6addr_t));
|
||||
|
||||
/* Calculate the checksum over both the ICMP header and payload */
|
||||
|
||||
@ -155,15 +153,12 @@ void icmpv6_rsolicit(FAR struct net_driver_s *dev)
|
||||
if (dev->d_lltype == NET_LL_ETHERNET)
|
||||
#endif
|
||||
{
|
||||
/* Set the destination IPv6 multicast Ethernet address */
|
||||
/* Set the destination IPv6 all-routers multicast Ethernet
|
||||
* address
|
||||
*/
|
||||
|
||||
eth = ETHBUF;
|
||||
eth->dest[0] = 0x33;
|
||||
eth->dest[1] = 0x33;
|
||||
eth->dest[2] = 0x00;
|
||||
eth->dest[3] = 0x00;
|
||||
eth->dest[4] = 0x00;
|
||||
eth->dest[5] = 0x02;
|
||||
eth = ETHBUF;
|
||||
memcpy(eth->dest, g_ipv6_ethallrouters.ether_addr_octet, ETHER_ADDR_LEN);
|
||||
|
||||
/* Move our source Ethernet addresses into the Ethernet header */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user