summaryrefslogtreecommitdiff
path: root/src/openvpn/comp.c
diff options
context:
space:
mode:
authorAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
committerAlberto Gonzalez Iniesta <agi@inittab.org>2016-12-27 18:25:47 +0100
commit3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (patch)
treef29063da5bec4caf3853d49a22a09c8619eebd21 /src/openvpn/comp.c
parentd53dba59e78da865c4fe820386ff2f4f76925f3b (diff)
New upstream version 2.4.0upstream/2.4.0
Diffstat (limited to 'src/openvpn/comp.c')
-rw-r--r--src/openvpn/comp.c136
1 files changed, 73 insertions, 63 deletions
diff --git a/src/openvpn/comp.c b/src/openvpn/comp.c
index 499fef9..0182a7c 100644
--- a/src/openvpn/comp.c
+++ b/src/openvpn/comp.c
@@ -5,7 +5,7 @@
* packet encryption, packet authentication, and
* packet compression.
*
- * Copyright (C) 2002-2012 OpenVPN Technologies, Inc. <sales@openvpn.net>
+ * Copyright (C) 2002-2017 OpenVPN Technologies, Inc. <sales@openvpn.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@ -41,59 +41,67 @@
struct compress_context *
comp_init(const struct compress_options *opt)
{
- struct compress_context *compctx = NULL;
- switch (opt->alg)
+ struct compress_context *compctx = NULL;
+ switch (opt->alg)
{
- case COMP_ALG_STUB:
- ALLOC_OBJ_CLEAR (compctx, struct compress_context);
- compctx->flags = opt->flags;
- compctx->alg = comp_stub_alg;
- break;
- case COMP_ALGV2_UNCOMPRESSED:
- ALLOC_OBJ_CLEAR (compctx, struct compress_context);
- compctx->flags = opt->flags;
- compctx->alg = compv2_stub_alg;
- break;
+ case COMP_ALG_STUB:
+ ALLOC_OBJ_CLEAR(compctx, struct compress_context);
+ compctx->flags = opt->flags;
+ compctx->alg = comp_stub_alg;
+ break;
+
+ case COMP_ALGV2_UNCOMPRESSED:
+ ALLOC_OBJ_CLEAR(compctx, struct compress_context);
+ compctx->flags = opt->flags;
+ compctx->alg = compv2_stub_alg;
+ break;
+
#ifdef ENABLE_LZO
- case COMP_ALG_LZO:
- ALLOC_OBJ_CLEAR (compctx, struct compress_context);
- compctx->flags = opt->flags;
- compctx->alg = lzo_alg;
- break;
+ case COMP_ALG_LZO:
+ ALLOC_OBJ_CLEAR(compctx, struct compress_context);
+ compctx->flags = opt->flags;
+ compctx->alg = lzo_alg;
+ break;
+
#endif
#ifdef ENABLE_LZ4
- case COMP_ALG_LZ4:
- ALLOC_OBJ_CLEAR (compctx, struct compress_context);
- compctx->flags = opt->flags;
- compctx->alg = lz4_alg;
- break;
- case COMP_ALGV2_LZ4:
- ALLOC_OBJ_CLEAR (compctx, struct compress_context);
- compctx->flags = opt->flags;
- compctx->alg = lz4v2_alg;
- break;
+ case COMP_ALG_LZ4:
+ ALLOC_OBJ_CLEAR(compctx, struct compress_context);
+ compctx->flags = opt->flags;
+ compctx->alg = lz4_alg;
+ break;
+
+ case COMP_ALGV2_LZ4:
+ ALLOC_OBJ_CLEAR(compctx, struct compress_context);
+ compctx->flags = opt->flags;
+ compctx->alg = lz4v2_alg;
+ break;
#endif
}
- if (compctx)
- (*compctx->alg.compress_init)(compctx);
+ if (compctx)
+ {
+ (*compctx->alg.compress_init)(compctx);
+ }
- return compctx;
+ return compctx;
}
/* In the v2 compression schemes, an uncompressed packet has
* has no opcode in front, unless the first byte is 0x50. In this
* case the packet needs to be escaped */
void
-compv2_escape_data_ifneeded (struct buffer *buf)
+compv2_escape_data_ifneeded(struct buffer *buf)
{
- uint8_t *head = BPTR (buf);
+ uint8_t *head = BPTR(buf);
if (head[0] != COMP_ALGV2_INDICATOR_BYTE)
- return;
+ {
+ return;
+ }
/* Header is 0x50 */
ASSERT(buf_prepend(buf, 2));
- head = BPTR (buf);
+ head = BPTR(buf);
head[0] = COMP_ALGV2_INDICATOR_BYTE;
head[1] = COMP_ALGV2_UNCOMPRESSED;
}
@@ -102,37 +110,37 @@ compv2_escape_data_ifneeded (struct buffer *buf)
void
comp_uninit(struct compress_context *compctx)
{
- if (compctx)
+ if (compctx)
{
- (*compctx->alg.compress_uninit)(compctx);
- free(compctx);
+ (*compctx->alg.compress_uninit)(compctx);
+ free(compctx);
}
}
void
comp_add_to_extra_frame(struct frame *frame)
{
- /* Leave room for our one-byte compressed/didn't-compress prefix byte. */
- frame_add_to_extra_frame (frame, COMP_PREFIX_LEN);
+ /* Leave room for our one-byte compressed/didn't-compress prefix byte. */
+ frame_add_to_extra_frame(frame, COMP_PREFIX_LEN);
}
void
comp_add_to_extra_buffer(struct frame *frame)
{
- /* Leave room for compression buffer to expand in worst case scenario
- where data is totally uncompressible */
- frame_add_to_extra_buffer (frame, COMP_EXTRA_BUFFER (EXPANDED_SIZE(frame)));
+ /* Leave room for compression buffer to expand in worst case scenario
+ * where data is totally uncompressible */
+ frame_add_to_extra_buffer(frame, COMP_EXTRA_BUFFER(EXPANDED_SIZE(frame)));
}
void
-comp_print_stats (const struct compress_context *compctx, struct status_output *so)
+comp_print_stats(const struct compress_context *compctx, struct status_output *so)
{
- if (compctx)
+ if (compctx)
{
- status_printf (so, "pre-compress bytes," counter_format, compctx->pre_compress);
- status_printf (so, "post-compress bytes," counter_format, compctx->post_compress);
- status_printf (so, "pre-decompress bytes," counter_format, compctx->pre_decompress);
- status_printf (so, "post-decompress bytes," counter_format, compctx->post_decompress);
+ status_printf(so, "pre-compress bytes," counter_format, compctx->pre_compress);
+ status_printf(so, "post-compress bytes," counter_format, compctx->post_compress);
+ status_printf(so, "pre-decompress bytes," counter_format, compctx->pre_decompress);
+ status_printf(so, "post-decompress bytes," counter_format, compctx->post_decompress);
}
}
@@ -142,25 +150,27 @@ comp_print_stats (const struct compress_context *compctx, struct status_output *
void
comp_generate_peer_info_string(const struct compress_options *opt, struct buffer *out)
{
- if (opt)
+ if (opt)
{
- bool lzo_avail = false;
- if (!(opt->flags & COMP_F_ADVERTISE_STUBS_ONLY))
- {
+ bool lzo_avail = false;
+ if (!(opt->flags & COMP_F_ADVERTISE_STUBS_ONLY))
+ {
#if defined(ENABLE_LZ4)
- buf_printf (out, "IV_LZ4=1\n");
- buf_printf (out, "IV_LZ4v2=1\n");
+ buf_printf(out, "IV_LZ4=1\n");
+ buf_printf(out, "IV_LZ4v2=1\n");
#endif
#if defined(ENABLE_LZO)
- buf_printf (out, "IV_LZO=1\n");
- lzo_avail = true;
+ buf_printf(out, "IV_LZO=1\n");
+ lzo_avail = true;
#endif
- }
- if (!lzo_avail)
- buf_printf (out, "IV_LZO_STUB=1\n");
- buf_printf (out, "IV_COMP_STUB=1\n");
- buf_printf (out, "IV_COMP_STUBv2=1\n");
- buf_printf (out, "IV_TCPNL=1\n");
+ }
+ if (!lzo_avail)
+ {
+ buf_printf(out, "IV_LZO_STUB=1\n");
+ }
+ buf_printf(out, "IV_COMP_STUB=1\n");
+ buf_printf(out, "IV_COMP_STUBv2=1\n");
+ buf_printf(out, "IV_TCPNL=1\n");
}
}