netsniff-ng: alias lb to rr as well
[netsniff-ng.git] / configure
blobb02eb187048f078847f82c07c652303e21c48e96
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 [ -z $STRIP ] && STRIP="${CROSS_COMPILE}strip"
26 if [ "x$SYSROOT" != "x" ] ; then
27 PKG_CONFIG_PATH="$SYSROOT/usr/lib/pkgconfig:$PKG_CONFIG_PATH"
29 [ -z $PKG_CONFIG ] && PKG_CONFIG="${CROSS_COMPILE}pkg-config"
31 TMPDIR=$(mktemp -d config.XXXXXX)
32 trap 'status=$?; rm -rf $TMPDIR; exit $status' EXIT HUP INT QUIT TERM
34 tools_remove()
36 local _tools=$TOOLS
37 local _todel=$1
38 TOOLS=""
39 for tool in $_tools ; do
40 case "$tool" in
41 $_todel)
42 case $_todel in
43 $TOOLS_NOBUILD) ;;
44 *) TOOLS_NOBUILD="$TOOLS_NOBUILD $tool" ;;
45 esac ;;
46 *) TOOLS="$TOOLS $tool" ;;
47 esac
48 done
50 TOOLS=${TOOLS# }
51 TOOLS_NOBUILD=${TOOLS_NOBUILD# }
54 check_toolchain()
56 if [ "x$CROSS_COMPILE" != "x" ] ; then
57 echo "[*] Cross-compiling for $($CC -print-multiarch)"
58 echo "CROSS_COMPILE=$CROSS_COMPILE" >> Config
61 echo -n "[*] Checking compiler $CC ... "
62 if [ "x$(which $CC 2>> config.log)" == "x" ] ; then
63 echo "[NO]"
64 MISSING_TOOLCHAIN=1
65 else
66 echo "[YES]"
67 echo "CC=$CC" >> Config
70 echo -n "[*] Checking linker $LD ... "
71 if [ "x$(which $LD 2>> config.log)" == "x" ] ; then
72 echo "[NO]"
73 MISSING_TOOLCHAIN=1
74 else
75 echo "[YES]"
76 echo "LD=$LD" >> Config
79 echo -n "[*] Checking $PKG_CONFIG ... "
80 if [ "x$(which $PKG_CONFIG 2>> config.log)" == "x" ] ; then
81 echo "[NO]"
82 MISSING_TOOLCHAIN=1
83 else
84 echo "[YES]"
85 echo "PKG_CONFIG=$PKG_CONFIG" >> Config
86 echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> Config
89 echo -n "[*] Checking $STRIP ... "
90 if [ "x$(which $STRIP 2>> config.log)" == "x" ] ; then
91 echo "[NO]"
92 MISSING_TOOLCHAIN=1
93 else
94 echo "[YES]"
95 echo "STRIP=$STRIP" >> Config
100 check_flex()
102 echo -n "[*] Checking flex ... "
104 if [ "x$(which flex 2>> config.log)" == "x" ] ; then
105 echo "[NO]"
106 MISSING_DEFS=1
107 tools_remove "trafgen"
108 tools_remove "bpfc"
109 else
110 echo "[YES]"
114 check_bison()
116 echo -n "[*] Checking bison ... "
118 if [ "x$(which bison 2>> config.log)" == "x" ] ; then
119 echo "[NO]"
120 MISSING_DEFS=1
121 tools_remove "trafgen"
122 tools_remove "bpfc"
123 else
124 echo "[YES]"
128 check_nacl()
130 echo -n "[*] Checking nacl ... "
132 cat > $TMPDIR/nacltest.c << EOF
133 #include "crypto_hash_sha512.h"
134 #include "crypto_verify_32.h"
135 #include "crypto_hash_sha512.h"
136 #include "crypto_box_curve25519xsalsa20poly1305.h"
137 #include "crypto_scalarmult_curve25519.h"
138 #include "crypto_auth_hmacsha512256.h"
140 int main(void) { }
143 if [ -z $NACL_INC_DIR ] ; then
144 NACL_INC_DIR="/usr/include/nacl"
147 if [ -z $NACL_LIB_DIR ] ; then
148 NACL_LIB_DIR="/usr/lib"
151 if [ -z $NACL_LIB ] ; then
152 NACL_LIB="nacl"
155 LDFLAGS="-L $NACL_LIB_DIR"
156 CFLAGS="-I $NACL_INC_DIR"
158 $CC $CFLAGS $LDFLAGS -o $TMPDIR/nacltest $TMPDIR/nacltest.c >> config.log 2>&1
159 if [ ! -x $TMPDIR/nacltest ] ; then
160 echo "[NO]"
161 MISSING_NACL=1
162 tools_remove "curvetun"
163 else
164 echo "[YES]"
165 echo "CONFIG_NACL_INC_DIR:=$NACL_INC_DIR" >> Config
166 echo "CONFIG_NACL_LIB_DIR:=$NACL_LIB_DIR" >> Config
167 echo "CONFIG_NACL_LIB:=$NACL_LIB" >> Config
171 check_libnl()
173 echo -n "[*] Checking libnl ... "
175 cat > $TMPDIR/libnltest.c << EOF
176 #include <netlink/genl/genl.h>
177 #include <netlink/genl/family.h>
178 #include <netlink/genl/ctrl.h>
179 #include <netlink/msg.h>
180 #include <netlink/attr.h>
181 #include <netlink/version.h>
183 #if LIBNL_VER_NUM < LIBNL_VER(3,0)
184 # error incompatible libnl version
185 #endif
187 int main(void)
189 struct nl_sock *sock = nl_socket_alloc();
190 struct nl_cache *nl_cache;
191 int ret = genl_connect(sock);
193 ret = genl_ctrl_alloc_cache(sock, &nl_cache);
197 $CC \
198 $($PKG_CONFIG --cflags libnl-3.0 2>> config.log) \
199 $($PKG_CONFIG --cflags libnl-genl-3.0 2>> config.log) \
200 -o $TMPDIR/libnltest \
201 $TMPDIR/libnltest.c \
202 $($PKG_CONFIG --libs libnl-3.0 2>> config.log) \
203 $($PKG_CONFIG --libs libnl-genl-3.0 2>> config.log) \
204 >> config.log 2>&1
205 if [ ! -x $TMPDIR/libnltest ] ; then
206 echo "[NO]"
207 MISSING_DEFS=1
208 tools_remove "trafgen"
209 tools_remove "netsniff-ng"
210 else
211 echo "[YES]"
215 check_tpacket_v3()
217 echo -n "[*] Checking tpacket_v3 ... "
219 cat > $TMPDIR/tpacketv3test.c << EOF
220 #include <stdio.h>
221 #include <linux/if_packet.h>
223 int main(void)
225 struct tpacket3_hdr *hdr;
226 int foo[] = {
227 TP_STATUS_BLK_TMO,
230 printf("%d\n", hdr->tp_status);
234 $CC -o $TMPDIR/tpacketv3test $TMPDIR/tpacketv3test.c >> config.log 2>&1
235 if [ ! -x $TMPDIR/tpacketv3test ] ; then
236 echo "[NO]"
237 MISSING_DEFS=1
238 else
239 echo "[YES]"
240 HAVE_TPACKET3=1
244 check_tpacket_v2()
246 echo -n "[*] Checking tpacket_v2 ... "
248 cat > $TMPDIR/tpacketv2test.c << EOF
249 #include <stdio.h>
250 #include <linux/if_packet.h>
252 int main(void)
254 struct tpacket2_hdr *hdr;
255 int foo[] = {
256 TP_STATUS_AVAILABLE,
257 TP_STATUS_SEND_REQUEST,
258 TP_STATUS_SENDING,
259 TP_STATUS_KERNEL,
260 TP_STATUS_USER,
263 printf("%d\n", hdr->tp_status);
267 $CC -o $TMPDIR/tpacketv2test $TMPDIR/tpacketv2test.c >> config.log 2>&1
268 if [ ! -x $TMPDIR/tpacketv2test ] ; then
269 echo "[NO]"
270 MISSING_DEFS=1
271 tools_remove "netsniff-ng"
272 tools_remove "trafgen"
273 else
274 echo "[YES]"
279 check_ncurses()
281 echo -n "[*] Checking ncurses ... "
283 cat > $TMPDIR/ncursestest.c << EOF
284 #include <curses.h>
286 int main(void)
288 WINDOW *screen = initscr();
292 $CC \
293 $($PKG_CONFIG --cflags ncurses 2>> config.log) \
294 -o $TMPDIR/ncursestest $TMPDIR/ncursestest.c \
295 $($PKG_CONFIG --libs ncurses 2>> config.log \
296 || echo '-lncurses' ) \
297 >> config.log 2>&1
298 if [ ! -x $TMPDIR/ncursestest ] ; then
299 echo "[NO]"
300 MISSING_DEFS=1
301 tools_remove "flowtop"
302 tools_remove "ifpps"
303 else
304 echo "[YES]"
308 check_libgeoip()
310 echo -n "[*] Checking libGeoIP ... "
312 cat > $TMPDIR/geoiptest.c << EOF
313 #include <GeoIP.h>
314 #include <GeoIPCity.h>
316 int main(void)
318 int dbs[] = {
319 GEOIP_CITY_EDITION_REV1,
320 GEOIP_CITY_EDITION_REV1_V6,
321 GEOIP_COUNTRY_EDITION,
322 GEOIP_COUNTRY_EDITION_V6,
323 GEOIP_ASNUM_EDITION,
324 GEOIP_ASNUM_EDITION_V6,
326 GeoIP *geoip = GeoIP_new(0);
330 $CC -o $TMPDIR/geoiptest $TMPDIR/geoiptest.c -lGeoIP >> config.log 2>&1
331 if [ ! -x $TMPDIR/geoiptest ] ; then
332 echo "[NO]"
333 MISSING_DEFS=1
334 else
335 echo "[YES]"
336 HAVE_LIBGEOIP=1
340 check_libnf_ct()
342 echo -n "[*] Checking libnetfilter-conntrack ... "
344 cat > $TMPDIR/nfcttest.c << EOF
345 #include <libnetfilter_conntrack/libnetfilter_conntrack.h>
346 #include <libnetfilter_conntrack/libnetfilter_conntrack_tcp.h>
347 #include <libnetfilter_conntrack/libnetfilter_conntrack_dccp.h>
348 #include <libnetfilter_conntrack/libnetfilter_conntrack_sctp.h>
350 int main(void)
352 struct nf_conntrack *ct;
353 const uint32_t id = nfct_get_attr_u32(ct, ATTR_ID);
357 $CC -o $TMPDIR/nfcttest $TMPDIR/nfcttest.c -lnetfilter_conntrack >> config.log 2>&1
358 if [ ! -x $TMPDIR/nfcttest ] ; then
359 echo "[NO]"
360 MISSING_DEFS=1
361 tools_remove "flowtop"
362 else
363 echo "[YES]"
367 check_zlib()
369 echo -n "[*] Checking libz ... "
371 cat > $TMPDIR/ztest.c << EOF
372 #include "zlib.h"
374 int main(void)
376 gzFile fp = gzopen("foo.gz", "rb");
380 $CC -o $TMPDIR/ztest $TMPDIR/ztest.c -lz >> config.log 2>&1
381 if [ ! -x $TMPDIR/ztest ] ; then
382 echo "[NO]"
383 echo "CONFIG_LIBZ=0" >> Config
384 MISSING_DEFS=1
385 tools_remove "astraceroute"
386 tools_remove "flowtop"
387 else
388 echo "[YES]"
389 echo "CONFIG_LIBZ=1" >> Config
390 HAVE_LIBZ=1
394 check_urcu()
396 echo -n "[*] Checking liburcu ... "
398 cat > $TMPDIR/urcutest.c << EOF
399 #include <urcu.h>
401 int main(void)
403 rcu_init();
404 synchronize_rcu();
408 $CC -o $TMPDIR/urcutest $TMPDIR/urcutest.c -lurcu >> config.log 2>&1
409 if [ ! -x $TMPDIR/urcutest ] ; then
410 echo "[NO]"
411 MISSING_DEFS=1
412 tools_remove "flowtop"
413 else
414 echo "[YES]"
418 check_libpcap()
420 echo -n "[*] Checking libpcap ... "
422 cat > $TMPDIR/pcaptest.c << EOF
423 #include <pcap.h>
425 int main(void)
427 struct bpf_program bpf;
428 int ret = pcap_compile_nopcap(65535, 1, &bpf, "foo.bpf", 1, 0xffffffff);
432 $CC -o $TMPDIR/pcaptest $TMPDIR/pcaptest.c -lpcap >> config.log 2>&1
433 if [ ! -x $TMPDIR/pcaptest ] ; then
434 echo "[NO]"
435 echo "CONFIG_LIBPCAP=0" >> Config
436 MISSING_DEFS=1
437 tools_remove "mausezahn"
438 else
439 echo "[YES]"
440 echo "CONFIG_LIBPCAP=1" >> Config
441 HAVE_LIBPCAP=1
445 check_hwtstamp()
447 echo -n "[*] Checking hw timestamping ... "
449 cat > $TMPDIR/hwtstest.c << EOF
450 #include <string.h>
451 #include <arpa/inet.h>
452 #include <sys/ioctl.h>
453 #include <sys/types.h>
454 #include <sys/socket.h>
455 #include <linux/sockios.h>
456 #include <linux/net_tstamp.h>
457 #include <linux/if_packet.h>
458 #include <linux/if_ether.h>
459 #include <linux/if.h>
461 int main(void)
463 int timesource = SOF_TIMESTAMPING_RAW_HARDWARE, ret;
464 int sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
465 struct hwtstamp_config hwconfig;
466 struct ifreq ifr;
468 memset(&hwconfig, 0, sizeof(hwconfig));
469 hwconfig.tx_type = HWTSTAMP_TX_OFF;
470 hwconfig.rx_filter = HWTSTAMP_FILTER_ALL;
472 memset(&ifr, 0, sizeof(ifr));
473 strncpy(ifr.ifr_name, "lo", sizeof(ifr.ifr_name));
474 ifr.ifr_data = &hwconfig;
476 ioctl(sock, SIOCSHWTSTAMP, &ifr);
477 setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
478 sizeof(timesource));
482 $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> config.log 2>&1
483 if [ ! -x $TMPDIR/hwtstest ] ; then
484 echo "[NO]"
485 echo "CONFIG_HWTSTAMP=0" >> Config
486 else
487 echo "[YES]"
488 echo "CONFIG_HWTSTAMP=1" >> Config
489 HAVE_HWTSTAMP=1
493 check_libcli()
495 echo -n "[*] Checking libcli ... "
497 cat > $TMPDIR/clitest.c << EOF
498 #include <sys/time.h>
499 #include <libcli.h>
501 int main(void)
503 struct cli_def *cli = cli_init();
507 $CC -o $TMPDIR/clitest $TMPDIR/clitest.c -lcli >> config.log 2>&1
508 if [ ! -x $TMPDIR/clitest ] ; then
509 echo "[NO]"
510 MISSING_DEFS=1
511 tools_remove "mausezahn"
512 else
513 echo "[YES]"
517 check_libnet()
519 echo -n "[*] Checking libnet ... "
521 cat > $TMPDIR/nettest.c << EOF
522 #include <libnet.h>
524 int main(void)
526 char err_buf[LIBNET_ERRBUF_SIZE];
527 libnet_t *l = libnet_init(LIBNET_LINK_ADV, "ethX", err_buf);
531 $CC -o $TMPDIR/nettest $TMPDIR/nettest.c -lnet >> config.log 2>&1
532 if [ ! -x $TMPDIR/nettest ] ; then
533 echo "[NO]"
534 MISSING_DEFS=1
535 tools_remove "mausezahn"
536 else
537 echo "[YES]"
541 gen_version_appendix()
543 local _appendix=""
545 git rev-parse > /dev/null 2>&1
546 if [ "$?" == "0" ] ; then
547 if [ ! "`git describe --always`" == \
548 "`git describe --abbrev=0 --tags`" ] ; then
549 _appendix="+"
553 echo "CONFIG_RC=\"$_appendix\"" >> Config
556 gen_config_hdr()
558 local _version=""
559 local _have_libpcap=""
560 local _have_libgeoip=""
561 local _have_libz=""
562 local _have_hwts=""
563 local _have_tp3=""
565 echo "[*] Generating config.h ..."
567 git rev-parse > /dev/null 2>&1
568 if [ "$?" == "0" ] ; then
569 _version="`git describe --always`"
570 else
571 _version="(none)"
574 if [ "$HAVE_LIBPCAP" == "1" ] ; then
575 _have_libpcap="#define HAVE_TCPDUMP_LIKE_FILTER 1"
578 if [ "$HAVE_HWTSTAMP" == "1" ] ; then
579 _have_hwts="#define HAVE_HARDWARE_TIMESTAMPING 1"
582 if [ "$HAVE_LIBGEOIP" == "1" ] ; then
583 _have_libgeoip="#define HAVE_GEOIP 1"
586 if [ "$HAVE_LIBZ" == "1" ] ; then
587 _have_libz="#define HAVE_LIBZ 1"
590 if [ "$HAVE_TPACKET3" == "1" ] ; then
591 _have_tp3="#define HAVE_TPACKET3 1"
594 cat > config.h << EOF
595 #ifndef CONFIG_H
596 #define CONFIG_H
597 #define FILE_CLIENTS ".curvetun/clients"
598 #define FILE_SERVERS ".curvetun/servers"
599 #define FILE_PRIVKEY ".curvetun/priv.key"
600 #define FILE_PUBKEY ".curvetun/pub.key"
601 #define FILE_USERNAM ".curvetun/username"
602 #define GITVERSION "$_version"
603 $_have_libpcap
604 $_have_libgeoip
605 $_have_libz
606 $_have_hwts
607 $_have_tp3
608 #endif /* CONFIG_H */
612 rm -f config.log
614 echo "# This file is autogenerated by the configure script" > Config
615 check_toolchain
617 if [ "$MISSING_TOOLCHAIN" == "1" ] ; then
618 echo "[!] One or more of the toolchain tools couldn't be found in your"
619 echo " \$PATH. Please check the file config.log for details."
620 exit 1
623 check_flex
624 check_bison
625 check_nacl
626 check_libnl
627 check_tpacket_v2
628 check_tpacket_v3
629 check_libnf_ct
630 check_ncurses
631 check_libgeoip
632 check_zlib
633 check_urcu
634 check_libpcap
635 check_hwtstamp
636 check_libcli
637 check_libnet
639 gen_config_hdr
640 gen_version_appendix
642 if [ "$MISSING_DEFS" == "1" ] ; then
643 echo "[!] Some libraries or header definitions are missing or too old. Thus"
644 echo " certain tools will not be built (see below). Please refer to the"
645 echo " INSTALL file for the libraries needed to build the complete"
646 echo " netsniff-ng toolkit."
649 if [ "$MISSING_NACL" == "1" ] ; then
650 echo "[!] The NaCl crypto library is currently not present on your system or"
651 echo " could not be found. Either install it from your distro or build it"
652 echo " manually using 'make nacl' and make sure that the NACL_INC_DIR and"
653 echo " NACL_LIB_DIR environment variables are set appropriately."
656 if [ "x$TOOLS_NOBUILD" != "x" ] ; then
657 echo "[!] The following tools will *not* be built: $TOOLS_NOBUILD"
658 echo "[*] The following tools will be built: $TOOLS"
659 else
660 echo "[*] Looks good! All tools will be built!"
663 if [ -s config.log ] ; then
664 echo "[!] There were errors in the configure script. Please check the file"
665 echo " config.log for details."
668 if [ "$HAVE_LIBGEOIP" == "1" -a "$HAVE_LIBZ" == "1" ] ; then
669 echo "CONFIG_GEOIP=1" >> Config
670 else
671 echo "CONFIG_GEOIP=0" >> Config
674 echo "CONFIG_TOOLS=$TOOLS" >> Config
675 echo "CONFIG_OK=1" >> Config
677 exit 0