From f72460bd5176c0c1a058b6e0e7bd236dfab188c9 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 24 Jun 2013 11:29:44 +0200 Subject: configure: Add configure script used to detect NaCl In order to use an installation of NaCl provided by the distro or by previous manual installation, provide a configure script which checks for nacl's presence. Also check of libnl-genl headers. More checks of the other libraries depended on by netsniff-ng as well as checks for necessary kernel headers should be added here too. The configure script is preliminary and has not yet extensively been tested on multiple systems. The concept was inspired by the configure script of trinity and iproute2. Signed-off-by: Tobias Klauser --- INSTALL | 3 +- Makefile | 3 ++ configure | 98 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100755 configure diff --git a/INSTALL b/INSTALL index a6e2015..3b9b041 100644 --- a/INSTALL +++ b/INSTALL @@ -55,8 +55,9 @@ repository root directory: $ cd netsniff-ng/ -The installation (deinstallation) process done by make is fairly simple: +The installation (deinstallation) process is fairly simple: + $ ./configure $ make # make install diff --git a/Makefile b/Makefile index 8a8b76b..ee03d86 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,8 @@ # Copyright 2012 - 2013 Daniel Borkmann # Subject to the GNU GPL, version 2. +include Config + VERSION = 0 PATCHLEVEL = 5 SUBLEVEL = 8 @@ -203,6 +205,7 @@ install_all: $(foreach tool,$(TOOLS),$(tool)_install) install_allbutcurvetun: $(foreach tool,$(filter-out curvetun,$(TOOLS)),$(tool)_install) install_allbutmausezahn: $(foreach tool,$(filter-out mausezahn,$(TOOLS)),$(tool)_install) clean mostlyclean: $(foreach tool,$(TOOLS),$(tool)_clean) + $(Q)$(call RM,Config) realclean distclean clobber: $(foreach tool,$(TOOLS),$(tool)_distclean) $(Q)$(call RMDIR,$(ETCDIRE)) mrproper: clean distclean diff --git a/configure b/configure new file mode 100755 index 0000000..fd690ed --- /dev/null +++ b/configure @@ -0,0 +1,98 @@ +#!/bin/bash +# This isn't a configure generated by autoconf! + +MISSING_DEFS=0 +MISSING_NACL=0 + +[ -z $CC ] && CC=cc + +TMPDIR=$(mktemp -d config.XXXXXX) +trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM + +check_nacl() +{ + echo -n "[*] Checking nacl ... " + + cat > $TMPDIR/nacltest.c << EOF +#include "crypto_hash_sha512.h" +#include "crypto_verify_32.h" +#include "crypto_hash_sha512.h" +#include "crypto_box_curve25519xsalsa20poly1305.h" +#include "crypto_scalarmult_curve25519.h" +#include "crypto_auth_hmacsha512256.h" + +int main(void) { } +EOF + + if [ -z $NACL_INC_DIR ] ; then + NACL_INC_DIR="/usr/include/nacl" + fi + + if [ -z $NACL_LIB_DIR ] ; then + NACL_LIB_DIR="/usr/lib" + fi + + LDFLAGS="-L $NACL_LIB_DIR" + CFLAGS="-I $NACL_INC_DIR" + + $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/nacltest ] ; then + echo "[NO]" + MISSING_NACL=1 + else + echo "[YES]" + echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config + echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config + fi + +} + +check_libnl() +{ + echo -n "[*] Checking libnl ... " + + cat > $TMPDIR/libnltest.c << EOF +#include +#include +#include +#include +#include +#include + +#if LIBNL_VER_NUM < LIBNL_VER(3,0) +# error incompatible libnl version +#endif + +int main(void) { } +EOF + + $CC $(pkg-config --cflags libnl-3.0) -o $TMPDIR/libnltest $TMPDIR/libnltest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/libnltest ] ; then + echo "[NO]" + MISSING_DEFS=1 + else + echo "[YES]" + fi +} + +echo "# This file is autogenerated by the configure script" > Config +check_nacl +check_libnl + +if [ "$MISSING_DEFS" == "1" ] ; then + echo "[!] Some libraries or header definitions are missing or too old." + echo " Please refer to the INSTALL file for the libraries needed to" + echo " build netsniff-ng." + exit 1 +fi + +if [ "$MISSING_NACL" == "1" ] ; then + echo "[!] The NaCl crypto library is currently not present on your" + echo " system or could not be found. Either install it from your" + echo " distro or build it manually using 'make nacl' and make sure" + echo " that the NACL_INC_DIR and NACL_LIB_DIR variables are set" + echo " appropriately." + exit 1 +fi + +exit 0 -- cgit v1.2.3-54-g00ecf From 2e59bad182649c3ac3e66b970bc8b0f2fef8c906 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 24 Jun 2013 11:36:59 +0200 Subject: gitignore: Ignore generated Config Ignore the build config generated by the configure script. Signed-off-by: Tobias Klauser --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index e46b817..bde10bc 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,9 @@ fuzzing/ # Ignore if someone adapts Makefile Makefile +# Ignore build config generated by configure +Config + # Other documentation ignores *.md *.ps -- cgit v1.2.3-54-g00ecf From 53d360c9f608103f95b9a2a74f64c9c494ff2333 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Mon, 24 Jun 2013 23:01:41 +0200 Subject: configure: Check for tpacket, ncurses, libgeoip Check for some more libraries we make use of in the configure step. Signed-off-by: Tobias Klauser --- configure | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/configure b/configure index fd690ed..d977b37 100755 --- a/configure +++ b/configure @@ -63,7 +63,7 @@ check_libnl() # error incompatible libnl version #endif -int main(void) { } +void main(void) { } EOF $CC $(pkg-config --cflags libnl-3.0) -o $TMPDIR/libnltest $TMPDIR/libnltest.c >> $TMPDIR/config.log 2>&1 @@ -75,9 +75,108 @@ EOF fi } +check_tpacket() +{ + echo -n "[*] Checking tpacket ... " + + cat > $TMPDIR/tpackettest.c << EOF +#include +#include + +struct tpacket3_hdr *hdr; + +void main(void) +{ + printf("%d\n", hdr->tp_status); +} +EOF + + $CC -o $TMPDIR/tpackettest $TMPDIR/tpackettest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/tpackettest ] ; then + echo "[NO]" + MISSING_DEFS=1 + else + echo "[YES]" + fi +} + +check_ncurses() +{ + echo -n "[*] Checking ncurses ... " + + cat > $TMPDIR/ncursestest.c << EOF +#include + +void main(void) +{ + WINDOW *screen = initscr(); +} +EOF + + $CC $(pkg-config --cflags --libs ncurses) -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/ncursestest ] ; then + echo "[NO]" + MISSING_DEFS=1 + else + echo "[YES]" + fi +} + +check_libgeoip() +{ + echo -n "[*] Checking libGeoIP ... " + + cat > $TMPDIR/geoiptest.c << EOF +#include +#include + +void main(void) +{ + GeoIP *geoip; +} +EOF + + $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/geoiptest ] ; then + echo "[NO]" + MISSING_DEFS=1 + else + echo "[YES]" + fi + +} + +check_libnf_ct() +{ + echo -n "[*] Checking libnetfilter-conntrack ... " + + cat > $TMPDIR/nfcttest.c << EOF +#include +#include +#include +#include + +void main(void) +{ + struct nfconntrack *ct; +} +EOF + + $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c >> $TMPDIR/config.log 2>&1 + if [ ! -x $TMPDIR/nfcttest ] ; then + echo "[NO]" + MISSING_DEFS=1 + else + echo "[YES]" + fi + +} echo "# This file is autogenerated by the configure script" > Config check_nacl check_libnl +check_tpacket +check_ncurses +check_libgeoip if [ "$MISSING_DEFS" == "1" ] ; then echo "[!] Some libraries or header definitions are missing or too old." -- cgit v1.2.3-54-g00ecf From 1c0833268c7179494aecabc5f0fae643715a7a98 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 28 Jun 2013 14:26:40 +0200 Subject: configure: Add linker flags for ncursestest to correct position Newer versions of GCC expect the linker flags after the object code, so move the ouput of 'pkg-config --libs ncurses' there to not make the test fail even if ncurses is present on the system. Signed-off-by: Tobias Klauser --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index d977b37..ed1eacd 100755 --- a/configure +++ b/configure @@ -113,7 +113,7 @@ void main(void) } EOF - $CC $(pkg-config --cflags --libs ncurses) -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c >> $TMPDIR/config.log 2>&1 + $CC $(pkg-config --cflags ncurses) -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c $(pkg-config --libs ncurses) >> $TMPDIR/config.log 2>&1 if [ ! -x $TMPDIR/ncursestest ] ; then echo "[NO]" MISSING_DEFS=1 -- cgit v1.2.3-54-g00ecf From 7199a4fe1d6f66722158d73d4403f8dad8637bd1 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 28 Jun 2013 14:28:06 +0200 Subject: configure: Check for presence of pkg-config and ccache binaries Check whether pkg-config and ccache are in the PATH. A missing pkg-config will cause the configure script to abort with an error. The presence of ccache is written to Config and used by the Makefile to conditionally make use of it. Signed-off-by: Tobias Klauser --- Makefile | 2 +- configure | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ee03d86..9ad9db5 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ TOOLS ?= netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn PREFIX ?= # Disable if you don't want it -CCACHE ?= ccache +CCACHE ?= $(CONFIG_CCACHE) # Location of installation paths. SBINDIR = $(PREFIX)/usr/sbin diff --git a/configure b/configure index ed1eacd..fd8211e 100755 --- a/configure +++ b/configure @@ -1,6 +1,7 @@ #!/bin/bash # This isn't a configure generated by autoconf! +MISSING_PKG_CONFIG=0 MISSING_DEFS=0 MISSING_NACL=0 @@ -9,6 +10,31 @@ MISSING_NACL=0 TMPDIR=$(mktemp -d config.XXXXXX) trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM +check_pkg_config() +{ + echo -n "[*] Checking pkg-config ... " + + if [ "x$(which pkg-config)" == "x" ] ; then + echo "[NO]" + MISSING_PKG_CONFIG=1 + else + echo "[YES]" + fi +} + +check_ccache() +{ + echo -n "[*] Checking ccache ... " + + if [ "x$(which ccache)" == "x" ] ; then + echo "[NO]" + echo "CONFIG_CCACHE=" >> Config + else + echo "[YES]" + echo "CONFIG_CCACHE=ccache" >> Config + fi +} + check_nacl() { echo -n "[*] Checking nacl ... " @@ -172,6 +198,14 @@ EOF } echo "# This file is autogenerated by the configure script" > Config +check_pkg_config + +if [ "$MISSING_PKG_CONFIG" == "1" ] ; then + echo "[!] pkg-config is not installed on your system or not in the PATH" + exit 1 +fi + +check_ccache check_nacl check_libnl check_tpacket -- cgit v1.2.3-54-g00ecf From f2da15da75130a11676d3083b2d70458b6ab38c2 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 28 Jun 2013 14:40:28 +0200 Subject: configure: Improve check for libnl/libnl-genl Actually call some functions in the check program so they will need to get linked. Signed-off-by: Tobias Klauser --- configure | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/configure b/configure index fd8211e..a5e8e21 100755 --- a/configure +++ b/configure @@ -89,10 +89,24 @@ check_libnl() # error incompatible libnl version #endif -void main(void) { } +void main(void) +{ + struct nl_sock *sock = nl_socket_alloc(); + struct nl_cache *nl_cache; + int ret = genl_connect(sock); + + ret = genl_ctrl_alloc_cache(sock, &nl_cache); +} EOF - $CC $(pkg-config --cflags libnl-3.0) -o $TMPDIR/libnltest $TMPDIR/libnltest.c >> $TMPDIR/config.log 2>&1 + $CC -W -Wall \ + $(pkg-config --cflags libnl-3.0) \ + $(pkg-config --cflags libnl-genl-3.0) \ + -o $TMPDIR/libnltest \ + $TMPDIR/libnltest.c \ + $(pkg-config --libs libnl-3.0) \ + $(pkg-config --libs libnl-genl-3.0) \ + >> $TMPDIR/config.log 2>&1 if [ ! -x $TMPDIR/libnltest ] ; then echo "[NO]" MISSING_DEFS=1 -- cgit v1.2.3-54-g00ecf