flowtop: Simplify flows refresh delay
[netsniff-ng-new.git] / configure
blob105b1ecc3643e228a10d95729f3a53609bb18db6
1 #!/bin/bash
2 # This isn't a configure generated by autoconf!
3 # netsniff-ng build system
4 # Copyright 2013-2015 Tobias Klauser <tklauser@distanz.ch>
5 # Copyright 2013 Daniel Borkmann <borkmann@gnumaniacs.org>
6 # Subject to the GNU GPL, version 2.
8 MISSING_TOOLCHAIN=0
9 MISSING_DEFS=0
10 MISSING_NACL=0
12 TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn"
13 TOOLS_NOBUILD=""
15 HAVE_LIBPCAP=0
16 HAVE_HWTSTAMP=0
17 HAVE_LIBGEOIP=0
18 HAVE_LIBZ=0
19 HAVE_TPACKET3=0
21 # use "CROSS_COMPILE=<prefix> SYSROOT=<path> ./configure && make" for cross compilation
23 [ -z "$CC" ] && CC="${CROSS_COMPILE}gcc"
24 [ -z "$LD" ] && LD="${CROSS_COMPILE}gcc"
25 if [ "x$SYSROOT" != "x" ] ; then
26 PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
28 [ -z $PKG_CONFIG ] && PKG_CONFIG="${CROSS_COMPILE}pkg-config"
30 TMPDIR=$(mktemp -d config.XXXXXX)
31 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
33 tools_remove()
35 local _tools=$TOOLS
36 local _todel=$1
37 TOOLS=""
38 for tool in $_tools ; do
39 case "$tool" in
40 $_todel)
41 case $_todel in
42 $TOOLS_NOBUILD) ;;
43 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
44 esac ;;
45 *) TOOLS="$TOOLS $tool" ;;
46 esac
47 done
49 TOOLS=${TOOLS# }
50 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
53 check_toolchain()
55 if [ "x$CROSS_COMPILE" != "x" ] ; then
56 echo "[*] Cross-compiling for $($CC -print-multiarch)"
57 echo "CROSS_COMPILE=$CROSS_COMPILE" >> Config
60 echo -n "[*] Checking compiler $CC ... "
61 if [ "x$(which $CC 2>> config.log)" == "x" ] ; then
62 echo "[NO]"
63 MISSING_TOOLCHAIN=1
64 else
65 echo "[YES]"
66 echo "CC=$CC" >> Config
69 echo -n "[*] Checking linker $LD ... "
70 if [ "x$(which $LD 2>> config.log)" == "x" ] ; then
71 echo "[NO]"
72 MISSING_TOOLCHAIN=1
73 else
74 echo "[YES]"
75 echo "LD=$LD" >> Config
78 echo -n "[*] Checking $PKG_CONFIG ... "
79 if [ "x$(which $PKG_CONFIG 2>> config.log)" == "x" ] ; then
80 echo "[NO]"
81 MISSING_TOOLCHAIN=1
82 else
83 echo "[YES]"
84 echo "PKG_CONFIG=$PKG_CONFIG" >> Config
85 echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> Config
89 check_flex()
91 echo -n "[*] Checking flex ... "
93 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
94 echo "[NO]"
95 MISSING_DEFS=1
96 tools_remove "trafgen"
97 tools_remove "bpfc"
98 else
99 echo "[YES]"
103 check_bison()
105 echo -n "[*] Checking bison ... "
107 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
108 echo "[NO]"
109 MISSING_DEFS=1
110 tools_remove "trafgen"
111 tools_remove "bpfc"
112 else
113 echo "[YES]"
117 check_nacl()
119 echo -n "[*] Checking nacl ... "
121 cat > $TMPDIR/nacltest.c << EOF
122 #include "crypto_hash_sha512.h"
123 #include "crypto_verify_32.h"
124 #include "crypto_hash_sha512.h"
125 #include "crypto_box_curve25519xsalsa20poly1305.h"
126 #include "crypto_scalarmult_curve25519.h"
127 #include "crypto_auth_hmacsha512256.h"
129 int main(void) { }
132 if [ -z $NACL_INC_DIR ] ; then
133 NACL_INC_DIR="$SYSROOT/usr/include/nacl"
136 if [ -z $NACL_LIB_DIR ] ; then
137 NACL_LIB_DIR="$SYSROOT/usr/lib"
140 if [ -z $NACL_LIB ] ; then
141 NACL_LIB="nacl"
144 LDFLAGS="-L $NACL_LIB_DIR"
145 CFLAGS="-I $NACL_INC_DIR"
147 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
148 if [ ! -x $TMPDIR/nacltest ] ; then
149 echo "[NO]"
150 MISSING_NACL=1
151 tools_remove "curvetun"
152 else
153 echo "[YES]"
154 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
155 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
156 echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
160 check_libnl()
162 echo -n "[*] Checking libnl ... "
164 cat > $TMPDIR/libnltest.c << EOF
165 #include <netlink/genl/genl.h>
166 #include <netlink/genl/family.h>
167 #include <netlink/genl/ctrl.h>
168 #include <netlink/msg.h>
169 #include <netlink/attr.h>
170 #include <netlink/version.h>
172 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
173 # error incompatible libnl version
174 #endif
176 int main(void)
178 struct nl_sock *sock = nl_socket_alloc();
179 struct nl_cache *nl_cache;
180 int ret = genl_connect(sock);
182 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
186 $CC \
187 $($PKG_CONFIG --cflags libnl-3.0 2>> config.log) \
188 $($PKG_CONFIG --cflags libnl-genl-3.0 2>> config.log) \
189 -o $TMPDIR/libnltest \
190 $TMPDIR/libnltest.c \
191 $($PKG_CONFIG --libs libnl-3.0 2>> config.log) \
192 $($PKG_CONFIG --libs libnl-genl-3.0 2>> config.log) \
193 >> config.log 2>&1
194 if [ ! -x $TMPDIR/libnltest ] ; then
195 echo "[NO]"
196 MISSING_DEFS=1
197 tools_remove "trafgen"
198 tools_remove "netsniff-ng"
199 else
200 echo "[YES]"
204 check_libnl_route()
206 echo -n "[*] Checking libnl-route ... "
208 cat > $TMPDIR/libnlroutetest.c << EOF
209 #include <netlink/route/link.h>
210 #include <netlink/route/addr.h>
212 int main(void)
214 char str[100];
216 rtnl_addr_flags2str(1, str, sizeof(str));
217 rtnl_link_flags2str(1, str, sizeof(str));
218 rtnl_link_operstate2str(1, str, sizeof(str));
220 return 0;
224 $CC \
225 $($PKG_CONFIG --cflags libnl-route-3.0 2>> config.log) \
226 -o $TMPDIR/libnlroutetest \
227 $TMPDIR/libnlroutetest.c \
228 $($PKG_CONFIG --libs libnl-route-3.0 2>> config.log) \
229 >> config.log 2>&1
230 if [ ! -x $TMPDIR/libnlroutetest ] ; then
231 echo "[NO]"
232 MISSING_DEFS=1
233 tools_remove "netsniff-ng"
234 else
235 echo "[YES]"
239 check_tpacket_v3()
241 echo -n "[*] Checking tpacket_v3 ... "
243 cat > $TMPDIR/tpacketv3test.c << EOF
244 #include <stdio.h>
245 #include <linux/if_packet.h>
247 int main(void)
249 struct tpacket3_hdr *hdr;
250 int foo[] = {
251 TP_STATUS_BLK_TMO,
254 printf("%d\n", hdr->tp_status);
258 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
259 if [ ! -x $TMPDIR/tpacketv3test ] ; then
260 echo "[NO]"
261 MISSING_DEFS=1
262 else
263 echo "[YES]"
264 HAVE_TPACKET3=1
268 check_tpacket_v2()
270 echo -n "[*] Checking tpacket_v2 ... "
272 cat > $TMPDIR/tpacketv2test.c << EOF
273 #include <stdio.h>
274 #include <linux/if_packet.h>
276 int main(void)
278 struct tpacket2_hdr *hdr;
279 int foo[] = {
280 TP_STATUS_AVAILABLE,
281 TP_STATUS_SEND_REQUEST,
282 TP_STATUS_SENDING,
283 TP_STATUS_KERNEL,
284 TP_STATUS_USER,
287 printf("%d\n", hdr->tp_status);
291 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
292 if [ ! -x $TMPDIR/tpacketv2test ] ; then
293 echo "[NO]"
294 MISSING_DEFS=1
295 tools_remove "netsniff-ng"
296 tools_remove "trafgen"
297 else
298 echo "[YES]"
303 check_ncurses()
305 echo -n "[*] Checking ncurses ... "
307 cat > $TMPDIR/ncursestest.c << EOF
308 #include <curses.h>
310 int main(void)
312 WINDOW *screen = initscr();
316 $CC \
317 $($PKG_CONFIG --cflags ncurses 2>> config.log) \
318 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
319 $($PKG_CONFIG --libs ncurses 2>> config.log \
320 || echo '-lncurses' ) \
321 >> config.log 2>&1
322 if [ ! -x $TMPDIR/ncursestest ] ; then
323 echo "[NO]"
324 MISSING_DEFS=1
325 tools_remove "flowtop"
326 tools_remove "ifpps"
327 else
328 echo "[YES]"
332 check_libgeoip()
334 echo -n "[*] Checking libGeoIP ... "
336 if [ "$DISABLE_GEOIP" == "1" ] ; then
337 echo "[DISABLED]"
338 return
341 cat > $TMPDIR/geoiptest.c << EOF
342 #include <GeoIP.h>
343 #include <GeoIPCity.h>
345 int main(void)
347 int dbs[] = {
348 GEOIP_CITY_EDITION_REV1,
349 GEOIP_CITY_EDITION_REV1_V6,
350 GEOIP_COUNTRY_EDITION,
351 GEOIP_COUNTRY_EDITION_V6,
352 GEOIP_ASNUM_EDITION,
353 GEOIP_ASNUM_EDITION_V6,
355 GeoIP *geoip = GeoIP_new(0);
359 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
360 if [ ! -x $TMPDIR/geoiptest ] ; then
361 echo "[NO]"
362 MISSING_DEFS=1
363 else
364 echo "[YES]"
365 HAVE_LIBGEOIP=1
369 check_libnf_ct()
371 echo -n "[*] Checking libnetfilter-conntrack ... "
373 cat > $TMPDIR/nfcttest.c << EOF
374 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
375 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
376 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
377 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
379 int main(void)
381 struct nf_conntrack *ct;
382 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
386 $CC \
387 $($PKG_CONFIG --cflags libnetfilter_conntrack 2>> config.log) \
388 -o $TMPDIR/nfcttest \
389 $TMPDIR/nfcttest.c \
390 $($PKG_CONFIG --libs libnetfilter_conntrack 2>> config.log) \
391 >> config.log 2>&1
392 if [ ! -x $TMPDIR/nfcttest ] ; then
393 echo "[NO]"
394 MISSING_DEFS=1
395 tools_remove "flowtop"
396 else
397 echo "[YES]"
401 check_zlib()
403 echo -n "[*] Checking libz ... "
405 if [ "$DISABLE_ZLIB" == "1" ] ; then
406 echo "[DISABLED]"
407 return
410 cat > $TMPDIR/ztest.c << EOF
411 #include "zlib.h"
413 int main(void)
415 gzFile fp = gzopen("foo.gz", "rb");
419 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
420 if [ ! -x $TMPDIR/ztest ] ; then
421 echo "[NO]"
422 echo "CONFIG_LIBZ=0" >> Config
423 MISSING_DEFS=1
424 tools_remove "astraceroute"
425 tools_remove "flowtop"
426 else
427 echo "[YES]"
428 echo "CONFIG_LIBZ=1" >> Config
429 HAVE_LIBZ=1
433 check_urcu()
435 echo -n "[*] Checking liburcu ... "
437 cat > $TMPDIR/urcutest.c << EOF
438 #include <urcu.h>
440 int main(void)
442 rcu_init();
443 synchronize_rcu();
447 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
448 if [ ! -x $TMPDIR/urcutest ] ; then
449 echo "[NO]"
450 MISSING_DEFS=1
451 tools_remove "flowtop"
452 else
453 echo "[YES]"
457 check_libpcap()
459 echo -n "[*] Checking libpcap ... "
461 cat > $TMPDIR/pcaptest.c << EOF
462 #include <pcap.h>
464 int main(void)
466 struct bpf_program bpf;
467 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
471 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
472 if [ ! -x $TMPDIR/pcaptest ] ; then
473 echo "[NO]"
474 echo "CONFIG_LIBPCAP=0" >> Config
475 MISSING_DEFS=1
476 tools_remove "mausezahn"
477 else
478 echo "[YES]"
479 echo "CONFIG_LIBPCAP=1" >> Config
480 HAVE_LIBPCAP=1
484 check_hwtstamp()
486 echo -n "[*] Checking hw timestamping ... "
488 cat > $TMPDIR/hwtstest.c << EOF
489 #include <string.h>
490 #include <arpa/inet.h>
491 #include <sys/ioctl.h>
492 #include <sys/types.h>
493 #include <sys/socket.h>
494 #include <linux/sockios.h>
495 #include <linux/net_tstamp.h>
496 #include <linux/if_packet.h>
497 #include <linux/if_ether.h>
498 #include <linux/if.h>
500 int main(void)
502 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
503 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
504 struct hwtstamp_config hwconfig;
505 struct ifreq ifr;
507 memset(&hwconfig, 0, sizeof(hwconfig));
508 hwconfig.tx_type = HWTSTAMP_TX_OFF;
509 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
511 memset(&ifr, 0, sizeof(ifr));
512 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
513 ifr.ifr_data = &hwconfig;
515 ioctl(sock, SIOCSHWTSTAMP, &ifr);
516 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
517 sizeof(timesource));
521 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
522 if [ ! -x $TMPDIR/hwtstest ] ; then
523 echo "[NO]"
524 echo "CONFIG_HWTSTAMP=0" >> Config
525 else
526 echo "[YES]"
527 echo "CONFIG_HWTSTAMP=1" >> Config
528 HAVE_HWTSTAMP=1
532 check_libcli()
534 echo -n "[*] Checking libcli ... "
536 cat > $TMPDIR/clitest.c << EOF
537 #include <sys/time.h>
538 #include <libcli.h>
540 int main(void)
542 struct cli_def *cli = cli_init();
546 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
547 if [ ! -x $TMPDIR/clitest ] ; then
548 echo "[NO]"
549 MISSING_DEFS=1
550 tools_remove "mausezahn"
551 else
552 echo "[YES]"
556 check_libnet()
558 echo -n "[*] Checking libnet ... "
560 cat > $TMPDIR/nettest.c << EOF
561 #include <libnet.h>
563 int main(void)
565 char err_buf[LIBNET_ERRBUF_SIZE];
566 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
570 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
571 if [ ! -x $TMPDIR/nettest ] ; then
572 echo "[NO]"
573 MISSING_DEFS=1
574 tools_remove "mausezahn"
575 else
576 echo "[YES]"
580 gen_version_appendix()
582 local _appendix=""
584 git rev-parse > /dev/null 2>&1
585 if [ "$?" == "0" ] ; then
586 if [ ! "`git describe --always`" == \
587 "`git describe --abbrev=0 --tags`" ] ; then
588 _appendix="+"
592 echo "CONFIG_RC=\"$_appendix\"" >> Config
595 gen_config_hdr()
597 local _version=""
598 local _have_libpcap=""
599 local _have_libgeoip=""
600 local _have_libz=""
601 local _have_hwts=""
602 local _have_tp3=""
604 echo "[*] Generating config.h ..."
606 git rev-parse > /dev/null 2>&1
607 if [ "$?" == "0" ] ; then
608 _version="`git describe --always`"
609 else
610 _version="(none)"
613 if [ "$HAVE_LIBPCAP" == "1" ] ; then
614 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
615 else
616 _have_libpcap="/* HAVE_TCPDUMP_LIKE_FILTER is not defined */"
619 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
620 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
621 else
622 _have_hwts="/* HAVE_HARDWARE_TIMESTAMPING is not defined */"
625 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
626 _have_libgeoip="#define HAVE_GEOIP 1"
627 else
628 _have_libgeoip="/* HAVE_GEOIP is not defined */"
631 if [ "$HAVE_LIBZ" == "1" ] ; then
632 _have_libz="#define HAVE_LIBZ 1"
633 else
634 _have_libz="/* HAVE_LIBZ is not defined */"
637 if [ "$HAVE_TPACKET3" == "1" ] ; then
638 _have_tp3="#define HAVE_TPACKET3 1"
639 else
640 _have_tp3="/* HAVE_TPACKET3 is not defined */"
643 cat > config.h << EOF
644 #ifndef CONFIG_H
645 #define CONFIG_H
646 #define FILE_CLIENTS ".curvetun/clients"
647 #define FILE_SERVERS ".curvetun/servers"
648 #define FILE_PRIVKEY ".curvetun/priv.key"
649 #define FILE_PUBKEY ".curvetun/pub.key"
650 #define FILE_USERNAM ".curvetun/username"
651 #define GITVERSION "$_version"
652 $_have_libpcap
653 $_have_libgeoip
654 $_have_libz
655 $_have_hwts
656 $_have_tp3
657 #endif /* CONFIG_H */
661 rm -f config.log
663 echo "# This file is autogenerated by the configure script" > Config
664 check_toolchain
666 if [ "$MISSING_TOOLCHAIN" == "1" ] ; then
667 echo "[!] One or more of the toolchain tools couldn't be found in your"
668 echo " \$PATH. Please check the file config.log for details."
669 exit 1
672 check_flex
673 check_bison
674 check_nacl
675 check_libnl
676 check_libnl_route
677 check_tpacket_v2
678 check_tpacket_v3
679 check_libnf_ct
680 check_ncurses
681 check_libgeoip
682 check_zlib
683 check_urcu
684 check_libpcap
685 check_hwtstamp
686 check_libcli
687 check_libnet
689 gen_config_hdr
690 gen_version_appendix
692 if [ "$MISSING_DEFS" == "1" ] ; then
693 echo "[!] Some libraries or header definitions are missing or too old. Thus"
694 echo " certain tools will not be built (see below). Please refer to the"
695 echo " INSTALL file for the libraries needed to build the complete"
696 echo " netsniff-ng toolkit."
699 if [ "$MISSING_NACL" == "1" ] ; then
700 echo "[!] The NaCl crypto library is currently not present on your system or"
701 echo " could not be found. Either install it from your distro or build it"
702 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
703 echo " NACL_LIB_DIR environment variables are set appropriately."
706 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
707 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
708 echo "[*] The following tools will be built: $TOOLS"
709 else
710 echo "[*] Looks good! All tools will be built!"
713 if [ -s config.log ] ; then
714 echo "[!] There were errors in the configure script. Please check the file"
715 echo " config.log for details."
718 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
719 echo "CONFIG_GEOIP=1" >> Config
720 else
721 echo "CONFIG_GEOIP=0" >> Config
724 echo "CONFIG_TOOLS=$TOOLS" >> Config
725 echo "CONFIG_OK=1" >> Config
727 exit 0