~ubuntu-branches/ubuntu/hardy/openvpn/hardy-proposed

« back to all changes in this revision

Viewing changes to lzo.h

  • Committer: Bazaar Package Importer
  • Author(s): Alberto Gonzalez Iniesta
  • Date: 2004-06-10 15:59:39 UTC
  • Revision ID: james.westby@ubuntu.com-20040610155939-dcmtiuvcoqnwek62
Tags: upstream-1.6.0
ImportĀ upstreamĀ versionĀ 1.6.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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
 
6
 *             packet compression.
 
7
 *
 
8
 *  Copyright (C) 2002-2004 James Yonan <jim@yonan.net>
 
9
 *
 
10
 *  This program is free software; you can redistribute it and/or modify
 
11
 *  it under the terms of the GNU General Public License as published by
 
12
 *  the Free Software Foundation; either version 2 of the License, or
 
13
 *  (at your option) any later version.
 
14
 *
 
15
 *  This program is distributed in the hope that it will be useful,
 
16
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 *  GNU General Public License for more details.
 
19
 *
 
20
 *  You should have received a copy of the GNU General Public License
 
21
 *  along with this program (see the file COPYING included with this
 
22
 *  distribution); if not, write to the Free Software Foundation, Inc.,
 
23
 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
24
 */
 
25
 
 
26
#ifdef USE_LZO
 
27
 
 
28
#include "lzoutil.h"
 
29
#include "lzo1x.h"
 
30
#include "buffer.h"
 
31
#include "mtu.h"
 
32
#include "common.h"
 
33
 
 
34
/*
 
35
 * Use LZO compress routine lzo1x_1_15_compress which is described
 
36
 * as faster but needs a bit more memory than the standard routine.
 
37
 * Use safe decompress (i.e. check for buffer overflows).
 
38
 * You may want to use the non-safe version
 
39
 * of decompress if speed is essential and if you know
 
40
 * that you will always be using a MAC to verify the
 
41
 * integrity of incoming packets.
 
42
 */
 
43
#define LZO_COMPRESS    lzo1x_1_15_compress
 
44
#define LZO_WORKSPACE   LZO1X_1_15_MEM_COMPRESS
 
45
#define LZO_DECOMPRESS  lzo1x_decompress_safe
 
46
 
 
47
#define LZO_EXTRA_BUFFER(len) ((len)/64 + 16 + 3)       /* LZO worst case size expansion. */
 
48
 
 
49
/*
 
50
 * Don't try to compress any packet smaller than this.
 
51
 */
 
52
#define COMPRESS_THRESHOLD 100
 
53
 
 
54
/*
 
55
 * Adaptive compress parameters
 
56
 */
 
57
#define AC_SAMP_SEC    2      /* number of seconds in sample period */
 
58
#define AC_MIN_BYTES   1000   /* sample period must have at least n bytes
 
59
                                 to be valid for testing */
 
60
#define AC_SAVE_PCT    5      /* turn off compress if we didn't save at
 
61
                                 least this % during sample period */
 
62
#define AC_OFF_SEC     60     /* if we turn off compression, don't do sample
 
63
                                 retest for n seconds */
 
64
 
 
65
struct lzo_adaptive_compress {
 
66
  bool enabled;
 
67
  bool compress_state;
 
68
  time_t next;
 
69
  int n_total;
 
70
  int n_comp;
 
71
};
 
72
 
 
73
/*
 
74
 * Compress and Uncompress routines.
 
75
 */
 
76
 
 
77
struct lzo_compress_workspace
 
78
{
 
79
  lzo_voidp wmem;
 
80
  int wmem_size;
 
81
  struct lzo_adaptive_compress ac;
 
82
 
 
83
  /* statistics */
 
84
  counter_type pre_decompress;
 
85
  counter_type post_decompress;
 
86
  counter_type pre_compress;
 
87
  counter_type post_compress;
 
88
};
 
89
 
 
90
void lzo_adjust_frame_parameters(struct frame *frame);
 
91
 
 
92
void lzo_compress_init (struct lzo_compress_workspace *lzowork, bool adaptive);
 
93
 
 
94
void lzo_compress_uninit (struct lzo_compress_workspace *lzowork);
 
95
 
 
96
void lzo_compress (struct buffer *buf, struct buffer work,
 
97
                   struct lzo_compress_workspace *lzowork,
 
98
                   const struct frame* frame,
 
99
                   const time_t current);
 
100
 
 
101
void lzo_decompress (struct buffer *buf, struct buffer work,
 
102
                     struct lzo_compress_workspace *lzowork,
 
103
                     const struct frame* frame);
 
104
 
 
105
void lzo_print_stats (struct lzo_compress_workspace *lzo_compwork);
 
106
 
 
107
#endif /* USE_LZO */