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)
60lz4_compress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
68 uint8_t comp_head_byte = NO_COMPRESS_BYTE_SWAP;
69 uint8_t *head =
BPTR(buf);
70 uint8_t *tail =
BEND(buf);
76 *head = comp_head_byte;
81lz4v2_compress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
89 compv2_escape_data_ifneeded(buf);
93do_lz4_decompress(
int zlen_max,
struct buffer *work,
struct buffer *buf,
94 struct compress_context *compctx)
97 int uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work),
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 const 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 };
#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.
struct frame::@074234134026241341315172337061247271261307273127 buf
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...