6loWPAN: Additional fixes related to buffer offsets primarily.

This commit is contained in:
Gregory Nutt 2017-04-04 13:52:02 -06:00
parent 1f394a61b3
commit fdf706a3a9
2 changed files with 23 additions and 20 deletions

View File

@ -234,6 +234,19 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
ninfo("Sending packet length %d\n", buflen);
/* Pre-calculate frame header length. */
framer_hdrlen = sixlowpan_send_hdrlen(ieee, ieee->i_panid);
if (framer_hdrlen < 0)
{
/* Failed to determine the size of the header failed. */
nerr("ERROR: sixlowpan_send_hdrlen() failed: %d\n", framer_hdrlen);
return framer_hdrlen;
}
g_frame_hdrlen = framer_hdrlen;
#ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6
if (buflen >= CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD)
{
@ -259,17 +272,6 @@ int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], destmac);
/* Pre-calculate frame header length. */
framer_hdrlen = sixlowpan_send_hdrlen(ieee, ieee->i_panid);
if (framer_hdrlen < 0)
{
/* Failed to determine the size of the header failed. */
nerr("ERROR: sixlowpan_send_hdrlen() failed: %d\n", framer_hdrlen);
return framer_hdrlen;
}
/* Check if we need to fragment the packet into several frames */
if ((int)buflen - (int)g_uncomp_hdrlen >

View File

@ -461,7 +461,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
if (hc1[RIME_HC1_DISPATCH] == SIXLOWPAN_DISPATCH_IPV6)
{
ninfo("IPV6 Dispatch\n");
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
g_frame_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
/* Put uncompressed IP header in d_buf. */
@ -469,7 +469,7 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
/* Update g_uncomp_hdrlen and g_frame_hdrlen. */
g_frame_hdrlen += IPv6_HDRLEN;
g_frame_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
else
@ -484,19 +484,20 @@ static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
copypayload:
#endif /* CONFIG_NET_6LOWPAN_FRAG */
/* Copy "payload" from the rime buffer to the d_buf. If this frame is a
* first fragment or not part of a fragmented packet, we have already
* copied the compressed headers, g_uncomp_hdrlen and g_frame_hdrlen are
* non-zerio, fragoffset is.
/* Copy "payload" from the rime buffer to the IEEE802.15.4 MAC drivers
* d_buf. If this frame is a first fragment or not part of a fragmented
* packet, we have already copied the compressed headers, g_uncomp_hdrlen
* and g_frame_hdrlen are non-zerio, fragoffset is.
*/
if (ieee->i_dev.d_len < g_frame_hdrlen)
if (g_frame_hdrlen > CONFIG_NET_6LOWPAN_MTU)
{
ninfo("SIXLOWPAN: packet dropped due to header > total packet\n");
nwarn("WARNING: Packet dropped due to header (%u) > packet buffer (%u)\n",
g_frame_hdrlen, CONFIG_NET_6LOWPAN_MTU);
return OK;
}
g_rime_payloadlen = ieee->i_dev.d_len - g_frame_hdrlen;
g_rime_payloadlen = iob->io_len - g_frame_hdrlen;
/* Sanity-check size of incoming packet to avoid buffer overflow */