Skip to contentSkip to conversation

pcap build fixes

PATCH In review David Marchand 2 participants 5 messages Nov 22, 2013 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

cover pcap build fixes

Fix build with old pcap library.
Make it possible to specify which pcap library to use.

David Marchand (3):
pcap: use pcap-config to guess compilation flags
pcap: fix build with old libpcap
pcap: fix build when pcap_sendpacket is unavailable

 app/test-pmd/Makefile              |    4 ----
 doc/build-sdk-quick.txt            |    2 ++
 lib/librte_pmd_pcap/rte_eth_pcap.c |   12 ++++++++++++
 lib/librte_pmd_pcap/rte_eth_pcap.h |    8 +++++++-
 mk/rte.app.mk                      |    5 ++++-
 mk/rte.sdkbuild.mk                 |    8 ++++++++
 mk/target/generic/rte.vars.mk      |    2 +-
 7 files changed, 34 insertions(+), 7 deletions(-)
Signature · 1 line
1.7.10.4

A message that is not in the archive (sent off-list or not yet received): cover.1385115073.git.david.marchand-pdR9zngts4EAvxtiuMwx3w@public.gmane.org

#2 lore raw

PATCH 1/3 pcap: use pcap-config to guess compilation flags

Use pcap-config to populate CFLAGS and LDFLAGS.
LIBPCAP_CFLAGS and LIBPCAP_LDFLAGS can be used to override this (useful when cross-compiling).

---
 app/test-pmd/Makefile         |    4 ----
 doc/build-sdk-quick.txt       |    2 ++
 mk/rte.app.mk                 |    5 ++++-
 mk/rte.sdkbuild.mk            |    8 ++++++++
 mk/target/generic/rte.vars.mk |    2 +-
 5 files changed, 15 insertions(+), 6 deletions(-)
app/test-pmd/Makefile +0 -4
index cd04ea5..2ced595 100644
@@ -39,10 +39,6 @@ APP = testpmd
 CFLAGS += -O3
 CFLAGS += $(WERROR_FLAGS)
 
-ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
-LDFLAGS += -lpcap
-endif
-
 #
 # all source are stored in SRCS-y
 #
doc/build-sdk-quick.txt +2 -0
index 18b0ee6..ca39c33 100644
@@ -11,6 +11,8 @@ Build variables
 	EXTRA_CPPFLAGS   preprocessor options
 	EXTRA_CFLAGS     compiler options
 	EXTRA_LDFLAGS    linker options
+	LIBPCAP_CFLAGS   libpcap compiler options
+	LIBPCAP_LDFLAGS  libpcap linker options
 	CROSS     toolchain prefix
 	V         verbose
 	D         debug dependencies
mk/rte.app.mk +4 -1
index d2ce5c0..9420f24 100644
@@ -150,7 +150,10 @@ LDLIBS += -lrte_eal
 endif
 
 ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
-LDLIBS += -lrte_pmd_pcap -lpcap
+LDLIBS += -lrte_pmd_pcap
+LIBPCAP_LDFLAGS ?= $(shell pcap-config --libs)
+$(if $(LIBPCAP_LDFLAGS),,$(error LIBPCAP_LDFLAGS is undefined))
+LDLIBS += $(LIBPCAP_LDFLAGS)
 endif
 
 LDLIBS += $(EXECENV_LDLIBS)
mk/rte.sdkbuild.mk +8 -0
index 0dc23ff..33bed57 100644
@@ -40,6 +40,14 @@ else
   include $(RTE_SDK)/mk/rte.vars.mk
 endif
 
+ifeq ($(CONFIG_RTE_LIBRTE_PMD_PCAP),y)
+LIBPCAP_CFLAGS ?= $(shell pcap-config --cflags)
+$(if $(LIBPCAP_CFLAGS),,$(error LIBPCAP_CFLAGS is undefined))
+EXTERNAL_LIB_CFLAGS += $(LIBPCAP_CFLAGS)
+endif
+
+export EXTERNAL_LIB_CFLAGS
+
 #
 # include .depdirs and define rules to order priorities between build
 # of directories.
mk/target/generic/rte.vars.mk +1 -1
index 9030f44..22893fc 100644
@@ -104,7 +104,7 @@ ifeq ($(KERNELRELEASE),)
 
 # merge all CFLAGS
 CFLAGS := $(CPU_CFLAGS) $(EXECENV_CFLAGS) $(TOOLCHAIN_CFLAGS) $(MACHINE_CFLAGS)
-CFLAGS += $(TARGET_CFLAGS)
+CFLAGS += $(TARGET_CFLAGS) $(EXTERNAL_LIB_CFLAGS)
 
 # merge all LDFLAGS
 LDFLAGS := $(CPU_LDFLAGS) $(EXECENV_LDFLAGS) $(TOOLCHAIN_LDFLAGS) $(MACHINE_LDFLAGS)
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH 2/3 pcap: fix build with old libpcap

In reply to a message not in the archive

For backwards compatibility, pcap.h includes pcap/pcap.h. Hence, to be compatible with older pcap libraries, we must include pcap.h.

---
 lib/librte_pmd_pcap/rte_eth_pcap.h |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/librte_pmd_pcap/rte_eth_pcap.h +1 -1
index 7ed68b1..a1bd513 100644
@@ -37,7 +37,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#include <pcap/pcap.h>
+#include <pcap.h>
 
 #define RTE_ETH_PCAP_PARAM_NAME "eth_pcap"
 
Signature · 1 line
1.7.10.4
#4 lore raw

PATCH 3/3 pcap: fix build when pcap_sendpacket is unavailable

In reply to a message not in the archive

Before libpcap 1.0.0, pcap_sendpacket was not available on linux targets (unless backported).
When using such a library, we won't be able to send packet on the wire, yet we can still dump packets into a pcap file.

---
 lib/librte_pmd_pcap/rte_eth_pcap.c |   12 ++++++++++++
 lib/librte_pmd_pcap/rte_eth_pcap.h |    6 ++++++
 2 files changed, 18 insertions(+)
lib/librte_pmd_pcap/rte_eth_pcap.c +12 -0
index 50de885..19d19b3 100644
@@ -199,6 +199,7 @@ eth_pcap_tx_dumper(void *queue,
 	return num_tx;
 }
 
+#ifdef PCAP_CAN_SEND
 /*
  * Callback to handle sending packets through a real NIC.
  */
@@ -229,6 +230,17 @@ eth_pcap_tx(void *queue,
 	tx_queue->err_pkts += nb_pkts - num_tx;
 	return num_tx;
 }
+#else
+static uint16_t
+eth_pcap_tx(__rte_unused void *queue,
+		__rte_unused struct rte_mbuf **bufs,
+		__rte_unused uint16_t nb_pkts)
+{
+	RTE_LOG(ERR, PMD, "pcap library cannot send packets, please rebuild "
+	                  "with a more up to date libpcap\n");
+	return -1;
+}
+#endif
 
 static int
 eth_dev_start(struct rte_eth_dev *dev)
lib/librte_pmd_pcap/rte_eth_pcap.h +6 -0
index a1bd513..368ed88 100644
@@ -39,6 +39,12 @@ extern "C" {
 #endif
 #include <pcap.h>
 
+#ifdef pcap_sendpacket
+#define PCAP_CAN_SEND
+#else
+#undef PCAP_CAN_SEND
+#endif
+
 #define RTE_ETH_PCAP_PARAM_NAME "eth_pcap"
 
 int rte_eth_from_pcaps(pcap_t * const rx_queues[],
Signature · 1 line
1.7.10.4
#5 lore raw
In reply to a message not in the archive

22/11/2013 11:24, David Marchand :

Quoted 7 lines

Fix build with old pcap library.
Make it possible to specify which pcap library to use.

David Marchand (3):
pcap: use pcap-config to guess compilation flags
pcap: fix build with old libpcap
pcap: fix build when pcap_sendpacket is unavailable

Acked and applied.
Thanks

Signature · 1 line
Thomas