From 9217b68f3c093ce5d4b66cac3adeeae820a175bb Mon Sep 17 00:00:00 2001 From: Ravi kumar Veeramally Date: Thu, 7 Jul 2016 18:14:08 +0300 Subject: [PATCH] net: Change 6lo API returned parameter 6lowpan compression and uncompression done on original input buffer. So no need to return paramter as net_buf *. If the compression or uncompression fails, unref the buffer as it cannot be used further. Change-Id: I64f496e22b2008a91a358fff65de1b87659cd9eb Signed-off-by: Ravi kumar Veeramally --- net/yaip/6lo.c | 28 ++++++++++++++-------------- net/yaip/6lo.h | 8 ++++---- tests/net/6lo/src/main.c | 6 ++---- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/net/yaip/6lo.c b/net/yaip/6lo.c index 009ec9e29bc..19b5210b183 100644 --- a/net/yaip/6lo.c +++ b/net/yaip/6lo.c @@ -93,7 +93,7 @@ static inline bool net_6lo_maddr_48_bit_compressible(struct in6_addr *addr) * context based (dst) address compression * Mesh header compression */ -static struct net_buf *compress_IPHC_header(struct net_buf *buf) +static inline bool compress_IPHC_header(struct net_buf *buf) { struct net_buf *frag; struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf); @@ -103,19 +103,19 @@ static struct net_buf *compress_IPHC_header(struct net_buf *buf) if (buf->frags->len < NET_IPV6H_LEN) { NET_DBG("Invalid length %d, min %d", buf->frags->len, NET_IPV6H_LEN); - return NULL; + return false; } if (ipv6->nexthdr == IPPROTO_UDP && buf->frags->len < NET_IPV6UDPH_LEN) { NET_DBG("Invalid length %d, min %d", buf->frags->len, NET_IPV6UDPH_LEN); - return NULL; + return false; } frag = net_nbuf_get_reserve_data(0); if (!frag) { - return NULL; + return false; } IPHC[offset++] = NET6LO_DISPATCH_IPHC; @@ -429,13 +429,13 @@ end: net_buf_frag_insert(buf, frag); /* compact the fragments, so that gaps will be filled */ - buf->frags = net_nbuf_compact(buf->frags); + net_nbuf_compact(buf->frags); - return buf; + return true; } /* TODO: context based uncompression not supported */ -static struct net_buf *uncompress_IPHC_header(struct net_buf *buf) +static inline bool uncompress_IPHC_header(struct net_buf *buf) { struct net_buf *frag; struct net_ipv6_hdr *ipv6; @@ -445,12 +445,12 @@ static struct net_buf *uncompress_IPHC_header(struct net_buf *buf) if (CIPHC[1] & NET6LO_IPHC_CID_1) { /* if it is supported increase offset to +1 */ - return NULL; + return false; } frag = net_nbuf_get_reserve_data(0); if (!frag) { - return NULL; + return false; } ipv6 = (struct net_ipv6_hdr *)(frag->data); @@ -733,7 +733,7 @@ end: /* insert the fragment (this one holds uncompressed headers) */ net_buf_frag_insert(buf, frag); - buf->frags = net_nbuf_compact(buf->frags); + net_nbuf_compact(buf->frags); /* set IPv6 header and UDP (if next header is) length */ len = net_buf_frags_len(buf) - NET_IPV6H_LEN; @@ -744,19 +744,19 @@ end: udp->len = len; } - return buf; + return true; fail: net_nbuf_unref(frag); - return NULL; + return false; } -struct net_buf *net_6lo_compress(struct net_buf *buf) +bool net_6lo_compress(struct net_buf *buf) { return compress_IPHC_header(buf); } -struct net_buf *net_6lo_uncompress(struct net_buf *buf) +bool net_6lo_uncompress(struct net_buf *buf) { if (!buf || !buf->frags) { return NULL; diff --git a/net/yaip/6lo.h b/net/yaip/6lo.h index d3d37c44fb1..91a3c35d148 100644 --- a/net/yaip/6lo.h +++ b/net/yaip/6lo.h @@ -37,9 +37,9 @@ * * @param Pointer to network buffer * - * @return Pointer to network buffer if ok, NULL otherwise + * @return True on success, false otherwise */ -struct net_buf *net_6lo_compress(struct net_buf *buf); +bool net_6lo_compress(struct net_buf *buf); /** * @brief Unompress IPv6 packet as per RFC 6282 @@ -50,9 +50,9 @@ struct net_buf *net_6lo_compress(struct net_buf *buf); * * @param Pointer to network buffer * - * @return Pointer to network buffer if ok, NULL otherwise + * @return True on success, false otherwise */ -struct net_buf *net_6lo_uncompress(struct net_buf *buf); +bool net_6lo_uncompress(struct net_buf *buf); #endif /* __NET_6LO_H */ diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index 5bd350938c6..2bfbdca5c37 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -374,8 +374,7 @@ static int test_6lo(struct net_6lo_data *data) net_hexdump_frags("before-compression", buf); #endif - buf = net_6lo_compress(buf); - if (!buf) { + if (!net_6lo_compress(buf)) { TC_PRINT("compression failed\n"); goto end; } @@ -385,8 +384,7 @@ static int test_6lo(struct net_6lo_data *data) net_hexdump_frags("after-compression", buf); #endif - buf = net_6lo_uncompress(buf); - if (!buf) { + if (!net_6lo_uncompress(buf)) { TC_PRINT("uncompression failed\n"); goto end; }