summaryrefslogtreecommitdiff
path: root/src/openvpn/compstub.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
commit79f3537f69e125f19f59c36aa090120a63186a54 (patch)
tree2089a3b7dac990841dbc2e4d9b2f535b82dbb0af /src/openvpn/compstub.c
parentf2137fedb30cb87448eb03b2f288920df6187571 (diff)
parent3a2bbdb05ca6a6996e424c9fb225cb0d53804125 (diff)
Merge tag 'upstream/2.4.0'
Upstream version 2.4.0
Diffstat (limited to 'src/openvpn/compstub.c')
-rw-r--r--src/openvpn/compstub.c179
1 files changed, 97 insertions, 82 deletions
diff --git a/src/openvpn/compstub.c b/src/openvpn/compstub.c
index 9c6aad2..5070c82 100644
--- a/src/openvpn/compstub.c
+++ b/src/openvpn/compstub.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
@@ -39,131 +39,146 @@
#include "memdbg.h"
static void
-stub_compress_init (struct compress_context *compctx)
+stub_compress_init(struct compress_context *compctx)
{
}
static void
-stub_compress_uninit (struct compress_context *compctx)
+stub_compress_uninit(struct compress_context *compctx)
{
}
static void
-stub_compress (struct buffer *buf, struct buffer work,
- struct compress_context *compctx,
- const struct frame* frame)
+stub_compress(struct buffer *buf, struct buffer work,
+ struct compress_context *compctx,
+ const struct frame *frame)
{
- if (buf->len <= 0)
- return;
- if (compctx->flags & COMP_F_SWAP)
+ if (buf->len <= 0)
+ {
+ return;
+ }
+ if (compctx->flags & COMP_F_SWAP)
{
- uint8_t *head = BPTR (buf);
- uint8_t *tail = BEND (buf);
- ASSERT (buf_safe (buf, 1));
- ++buf->len;
-
- /* move head byte of payload to tail */
- *tail = *head;
- *head = NO_COMPRESS_BYTE_SWAP;
+ uint8_t *head = BPTR(buf);
+ uint8_t *tail = BEND(buf);
+ ASSERT(buf_safe(buf, 1));
+ ++buf->len;
+
+ /* move head byte of payload to tail */
+ *tail = *head;
+ *head = NO_COMPRESS_BYTE_SWAP;
}
- else
+ else
{
- uint8_t *header = buf_prepend (buf, 1);
- *header = NO_COMPRESS_BYTE;
+ uint8_t *header = buf_prepend(buf, 1);
+ *header = NO_COMPRESS_BYTE;
}
}
static void
-stub_decompress (struct buffer *buf, struct buffer work,
- struct compress_context *compctx,
- const struct frame* frame)
+stub_decompress(struct buffer *buf, struct buffer work,
+ struct compress_context *compctx,
+ const struct frame *frame)
{
- uint8_t c;
- if (buf->len <= 0)
- return;
- if (compctx->flags & COMP_F_SWAP)
+ uint8_t c;
+ if (buf->len <= 0)
+ {
+ return;
+ }
+ if (compctx->flags & COMP_F_SWAP)
{
- uint8_t *head = BPTR (buf);
- c = *head;
- --buf->len;
- *head = *BEND (buf);
- if (c != NO_COMPRESS_BYTE_SWAP)
- {
- dmsg (D_COMP_ERRORS, "Bad compression stub (swap) decompression header byte: %d", c);
- buf->len = 0;
- }
+ uint8_t *head = BPTR(buf);
+ c = *head;
+ --buf->len;
+ *head = *BEND(buf);
+ if (c != NO_COMPRESS_BYTE_SWAP)
+ {
+ dmsg(D_COMP_ERRORS, "Bad compression stub (swap) decompression header byte: %d", c);
+ buf->len = 0;
+ }
}
- else
+ else
{
- c = *BPTR (buf);
- ASSERT (buf_advance (buf, 1));
- if (c != NO_COMPRESS_BYTE)
- {
- dmsg (D_COMP_ERRORS, "Bad compression stub decompression header byte: %d", c);
- buf->len = 0;
- }
+ c = *BPTR(buf);
+ ASSERT(buf_advance(buf, 1));
+ if (c != NO_COMPRESS_BYTE)
+ {
+ dmsg(D_COMP_ERRORS, "Bad compression stub decompression header byte: %d", c);
+ buf->len = 0;
+ }
}
}
static void
-stubv2_compress (struct buffer *buf, struct buffer work,
- struct compress_context *compctx,
- const struct frame* frame)
+stubv2_compress(struct buffer *buf, struct buffer work,
+ struct compress_context *compctx,
+ const struct frame *frame)
{
if (buf->len <= 0)
- return;
+ {
+ return;
+ }
- compv2_escape_data_ifneeded (buf);
+ compv2_escape_data_ifneeded(buf);
}
static void
-stubv2_decompress (struct buffer *buf, struct buffer work,
- struct compress_context *compctx,
- const struct frame* frame)
+stubv2_decompress(struct buffer *buf, struct buffer work,
+ struct compress_context *compctx,
+ const struct frame *frame)
{
- if (buf->len <= 0)
- return;
+ if (buf->len <= 0)
+ {
+ return;
+ }
- uint8_t *head = BPTR (buf);
+ uint8_t *head = BPTR(buf);
- /* no compression or packet to short*/
- if (head[0] != COMP_ALGV2_INDICATOR_BYTE)
- return;
+ /* no compression or packet to short*/
+ if (head[0] != COMP_ALGV2_INDICATOR_BYTE)
+ {
+ return;
+ }
- /* compression header (0x50) is present */
- buf_advance(buf, 1);
+ /* compression header (0x50) is present */
+ buf_advance(buf, 1);
- /* Packet buffer too short (only 1 byte) */
- if (buf->len <= 0)
- return;
+ /* Packet buffer too short (only 1 byte) */
+ if (buf->len <= 0)
+ {
+ return;
+ }
- head = BPTR (buf);
- buf_advance(buf, 1);
+ head = BPTR(buf);
+ buf_advance(buf, 1);
- if (head[0] != COMP_ALGV2_UNCOMPRESSED_BYTE) {
- dmsg (D_COMP_ERRORS, "Bad compression stubv2 decompression header byte: %d", *head);
- buf->len = 0;
- return;
- }
+ if (head[0] != COMP_ALGV2_UNCOMPRESSED_BYTE)
+ {
+ dmsg(D_COMP_ERRORS, "Bad compression stubv2 decompression header byte: %d", *head);
+ buf->len = 0;
+ return;
+ }
}
const struct compress_alg compv2_stub_alg = {
- "stubv2",
- stub_compress_init,
- stub_compress_uninit,
- stubv2_compress,
- stubv2_decompress
+ "stubv2",
+ stub_compress_init,
+ stub_compress_uninit,
+ stubv2_compress,
+ stubv2_decompress
};
const struct compress_alg comp_stub_alg = {
- "stub",
- stub_compress_init,
- stub_compress_uninit,
- stub_compress,
- stub_decompress
+ "stub",
+ stub_compress_init,
+ stub_compress_uninit,
+ stub_compress,
+ stub_decompress
};
-#else
-static void dummy(void) {}
+#else /* if defined(USE_COMP) */
+static void
+dummy(void) {
+}
#endif /* USE_STUB */