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);
91#if defined(__GNUC__) || defined(__clang__)
92#pragma GCC diagnostic push
93#pragma GCC diagnostic ignored "-Wconversion"
97do_lz4_decompress(
size_t zlen_max,
struct buffer *work,
struct buffer *buf,
98 struct compress_context *compctx)
102 uncomp_len = LZ4_decompress_safe((
const char *)
BPTR(buf), (
char *)
BPTR(work), (
size_t)
BLEN(buf),
112 work->
len = uncomp_len;
115 compctx->pre_decompress += buf->
len;
116 compctx->post_decompress += work->
len;
121#if defined(__GNUC__) || defined(__clang__)
122#pragma GCC diagnostic pop
126lz4_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
141 uint8_t *head =
BPTR(buf);
147 if (c == LZ4_COMPRESS_BYTE)
149 do_lz4_decompress(zlen_max, &work, buf, compctx);
151 else if (c == NO_COMPRESS_BYTE_SWAP)
163lz4v2_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
177 uint8_t *head =
BPTR(buf);
181 if (c != COMP_ALGV2_INDICATOR_BYTE)
194 if (c == COMP_ALGV2_LZ4_BYTE)
197 do_lz4_decompress(zlen_max, &work, buf, compctx);
199 else if (c == COMP_ALGV2_UNCOMPRESSED_BYTE)
210const struct compress_alg lz4_alg = {
"lz4", lz4_compress_init, lz4_compress_uninit, lz4_compress,
213const struct compress_alg lz4v2_alg = {
"lz4v2", lz4v2_compress_init, lz4_compress_uninit,
214 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...