34#if defined(ENABLE_LZO)
43#if defined(__GNUC__) || defined(__clang__)
44#pragma GCC diagnostic push
45#pragma GCC diagnostic ignored "-Wsign-conversion"
49lzo_compress_init(
struct compress_context *compctx)
53 compctx->wu.lzo.wmem_size = LZO_WORKSPACE;
55 int lzo_status = lzo_init();
56 if (lzo_status != LZO_E_OK)
58 msg(
M_FATAL,
"Cannot initialize LZO compression library (lzo_init() returns %d)",
61 compctx->wu.lzo.wmem = (lzo_voidp)malloc(compctx->wu.lzo.wmem_size);
66lzo_compress_uninit(
struct compress_context *compctx)
68 free(compctx->wu.lzo.wmem);
69 compctx->wu.lzo.wmem = NULL;
73lzo_decompress(
struct buffer *buf,
struct buffer work,
struct compress_context *compctx,
89 if (c == LZO_COMPRESS_BYTE)
92 int err = LZO_DECOMPRESS(
BPTR(buf),
BLENZ(buf),
BPTR(&work), &zlen, compctx->wu.lzo.wmem);
101 work.
len = (int)zlen;
104 compctx->pre_decompress += buf->
len;
105 compctx->post_decompress += work.
len;
109 else if (c == NO_COMPRESS_BYTE)
120#if defined(__GNUC__) || defined(__clang__)
121#pragma GCC diagnostic pop
124const struct compress_alg lzo_alg = {
"lzo", lzo_compress_init, lzo_compress_uninit,
125 comp_stub_compress, lzo_decompress };
#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 BLENZ(buf)
Return the length of the buffer content as a size_t.
static void check_malloc_return(void *p)
Abort if a memory allocation returned NULL.
#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...