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(
int zlen_max,
struct buffer *work,
struct buffer *buf,
93 struct compress_context *compctx)
96 int uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work),
BLEN(buf),
106 work->
len = uncomp_len;
109 compctx->pre_decompress += buf->
len;
110 compctx->post_decompress += work->
len;
116lz4_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
131 uint8_t *head =
BPTR(buf);
137 if (c == LZ4_COMPRESS_BYTE)
139 do_lz4_decompress(zlen_max, &work, buf, compctx);
141 else if (c == NO_COMPRESS_BYTE_SWAP)
153lz4v2_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
167 uint8_t *head =
BPTR(buf);
171 if (c != COMP_ALGV2_INDICATOR_BYTE)
184 if (c == COMP_ALGV2_LZ4_BYTE)
187 do_lz4_decompress(zlen_max, &work, buf, compctx);
189 else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE)
200const struct compress_alg lz4_alg = {
"lz4", lz4_compress_init, lz4_compress_uninit, lz4_compress,
203const struct compress_alg lz4v2_alg = {
"lz4v2", lz4v2_compress_init, lz4_compress_uninit,
204 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...