2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2009 OpenVPN Technologies, Inc. <sales@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program (see the file COPYING included with this
21 * distribution); if not, write to the Free Software Foundation, Inc.,
22 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #include "lzo/lzoutil.h"
32 #include "lzo/lzo1x.h"
44 #define LZO_SELECTED (1<<0)
46 #define LZO_ADAPTIVE (1<<2)
49 * Use LZO compress routine lzo1x_1_15_compress which is described
50 * as faster but needs a bit more memory than the standard routine.
51 * Use safe decompress (i.e. check for buffer overflows).
52 * You may want to use the non-safe version
53 * of decompress if speed is essential and if you know
54 * that you will always be using a MAC to verify the
55 * integrity of incoming packets.
57 #define LZO_COMPRESS lzo1x_1_15_compress
58 #define LZO_WORKSPACE LZO1X_1_15_MEM_COMPRESS
59 #define LZO_DECOMPRESS lzo1x_decompress_safe
61 #define LZO_EXTRA_BUFFER(len) ((len)/8 + 128 + 3) /* LZO 2.0 worst case size expansion. */
64 * Don't try to compress any packet smaller than this.
66 #define COMPRESS_THRESHOLD 100
69 * Length of prepended prefix on LZO packets
71 #define LZO_PREFIX_LEN 1
74 * Adaptive compress parameters
76 #define AC_SAMP_SEC 2 /* number of seconds in sample period */
77 #define AC_MIN_BYTES 1000 /* sample period must have at least n bytes
78 to be valid for testing */
79 #define AC_SAVE_PCT 5 /* turn off compress if we didn't save at
80 least this % during sample period */
81 #define AC_OFF_SEC 60 /* if we turn off compression, don't do sample
82 retest for n seconds */
84 struct lzo_adaptive_compress
{
92 * Compress and Uncompress routines.
95 struct lzo_compress_workspace
99 struct lzo_adaptive_compress ac
;
104 counter_type pre_decompress
;
105 counter_type post_decompress
;
106 counter_type pre_compress
;
107 counter_type post_compress
;
110 void lzo_adjust_frame_parameters(struct frame
*frame
);
112 void lzo_compress_init (struct lzo_compress_workspace
*lzowork
, unsigned int flags
);
114 void lzo_compress_uninit (struct lzo_compress_workspace
*lzowork
);
116 void lzo_modify_flags (struct lzo_compress_workspace
*lzowork
, unsigned int flags
);
118 void lzo_compress (struct buffer
*buf
, struct buffer work
,
119 struct lzo_compress_workspace
*lzowork
,
120 const struct frame
* frame
);
122 void lzo_decompress (struct buffer
*buf
, struct buffer work
,
123 struct lzo_compress_workspace
*lzowork
,
124 const struct frame
* frame
);
126 void lzo_print_stats (const struct lzo_compress_workspace
*lzo_compwork
, struct status_output
*so
);
129 lzo_defined (const struct lzo_compress_workspace
*lzowork
)
131 return lzowork
->defined
;