]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
build: proper lzo detection and usage
authorAlon Bar-Lev <alon.barlev@gmail.com>
Wed, 29 Feb 2012 20:12:09 +0000 (22:12 +0200)
committerDavid Sommerseth <davids@redhat.com>
Thu, 22 Mar 2012 21:17:27 +0000 (22:17 +0100)
Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Adriaan de Jong <dejong@fox-it.com>
Acked-by: David Sommerseth <davids@redhat.com>
Signed-off-by: David Sommerseth <davids@redhat.com>
12 files changed:
configure.ac
distro/rpm/openvpn.spec.in
doc/doxygen/doc_compression.h
src/openvpn/Makefile.am
src/openvpn/forward.c
src/openvpn/init.c
src/openvpn/lzo.c
src/openvpn/lzo.h
src/openvpn/openvpn.h
src/openvpn/options.c
src/openvpn/options.h
src/openvpn/sig.c

index da415549e3a7681c9058a514e6b44af7e139f5c2..513471a82a948db85a261ca96886ec1e8b798271 100644 (file)
@@ -41,9 +41,9 @@ AC_USE_SYSTEM_EXTENSIONS
 
 AC_ARG_ENABLE(
        [lzo],
-       [AS_HELP_STRING([--disable-lzo], [disable LZO compression support])],
+       [AS_HELP_STRING([--enable-lzo], [enable LZO compression support])],
        ,
-       [enable_lzo="yes"]
+       [enable_lzo="no"]
 )
 
 AC_ARG_ENABLE(
@@ -240,19 +240,6 @@ AC_ARG_WITH(
        [LDFLAGS="$LDFLAGS -L$withval"] 
 )
 
-AC_ARG_WITH(
-       [lzo-headers],
-       [AS_HELP_STRING([--with-lzo-headers=DIR], [LZO Include files location])],
-       [LZO_HDR_DIR="$withval"]
-       [CPPFLAGS="$CPPFLAGS -I$withval"] 
-)
-
-AC_ARG_WITH(
-       [lzo-lib],
-       [AS_HELP_STRING([--with-lzo-lib=DIR], [LZO Library location])],
-       [LDFLAGS="$LDFLAGS -L$withval"] 
-)
-
 AC_ARG_WITH(
        [mem-check],
        [AS_HELP_STRING([--with-mem-check=TYPE], [build with debug memory checking, TYPE=dmalloc|valgrind|ssl])],
@@ -664,41 +651,44 @@ case "${with_mem_check}" in
                ;;
 esac
 
-dnl
-dnl check for LZO library
-dnl
-if test "${enable_lzo}" = "yes" && test "${enable_lzo_stub}" = "no"; then
-   LZO_H=""
-   AC_CHECKING([for LZO Library and Header files])
-   AC_CHECK_HEADER(lzo/lzo1x.h,
-       [ LZO_H="2"
-         lzolibs="lzo2 lzo"
-         AC_DEFINE(LZO_HEADER_DIR, 1, [Use lzo/ directory prefix for LZO header files (for LZO 2.0)])
-       ],
-       [ AC_CHECK_HEADER(lzo1x.h, [ LZO_H="1" ; lzolibs=lzo ]) ]
-   )
-
-   if test -n "$LZO_H"; then
-     havelzolib=0
-     for i in $lzolibs ; do
-       if test $havelzolib = 1 ; then break ; fi
-       AC_CHECK_LIB($i, lzo1x_1_15_compress,
-          [
-           LIBS="${LIBS} -l$i"
-           AC_DEFINE(USE_LZO, 1, [Use LZO compression library])
-           AC_DEFINE_UNQUOTED(LZO_VERSION_NUM, "$LZO_H", [LZO version number])
-           havelzolib=1
-         ]
-        )
-     done
-     if test $havelzolib = 0 ; then
-       AC_MSG_ERROR([LZO headers were found but LZO library was not found])
-     fi
-   else
-     AC_MSG_RESULT([LZO headers were not found])
-     AC_MSG_RESULT([LZO library available from http://www.oberhumer.com/opensource/lzo/])
-     AC_MSG_ERROR([Or try ./configure --disable-lzo OR ./configure --enable-lzo-stub])
-   fi
+AC_ARG_VAR([LZO_CFLAGS], [C compiler flags for lzo])
+AC_ARG_VAR([LZO_LIBS], [linker flags for lzo])
+have_lzo="yes"
+if test -z "${LZO_LIBS}"; then
+       AC_CHECK_LIB(
+               [lzo2],
+               [lzo1x_1_15_compress],
+               [LZO_LIBS="-llzo2"],
+               [AC_CHECK_LIB(
+                       [lzo],
+                       [lzo1x_1_15_compress],
+                       [LZO_LIBS="-llzo"],
+                       [have_lzo="no"]
+               )]
+       )
+fi
+if test "${have_lzo}" = "yes"; then
+       saved_CFLAGS="${CFLAGS}"
+       CFLAGS="${CFLAGS} ${LZO_CFLAGS}"
+       AC_CHECK_HEADERS(
+               [lzo/lzoutil.h],
+               ,
+               [AC_CHECK_HEADERS(
+                       [lzoutil.h],
+                       ,
+                       [AC_MSG_ERROR([lzoutil.h is missing])]
+               )]
+       )
+       AC_CHECK_HEADERS(
+               [lzo/lzo1x.h],
+               ,
+               [AC_CHECK_HEADERS(
+                       [lzo1x.h],
+                       ,
+                       [AC_MSG_ERROR([lzo1x.h is missing])]
+               )]
+       )
+       CFLAGS="${saved_CFLAGS}"
 fi
 
 PKG_CHECK_MODULES(
@@ -862,11 +852,16 @@ if test "${enable_selinux}" = "yes"; then
        AC_DEFINE([ENABLE_SELINUX], [1], [SELinux support])
 fi
 
+if test "${enable_lzo}" = "yes"; then
+       test "${have_lzo}" != "yes" && AC_MSG_ERROR([lzo enabled but missing])
+       OPTIONAL_LZO_CFLAGS="${LZO_CFLAGS}"
+       OPTIONAL_LZO_LIBS="${LZO_LIBS}"
+       AC_DEFINE([ENABLE_LZO], [1], [Enable LZO compression library])
+fi
 if test "${enable_lzo_stub}" = "yes"; then
        test "${enable_lzo}" = "yes" && AC_MSG_ERROR([Cannot have both lzo stub and lzo enabled])
        AC_DEFINE([ENABLE_LZO_STUB], [1], [Enable LZO stub capability])
-       AC_DEFINE([USE_LZO], [1], [Enable LZO compression library])
-       AC_DEFINE([LZO_VERSION_NUM], ["STUB"], [LZO version number])
+       AC_DEFINE([ENABLE_LZO], [1], [Enable LZO compression library])
 fi
 
 if test "${enable_pkcs11}" = "yes"; then
@@ -904,6 +899,8 @@ AC_SUBST([TAP_WIN_MIN_MINOR])
 
 AC_SUBST([OPTIONAL_DL_LIBS])
 AC_SUBST([OPTIONAL_SELINUX_LIBS])
+AC_SUBST([OPTIONAL_LZO_CFLAGS])
+AC_SUBST([OPTIONAL_LZO_LIBS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_CFLAGS])
 AC_SUBST([OPTIONAL_PKCS11_HELPER_LIBS])
 
index 8db5172e18ae1197d977467ddafc47f1e4b15e66..652144b0ccecc97f3d7f6bf29fd7d9ae8d185b11 100644 (file)
@@ -110,7 +110,7 @@ Development support for OpenVPN.
        --disable-dependency-tracking \
        --docdir="%{_docdir}/%{name}-%{version}" \
        %{?with_password_save:--enable-password-save} \
-       %{?without_lzo:--disable-lzo} \
+       %{!?without_lzo:--enable-lzo} \
        %{?with_pkcs11:--enable-pkcs11} \
        %{?with_kerberos:--with-ssl-headers=/usr/kerberos/include}
 %__make
index c28c0b67aa4fd26eac2874f7809e6bbdd0edb004..bdc4a7ed8333c672d7ab34b43cff8c82f8b3d02b 100644 (file)
@@ -68,7 +68,7 @@
  *
  * @par Settings that control this module's activity
  * Whether or not the Data Channel Compression module is active depends on
- * the compile-time \c USE_LZO preprocessor macro and the runtime flags
+ * the compile-time \c ENABLE_LZO preprocessor macro and the runtime flags
  * stored in \c lzo_compress_workspace.flags of the associated VPN tunnel.
  * The latter are initialized from \c options.lzo, which gets its value
  * from the process's configuration sources, such as its configuration
index fd92225c5631a3221bdb2d61ab5176e58aabc7ce..ca2804dbd35d088a97fbf2cb75f5eed207c42449 100644 (file)
@@ -17,6 +17,7 @@ MAINTAINERCLEANFILES = \
 INCLUDES = -I$(top_srcdir)/include
 
 AM_CFLAGS = \
+       $(OPTIONAL_LZO_CFLAGS) \
        $(OPTIONAL_PKCS11_HELPER_CFLAGS)
 
 sbin_PROGRAMS = openvpn
@@ -100,6 +101,7 @@ openvpn_SOURCES = \
        cryptoapi.h cryptoapi.c
 openvpn_LDADD = \
        $(SOCKETS_LIBS) \
+       $(OPTIONAL_LZO_LIBS) \
        $(OPTIONAL_PKCS11_HELPER_LIBS) \
        $(OPTIONAL_SELINUX_LIBS) \
        $(OPTIONAL_DL_LIBS)
index ace7d2ae8c99afde0c44b3a1ea8c2c4f44e3ed17..46bbfe748d67ae5d1da863decae639a7cd146f10 100644 (file)
@@ -438,7 +438,7 @@ encrypt_sign (struct context *c, bool comp_frag)
 
   if (comp_frag)
     {
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
       /* Compress the packet. */
       if (lzo_defined (&c->c2.lzo_compwork))
        lzo_compress (&c->c2.buf, b->lzo_compress_buf, &c->c2.lzo_compwork, &c->c2.frame);
@@ -840,7 +840,7 @@ process_incoming_link (struct context *c)
        fragment_incoming (c->c2.fragment, &c->c2.buf, &c->c2.frame_fragment);
 #endif
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
       /* decompress the incoming packet */
       if (lzo_defined (&c->c2.lzo_compwork))
        lzo_decompress (&c->c2.buf, c->c2.buffers->lzo_decompress_buf, &c->c2.lzo_compwork, &c->c2.frame);
index 0c995ffd28ae6b4690351d4113746535cd881c71..766e498a47db055c8d62a88268fb5b869ec74397 100644 (file)
@@ -1789,7 +1789,7 @@ do_deferred_options (struct context *c, const unsigned int found)
     }
 #endif
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   if (found & OPT_P_COMP)
     {
       if (lzo_defined (&c->c2.lzo_compwork))
@@ -2370,7 +2370,7 @@ do_init_crypto (struct context *c, const unsigned int flags)
 static void
 do_init_frame (struct context *c)
 {
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   /*
    * Initialize LZO compression library.
    */
@@ -2393,7 +2393,7 @@ do_init_frame (struct context *c)
       lzo_adjust_frame_parameters (&c->c2.frame_fragment_omit);        /* omit LZO frame delta from final frame_fragment */
 #endif
     }
-#endif /* USE_LZO */
+#endif /* ENABLE_LZO */
 
 #ifdef ENABLE_SOCKS
   /*
@@ -2564,7 +2564,7 @@ init_context_buffers (const struct frame *frame)
   b->decrypt_buf = alloc_buf (BUF_SIZE (frame));
 #endif
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   b->lzo_compress_buf = alloc_buf (BUF_SIZE (frame));
   b->lzo_decompress_buf = alloc_buf (BUF_SIZE (frame));
 #endif
@@ -2581,7 +2581,7 @@ free_context_buffers (struct context_buffers *b)
       free_buf (&b->read_tun_buf);
       free_buf (&b->aux_buf);
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
       free_buf (&b->lzo_compress_buf);
       free_buf (&b->lzo_decompress_buf);
 #endif
@@ -3419,7 +3419,7 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int
       goto sig;
   }
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   /* initialize LZO compression library. */
   if ((options->lzo & LZO_SELECTED) && (c->mode == CM_P2P || child))
     lzo_compress_init (&c->c2.lzo_compwork, options->lzo);
@@ -3536,7 +3536,7 @@ close_instance (struct context *c)
        /* if xinetd/inetd mode, don't allow restart */
        do_close_check_if_restart_permitted (c);
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
        if (lzo_defined (&c->c2.lzo_compwork))
          lzo_compress_uninit (&c->c2.lzo_compwork);
 #endif
index ca06f714a98af7bacd739453e24b818e9bf57d71..4becd4d274744eb0fe6329238fef1d1dadbdd13f 100644 (file)
@@ -28,7 +28,7 @@
 
 #include "syshead.h"
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
 
 #include "lzo.h"
 #include "error.h"
@@ -301,4 +301,4 @@ void lzo_print_stats (const struct lzo_compress_workspace *lzo_compwork, struct
 
 #else
 static void dummy(void) {}
-#endif /* USE_LZO */
+#endif /* ENABLE_LZO */
index da4bd8867b343e0e073b0fd04f4f0805d62fb092..472204d05f8297292a2d8cee4733ab816466699c 100644 (file)
@@ -32,7 +32,7 @@
  */
 
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
 
 /**
  * @addtogroup compression
  */
 
 #ifndef ENABLE_LZO_STUB
-#ifdef LZO_HEADER_DIR
+#if defined(HAVE_LZO_LZOUTIL_H)
 #include "lzo/lzoutil.h"
-#include "lzo/lzo1x.h"
-#else
+#elif defined(HAVE_LZOUTIL_H)
 #include "lzoutil.h"
+#endif
+#if defined(HAVE_LZO_LZO1X_H)
+#include "lzo/lzo1x.h"
+#elif defined(HAVE_LZO1X_H)
 #include "lzo1x.h"
 #endif
 #endif
@@ -340,5 +343,5 @@ lzo_defined (const struct lzo_compress_workspace *lzowork)
 /** @} addtogroup compression */
 
 
-#endif /* USE_LZO */
+#endif /* ENABLE_LZO */
 #endif
index a07b03fe6df3f22be9efc895807d43218e135cf0..5af422eb943ccdb555514d7c0a3b0ea1cc01b444 100644 (file)
@@ -105,7 +105,7 @@ struct context_buffers
 #endif
 
   /* workspace buffers for LZO compression */
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   struct buffer lzo_compress_buf;
   struct buffer lzo_decompress_buf;
 #endif
@@ -372,7 +372,7 @@ struct context_2
 
 #endif /* USE_CRYPTO */
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   struct lzo_compress_workspace lzo_compwork;
                                 /**< Compression workspace used by the
                                  *   \link compression Data Channel
index 4e95b83326cb5e1b9346890a89280d27c90086dc..12f46c78aa66db2a1a78524e48396d45a3047e3f 100644 (file)
@@ -75,8 +75,12 @@ const char title_string[] =
 #endif /* defined(USE_POLARSSL) */
 #endif /* USE_SSL */
 #endif /* USE_CRYPTO */
-#ifdef USE_LZO
-  " [LZO" LZO_VERSION_NUM "]"
+#ifdef ENABLE_LZO
+#ifdef ENABLE_LZO_STUB
+  " [LZO (STUB)]"
+#else
+  " [LZO]"
+#endif
 #endif
 #if EPOLL
   " [EPOLL]"
@@ -354,7 +358,7 @@ static const char usage_message[] =
 #ifdef ENABLE_DEBUG
   "--gremlin mask  : Special stress testing mode (for debugging only).\n"
 #endif
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   "--comp-lzo      : Use fast LZO compression -- may add up to 1 byte per\n"
   "                  packet for uncompressible data.\n"
   "--comp-noadapt  : Don't use adaptive compression when --comp-lzo\n"
@@ -1512,7 +1516,7 @@ show_settings (const struct options *o)
 
   SHOW_BOOL (fast_io);
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   SHOW_INT (lzo);
 #endif
 
@@ -2954,7 +2958,7 @@ options_string (const struct options *o,
       tt = NULL;
     }
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   if (o->lzo & LZO_SELECTED)
     buf_printf (&out, ",comp-lzo");
 #endif
@@ -6180,7 +6184,7 @@ add_option (struct options *options,
       options->passtos = true;
     }
 #endif
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   else if (streq (p[0], "comp-lzo"))
     {
       VERIFY_PERMISSION (OPT_P_COMP);
@@ -6206,7 +6210,7 @@ add_option (struct options *options,
       VERIFY_PERMISSION (OPT_P_COMP);
       options->lzo &= ~LZO_ADAPTIVE;
     }
-#endif /* USE_LZO */
+#endif /* ENABLE_LZO */
 #ifdef USE_CRYPTO
   else if (streq (p[0], "show-ciphers"))
     {
index 57b88b7dc67137540f0356aac5deec419f626da3..87fea48ec4f1e2b441d46b0410ec2fc1ed96e684 100644 (file)
@@ -343,7 +343,7 @@ struct options
   /* optimize TUN/TAP/UDP writes */
   bool fast_io;
 
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   /* LZO_x flags from lzo.h */
   unsigned int lzo;
 #endif
index 33958b09f17b1841dfd78ad628d59e7eb5781444..231f676a53dd4830aa4aa01c3a15789c7be44c42 100644 (file)
@@ -259,7 +259,7 @@ print_status (const struct context *c, struct status_output *so)
   status_printf (so, "TCP/UDP read bytes," counter_format, c->c2.link_read_bytes);
   status_printf (so, "TCP/UDP write bytes," counter_format, c->c2.link_write_bytes);
   status_printf (so, "Auth read bytes," counter_format, c->c2.link_read_bytes_auth);
-#ifdef USE_LZO
+#ifdef ENABLE_LZO
   if (lzo_defined (&c->c2.lzo_compwork))
     lzo_print_stats (&c->c2.lzo_compwork, so);
 #endif