30#if defined(ENABLE_LZ4)
41lz4_compress_init(
struct compress_context *compctx)
48lz4v2_compress_init(
struct compress_context *compctx)
54lz4_compress_uninit(
struct compress_context *compctx)
58#if defined(__GNUC__) || defined(__clang__)
59#pragma GCC diagnostic push
60#pragma GCC diagnostic ignored "-Wsign-conversion"
64do_lz4_decompress(
int zlen_max,
struct buffer *work,
struct buffer *buf,
65 struct compress_context *compctx)
68 int uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work),
BLEN(buf),
78 work->
len = uncomp_len;
81 compctx->pre_decompress += buf->
len;
82 compctx->post_decompress += work->
len;
88lz4_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
103 uint8_t *head =
BPTR(buf);
109 if (c == LZ4_COMPRESS_BYTE)
111 do_lz4_decompress(zlen_max, &work, buf, compctx);
113 else if (c == NO_COMPRESS_BYTE_SWAP)
125lz4v2_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
139 const uint8_t *head =
BPTR(buf);
143 if (c != COMP_ALGV2_INDICATOR_BYTE)
156 if (c == COMP_ALGV2_LZ4_BYTE)
159 do_lz4_decompress(zlen_max, &work, buf, compctx);
161 else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE)
172#if defined(__GNUC__) || defined(__clang__)
173#pragma GCC diagnostic pop
176const struct compress_alg lz4_alg = {
"lz4", lz4_compress_init, lz4_compress_uninit,
177 comp_stub_compress, lz4_decompress };
179const struct compress_alg lz4v2_alg = {
"lz4v2", lz4v2_compress_init, lz4_compress_uninit,
180 compv2_stub_compress, lz4v2_decompress };
#define BEND(buf)
Return a pointer one past the end of the buffer content.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static bool buf_safe(const struct buffer *buf, size_t len)
Check whether len bytes can be appended to a buffer.
static bool buf_advance(struct buffer *buf, ssize_t size)
Advance the content start of a buffer, consuming bytes from the front.
#define BLEN(buf)
Return the length of the buffer content in bytes.
#define buf_init(buf, offset)
#define COMP_F_SWAP
initial command byte is swapped with last byte in buffer to preserve payload alignment
Wrapper structure for dynamically allocated memory.
int len
Length in bytes of the actual content within the allocated memory.
Packet geometry parameters.
int payload_size
the maximum size that a payload that our buffers can hold from either tun device or network link.
int headroom
the headroom in the buffer, this is choosen to allow all potential header to be added before the pack...