diff --git a/net/yaip/6lo.c b/net/yaip/6lo.c index 04698efdfa9..d036812718b 100644 --- a/net/yaip/6lo.c +++ b/net/yaip/6lo.c @@ -93,7 +93,8 @@ static inline bool net_6lo_maddr_48_bit_compressible(struct in6_addr *addr) * context based (dst) address compression * Mesh header compression */ -static inline bool compress_IPHC_header(struct net_buf *buf) +static inline bool compress_IPHC_header(struct net_buf *buf, + fragment_handler_t fragment) { struct net_buf *frag; struct net_ipv6_hdr *ipv6 = NET_IPV6_BUF(buf); @@ -431,6 +432,10 @@ end: /* compact the fragments, so that gaps will be filled */ net_nbuf_compact(buf->frags); + if (fragment) { + return fragment(buf, compressed - offset); + } + return true; } @@ -752,7 +757,8 @@ fail: } /* Adds IPv6 dispatch as first byte and adjust fragments */ -static inline bool compress_ipv6_header(struct net_buf *buf) +static inline bool compress_ipv6_header(struct net_buf *buf, + fragment_handler_t fragment) { struct net_buf *frag; @@ -769,6 +775,10 @@ static inline bool compress_ipv6_header(struct net_buf *buf) /* compact the fragments, so that gaps will be filled */ buf->frags = net_nbuf_compact(buf->frags); + if (fragment) { + return fragment(buf, -1); + } + return true; } @@ -783,12 +793,13 @@ static inline bool uncompress_ipv6_header(struct net_buf *buf) return true; } -bool net_6lo_compress(struct net_buf *buf, bool iphc) +bool net_6lo_compress(struct net_buf *buf, bool iphc, + fragment_handler_t fragment) { if (iphc) { - return compress_IPHC_header(buf); + return compress_IPHC_header(buf, fragment); } else { - return compress_ipv6_header(buf); + return compress_ipv6_header(buf, fragment); } } diff --git a/net/yaip/6lo.h b/net/yaip/6lo.h index ce12f43ff65..65f6b14c563 100644 --- a/net/yaip/6lo.h +++ b/net/yaip/6lo.h @@ -28,6 +28,8 @@ #include +typedef bool (*fragment_handler_t)(struct net_buf *, int); + /** * @brief Compress IPv6 packet as per RFC 6282 * @@ -37,10 +39,12 @@ * * @param Pointer to network buffer * @param iphc true for IPHC compression, false for IPv6 dispatch header + * @param Pointer to fragment function * * @return True on success, false otherwise */ -bool net_6lo_compress(struct net_buf *buf, bool iphc); +bool net_6lo_compress(struct net_buf *buf, bool iphc, + fragment_handler_t fragment); /** * @brief Unompress IPv6 packet as per RFC 6282 diff --git a/tests/net/6lo/src/main.c b/tests/net/6lo/src/main.c index 7b393c03b60..f887a96b318 100644 --- a/tests/net/6lo/src/main.c +++ b/tests/net/6lo/src/main.c @@ -415,7 +415,7 @@ static int test_6lo(struct net_6lo_data *data) net_hexdump_frags("before-compression", buf); #endif - if (!net_6lo_compress(buf, data->iphc)) { + if (!net_6lo_compress(buf, data->iphc, NULL)) { TC_PRINT("compression failed\n"); goto end; }