#!/bin/bash # This isn't a configure generated by autoconf! # netsniff-ng build system # Copyright 2013 Tobias Klauser # Copyright 2013 Daniel Borkmann # Subject to the GNU GPL, version 2. MISSING_PKG_CONFIG=0 MISSING_DEFS=0 MISSING_NACL=0 TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn" TOOLS_NOBUILD="" HAVE_LIBPCAP=0 HAVE_HWTSTAMP=0 HAVE_LIBGEOIP=0 HAVE_LIBZ=0 HAVE_TPACKET3=0 [ -z $CC ] && CC=cc TMPDIR=$(mktemp -d config.XXXXXX) trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM tools_remove() { local _tools=$TOOLS local _todel=$1 TOOLS="" for tool in $_tools ; do case "$tool" in $_todel) case $_todel in $TOOLS_NOBUILD) ;; *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;; esac ;; *) TOOLS="$TOOLS $tool" ;; esac done TOOLS=${TOOLS# } TOOLS_NOBUILD=${TOOLS_NOBUILD# } } check_pkg_config() { echo -n "[*] Checking pkg-config ... " if [ "x$(which pkg-config 2>> config.log)" == "x" ] ; then echo "[NO]" MISSING_PKG_CONFIG=1 else echo "[YES]" fi } check_ccache() { echo -n "[*] Checking ccache ... " if [ "x$(which ccache 2>> config.log)" == "x" ] ; then echo "[NO]" echo "CONFIG_CCACHE=" >> Config else echo "[YES]" echo "CONFIG_CCACHE=ccache" >> Config fi } check_flex() { echo -n "[*] Checking flex ... " if [ "x$(which flex 2>> config.log)" == "x" ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "trafgen" tools_remove "bpfc" else echo "[YES]" fi } check_bison() { echo -n "[*] Checking bison ... " if [ "x$(which bison 2>> config.log)" == "x" ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "trafgen" tools_remove "bpfc" else echo "[YES]" fi } 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 if [ -z $NACL_LIB ] ; then NACL_LIB="nacl" fi LDFLAGS="-L $NACL_LIB_DIR" CFLAGS="-I $NACL_INC_DIR" $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1 if [ ! -x $TMPDIR/nacltest ] ; then echo "[NO]" MISSING_NACL=1 tools_remove "curvetun" else echo "[YES]" echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config echo "CONFIG_NACL_LIB:=$NACL_LIB" >> 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 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 2>> config.log) \ $(pkg-config --cflags libnl-genl-3.0 2>> config.log) \ -o $TMPDIR/libnltest \ $TMPDIR/libnltest.c \ $(pkg-config --libs libnl-3.0 2>> config.log) \ $(pkg-config --libs libnl-genl-3.0 2>> config.log) \ >> config.log 2>&1 if [ ! -x $TMPDIR/libnltest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "trafgen" tools_remove "netsniff-ng" else echo "[YES]" fi } check_tpacket_v3() { echo -n "[*] Checking tpacket_v3 ... " cat > $TMPDIR/tpacketv3test.c << EOF #include #include void main(void) { struct tpacket3_hdr *hdr; int foo[] = { TP_STATUS_BLK_TMO, }; printf("%d\n", hdr->tp_status); } EOF $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1 if [ ! -x $TMPDIR/tpacketv3test ] ; then echo "[NO]" MISSING_DEFS=1 else echo "[YES]" HAVE_TPACKET3=1 fi } check_tpacket_v2() { echo -n "[*] Checking tpacket_v2 ... " cat > $TMPDIR/tpacketv2test.c << EOF #include #include void main(void) { struct tpacket2_hdr *hdr; int foo[] = { TP_STATUS_AVAILABLE, TP_STATUS_SEND_REQUEST, TP_STATUS_SENDING, TP_STATUS_KERNEL, TP_STATUS_USER, }; printf("%d\n", hdr->tp_status); } EOF $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1 if [ ! -x $TMPDIR/tpacketv2test ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "netsniff-ng" tools_remove "trafgen" 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 ncurses 2>> config.log) \ -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \ $(pkg-config --libs ncurses 2>> config.log \ || echo '-lncurses' ) \ >> config.log 2>&1 if [ ! -x $TMPDIR/ncursestest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "flowtop" tools_remove "ifpps" else echo "[YES]" fi } check_libgeoip() { echo -n "[*] Checking libGeoIP ... " cat > $TMPDIR/geoiptest.c << EOF #include #include void main(void) { int dbs[] = { GEOIP_CITY_EDITION_REV1, GEOIP_CITY_EDITION_REV1_V6, GEOIP_COUNTRY_EDITION, GEOIP_COUNTRY_EDITION_V6, GEOIP_ASNUM_EDITION, GEOIP_ASNUM_EDITION_V6, }; GeoIP *geoip = GeoIP_new(0); } EOF $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1 if [ ! -x $TMPDIR/geoiptest ] ; then echo "[NO]" MISSING_DEFS=1 else echo "[YES]" HAVE_LIBGEOIP=1 fi } check_libnf_ct() { echo -n "[*] Checking libnetfilter-conntrack ... " cat > $TMPDIR/nfcttest.c << EOF #include #include #include #include void main(void) { struct nf_conntrack *ct; const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID); } EOF $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1 if [ ! -x $TMPDIR/nfcttest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "flowtop" else echo "[YES]" fi } check_zlib() { echo -n "[*] Checking libz ... " cat > $TMPDIR/ztest.c << EOF #include "zlib.h" void main(void) { gzFile fp = gzopen("foo.gz", "rb"); } EOF $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1 if [ ! -x $TMPDIR/ztest ] ; then echo "[NO]" echo "CONFIG_LIBZ=0" >> Config MISSING_DEFS=1 tools_remove "astraceroute" tools_remove "flowtop" else echo "[YES]" echo "CONFIG_LIBZ=1" >> Config HAVE_LIBZ=1 fi } check_urcu() { echo -n "[*] Checking liburcu ... " cat > $TMPDIR/urcutest.c << EOF #include void main(void) { rcu_init(); synchronize_rcu(); } EOF $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1 if [ ! -x $TMPDIR/urcutest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "flowtop" else echo "[YES]" fi } check_libpcap() { echo -n "[*] Checking libpcap ... " cat > $TMPDIR/pcaptest.c << EOF #include void main(void) { struct bpf_program bpf; int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff); } EOF $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1 if [ ! -x $TMPDIR/pcaptest ] ; then echo "[NO]" echo "CONFIG_LIBPCAP=0" >> Config MISSING_DEFS=1 tools_remove "mausezahn" else echo "[YES]" echo "CONFIG_LIBPCAP=1" >> Config HAVE_LIBPCAP=1 fi } check_hwtstamp() { echo -n "[*] Checking hw timestamping ... " cat > $TMPDIR/hwtstest.c << EOF #include #include #include #include #include #include #include #include #include #include void main(void) { int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret; int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); struct hwtstamp_config hwconfig; struct ifreq ifr; memset(&hwconfig, 0, sizeof(hwconfig)); hwconfig.tx_type = HWTSTAMP_TX_OFF; hwconfig.rx_filter = HWTSTAMP_FILTER_ALL; memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name)); ifr.ifr_data = &hwconfig; ioctl(sock, SIOCSHWTSTAMP, &ifr); setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, ×ource, sizeof(timesource)); } EOF $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1 if [ ! -x $TMPDIR/hwtstest ] ; then echo "[NO]" echo "CONFIG_HWTSTAMP=0" >> Config else echo "[YES]" echo "CONFIG_HWTSTAMP=1" >> Config HAVE_HWTSTAMP=1 fi } check_libcli() { echo -n "[*] Checking libcli ... " cat > $TMPDIR/clitest.c << EOF #include #include void main(void) { struct cli_def *cli = cli_init(); } EOF $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1 if [ ! -x $TMPDIR/clitest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "mausezahn" else echo "[YES]" fi } check_libnet() { echo -n "[*] Checking libnet ... " cat > $TMPDIR/nettest.c << EOF #include void main(void) { char err_buf[LIBNET_ERRBUF_SIZE]; libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf); } EOF $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1 if [ ! -x $TMPDIR/nettest ] ; then echo "[NO]" MISSING_DEFS=1 tools_remove "mausezahn" else echo "[YES]" fi } gen_version_appendix() { local _appendix="" git rev-parse > /dev/null 2>&1 if [ "$?" == "0" ] ; then if [ ! "`git describe --always`" == \ "`git describe --abbrev=0 --tags`" ] ; then _appendix="+" fi fi echo "CONFIG_RC=\"$_appendix\"" >> Config } gen_config_hdr() { local _version="" local _have_libpcap="" local _have_libgeoip="" local _have_libz="" local _have_hwts="" local _have_tp3="" echo "[*] Generating config.h ..." git rev-parse > /dev/null 2>&1 if [ "$?" == "0" ] ; then _version="`git describe --always`" else _version="(none)" fi if [ "$HAVE_LIBPCAP" == "1" ] ; then _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1" fi if [ "$HAVE_HWTSTAMP" == "1" ] ; then _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1" fi if [ "$HAVE_LIBGEOIP" == "1" ] ; then _have_libgeoip="#define HAVE_GEOIP 1" fi if [ "$HAVE_LIBZ" == "1" ] ; then _have_libz="#define HAVE_LIBZ 1" fi if [ "$HAVE_TPACKET3" == "1" ] ; then _have_tp3="#define HAVE_TPACKET3 1" fi cat > config.h << EOF #ifndef CONFIG_H #define CONFIG_H #define FILE_CLIENTS ".curvetun/clients" #define FILE_SERVERS ".curvetun/servers" #define FILE_PRIVKEY ".curvetun/priv.key" #define FILE_PUBKEY ".curvetun/pub.key" #define FILE_USERNAM ".curvetun/username" #define GITVERSION "$_version" $_have_libpcap $_have_libgeoip $_have_libz $_have_hwts $_have_tp3 #endif /* CONFIG_H */ EOF } rm -f config.log 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_flex check_bison check_nacl check_libnl check_tpacket_v2 check_tpacket_v3 check_libnf_ct check_ncurses check_libgeoip check_zlib check_urcu check_libpcap check_hwtstamp check_libcli check_libnet gen_config_hdr gen_version_appendix if [ "$MISSING_DEFS" == "1" ] ; then echo "[!] Some libraries or header definitions are missing or too old. Thus" echo " certain tools will not be built (see below). Please refer to the" echo " INSTALL file for the libraries needed to build the complete" echo " netsniff-ng toolkit." fi if [ "$MISSING_NACL" == "1" ] ; then echo "[!] The NaCl crypto library is currently not present on your system or" echo " could not be found. Either install it from your distro or build it" echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and" echo " NACL_LIB_DIR environment variables are set appropriately." fi if [ "x$TOOLS_NOBUILD" != "x" ] ; then echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD" echo "[*] The following tools will be built: $TOOLS" else echo "[*] Looks good! All tools will be built!" fi if [ -s config.log ] ; then echo "[!] There were errors in the configure script. Please check the file" echo " config.log for details." fi if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then echo "CONFIG_GEOIP=1" >> Config else echo "CONFIG_GEOIP=0" >> Config fi echo "CONFIG_TOOLS=$TOOLS" >> Config echo "CONFIG_OK=1" >> Config exit 0