ICMPv6: Add 6LoWPAN and IP forwarding support.

This commit is contained in:
Gregory Nutt
2017-07-09 11:35:26 -06:00
parent 9db4350097
commit 975473fed8
14 changed files with 366 additions and 31 deletions
+44 -7
View File
@@ -107,6 +107,12 @@ systime_t g_polltime;
* IEEE802.15.4 MAC network driver. Under those conditions, 6LoWPAN
* logic will be called to create the IEEE80215.4 frames.
*
* All outgoing ICMPv6 messages come through one of two mechanisms:
*
* 1. The output from internal ICMPv6 message passing. These outgoing
* messages will use device polling and will be handled here.
* 2. ICMPv6 output resulting from TX or timer polling.
*
* Assumptions:
* The network is locked.
*
@@ -124,17 +130,25 @@ static void devif_packet_conversion(FAR struct net_driver_s *dev,
if (dev->d_len > 0)
#endif
{
FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)dev->d_buf;
#ifdef CONFIG_NET_IPv4
if ((ipv6->vtc & IP_VERSION_MASK) != IPv6_VERSION)
{
nerr("ERROR: IPv6 version error: %02x... Packet dropped\n",
ipv6->vtc);
}
else
#endif
#ifdef CONFIG_NET_TCP
if (pkttype == DEVIF_TCP)
{
FAR struct ipv6_hdr_s *ipv6 = (FAR struct ipv6_hdr_s *)dev->d_buf;
/* This packet came from a response to TCP polling and is directed
* to an IEEE802.15.4 device using 6LoWPAN. Verify that the outgoing
* packet is IPv6 with TCP protocol.
*/
if (ipv6->vtc == IPv6_VERSION && ipv6->proto == IP_PROTO_TCP)
if (ipv6->proto == IP_PROTO_TCP)
{
/* Let 6LoWPAN convert IPv6 TCP output into IEEE802.15.4 frames. */
@@ -142,17 +156,40 @@ static void devif_packet_conversion(FAR struct net_driver_s *dev,
}
else
{
nerr("ERROR: IPv6 version or protocol error. Packet dropped\n");
nerr(" IP version: %02x proocol: %u\n",
ipv6->vtc, ipv6->proto);
nerr("ERROR: TCP protocol error: %u... Packet dropped\n",
ipv6->proto);
}
}
else
#endif
#ifdef CONFIG_NET_ICMPv6
if (pkttype == DEVIF_ICMP6)
{
/* This packet came from a response to TCP polling and is directed
* to an IEEE802.15.4 device using 6LoWPAN. Verify that the outgoing
* packet is IPv6 with TCP protocol.
*/
if (ipv6->proto == IP_PROTO_ICMP6)
{
/* Let 6LoWPAN convert IPv6 ICMPv6 output into IEEE802.15.4 frames. */
sixlowpan_icmpv6_send(dev, dev, ipv6);
}
else
{
nerr("ERROR: ICMPv6 protocol error: %u... Packet dropped\n",
ipv6->proto);
}
}
else
#endif
{
nerr("ERROR: Non-TCP packet dropped. Packet type: %u\n", pkttype);
nerr("ERROR: Unhandled packet dropped. pkttype=%u protocol=%u\n",
pkttype, ipv6->proto);
}
UNUSED(ipv6);
dev->d_len = 0;
}
}
+34 -2
View File
@@ -416,7 +416,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
* during TCP packet processing by the TCP state meachine.
* 3. TCP output resulting from TX or timer polling
*
* Cases 2 is handled here. Logic here detected if (1) an attempt
* Case 3 is handled here. Logic here detects if (1) an attempt
* to return with d_len > 0 and (2) that the device is an
* IEEE802.15.4 MAC network driver. Under those conditions, 6LoWPAN
* logic will be called to create the IEEE80215.4 frames.
@@ -457,8 +457,40 @@ int ipv6_input(FAR struct net_driver_s *dev)
/* Forward the ICMPv6 packet */
icmpv6_input(dev);
break;
#ifdef CONFIG_NET_6LOWPAN
/* All outgoing ICMPv6 messages come through one of two mechanisms:
*
* 1. The output from internal ICMPv6 message passing. These
* outgoing messages will use device polling and will be
* handled elsewhere.
* 2. ICMPv6 output resulting from TX or timer polling.
*
* Case 2 is handled here. Logic here detects if (1) an attempt
* to return with d_len > 0 and (2) that the device is an
* IEEE802.15.4 MAC network driver. Under those conditions, 6LoWPAN
* logic will be called to create the IEEE80215.4 frames.
*/
#ifdef CONFIG_NET_MULTILINK
/* Handle the case where multiple link layer protocols are supported */
if (dev->d_len > 0 && dev->d_lltype == CONFIG_NET_6LOWPAN)
#else
if (dev->d_len > 0)
#endif
{
/* Let 6LoWPAN handle the ICMPv6 output */
sixlowpan_icmpv6_send(dev, dev, ipv6);
/* Drop the packet in the d_buf */
goto drop;
}
#endif /* CONFIG_NET_6LOWPAN */
break;
#endif /* CONFIG_NET_ICMPv6 */
default: /* Unrecognized/unsupported protocol */
#ifdef CONFIG_NET_STATISTICS