Skip to content
Permalink
Browse files

net: ip: 6lo: Remove unnecessary net_buf allocation and memmove

This patch tries to avoid memmoves and buffer allocations when there
is enough space in the original buffer. Headers are still contiguous
but not in the same buffer.

Signed-off-by: Alexander Wachter <alexander.wachter@student.tugraz.at>
  • Loading branch information...
alexanderwachter authored and jukkar committed Jul 2, 2019
1 parent f10da7b commit 144dc592a676add117ab10eef506f562a3cab14d
Showing with 17 additions and 10 deletions.
  1. +17 −10 subsys/net/ip/6lo.c
@@ -1469,6 +1469,8 @@ static bool uncompress_IPHC_header(struct net_pkt *pkt)
}
}

net_pkt_cursor_init(pkt);

return true;

fail:
@@ -1482,17 +1484,24 @@ static bool uncompress_IPHC_header(struct net_pkt *pkt)
/* Adds IPv6 dispatch as first byte and adjust fragments */
static inline int compress_ipv6_header(struct net_pkt *pkt)
{
struct net_buf *frag;
struct net_buf *buffer = pkt->buffer;

frag = net_pkt_get_frag(pkt, K_FOREVER);
if (!frag) {
if (net_buf_tailroom(buffer) >= 1U) {
memmove(buffer->data + 1U, buffer->data, buffer->len);
net_buf_add(buffer, 1U);
buffer->data[0] = NET_6LO_DISPATCH_IPV6;
return 0;
}

buffer = net_pkt_get_frag(pkt, K_FOREVER);
if (!buffer) {
return -ENOBUFS;
}

frag->data[0] = NET_6LO_DISPATCH_IPV6;
net_buf_add(frag, 1);
buffer->data[0] = NET_6LO_DISPATCH_IPV6;
net_buf_add(buffer, 1);

net_pkt_frag_insert(pkt, frag);
net_pkt_frag_insert(pkt, buffer);

/* Compact the fragments, so that gaps will be filled */
net_pkt_compact(pkt);
@@ -1502,11 +1511,9 @@ static inline int compress_ipv6_header(struct net_pkt *pkt)

static inline bool uncompress_ipv6_header(struct net_pkt *pkt)
{
struct net_buf *frag = pkt->frags;

/* Pull off IPv6 dispatch header and adjust data and length */
memmove(frag->data, frag->data + 1, frag->len - 1U);
frag->len -= 1U;
net_buf_pull(pkt->buffer, 1U);
net_pkt_cursor_init(pkt);

return true;
}

0 comments on commit 144dc59

Please sign in to comment.
You can’t perform that action at this time.