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:
Gregory Nutt
2015-02-04 14:51:20 -06:00
parent 72645e184d
commit 24d800398e
8 changed files with 221 additions and 52 deletions
-12
View File
@@ -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;
+51 -3
View File
@@ -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 */
/****************************************************************************
+9 -14
View File
@@ -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 */