30#if defined(ENABLE_LZ4)
40lz4_compress_init(
struct compress_context *compctx)
47lz4v2_compress_init(
struct compress_context *compctx)
53lz4_compress_uninit(
struct compress_context *compctx)
59lz4_compress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
67 uint8_t comp_head_byte = NO_COMPRESS_BYTE_SWAP;
68 uint8_t *head =
BPTR(buf);
69 uint8_t *tail =
BEND(buf);
75 *head = comp_head_byte;
80lz4v2_compress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
88 compv2_escape_data_ifneeded(buf);
92do_lz4_decompress(
size_t zlen_max,
struct buffer *work,
struct buffer *buf,
93 struct compress_context *compctx)
97 uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work), (
size_t)
BLEN(buf),
107 work->
len = uncomp_len;
110 compctx->pre_decompress += buf->
len;
111 compctx->post_decompress += work->
len;
117lz4_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
132 uint8_t *head =
BPTR(buf);
138 if (c == LZ4_COMPRESS_BYTE)
140 do_lz4_decompress(zlen_max, &work, buf, compctx);
142 else if (c == NO_COMPRESS_BYTE_SWAP)
154lz4v2_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
168 uint8_t *head =
BPTR(buf);
172 if (c != COMP_ALGV2_INDICATOR_BYTE)
185 if (c == COMP_ALGV2_LZ4_BYTE)
188 do_lz4_decompress(zlen_max, &work, buf, compctx);
190 else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE)
201const struct compress_alg lz4_alg = {
"lz4", lz4_compress_init, lz4_compress_uninit, lz4_compress,
204const struct compress_alg lz4v2_alg = {
"lz4v2", lz4v2_compress_init, lz4_compress_uninit,
205 lz4v2_compress, lz4v2_decompress };
static bool buf_safe(const struct buffer *buf, size_t len)
static bool buf_advance(struct buffer *buf, int size)
#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...