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 <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2016-07-07 18:14:08 +03:00 committed by Jukka Rissanen
commit 9217b68f3c
3 changed files with 20 additions and 22 deletions

View file

@ -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;

View file

@ -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 */

View file

@ -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;
}