From e527b8e588baaf2a1a160d399308db0ec7d9362e Mon Sep 17 00:00:00 2001 From: Yves Rutschle Date: Sat, 1 Feb 2025 10:12:04 +0100 Subject: [PATCH] libproxyprotocol: add test and options to link the library if present --- Makefile.in | 2 +- config.h.in | 3 +++ configure | 22 ++++++++++++++++++++++ configure.ac | 12 ++++++++++++ doc/INSTALL.md | 9 +++++++++ 5 files changed, 47 insertions(+), 1 deletion(-) diff --git a/Makefile.in b/Makefile.in index 5eb38ab..343c6bf 100644 --- a/Makefile.in +++ b/Makefile.in @@ -37,7 +37,7 @@ AR ?= ar CFLAGS +=-Wall -O2 -DLIBPCRE -g $(CFLAGS_COV) $(CFLAGS_SAN) -LIBS=-lm -lpcre2-8 +LIBS=-lm -lpcre2-8 @LIBS@ OBJS=sslh-conf.o common.o log.o sslh-main.o probe.o tls.o argtable3.o collection.o gap.o tcp-probe.o landlock.o OBJS_A=libsslh.a FORK_OBJS=sslh-fork.o $(OBJS_A) diff --git a/config.h.in b/config.h.in index 509c310..62ee771 100644 --- a/config.h.in +++ b/config.h.in @@ -6,4 +6,7 @@ /* Landlock sandboxing Linux LSM */ #undef HAVE_LANDLOCK +/* Support for Proxy-protocol using libproxyprotocol */ +#undef HAVE_PROXYPROTOCOL + #endif diff --git a/configure b/configure index fec0263..389f127 100755 --- a/configure +++ b/configure @@ -2163,6 +2163,7 @@ ac_config_headers="$ac_config_headers config.h" ac_config_files="$ac_config_files Makefile" +have_proxyprotocol=0 @@ -3199,6 +3200,27 @@ then : fi done + for ac_header in proxy_protocol.h +do : + ac_fn_c_check_header_compile "$LINENO" "proxy_protocol.h" "ac_cv_header_proxy_protocol_h" "$ac_includes_default" +if test "x$ac_cv_header_proxy_protocol_h" = xyes +then : + printf "%s\n" "#define HAVE_PROXY_PROTOCOL_H 1" >>confdefs.h + printf "%s\n" "#define HAVE_PROXYPROTOCOL 1" >>confdefs.h + +else $as_nop + have_proxyprotocol=1 +fi + +done +if test $have_proxyprotocol == 0 +then + LIBS="$LIBS -lproxyprotocol" +fi + +LIBS="$LIBS" + + cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure # tests run on this system so they can be shared between configure diff --git a/configure.ac b/configure.ac index ebab420..ab26206 100644 --- a/configure.ac +++ b/configure.ac @@ -1,9 +1,21 @@ dnl Use autoconf to generate the `configure` script from this and Makefile.in +dnl This is awkardly adapted from https://github.com/edrosten/autoconf_tutorial +dnl (all mistakes mine) AC_INIT AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES([Makefile]) +have_proxyprotocol=0 AC_CHECK_HEADERS(linux/landlock.h, AC_DEFINE(HAVE_LANDLOCK), []) +AC_CHECK_HEADERS(proxy_protocol.h, AC_DEFINE(HAVE_PROXYPROTOCOL), [have_proxyprotocol=1]) +if test $have_proxyprotocol == 0 +then + LIBS="$LIBS -lproxyprotocol" +fi + +LIBS="$LIBS" +AC_SUBST([LIBS]) + AC_OUTPUT diff --git a/doc/INSTALL.md b/doc/INSTALL.md index cd66402..8ce26d2 100644 --- a/doc/INSTALL.md +++ b/doc/INSTALL.md @@ -42,6 +42,15 @@ Dependencies * libev-dev, in package `libev-dev`. If you build a binary specifically and do not build `sslh-ev`, you don't need this. +* [libproxyprotocol](https://github.com/kosmas-valianos/libproxyprotocol.git) + to support HAProxy's [ProxyProtocol](https://www.haproxy.org/download/2.3/doc/proxy-protocol.txt). + As this is not part of the distribution packages, set + C_INCLUDE_PATH and LD_LIBRARY_PATH to the appropriate + values: + ``` + export C_INCLUDE_PATH=/home/user/src/libproxyprotocol/src + export LD_LIBRARY_PATH=/home/user/src/libproxyprotocol/src + ``` For OpenSUSE, these are contained in packages libconfig9 and libconfig-dev in repository