1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

gnrc_sixlowpan_nhc: fix forwarding case

This commit is contained in:
Martine Lenders 2016-11-07 15:46:56 +01:00
parent e6ad438a0b
commit 1605b506c9

View File

@ -568,20 +568,14 @@ inline static size_t iphc_nhc_udp_encode(gnrc_pktsnip_t *udp, ipv6_hdr_t *ipv6_h
/* Set UDP header ID (rfc6282#section-5). */
ipv6_hdr->nh |= NHC_UDP_ID;
if (udp->type == GNRC_NETTYPE_IPV6) {
/* forwarded ipv6 packet */
size_t diff = sizeof(udp_hdr_t) - nhc_len;
for (size_t i = nhc_len; i < (udp->size - diff); i++) {
udp_data[i] = udp_data[i + diff];
}
/* NOTE: gnrc_pktbuf_realloc_data overflow if (udp->size - diff) < 4 */
gnrc_pktbuf_realloc_data(udp, (udp->size - diff));
}
else {
/* shrink udp allocation to final size */
gnrc_pktbuf_realloc_data(udp, nhc_len);
DEBUG("6lo iphc nhc: set udp len to %d\n", (int) nhc_len);
/* In case payload is in this snip (e.g. a forwarded packet):
* move data to right place */
size_t diff = sizeof(udp_hdr_t) - nhc_len;
for (size_t i = nhc_len; i < (udp->size - diff); i++) {
udp_data[i] = udp_data[i + diff];
}
/* NOTE: gnrc_pktbuf_realloc_data overflow if (udp->size - diff) < 4 */
gnrc_pktbuf_realloc_data(udp, (udp->size - diff));
return nhc_len;
}