]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
lz4: Move towards a newer LZ4 API
authorDavid Sommerseth <davids@openvpn.net>
Thu, 7 Sep 2017 17:20:04 +0000 (19:20 +0200)
committerDavid Sommerseth <davids@openvpn.net>
Fri, 22 Sep 2017 21:39:29 +0000 (23:39 +0200)
We are using a deprecated function, LZ4_compress_limitedOutput(), which
will be removed with time.  The correct function to use is
LZ4_compress_default().  Both function takes the same number of
arguments and data types, so the change is minimal.

This patch will also enforce the system LZ4 library to be at least v1.7.1.
If the system library is not found or it is older, it will be build using
the bundled LZ4 library.  The version number requirement is based on the
LZ4 version we ship.

The changes in configure.ac for the version check is modelled around the
same approach we use for OpenSSL.  Plus it does a few minor reformats and
improvements to comply with more recommend autoconf coding style.

This patch is a result of the discussions in this mail thread:
https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg14135.html

Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20170907172004.22534-1-davids@openvpn.net>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg15396.html
Signed-off-by: David Sommerseth <davids@openvpn.net>
(cherry picked from commit 5f6225c32e41a922069964d9d59c2fcd6589f74c)

configure.ac
src/openvpn/comp-lz4.c

index db671875515f68f8464cd8e265ca64ff2316ffa0..50d254560637c2819dc41df261274268a4bd400b 100644 (file)
@@ -1068,37 +1068,67 @@ dnl
 AC_ARG_VAR([LZ4_CFLAGS], [C compiler flags for lz4])
 AC_ARG_VAR([LZ4_LIBS], [linker flags for lz4])
 if test "$enable_lz4" = "yes" && test "$enable_comp_stub" = "no"; then
-    AC_CHECKING([for LZ4 Library and Header files])
-    havelz4lib=1
-
-    # if LZ4_LIBS is set, we assume it will work, otherwise test
-    if test -z "${LZ4_LIBS}"; then
-       AC_CHECK_LIB(lz4, LZ4_compress,
-           [ LZ4_LIBS="-llz4" ],
-           [
-               AC_MSG_RESULT([LZ4 library not found.])
-               havelz4lib=0
-           ])
+    if test -z "${LZ4_CFLAGS}" -a -z "${LZ4_LIBS}"; then
+       # if the user did not explicitly specify flags, try to autodetect
+       PKG_CHECK_MODULES([LZ4],
+                         [liblz4 >= 1.7.1],
+                         [have_lz4="yes"],
+                         [] # If this fails, we will do another test next
+       )
     fi
 
     saved_CFLAGS="${CFLAGS}"
+    saved_LIBS="${LIBS}"
     CFLAGS="${CFLAGS} ${LZ4_CFLAGS}"
-    AC_CHECK_HEADERS(lz4.h,
-       ,
-       [
-          AC_MSG_RESULT([LZ4 headers not found.])
-          havelz4lib=0
-       ])
+    LIBS="${LIBS} ${LZ4_LIBS}"
+
+    # If pkgconfig check failed or LZ4_CFLAGS/LZ4_LIBS env vars
+    # are used, check the version directly in the LZ4 include file
+    if test "${have_lz4}" != "yes"; then
+       AC_CHECK_HEADERS([lz4.h],
+                        [have_lz4h="yes"],
+                        [])
+
+       if test "${have_lz4h}" = "yes" ; then
+           AC_MSG_CHECKING([additionally if system LZ4 version >= 1.7.1])
+           AC_COMPILE_IFELSE(
+               [AC_LANG_PROGRAM([[
+#include <lz4.h>
+                                ]],
+                                [[
+/* Version encoding: MMNNPP (Major miNor Patch) - see lz4.h for details */
+#if LZ4_VERSION_NUMBER < 10701L
+#error LZ4 is too old
+#endif
+                                ]]
+                               )],
+               [
+                   AC_MSG_RESULT([ok])
+                   have_lz4="yes"
+               ],
+               [AC_MSG_RESULT([system LZ4 library is too old])]
+           )
+       fi
+    fi
+
+    # if LZ4_LIBS is set, we assume it will work, otherwise test
+    if test -z "${LZ4_LIBS}"; then
+       AC_CHECK_LIB([lz4],
+                    [LZ4_compress],
+                    [LZ4_LIBS="-llz4"],
+                    [have_lz4="no"])
+    fi
 
-    if test $havelz4lib = 0 ; then
-       AC_MSG_RESULT([LZ4 library or header not found, using version in src/compat/compat-lz4.*])
+    if test "${have_lz4}" != "yes" ; then
+       AC_MSG_RESULT([         usuable LZ4 library or header not found, using version in src/compat/compat-lz4.*])
        AC_DEFINE([NEED_COMPAT_LZ4], [1], [use copy of LZ4 source in compat/])
        LZ4_LIBS=""
     fi
     OPTIONAL_LZ4_CFLAGS="${LZ4_CFLAGS}"
     OPTIONAL_LZ4_LIBS="${LZ4_LIBS}"
-    AC_DEFINE(ENABLE_LZ4, 1, [Enable LZ4 compression library])
+    AC_DEFINE(ENABLE_LZ4, [1], [Enable LZ4 compression library])
     CFLAGS="${saved_CFLAGS}"
+    LIBS="${saved_LIBS}"
 fi
 
 
index e056caa8a8c0e13b9052fa9c56ae8864572ae07a..9598853ff60dd37599caea0d392c951a42599882 100644 (file)
@@ -43,6 +43,7 @@
 
 #include "memdbg.h"
 
+
 static void
 lz4_compress_init(struct compress_context *compctx)
 {
@@ -86,7 +87,7 @@ do_lz4_compress(struct buffer *buf,
             return false;
         }
 
-        zlen = LZ4_compress_limitedOutput((const char *)BPTR(buf), (char *)BPTR(work), BLEN(buf), zlen_max );
+        zlen = LZ4_compress_default((const char *)BPTR(buf), (char *)BPTR(work), BLEN(buf), zlen_max);
 
         if (zlen <= 0)
         {