28 #ifndef OPENVPN_COMP_H
29 #define OPENVPN_COMP_H
35 #define COMP_F_ADAPTIVE (1<<0)
36 #define COMP_F_ALLOW_COMPRESS (1<<1)
37 #define COMP_F_SWAP (1<<2)
38 #define COMP_F_ADVERTISE_STUBS_ONLY (1<<3)
39 #define COMP_F_ALLOW_STUB_ONLY (1<<4)
41 #define COMP_F_MIGRATE (1<<5)
42 #define COMP_F_ALLOW_ASYM (1<<6)
43 #define COMP_F_ALLOW_NOCOMP_ONLY (1<<7)
46 #define COMP_ALG_UNDEF 0
47 #define COMP_ALG_STUB 1
48 #define COMP_ALG_LZO 2
49 #define COMP_ALG_SNAPPY 3
50 #define COMP_ALG_LZ4 4
54 #define COMP_ALGV2_UNCOMPRESSED 10
55 #define COMP_ALGV2_LZ4 11
96 #define COMP_PREFIX_LEN 1
104 #define LZO_COMPRESS_BYTE 0x66
105 #define LZ4_COMPRESS_BYTE 0x69
106 #define NO_COMPRESS_BYTE 0xFA
107 #define NO_COMPRESS_BYTE_SWAP 0xFB
110 #define COMP_ALGV2_INDICATOR_BYTE 0x50
111 #define COMP_ALGV2_UNCOMPRESSED_BYTE 0
112 #define COMP_ALGV2_LZ4_BYTE 1
113 #define COMP_ALGV2_LZO_BYTE 2
114 #define COMP_ALGV2_SNAPPY_BYTE 3
123 #define COMP_EXTRA_BUFFER(len) ((len)/6 + 128 + 3 + COMP_PREFIX_LEN)
128 #define COMPRESS_THRESHOLD 100
131 struct compress_context;
139 void (*compress_init)(
struct compress_context *compctx);
140 void (*compress_uninit)(
struct compress_context *compctx);
141 void (*compress)(
struct buffer *buf,
struct buffer work,
142 struct compress_context *compctx,
145 void (*decompress)(
struct buffer *buf,
struct buffer work,
146 struct compress_context *compctx,
164 union compress_workspace_union
167 struct lzo_compress_workspace lzo;
170 struct lz4_workspace lz4;
177 struct compress_context
180 struct compress_alg alg;
181 union compress_workspace_union wu;
190 extern const struct compress_alg comp_stub_alg;
191 extern const struct compress_alg compv2_stub_alg;
195 void comp_uninit(
struct compress_context *compctx);
197 void comp_print_stats(
const struct compress_context *compctx,
struct status_output *so);
201 void compv2_escape_data_ifneeded(
struct buffer *buf);