Networking: Misck IPv6 detanglement

This commit is contained in:
Gregory Nutt
2015-01-15 12:19:44 -06:00
parent a40189bcd8
commit 5a441ce03b
28 changed files with 495 additions and 307 deletions
+12 -12
View File
@@ -114,20 +114,20 @@ struct icmpv6_iphdr_s
{
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ip6addr_t srcipaddr; /* 128-bit Source address */
net_ip6addr_t destipaddr; /* 128-bit Destination address */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* ICMPv6 header */
uint8_t type; /* Defines the format of the ICMP message */
uint8_t icode; /* Further qualifies the ICMP messsage */
uint16_t icmpv6chksum; /* Checksum of ICMP header and data */
uint8_t type; /* Defines the format of the ICMP message */
uint8_t icode; /* Further qualifies the ICMP messages */
uint16_t icmpv6chksum; /* Checksum of ICMP header and data */
/* Data following the ICMP header contains the data specific to the
* message type indicated by the Type and Code fields.
@@ -200,7 +200,7 @@ extern "C"
*
****************************************************************************/
int icmpv6_ping(net_ipaddr_t addr, uint16_t id, uint16_t seqno,
int icmpv6_ping(net_ipv6addr_t addr, uint16_t id, uint16_t seqno,
uint16_t datalen, int dsecs);
#undef EXTERN
+52 -31
View File
@@ -125,37 +125,21 @@
* (0x11); in other messages it is set to 0 and ignored by the receiver.
*/
#ifdef CONFIG_NET_IPv4
struct igmp_iphdr_s
{
#ifdef CONFIG_NET_IPv6
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ip6addr_t srcipaddr; /* 128-bit Source address */
net_ip6addr_t destipaddr; /* 128-bit Destination address */
#else /* CONFIG_NET_IPv6 */
/* IPv4 IP header */
uint8_t vhl; /* 8-bit Version (4) and header length (6 with Router Alert) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
#endif /* CONFIG_NET_IPv6 */
uint8_t vhl; /* 8-bit Version (4) and header length (6 with Router Alert) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
/* Router Alert IP header option */
@@ -172,11 +156,48 @@ struct igmp_iphdr_s
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
uint8_t type; /* 8-bit IGMP packet type */
uint8_t maxresp; /* 8-bit Max response time */
uint16_t chksum; /* 16-bit Checksum */
uint16_t grpaddr[2]; /* 32-bit Group address */
uint8_t type; /* 8-bit IGMP packet type */
uint8_t maxresp; /* 8-bit Max response time */
uint16_t chksum; /* 16-bit Checksum */
uint16_t grpaddr[2]; /* 32-bit Group address */
};
#endif
#ifdef CONFIG_NET_IPv6
struct igmp_ipv6hdr_s
{
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), bits 4-7: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* Router Alert IP header option */
uint16_t ra[2];
/* IGMPv2 header:
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Type | Max Resp Time | Checksum |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | Group Address |
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
uint8_t type; /* 8-bit IGMP packet type */
uint8_t maxresp; /* 8-bit Max response time */
uint16_t chksum; /* 16-bit Checksum */
uint16_t grpaddr[2]; /* 32-bit Group address */
};
#endif
#ifdef CONFIG_NET_STATISTICS
struct igmp_stats_s
+31 -27
View File
@@ -92,13 +92,12 @@
/* Representation of an IP address */
typedef in_addr_t net_ip4addr_t;
typedef uint16_t net_ip6addr_t[8];
typedef uint16_t net_ipv6addr_t[8];
#ifdef CONFIG_NET_IPv6
typedef net_ip6addr_t net_ipaddr_t;
typedef net_ipv6addr_t net_ipaddr_t;
#else
typedef net_ip4addr_t net_ipaddr_t;
typedef in_addr_t net_ipaddr_t;
#endif
#ifdef CONFIG_NET_IPv4
@@ -106,16 +105,16 @@ typedef net_ip4addr_t net_ipaddr_t;
struct net_iphdr_s
{
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
};
#endif
@@ -124,14 +123,14 @@ struct net_iphdr_s
struct net_ipv6hdr_s
{
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ip6addr_t srcipaddr; /* 128-bit Source address */
net_ip6addr_t destipaddr; /* 128-bit Destination address */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
};
#endif
@@ -229,7 +228,7 @@ struct net_ipv6hdr_s
((uint16_t*)(dest))[1] = ((uint16_t*)(src))[1]; \
} while (0)
#define net_ipv6addr_copy(dest, src) memcpy(&dest, &src, sizeof(net_ip6addr_t))
#define net_ipv6addr_copy(dest, src) memcpy(&dest, &src, sizeof(net_ipv6addr_t))
#define net_ipv6addr_hdrcopy(dest, src) net_ipv6addr_copy(dest, src)
#ifndef CONFIG_NET_IPv6
@@ -262,7 +261,7 @@ struct net_ipv6hdr_s
net_ipv4addr_cmp(net_ip4addr_conv32(addr1), net_ip4addr_conv32(addr2))
#define net_ipv6addr_cmp(addr1, addr2) \
(memcmp(&addr1, &addr2, sizeof(net_ip6addr_t)) == 0)
(memcmp(&addr1, &addr2, sizeof(net_ipv6addr_t)) == 0)
#define net_ipv6addr_hdrcmp(addr1, addr2) \
net_ipv6addr_cmp(addr1, addr2)
@@ -297,13 +296,18 @@ struct net_ipv6hdr_s
* mask The netmask.
*/
#ifndef CONFIG_NET_IPv6
# define net_ipaddr_maskcmp(addr1, addr2, mask) \
#define net_ipv4addr_maskcmp(addr1, addr2, mask) \
(((in_addr_t)(addr1) & (in_addr_t)(mask)) == \
((in_addr_t)(addr2) & (in_addr_t)(mask)))
#ifndef CONFIG_NET_IPv6
# define net_ipaddr_maskcmp(a,b,m) net_ipv4addr_maskcmp(a,b,m)
#else
bool net_ipaddr_maskcmp(net_ipaddr_t addr1, net_ipaddr_t addr2,
bool net_ipv6addr_maskcmp(net_ipaddr_t addr1, net_ipaddr_t addr2,
net_ipaddr_t mask);
# define net_ipaddr_maskcmp(a,b,m) net_ipv6addr_maskcmp(a,b,m)
#endif
/* Mask out the network part of an IP address, given the address and
+4 -3
View File
@@ -9,7 +9,7 @@
* Note: Network configuration options the netconfig.h should not be changed,
* but rather the per-project defconfig file.
*
* Copyright (C) 2007, 2011, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2011, 2014-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* This logic was leveraged from uIP which also has a BSD-style license:
@@ -139,9 +139,10 @@
#elif defined(CONFIG_NET_SLIP)
/* There is no link layer header with SLIP */
# ifdef CONFIG_NET_IPv6
# error SLIP is not available for IPv6
# ifdef CONFIG_NET_IPv4
# error SLIP requires IPv4 support
# endif
# define NET_LL_HDRLEN(d) 0
# define NET_DEV_MTU(d) CONFIG_NET_SLIP_MTU
# define MIN_NET_DEV_MTU CONFIG_NET_SLIP_MTU
+1 -1
View File
@@ -2,7 +2,7 @@
* include/nuttx/net/netdev.h
* Defines architecture-specific device driver interfaces to the uIP network.
*
* Copyright (C) 2007, 2009, 2011-2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2009, 2011-2015 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Derived largely from portions of uIP with has a similar BSD-styple license:
+41 -27
View File
@@ -123,37 +123,21 @@
/* The TCP and IP headers */
#ifdef CONFIG_NET_IPv4
struct tcp_iphdr_s
{
#ifdef CONFIG_NET_IPv6
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ip6addr_t srcipaddr; /* 128-bit Source address */
net_ip6addr_t destipaddr; /* 128-bit Destination address */
#else /* CONFIG_NET_IPv6 */
/* IPv4 IP header */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
#endif /* CONFIG_NET_IPv6 */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
/* TCP header */
@@ -168,6 +152,36 @@ struct tcp_iphdr_s
uint8_t urgp[2];
uint8_t optdata[4];
};
#endif
#ifdef CONFIG_NET_IPv6
struct tcp_ipv6hdr_s
{
/* IPv6 IP header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* TCP header */
uint16_t srcport;
uint16_t destport;
uint8_t seqno[4];
uint8_t ackno[4];
uint8_t tcpoffset;
uint8_t flags;
uint8_t wnd[2];
uint16_t tcpchksum;
uint8_t urgp[2];
uint8_t optdata[4];
};
#endif
/* The structure holding the TCP/IP statistics that are gathered if
* CONFIG_NET_STATISTICS is defined.
+36 -27
View File
@@ -68,39 +68,24 @@
/****************************************************************************
* Public Type Definitions
****************************************************************************/
/* The UDP and IP headers */
#ifdef CONFIG_NET_IPv4
struct udp_iphdr_s
{
#ifdef CONFIG_NET_IPv6
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ip6addr_t srcipaddr; /* 128-bit Source address */
net_ip6addr_t destipaddr; /* 128-bit Destination address */
#else /* CONFIG_NET_IPv6 */
/* IPv4 header */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
#endif /* CONFIG_NET_IPv6 */
uint8_t vhl; /* 8-bit Version (4) and header length (5 or 6) */
uint8_t tos; /* 8-bit Type of service (e.g., 6=TCP) */
uint8_t len[2]; /* 16-bit Total length */
uint8_t ipid[2]; /* 16-bit Identification */
uint8_t ipoffset[2]; /* 16-bit IP flags + fragment offset */
uint8_t ttl; /* 8-bit Time to Live */
uint8_t proto; /* 8-bit Protocol */
uint16_t ipchksum; /* 16-bit Header checksum */
uint16_t srcipaddr[2]; /* 32-bit Source IP address */
uint16_t destipaddr[2]; /* 32-bit Destination IP address */
/* UDP header */
@@ -109,6 +94,30 @@ struct udp_iphdr_s
uint16_t udplen;
uint16_t udpchksum;
};
#endif
#ifdef CONFIG_NET_IPv6
struct udp_ipv6hdr_s
{
/* IPv6 Ip header */
uint8_t vtc; /* Bits 0-3: version, bits 4-7: traffic class (MS) */
uint8_t tcf; /* Bits 0-3: traffic class (LS), 4-bits: flow label (MS) */
uint16_t flow; /* 16-bit flow label (LS) */
uint8_t len[2]; /* 16-bit Payload length */
uint8_t proto; /* 8-bit Next header (same as IPv4 protocol field) */
uint8_t ttl; /* 8-bit Hop limit (like IPv4 TTL field) */
net_ipv6addr_t srcipaddr; /* 128-bit Source address */
net_ipv6addr_t destipaddr; /* 128-bit Destination address */
/* UDP header */
uint16_t srcport;
uint16_t destport;
uint16_t udplen;
uint16_t udpchksum;
};
#endif
/* The structure holding the UDP statistics that are gathered if
* CONFIG_NET_STATISTICS is defined.