diff options
author | Arne Schwabe | 2016-01-03 18:27:46 +0100 |
---|---|---|
committer | Gert Doering | 2016-01-04 20:22:25 +0100 |
commit | a75bb2e40a431e053ea1ef328ec022aaf851ccc0 (patch) | |
tree | 45cd9ac56b0c9b792f78a9b22c814e6c144285cf /src/openvpn/comp.h | |
parent | 868d9d01802da9bbbb3a758981f3c7310a905813 (diff) | |
download | openvpn-a75bb2e40a431e053ea1ef328ec022aaf851ccc0.zip openvpn-a75bb2e40a431e053ea1ef328ec022aaf851ccc0.tar.gz |
Implement the compression V2 data format for stub and lz4.
Patch V2: Fix minor issues found by Steffan
Patch V3: split wire codes and compression flags
Patch V4: Fix further issues reported by Gert
Patch V5: really fix the issues that should be fixed in v2
Patch V6: fix more minor things
It has been tested against v3 server and again itself. From James Mail:
Compression V2
I have observed that compression in many cases, even when
enabled, often does not produce packet size reduction
because much of the packet data typically generated by web
sessions is already compressed. Further, the single byte that
precedes the packet and indicates whether or not compression
occurred has the unfortunate side effect of misaligning the IP
packet in cases where compression did not occur. To remedy this,
I propose a Compression V2 header that is optimized for the
case where compression does not occur.
a. No compression occurred and first byte of IP/Ethernet packet
is NOT 0x50 (0 bytes of overhead and maintains alignment):
[ uncompressed IP/Ethernet packet ]
b. No compression occurred and first byte of IP/Ethernet packet
is 0x50 (2 bytes of overhead but unlikely since no known
IP packet can begin with 0x50):
[ 0x50 ] [ 0x00 ] [ uncompressed IP/Ethernet packet ]
c. Compression occurred (2 bytes of overhead):
[ 0x50 ] [ compression Alg ID ] [ compressed IP/Ethernet packet ]
Compression Alg ID is one-byte algorithm identifier
for LZ4 (0x1), LZO (0x2), or Snappy (0x3).
This approach has several beneficial effects:
1. In the common case where compression does not occur, no
compression op is required, therefore there is zero overhead.
2. When compression does not occur, the IP/Ethernet packet
alignment is retained.
3. This technique does not require any byte swapping with
the tail of the packet which can potentially incur an
expensive cache miss.
Acked-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1451842066-13475-1-git-send-email-arne@rfc2549.org>
URL: http://article.gmane.org/gmane.network.openvpn.devel/10925
Signed-off-by: Gert Doering <gert@greenie.muc.de>
Diffstat (limited to 'src/openvpn/comp.h')
-rw-r--r-- | src/openvpn/comp.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/openvpn/comp.h b/src/openvpn/comp.h index 716b1c0..9ed9532 100644 --- a/src/openvpn/comp.h +++ b/src/openvpn/comp.h @@ -43,12 +43,22 @@ #define COMP_ALG_SNAPPY 3 /* Snappy algorithm (no longer supported) */ #define COMP_ALG_LZ4 4 /* LZ4 algorithm */ + +/* algorithm v2 */ +#define COMP_ALGV2_UNCOMPRESSED 10 +#define COMP_ALGV2_LZ4 11 +/* +#define COMP_ALGV2_LZO 12 +#define COMP_ALGV2_SNAPPY 13 +*/ + /* Compression flags */ #define COMP_F_ADAPTIVE (1<<0) /* COMP_ALG_LZO only */ #define COMP_F_ASYM (1<<1) /* only downlink is compressed, not uplink */ #define COMP_F_SWAP (1<<2) /* initial command byte is swapped with last byte in buffer to preserve payload alignment */ #define COMP_F_ADVERTISE_STUBS_ONLY (1<<3) /* tell server that we only support compression stubs */ + /* * Length of prepended prefix on compressed packets */ @@ -57,9 +67,21 @@ /* * Prefix bytes */ + +/* V1 on wire codes */ +/* Initial command byte to tell our peer if we compressed */ +#define LZO_COMPRESS_BYTE 0x66 +#define LZ4_COMPRESS_BYTE 0x69 #define NO_COMPRESS_BYTE 0xFA #define NO_COMPRESS_BYTE_SWAP 0xFB /* to maintain payload alignment, replace this byte with last byte of packet */ +/* V2 on wire code */ +#define COMP_ALGV2_INDICATOR_BYTE 0x50 +#define COMP_ALGV2_UNCOMPRESSED_BYTE 0 +#define COMP_ALGV2_LZ4_BYTE 1 +#define COMP_ALGV2_LZO_BYTE 2 +#define COMP_ALGV2_SNAPPY_BYTE 3 + /* * Compress worst case size expansion (for any algorithm) * @@ -145,6 +167,7 @@ struct compress_context }; extern const struct compress_alg comp_stub_alg; +extern const struct compress_alg compv2_stub_alg; struct compress_context *comp_init(const struct compress_options *opt); @@ -157,6 +180,8 @@ void comp_print_stats (const struct compress_context *compctx, struct status_out void comp_generate_peer_info_string(const struct compress_options *opt, struct buffer *out); +void compv2_escape_data_ifneeded (struct buffer *buf); + static inline bool comp_enabled(const struct compress_options *info) { |