Remove unused '#include's.
[tinc] / src / net_packet.c
index b8997e5..f9907ee 100644 (file)
@@ -25,6 +25,8 @@
 #ifdef HAVE_ZLIB
 #define ZLIB_CONST
 #include <zlib.h>
+#include <assert.h>
+
 #endif
 
 #ifdef HAVE_LZO
 #include LZ4_H
 #endif
 
-#ifdef HAVE_LZ4_BUILTIN
-#include "lib/lz4/lz4.h"
-#endif
-
 #include "address_cache.h"
 #include "cipher.h"
 #include "conf.h"
 #include "ethernet.h"
 #include "ipv4.h"
 #include "ipv6.h"
-#include "graph.h"
 #include "logger.h"
 #include "net.h"
 #include "netutl.h"
 #include "protocol.h"
 #include "route.h"
 #include "utils.h"
-#include "xalloc.h"
 
 #ifndef MAX
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
@@ -75,9 +71,7 @@ static char lzo_wrkmem[LZO1X_999_MEM_COMPRESS > LZO1X_1_MEM_COMPRESS ? LZO1X_999
 #ifdef HAVE_LZ4_BUILTIN
 static LZ4_stream_t lz4_stream;
 #else
-#ifdef HAVE_LZ4_STATE
 static void *lz4_state = NULL;
-#endif /* HAVE_LZ4_STATE   */
 #endif /* HAVE_LZ4_BUILTIN */
 
 static void send_udppacket(node_t *, vpn_packet_t *);
@@ -222,57 +216,61 @@ static void udp_probe_h(node_t *n, vpn_packet_t *packet, length_t len) {
        }
 }
 
-static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
-       switch(level) {
 #ifdef HAVE_LZ4
-
-       case 12:
+static length_t compress_packet_lz4(uint8_t *dest, const uint8_t *source, length_t len) {
 #ifdef HAVE_LZ4_BUILTIN
-               return LZ4_compress_fast_extState(&lz4_stream, (char *)source, (char *) dest, len, MAXSIZE, 0);
-
+       return LZ4_compress_fast_extState(&lz4_stream, (const char *) source, (char *) dest, len, MAXSIZE, 0);
 #else
-#ifdef HAVE_LZ4_STATE
-
-               /* @FIXME: Put this in a better place, and free() it too. */
-               if(lz4_state == NULL) {
-                       lz4_state = malloc(LZ4_sizeofState());
-               }
 
-               if(lz4_state == NULL) {
-                       logger(DEBUG_ALWAYS, LOG_ERR, "Failed to allocate lz4_state, error: %i", errno);
-                       return 0;
-               }
-
-               return LZ4_compress_fast_extState(lz4_state, source, dest, len, MAXSIZE, 0);
+       /* @FIXME: Put this in a better place, and free() it too. */
+       if(lz4_state == NULL) {
+               lz4_state = malloc(LZ4_sizeofState());
+       }
 
-#else
-               return LZ4_compress_shim(source, dest, len, MAXSIZE);
+       if(lz4_state == NULL) {
+               logger(DEBUG_ALWAYS, LOG_ERR, "Failed to allocate lz4_state, error: %i", errno);
+               return 0;
+       }
 
-#endif /* HAVE_LZ4_STATE   */
+       return LZ4_compress_fast_extState(lz4_state, (const char *) source, (char *) dest, len, MAXSIZE, 0);
 #endif /* HAVE_LZ4_BUILTIN */
-#endif /* HAVE_LZ4         */
+}
+#endif /* HAVE_LZ4 */
+
 #ifdef HAVE_LZO
+static length_t compress_packet_lzo(uint8_t *dest, const uint8_t *source, length_t len, int level) {
+       assert(level == 10 || level == 11);
 
-       case 11: {
-               lzo_uint lzolen = MAXSIZE;
+       lzo_uint lzolen = MAXSIZE;
+       int result;
 
-               if(lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem) == LZO_E_OK) {
-                       return lzolen;
-               } else {
-                       return 0;
-               }
+       if(level == 11) {
+               result = lzo1x_999_compress(source, len, dest, &lzolen, lzo_wrkmem);
+       } else { // level == 10
+               result = lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem);
        }
 
-       case 10: {
-               lzo_uint lzolen = MAXSIZE;
-
-               if(lzo1x_1_compress(source, len, dest, &lzolen, lzo_wrkmem) == LZO_E_OK) {
-                       return lzolen;
-               } else {
-                       return 0;
-               }
+       if(result == LZO_E_OK) {
+               return lzolen;
+       } else {
+               return 0;
        }
+}
+#endif
 
+static length_t compress_packet(uint8_t *dest, const uint8_t *source, length_t len, int level) {
+       switch(level) {
+#ifdef HAVE_LZ4
+
+       case 12:
+               return compress_packet_lz4(dest, source, len);
+#endif
+
+#ifdef HAVE_LZO
+
+       case 11:
+       case 10:
+               return compress_packet_lzo(dest, source, len, level);
 #endif
 #ifdef HAVE_ZLIB