]> The Tcpdump Group git mirrors - libpcap/commitdiff
dpdk: check for rte_ether_addr and RTE_ETHER_MAX_JUMBO_FRAME_LEN.
authorGuy Harris <[email protected]>
Tue, 19 May 2020 23:59:59 +0000 (16:59 -0700)
committerGuy Harris <[email protected]>
Tue, 19 May 2020 23:59:59 +0000 (16:59 -0700)
This lets us build with older versions of DPDK that define struct
ether_addr and ETHER_MAX_JUMBO_FRAME_LEN and newer versions that define
struct rte_ether_addr and RTE_ETHER_MAX_JUMBO_FRAME_LEN.

That addresses the issue in GitHub pull request #921.

CMakeLists.txt
cmakeconfig.h.in
config.h.in
configure
configure.ac
pcap-dpdk.c

index b459132e74d1a4abd3e865c9a5a42adced5eab1c..41f6062cce6238039725ba6138ea4682d10eae65 100644 (file)
@@ -1589,6 +1589,18 @@ if(NOT DISABLE_DPDK)
             set(PCAP_LINK_LIBRARIES ${PCAP_LINK_LIBRARIES} ${dpdk_LIBRARIES})
             set(PROJECT_SOURCE_LIST_C ${PROJECT_SOURCE_LIST_C} pcap-dpdk.c)
             set(PCAP_SUPPORT_DPDK TRUE)
+
+            #
+            # Check whether the rte_ether.h file defines
+            # struct ether_addr or struct rte_ether_addr.
+            #
+            # ("API compatibility?  That's for losers!")
+            #
+            cmake_push_check_state()
+            set(CMAKE_REQUIRED_INCLUDES ${dpdk_INCLUDE_DIRS})
+            set(CMAKE_EXTRA_INCLUDE_FILES rte_ether.h)
+            check_type_size("struct rte_ether_addr" STRUCT_RTE_ETHER_ADDR)
+            cmake_pop_check_state()
         endif()
     endif()
 endif()
index f2e03c19e0ef145b9ee0980076ce19d289c2f600..ea87e70ff0cc276a0bf6ef320890a84145dd416f 100644 (file)
 /* Define to 1 if `msg_flags' is a member of `struct msghdr'. */
 #cmakedefine HAVE_STRUCT_MSGHDR_MSG_FLAGS 1
 
+/* Define to 1 if the system has the type `struct rte_ether_addr'. */
+#cmakedefine HAVE_STRUCT_RTE_ETHER_ADDR 1
+
 /* Define to 1 if `hci_channel' is a member of `struct sockaddr_hci'. */
 #cmakedefine HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL 1
 
index 3e7495eb2d581fb5e3a90c499beb6709f6a893d6..00618aec0f295a0148183c845284a9111b50904d 100644 (file)
 /* Define to 1 if `msg_flags' is a member of `struct msghdr'. */
 #undef HAVE_STRUCT_MSGHDR_MSG_FLAGS
 
+/* Define to 1 if the system has the type `struct rte_ether_addr'. */
+#undef HAVE_STRUCT_RTE_ETHER_ADDR
+
 /* Define to 1 if `hci_channel' is a member of `struct sockaddr_hci'. */
 #undef HAVE_STRUCT_SOCKADDR_HCI_HCI_CHANNEL
 
index 939bd59839fbe0fa67cc39d19f0984765047b2f6..8a4cb0bdfbf495a1b5b16913224af8fb8b7d9862 100755 (executable)
--- a/configure
+++ b/configure
@@ -11316,6 +11316,26 @@ $as_echo "#define PCAP_SUPPORT_DPDK 1" >>confdefs.h
                if test $V_PCAP != dpdk ; then
                        MODULE_C_SRC="$MODULE_C_SRC pcap-dpdk.c"
                fi
+
+               #
+               # Check whether the rte_ether.h file defines
+               # struct ether_addr or struct rte_ether_addr.
+               #
+               # ("API compatibility?  That's for losers!")
+               #
+               ac_fn_c_check_type "$LINENO" "struct rte_ether_addr" "ac_cv_type_struct_rte_ether_addr" "
+                       #include <rte_ether.h>
+
+"
+if test "x$ac_cv_type_struct_rte_ether_addr" = xyes; then :
+
+cat >>confdefs.h <<_ACEOF
+#define HAVE_STRUCT_RTE_ETHER_ADDR 1
+_ACEOF
+
+
+fi
+
        else
                if test "$V_PCAP" = dpdk; then
                        # User requested DPDK-only capture support, but
index cbd6f14585f6e41659a76200618ee811504c4a5c..d93f9b079a533a2853f28416f1f51fb5ae4613be 100644 (file)
@@ -2498,6 +2498,17 @@ AC_INCLUDES_DEFAULT
                if test $V_PCAP != dpdk ; then
                        MODULE_C_SRC="$MODULE_C_SRC pcap-dpdk.c"
                fi
+
+               #
+               # Check whether the rte_ether.h file defines
+               # struct ether_addr or struct rte_ether_addr.
+               #
+               # ("API compatibility?  That's for losers!")
+               #
+               AC_CHECK_TYPES(struct rte_ether_addr,,,
+                   [
+                       #include <rte_ether.h>
+                   ])
        else
                if test "$V_PCAP" = dpdk; then
                        # User requested DPDK-only capture support, but
index 6c2f21fca5f052caee17b8e81f4f884198d36836..4513ffbac91825d9dea13eec363523067e58021b 100644 (file)
@@ -115,6 +115,16 @@ env DPDK_CFG="--log-level=debug -l0 -dlibrte_pmd_e1000.so -dlibrte_pmd_ixgbe.so
 #include "pcap-int.h"
 #include "pcap-dpdk.h"
 
+/*
+ * Deal with API changes that break source compatibility.
+ */
+
+#ifdef HAVE_STRUCT_RTE_ETHER_ADDR
+#define ETHER_ADDR_TYPE        struct rte_ether_addr
+#else
+#define ETHER_ADDR_TYPE        struct ether_addr
+#endif
+
 #define DPDK_DEF_LOG_LEV RTE_LOG_ERR
 //
 // This is set to 0 if we haven't initialized DPDK yet, 1 if we've
@@ -152,7 +162,11 @@ static char dpdk_cfg_buf[DPDK_CFG_MAX_LEN];
 static uint16_t nb_rxd = RTE_TEST_RX_DESC_DEFAULT;
 static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
 
+#ifdef RTE_ETHER_MAX_JUMBO_FRAME_LEN
+#define RTE_ETH_PCAP_SNAPLEN RTE_ETHER_MAX_JUMBO_FRAME_LEN
+#else
 #define RTE_ETH_PCAP_SNAPLEN ETHER_MAX_JUMBO_FRAME_LEN
+#endif
 
 static struct rte_eth_dev_tx_buffer *tx_buffer;
 
@@ -176,7 +190,7 @@ struct pcap_dpdk{
        uint64_t bps;
        struct rte_mempool * pktmbuf_pool;
        struct dpdk_ts_helper ts_helper;
-       struct ether_addr eth_addr;
+       ETHER_ADDR_TYPE eth_addr;
        char mac_addr[DPDK_MAC_ADDR_SIZE];
        char pci_addr[DPDK_PCI_ADDR_SIZE];
        unsigned char pcap_tmp_buf[RTE_ETH_PCAP_SNAPLEN];
@@ -365,7 +379,7 @@ static int pcap_dpdk_dispatch(pcap_t *p, int max_cnt, pcap_handler cb, u_char *c
                                bp = rte_pktmbuf_mtod(m, u_char *);
                        }else{
                                // use fast buffer pcap_tmp_buf if pkt_len is small, no need to call malloc and free
-                               if ( pkt_len <= ETHER_MAX_JUMBO_FRAME_LEN)
+                               if ( pkt_len <= RTE_ETH_PCAP_SNAPLEN)
                                {
                                        gather_len = dpdk_gather_data(pd->pcap_tmp_buf, RTE_ETH_PCAP_SNAPLEN, m);
                                        bp = pd->pcap_tmp_buf;
@@ -472,7 +486,7 @@ static int check_link_status(uint16_t portid, struct rte_eth_link *plink)
        rte_eth_link_get(portid, plink);
        return plink->link_status == ETH_LINK_UP;
 }
-static void eth_addr_str(struct ether_addr *addrp, char* mac_str, int len)
+static void eth_addr_str(ETHER_ADDR_TYPE *addrp, char* mac_str, int len)
 {
        int offset=0;
        if (addrp == NULL){
@@ -973,7 +987,7 @@ int pcap_dpdk_findalldevs(pcap_if_list_t *devlistp, char *ebuf)
        unsigned int nb_ports = 0;
        char dpdk_name[DPDK_DEV_NAME_MAX];
        char dpdk_desc[DPDK_DEV_DESC_MAX];
-       struct ether_addr eth_addr;
+       ETHER_ADDR_TYPE eth_addr;
        char mac_addr[DPDK_MAC_ADDR_SIZE];
        char pci_addr[DPDK_PCI_ADDR_SIZE];
        do{