1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00

Merge pull request #5029 from gebart/pr/6lo-decoded-hdr-snip-ordering

gnrc_sixlowpan: Preserve order when replacing 6lowpan header by decoded IPv6 header
This commit is contained in:
Martine Lenders 2016-03-16 11:53:53 +01:00
commit 312047fa84
3 changed files with 36 additions and 5 deletions

View File

@ -204,6 +204,17 @@ gnrc_pktsnip_t *gnrc_pktbuf_get_iovec(gnrc_pktsnip_t *pkt, size_t *len);
*/
gnrc_pktsnip_t *gnrc_pktbuf_remove_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *snip);
/**
* @brief Replace a snip from a packet and the packet buffer by another snip.
*
* @param[in] pkt A packet
* @param[in] old snip currently in the packet
* @param[in] add snip which will replace old
*
* @return The new reference to @p pkt
*/
gnrc_pktsnip_t *gnrc_pktbuf_replace_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *old, gnrc_pktsnip_t *add);
#ifdef DEVELHELP
/**
* @brief Prints some statistics about the packet buffer to stdout.

View File

@ -130,7 +130,7 @@ static void _receive(gnrc_pktsnip_t *pkt)
#ifdef MODULE_GNRC_SIXLOWPAN_IPHC
else if (sixlowpan_iphc_is(dispatch)) {
size_t dispatch_size, nh_len;
gnrc_pktsnip_t *sixlowpan, *tmp;
gnrc_pktsnip_t *sixlowpan;
gnrc_pktsnip_t *dec_hdr = gnrc_pktbuf_add(NULL, NULL, sizeof(ipv6_hdr_t),
GNRC_NETTYPE_IPV6);
if ((dec_hdr == NULL) ||
@ -152,11 +152,8 @@ static void _receive(gnrc_pktsnip_t *pkt)
}
/* Remove IPHC dispatches */
pkt = gnrc_pktbuf_remove_snip(pkt, sixlowpan);
/* Insert decoded header instead */
LL_SEARCH_SCALAR(dec_hdr, tmp, next, NULL); /* search last decoded header */
tmp->next = pkt->next;
pkt->next = dec_hdr;
pkt = gnrc_pktbuf_replace_snip(pkt, sixlowpan, dec_hdr);
payload->type = GNRC_NETTYPE_UNDEF;
}
#endif

View File

@ -503,4 +503,27 @@ gnrc_pktsnip_t *gnrc_pktbuf_remove_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *sni
return pkt;
}
gnrc_pktsnip_t *gnrc_pktbuf_replace_snip(gnrc_pktsnip_t *pkt, gnrc_pktsnip_t *old, gnrc_pktsnip_t *add)
{
/* If add is a list we need to preserve its tail */
if (add->next != NULL) {
gnrc_pktsnip_t *tail = add->next;
gnrc_pktsnip_t *back;
LL_SEARCH_SCALAR(tail, back, next, NULL); /* find the last snip in add */
/* Replace old */
LL_REPLACE_ELEM(pkt, old, add);
/* and wire in the tail between */
back->next = add->next;
add->next = tail;
}
else {
/* add is a single element, has no tail, simply replace */
LL_REPLACE_ELEM(pkt, old, add);
}
old->next = NULL;
gnrc_pktbuf_release(old);
return pkt;
}
/** @} */