summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Borkmann <dborkman@redhat.com>2013-07-09 20:16:40 +0200
committerDaniel Borkmann <dborkman@redhat.com>2013-07-09 20:20:52 +0200
commitd4e385dd0e633525666bf95c56a2045bacc2a485 (patch)
treea87c451e7f988b65d5a3e350969ca765cff02add
parentc07bdeb7419baf7f66e8de386744be9ec4891bb3 (diff)
configure: fix multiple issues in build configuration
This patch is a bundle of multiple fixes. 1) Fix compilation of astraceroute when HAVE_LIBPCAP=1: astraceroute doesn't need libpcap, so add an additional guard/define to bpf.h and bpf_comp.c and netsniff-ng.c. Also since we generate a config.h file, we do not need to have this additional compile flag anymore. 2) Fix tstamping.{h,c} to use the configure script instead of the Makefile. For doing this, also fix the object inclusion in netsniff-ng/Makefile. Last but not least, rename __WITH_... into HAVE_... as this is more clean. Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
-rw-r--r--Makefile11
-rw-r--r--bpf.h3
-rw-r--r--bpf_comp.c3
-rwxr-xr-xconfigure67
-rw-r--r--netsniff-ng.c2
-rw-r--r--netsniff-ng/Makefile4
-rw-r--r--tstamping.c8
-rw-r--r--tstamping.h9
8 files changed, 86 insertions, 21 deletions
diff --git a/Makefile b/Makefile
index cb18177..46f8ec8 100644
--- a/Makefile
+++ b/Makefile
@@ -81,12 +81,6 @@ CFLAGS_DEF += -D_LARGEFILE_SOURCE
CFLAGS_DEF += -D_LARGEFILE64_SOURCE
CFLAGS_DEF += -D_FILE_OFFSET_BITS=64
-ifeq ($(CONFIG_LIBPCAP), 1)
- CFLAGS_PCAP = -D__WITH_TCPDUMP_LIKE_FILTER
-else
- CFLAGS_PCAP =
-endif
-
WFLAGS_DEF = -Wall
WFLAGS_DEF += -Wformat=2
WFLAGS_DEF += -Wmissing-prototypes
@@ -124,9 +118,6 @@ ALL_CFLAGS = $(CFLAGS) $(CPPFLAGS) -I.
ALL_CFLAGS += -DVERSION_STRING=\"$(VERSION_STRING)\"
ALL_CFLAGS += -DVERSION_LONG=\"$(VERSION_LONG)\"
ALL_CFLAGS += -DPREFIX_STRING=\"$(PREFIX)\"
-ifneq ($(wildcard /usr/include/linux/net_tstamp.h),)
- ALL_CFLAGS += -D__WITH_HARDWARE_TIMESTAMPING
-endif
VERSION_STRING = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
VERSION_LONG = $(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)~$(NAME)
@@ -252,7 +243,7 @@ $(foreach tool,$(TOOLS),$(eval $(call TOOL_templ,$(tool))))
%:: ;
-netsniff-ng: ALL_CFLAGS += $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) $(CFLAGS_PCAP) -D__WITH_PROTOS
+netsniff-ng: ALL_CFLAGS += $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS
trafgen: ALL_CFLAGS += -I.. $(shell pkg-config --cflags libnl-3.0) $(shell pkg-config --cflags libnl-genl-3.0) -D__WITH_PROTOS
ifpps: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
flowtop: ALL_CFLAGS += $(shell pkg-config --cflags ncurses)
diff --git a/bpf.h b/bpf.h
index 1f6b21c..d63205e 100644
--- a/bpf.h
+++ b/bpf.h
@@ -8,6 +8,7 @@
#include "xmalloc.h"
#include "bpf_insns.h"
#include "bpf_ext.h"
+#include "config.h"
extern void bpf_dump_op_table(void);
extern void bpf_dump_all(struct sock_fprog *bpf);
@@ -18,7 +19,7 @@ extern void bpf_attach_to_sock(int sock, struct sock_fprog *bpf);
extern void bpf_detach_from_sock(int sock);
extern int enable_kernel_bpf_jit_compiler(void);
extern void bpf_parse_rules(char *rulefile, struct sock_fprog *bpf, uint32_t link_type);
-#ifdef __WITH_TCPDUMP_LIKE_FILTER
+#if defined(HAVE_TCPDUMP_LIKE_FILTER) && defined(NEED_TCPDUMP_LIKE_FILTER)
extern void bpf_try_compile(const char *rulefile, struct sock_fprog *bpf,
uint32_t link_type);
#else
diff --git a/bpf_comp.c b/bpf_comp.c
index f7fa278..8946621 100644
--- a/bpf_comp.c
+++ b/bpf_comp.c
@@ -4,10 +4,13 @@
* Subject to the GPL, version 2.
*/
+#define NEED_TCPDUMP_LIKE_FILTER
+
#include <pcap.h>
#include <linux/filter.h>
#include "xmalloc.h"
+#include "config.h"
#include "bpf.h"
#include "die.h"
diff --git a/configure b/configure
index 7998572..120d5bf 100755
--- a/configure
+++ b/configure
@@ -12,6 +12,9 @@ MISSING_NACL=0
TOOLS="netsniff-ng trafgen astraceroute flowtop ifpps bpfc curvetun mausezahn"
TOOLS_NOBUILD=""
+HAVE_LIBPCAP=0
+HAVE_HWTSTAMP=0
+
[ -z $CC ] && CC=cc
TMPDIR=$(mktemp -d config.XXXXXX)
@@ -369,6 +372,55 @@ EOF
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 <string.h>
+#include <arpa/inet.h>
+#include <sys/ioctl.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <linux/sockios.h>
+#include <linux/net_tstamp.h>
+#include <linux/if_packet.h>
+#include <linux/if_ether.h>
+#include <linux/if.h>
+
+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, &timesource,
+ sizeof(timesource));
+}
+EOF
+
+ $CC -o $TMPDIR/hwtstest $TMPDIR/hwtstest.c >> $TMPDIR/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
}
@@ -422,8 +474,19 @@ EOF
gen_config_hdr()
{
local _version="`git describe --always`"
+ local _have_libpcap=""
+ local _have_hwts=""
+
echo "[*] Generating config.h ... "
+ 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
+
cat > config.h << EOF
#ifndef CONFIG_H
#define CONFIG_H
@@ -433,6 +496,8 @@ gen_config_hdr()
#define FILE_PUBKEY ".curvetun/pub.key"
#define FILE_USERNAM ".curvetun/username"
#define GITVERSION "$_version"
+$_have_libpcap
+$_have_hwts
#endif /* CONFIG_H */
EOF
}
@@ -456,7 +521,7 @@ check_libgeoip
check_zlib
check_urcu
check_libpcap
-# mausezahn dependencies
+check_hwtstamp
check_libcli
check_libnet
diff --git a/netsniff-ng.c b/netsniff-ng.c
index 09dbf41..7f03d4b 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -6,6 +6,8 @@
*/
#define _GNU_SOURCE
+#define NEED_TCPDUMP_LIKE_FILTER
+
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
diff --git a/netsniff-ng/Makefile b/netsniff-ng/Makefile
index e05ad1d..2f64c0f 100644
--- a/netsniff-ng/Makefile
+++ b/netsniff-ng/Makefile
@@ -57,7 +57,6 @@ netsniff-ng-objs = dissector.o \
ring_tx.o \
ring.o \
tprintf.o \
- tstamping.o \
timer.o \
geoip.o \
mac80211.o \
@@ -66,3 +65,6 @@ netsniff-ng-objs = dissector.o \
ifeq ($(CONFIG_LIBPCAP), 1)
netsniff-ng-objs += bpf_comp.o
endif
+ifeq ($(CONFIG_HWTSTAMP), 1)
+netsniff-ng-objs += tstamping.o
+endif
diff --git a/tstamping.c b/tstamping.c
index 7c97850..860b7a0 100644
--- a/tstamping.c
+++ b/tstamping.c
@@ -4,14 +4,12 @@
#include <sys/socket.h>
#include <linux/sockios.h>
#include <linux/net_tstamp.h>
-#include <linux/net_tstamp.h>
#include <linux/if_packet.h>
#include <linux/if.h>
#include "str.h"
#include "tstamping.h"
-#ifdef __WITH_HARDWARE_TIMESTAMPING
int set_sockopt_hwtimestamp(int sock, const char *dev)
{
int timesource, ret;
@@ -38,9 +36,3 @@ int set_sockopt_hwtimestamp(int sock, const char *dev)
return setsockopt(sock, SOL_PACKET, PACKET_TIMESTAMP, &timesource,
sizeof(timesource));
}
-#else
-int set_sockopt_hwtimestamp(int sock, const char *dev)
-{
- return -1;
-}
-#endif
diff --git a/tstamping.h b/tstamping.h
index 41df9aa..ccc642e 100644
--- a/tstamping.h
+++ b/tstamping.h
@@ -1,6 +1,15 @@
#ifndef TSTAMPING_H
#define TSTAMPING_H
+#include "config.h"
+
+#ifdef HAVE_HARDWARE_TIMESTAMPING
extern int set_sockopt_hwtimestamp(int sock, const char *dev);
+#else
+static inline int set_sockopt_hwtimestamp(int sock, const char *dev)
+{
+ return -1;
+}
+#endif
#endif /* TSTAMPING_H */