diff --git a/Pcap++/CMakeLists.txt b/Pcap++/CMakeLists.txt index f28fcb6be6..ab3ef642bd 100644 --- a/Pcap++/CMakeLists.txt +++ b/Pcap++/CMakeLists.txt @@ -71,9 +71,9 @@ if(WIN32) list( APPEND public_headers - header/WinPcapLiveDevice.h header/PcapRemoteDevice.h - header/PcapRemoteDeviceList.h) + header/PcapRemoteDeviceList.h + header/WinPcapLiveDevice.h) endif() set_property(TARGET Pcap++ PROPERTY PUBLIC_HEADER ${public_headers}) diff --git a/Pcap++/header/PcapRemoteDevice.h b/Pcap++/header/PcapRemoteDevice.h index 26104b6db9..b0c366cb2f 100644 --- a/Pcap++/header/PcapRemoteDevice.h +++ b/Pcap++/header/PcapRemoteDevice.h @@ -1,10 +1,8 @@ #pragma once -#if defined(_WIN32) - -# include -# include -# include "PcapLiveDevice.h" +#include +#include +#include "PcapLiveDevice.h" /// @file @@ -160,5 +158,3 @@ namespace pcpp }; } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/header/PcapRemoteDeviceList.h b/Pcap++/header/PcapRemoteDeviceList.h index df6e6a93eb..9d1d1fac6c 100644 --- a/Pcap++/header/PcapRemoteDeviceList.h +++ b/Pcap++/header/PcapRemoteDeviceList.h @@ -1,11 +1,9 @@ #pragma once -#if defined(_WIN32) - -# include -# include "IpAddress.h" -# include "PcapRemoteDevice.h" -# include "DeprecationUtils.h" +#include +#include "IpAddress.h" +#include "PcapRemoteDevice.h" +#include "DeprecationUtils.h" /// @file @@ -222,5 +220,3 @@ namespace pcpp }; } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/header/WinPcapLiveDevice.h b/Pcap++/header/WinPcapLiveDevice.h index 9cc5a501a3..0139e7c2cd 100644 --- a/Pcap++/header/WinPcapLiveDevice.h +++ b/Pcap++/header/WinPcapLiveDevice.h @@ -1,10 +1,8 @@ #pragma once -#if defined(_WIN32) - /// @file -# include "PcapLiveDevice.h" +#include "PcapLiveDevice.h" /** * \namespace pcpp @@ -76,5 +74,3 @@ namespace pcpp }; } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/src/DpdkDevice.cpp b/Pcap++/src/DpdkDevice.cpp index 6b44fb11c9..28f37caa0b 100644 --- a/Pcap++/src/DpdkDevice.cpp +++ b/Pcap++/src/DpdkDevice.cpp @@ -1,38 +1,36 @@ -#ifdef USE_DPDK - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModuleDpdkDevice - -# define __STDC_LIMIT_MACROS -# define __STDC_FORMAT_MACROS - -# include "DpdkDevice.h" -# include "DpdkDeviceList.h" -# include "Logger.h" -# include "rte_version.h" -# if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) -# include "rte_bus_pci.h" -# endif -# include "rte_pci.h" -# include "rte_config.h" -# include "rte_ethdev.h" -# include "rte_errno.h" -# include "rte_malloc.h" -# include "rte_cycles.h" -# include -# include -# include - -# define MAX_BURST_SIZE 64 - -# define MEMPOOL_CACHE_SIZE 256 - -# if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) -# define GET_MASTER_CORE rte_get_master_lcore -# else -# define GET_MASTER_CORE rte_get_main_lcore -# endif +#define LOG_MODULE PcapLogModuleDpdkDevice + +#define __STDC_LIMIT_MACROS +#define __STDC_FORMAT_MACROS + +#include "DpdkDevice.h" +#include "DpdkDeviceList.h" +#include "Logger.h" +#include "rte_version.h" +#if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) +# include "rte_bus_pci.h" +#endif +#include "rte_pci.h" +#include "rte_config.h" +#include "rte_ethdev.h" +#include "rte_errno.h" +#include "rte_malloc.h" +#include "rte_cycles.h" +#include +#include +#include + +#define MAX_BURST_SIZE 64 + +#define MEMPOOL_CACHE_SIZE 256 + +#if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) +# define GET_MASTER_CORE rte_get_master_lcore +#else +# define GET_MASTER_CORE rte_get_main_lcore +#endif namespace pcpp { @@ -43,65 +41,65 @@ namespace pcpp * ================ */ -# define DPDK_CONFIG_HEADER_SPLIT 0 /**< Header Split disabled */ -# define DPDK_CONFIG_SPLIT_HEADER_SIZE 0 -# define DPDK_CONFIG_HW_IP_CHECKSUM 0 /**< IP checksum offload disabled */ -# define DPDK_CONFIG_HW_VLAN_FILTER 0 /**< VLAN filtering disabled */ -# define DPDK_CONFIG_JUMBO_FRAME 0 /**< Jumbo Frame Support disabled */ -# define DPDK_CONFIG_HW_STRIP_CRC 0 /**< CRC stripped by hardware disabled */ -# if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) -# define DPDK_CONFIG_ETH_LINK_FULL_DUPLEX ETH_LINK_FULL_DUPLEX -# define DPDK_CONFIG_MQ_RSS ETH_RSS -# define DPDK_CONFIG_MQ_NO_RSS ETH_MQ_RX_NONE -# else -# define DPDK_CONFIG_ETH_LINK_FULL_DUPLEX RTE_ETH_LINK_FULL_DUPLEX -# define DPDK_CONFIG_MQ_RSS RTE_ETH_MQ_RX_RSS -# define DPDK_CONFIG_MQ_NO_RSS RTE_ETH_MQ_RX_NONE -# endif - -# if (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) -# define DPDK_CONFIG_ETH_RSS_IPV4 ETH_RSS_IPV4 -# define DPDK_CONFIG_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4 -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER -# define DPDK_CONFIG_ETH_RSS_IPV6 ETH_RSS_IPV6 -# define DPDK_CONFIG_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6 -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER -# define DPDK_CONFIG_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD -# define DPDK_CONFIG_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX -# define DPDK_CONFIG_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX -# define DPDK_CONFIG_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX -# define DPDK_CONFIG_ETH_RSS_PORT ETH_RSS_PORT -# define DPDK_CONFIG_ETH_RSS_VXLAN ETH_RSS_VXLAN -# define DPDK_CONFIG_ETH_RSS_GENEVE ETH_RSS_GENEVE -# define DPDK_CONFIG_ETH_RSS_NVGRE ETH_RSS_NVGRE -# else -# define DPDK_CONFIG_ETH_RSS_IPV4 RTE_ETH_RSS_IPV4 -# define DPDK_CONFIG_ETH_RSS_FRAG_IPV4 RTE_ETH_RSS_FRAG_IPV4 -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_TCP RTE_ETH_RSS_NONFRAG_IPV4_TCP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_UDP RTE_ETH_RSS_NONFRAG_IPV4_UDP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_SCTP RTE_ETH_RSS_NONFRAG_IPV4_SCTP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_OTHER RTE_ETH_RSS_NONFRAG_IPV4_OTHER -# define DPDK_CONFIG_ETH_RSS_IPV6 RTE_ETH_RSS_IPV6 -# define DPDK_CONFIG_ETH_RSS_FRAG_IPV6 RTE_ETH_RSS_FRAG_IPV6 -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_TCP RTE_ETH_RSS_NONFRAG_IPV6_TCP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_UDP RTE_ETH_RSS_NONFRAG_IPV6_UDP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_SCTP RTE_ETH_RSS_NONFRAG_IPV6_SCTP -# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_OTHER RTE_ETH_RSS_NONFRAG_IPV6_OTHER -# define DPDK_CONFIG_ETH_RSS_L2_PAYLOAD RTE_ETH_RSS_L2_PAYLOAD -# define DPDK_CONFIG_ETH_RSS_IPV6_EX RTE_ETH_RSS_IPV6_EX -# define DPDK_CONFIG_ETH_RSS_IPV6_TCP_EX RTE_ETH_RSS_IPV6_TCP_EX -# define DPDK_CONFIG_ETH_RSS_IPV6_UDP_EX RTE_ETH_RSS_IPV6_UDP_EX -# define DPDK_CONFIG_ETH_RSS_PORT RTE_ETH_RSS_PORT -# define DPDK_CONFIG_ETH_RSS_VXLAN RTE_ETH_RSS_VXLAN -# define DPDK_CONFIG_ETH_RSS_GENEVE RTE_ETH_RSS_GENEVE -# define DPDK_CONFIG_ETH_RSS_NVGRE RTE_ETH_RSS_NVGRE -# endif +#define DPDK_CONFIG_HEADER_SPLIT 0 /**< Header Split disabled */ +#define DPDK_CONFIG_SPLIT_HEADER_SIZE 0 +#define DPDK_CONFIG_HW_IP_CHECKSUM 0 /**< IP checksum offload disabled */ +#define DPDK_CONFIG_HW_VLAN_FILTER 0 /**< VLAN filtering disabled */ +#define DPDK_CONFIG_JUMBO_FRAME 0 /**< Jumbo Frame Support disabled */ +#define DPDK_CONFIG_HW_STRIP_CRC 0 /**< CRC stripped by hardware disabled */ +#if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) +# define DPDK_CONFIG_ETH_LINK_FULL_DUPLEX ETH_LINK_FULL_DUPLEX +# define DPDK_CONFIG_MQ_RSS ETH_RSS +# define DPDK_CONFIG_MQ_NO_RSS ETH_MQ_RX_NONE +#else +# define DPDK_CONFIG_ETH_LINK_FULL_DUPLEX RTE_ETH_LINK_FULL_DUPLEX +# define DPDK_CONFIG_MQ_RSS RTE_ETH_MQ_RX_RSS +# define DPDK_CONFIG_MQ_NO_RSS RTE_ETH_MQ_RX_NONE +#endif + +#if (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) +# define DPDK_CONFIG_ETH_RSS_IPV4 ETH_RSS_IPV4 +# define DPDK_CONFIG_ETH_RSS_FRAG_IPV4 ETH_RSS_FRAG_IPV4 +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_TCP ETH_RSS_NONFRAG_IPV4_TCP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_UDP ETH_RSS_NONFRAG_IPV4_UDP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_SCTP ETH_RSS_NONFRAG_IPV4_SCTP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_OTHER ETH_RSS_NONFRAG_IPV4_OTHER +# define DPDK_CONFIG_ETH_RSS_IPV6 ETH_RSS_IPV6 +# define DPDK_CONFIG_ETH_RSS_FRAG_IPV6 ETH_RSS_FRAG_IPV6 +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_TCP ETH_RSS_NONFRAG_IPV6_TCP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_UDP ETH_RSS_NONFRAG_IPV6_UDP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_SCTP ETH_RSS_NONFRAG_IPV6_SCTP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_OTHER ETH_RSS_NONFRAG_IPV6_OTHER +# define DPDK_CONFIG_ETH_RSS_L2_PAYLOAD ETH_RSS_L2_PAYLOAD +# define DPDK_CONFIG_ETH_RSS_IPV6_EX ETH_RSS_IPV6_EX +# define DPDK_CONFIG_ETH_RSS_IPV6_TCP_EX ETH_RSS_IPV6_TCP_EX +# define DPDK_CONFIG_ETH_RSS_IPV6_UDP_EX ETH_RSS_IPV6_UDP_EX +# define DPDK_CONFIG_ETH_RSS_PORT ETH_RSS_PORT +# define DPDK_CONFIG_ETH_RSS_VXLAN ETH_RSS_VXLAN +# define DPDK_CONFIG_ETH_RSS_GENEVE ETH_RSS_GENEVE +# define DPDK_CONFIG_ETH_RSS_NVGRE ETH_RSS_NVGRE +#else +# define DPDK_CONFIG_ETH_RSS_IPV4 RTE_ETH_RSS_IPV4 +# define DPDK_CONFIG_ETH_RSS_FRAG_IPV4 RTE_ETH_RSS_FRAG_IPV4 +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_TCP RTE_ETH_RSS_NONFRAG_IPV4_TCP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_UDP RTE_ETH_RSS_NONFRAG_IPV4_UDP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_SCTP RTE_ETH_RSS_NONFRAG_IPV4_SCTP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV4_OTHER RTE_ETH_RSS_NONFRAG_IPV4_OTHER +# define DPDK_CONFIG_ETH_RSS_IPV6 RTE_ETH_RSS_IPV6 +# define DPDK_CONFIG_ETH_RSS_FRAG_IPV6 RTE_ETH_RSS_FRAG_IPV6 +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_TCP RTE_ETH_RSS_NONFRAG_IPV6_TCP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_UDP RTE_ETH_RSS_NONFRAG_IPV6_UDP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_SCTP RTE_ETH_RSS_NONFRAG_IPV6_SCTP +# define DPDK_CONFIG_ETH_RSS_NONFRAG_IPV6_OTHER RTE_ETH_RSS_NONFRAG_IPV6_OTHER +# define DPDK_CONFIG_ETH_RSS_L2_PAYLOAD RTE_ETH_RSS_L2_PAYLOAD +# define DPDK_CONFIG_ETH_RSS_IPV6_EX RTE_ETH_RSS_IPV6_EX +# define DPDK_CONFIG_ETH_RSS_IPV6_TCP_EX RTE_ETH_RSS_IPV6_TCP_EX +# define DPDK_CONFIG_ETH_RSS_IPV6_UDP_EX RTE_ETH_RSS_IPV6_UDP_EX +# define DPDK_CONFIG_ETH_RSS_PORT RTE_ETH_RSS_PORT +# define DPDK_CONFIG_ETH_RSS_VXLAN RTE_ETH_RSS_VXLAN +# define DPDK_CONFIG_ETH_RSS_GENEVE RTE_ETH_RSS_GENEVE +# define DPDK_CONFIG_ETH_RSS_NVGRE RTE_ETH_RSS_NVGRE +#endif // RSS random key: uint8_t DpdkDevice::m_RSSKey[40] = { @@ -119,11 +117,11 @@ namespace pcpp m_DeviceName = deviceNameStream.str(); m_DeviceSocketId = rte_eth_dev_socket_id(m_Id); -# if (RTE_VER_YEAR > 19) || (RTE_VER_YEAR == 19 && RTE_VER_MONTH >= 8) +#if (RTE_VER_YEAR > 19) || (RTE_VER_YEAR == 19 && RTE_VER_MONTH >= 8) struct rte_ether_addr etherAddr; -# else +#else struct ether_addr etherAddr; -# endif +#endif rte_eth_macaddr_get((uint8_t)m_Id, ðerAddr); m_MacAddress = MacAddress(etherAddr.addr_bytes[0], etherAddr.addr_bytes[1], etherAddr.addr_bytes[2], etherAddr.addr_bytes[3], etherAddr.addr_bytes[4], etherAddr.addr_bytes[5]); @@ -309,16 +307,16 @@ namespace pcpp struct rte_eth_conf portConf; memset(&portConf, 0, sizeof(rte_eth_conf)); -# if (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) +#if (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) portConf.rxmode.split_hdr_size = DPDK_CONFIG_SPLIT_HEADER_SIZE; -# endif -# if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 8) +#endif +#if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 8) portConf.rxmode.header_split = DPDK_CONFIG_HEADER_SPLIT; portConf.rxmode.hw_ip_checksum = DPDK_CONFIG_HW_IP_CHECKSUM; portConf.rxmode.hw_vlan_filter = DPDK_CONFIG_HW_VLAN_FILTER; portConf.rxmode.jumbo_frame = DPDK_CONFIG_JUMBO_FRAME; portConf.rxmode.hw_strip_crc = DPDK_CONFIG_HW_STRIP_CRC; -# endif +#endif // Enable RSS only if hardware supports it and the user wants to use it if (m_Config.rssHashFunction == RSS_NONE) { @@ -545,19 +543,19 @@ namespace pcpp else m_PMDType = PMD_UNKNOWN; -# if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 5) // before 18.05 +#if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 5) // before 18.05 char pciName[30]; -# if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) // 17.11 - 18.02 +# if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) // 17.11 - 18.02 rte_pci_device_name(&(portInfo.pci_dev->addr), pciName, 30); -# else // 16.11 - 17.11 +# else // 16.11 - 17.11 rte_eal_pci_device_name(&(portInfo.pci_dev->addr), pciName, 30); -# endif +# endif m_PciAddress = std::string(pciName); -# elif (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) // before 22.11 +#elif (RTE_VER_YEAR < 22) || (RTE_VER_YEAR == 22 && RTE_VER_MONTH < 11) // before 22.11 m_PciAddress = std::string(portInfo.device->name); -# else // 22.11 forward +#else // 22.11 forward m_PciAddress = std::string(rte_dev_name(portInfo.device)); -# endif +#endif PCPP_LOG_DEBUG("Device [" << m_DeviceName << "] has " << portInfo.max_rx_queues << " RX queues"); PCPP_LOG_DEBUG("Device [" << m_DeviceName << "] has " << portInfo.max_tx_queues << " TX queues"); @@ -788,7 +786,7 @@ namespace pcpp return 0; } -# define nanosec_gap(begin, end) ((end.tv_sec - begin.tv_sec) * 1000000000.0 + (end.tv_nsec - begin.tv_nsec)) +#define nanosec_gap(begin, end) ((end.tv_sec - begin.tv_sec) * 1000000000.0 + (end.tv_nsec - begin.tv_nsec)) void DpdkDevice::getStatistics(DpdkDeviceStats& stats) const { @@ -1066,7 +1064,7 @@ namespace pcpp uint16_t packetsSent = 0; int lastSleep = 0; -# define PACKET_TRANSMISSION_THRESHOLD 0.8 +#define PACKET_TRANSMISSION_THRESHOLD 0.8 int packetTxThreshold = m_Config.transmitDescriptorsNumber * PACKET_TRANSMISSION_THRESHOLD; while (packetIndex < arrLength) @@ -1541,5 +1539,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* USE_DPDK */ diff --git a/Pcap++/src/DpdkDeviceList.cpp b/Pcap++/src/DpdkDeviceList.cpp index 4517e6c6c3..f41d1bba9e 100644 --- a/Pcap++/src/DpdkDeviceList.cpp +++ b/Pcap++/src/DpdkDeviceList.cpp @@ -1,54 +1,52 @@ -#ifdef USE_DPDK - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModuleDpdkDevice - -# define __STDC_LIMIT_MACROS -# define __STDC_FORMAT_MACROS - -# include "DpdkDeviceList.h" -# include "Logger.h" - -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include -# include - -# if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) -# define GET_MASTER_CORE rte_get_master_lcore -# define MASTER_LCORE "--master-lcore" -# else -# define GET_MASTER_CORE rte_get_main_lcore -# define MASTER_LCORE "--main-lcore" -# endif +#define LOG_MODULE PcapLogModuleDpdkDevice + +#define __STDC_LIMIT_MACROS +#define __STDC_FORMAT_MACROS + +#include "DpdkDeviceList.h" +#include "Logger.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#if (RTE_VER_YEAR < 21) || (RTE_VER_YEAR == 21 && RTE_VER_MONTH < 11) +# define GET_MASTER_CORE rte_get_master_lcore +# define MASTER_LCORE "--master-lcore" +#else +# define GET_MASTER_CORE rte_get_main_lcore +# define MASTER_LCORE "--main-lcore" +#endif namespace pcpp { @@ -179,11 +177,11 @@ namespace pcpp if (m_IsInitialized) return true; -# if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 5) +#if (RTE_VER_YEAR < 18) || (RTE_VER_YEAR == 18 && RTE_VER_MONTH < 5) int numOfPorts = (int)rte_eth_dev_count(); -# else +#else int numOfPorts = (int)rte_eth_dev_count_avail(); -# endif +#endif if (numOfPorts <= 0) { @@ -299,26 +297,26 @@ namespace pcpp void DpdkDeviceList::setDpdkLogLevel(Logger::LogLevel logLevel) { -# if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) +#if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) if (logLevel == Logger::Info) rte_log_set_global_level(RTE_LOG_NOTICE); else // logLevel == Logger::Debug rte_log_set_global_level(RTE_LOG_DEBUG); -# else +#else if (logLevel == Logger::Info) rte_set_log_level(RTE_LOG_NOTICE); else // logLevel == Logger::Debug rte_set_log_level(RTE_LOG_DEBUG); -# endif +#endif } Logger::LogLevel DpdkDeviceList::getDpdkLogLevel() const { -# if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) +#if (RTE_VER_YEAR > 17) || (RTE_VER_YEAR == 17 && RTE_VER_MONTH >= 11) if (rte_log_get_global_level() <= RTE_LOG_NOTICE) -# else +#else if (rte_get_log_level() <= RTE_LOG_NOTICE) -# endif +#endif return Logger::Info; else return Logger::Debug; @@ -438,5 +436,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* USE_DPDK */ diff --git a/Pcap++/src/KniDevice.cpp b/Pcap++/src/KniDevice.cpp index aeb012eda5..0d144ec8b3 100644 --- a/Pcap++/src/KniDevice.cpp +++ b/Pcap++/src/KniDevice.cpp @@ -1,44 +1,42 @@ -#if defined(USE_DPDK) && defined(__linux__) - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModuleKniDevice - -# include "KniDevice.h" -# include "Logger.h" -# include "SystemUtils.h" - -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include -# include -# include -# include - -# include -# include -# include -# include - -# ifndef KNI_MEMPOOL_NAME_PREFIX -# define KNI_MEMPOOL_NAME_PREFIX "kniMempool" -# endif -# ifndef MEMPOOL_CACHE_SIZE -# define MEMPOOL_CACHE_SIZE 256 -# endif -# ifndef MAX_BURST_SIZE -# define MAX_BURST_SIZE 64 -# endif - -# define CPP_VLA(TYPE, SIZE) (TYPE*)__builtin_alloca(sizeof(TYPE) * SIZE) +#define LOG_MODULE PcapLogModuleKniDevice + +#include "KniDevice.h" +#include "Logger.h" +#include "SystemUtils.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifndef KNI_MEMPOOL_NAME_PREFIX +# define KNI_MEMPOOL_NAME_PREFIX "kniMempool" +#endif +#ifndef MEMPOOL_CACHE_SIZE +# define MEMPOOL_CACHE_SIZE 256 +#endif +#ifndef MAX_BURST_SIZE +# define MAX_BURST_SIZE 64 +#endif + +#define CPP_VLA(TYPE, SIZE) (TYPE*)__builtin_alloca(sizeof(TYPE) * SIZE) namespace pcpp { @@ -119,17 +117,17 @@ namespace pcpp { return oldState = KniDevice::LINK_ERROR; } -# if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0) oldState = (KniDevice::KniLinkState)rte_kni_update_link(kni, state); if (oldState == KniDevice::LINK_ERROR) { //? NOTE(echo-Mike): Not LOG_ERROR because will generate a lot of junk messages on some DPDK versions PCPP_LOG_DEBUG("DPDK KNI Failed to update links state for device '" << deviceName << "'"); } -# else +#else // To avoid compiler warnings (void)kni; (void)deviceName; -# endif +#endif return oldState; } @@ -175,30 +173,30 @@ namespace pcpp kniConf.core_id = conf.kthreadCoreId; kniConf.mbuf_size = RTE_MBUF_DEFAULT_BUF_SIZE; kniConf.force_bind = conf.bindKthread ? 1 : 0; -# if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) if (conf.mac != MacAddress::Zero) conf.mac.copyTo((uint8_t*)kniConf.mac_addr); kniConf.mtu = conf.mtu; -# endif +#endif kniOps.port_id = conf.portId; -# if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0) if (conf.callbacks != nullptr) { kniOps.change_mtu = conf.callbacks->change_mtu; kniOps.config_network_if = conf.callbacks->config_network_if; -# if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) +# if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) kniOps.config_mac_address = conf.callbacks->config_mac_address; kniOps.config_promiscusity = conf.callbacks->config_promiscusity; -# endif +# endif } -# else +#else if (conf.oldCallbacks != nullptr) { kniOps.change_mtu = conf.oldCallbacks->change_mtu; kniOps.config_network_if = conf.oldCallbacks->config_network_if; } -# endif +#endif m_Device = rte_kni_alloc(m_MBufMempool, &kniConf, &kniOps); if (m_Device == nullptr) @@ -984,5 +982,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* defined(USE_DPDK) && defined(__linux__) */ diff --git a/Pcap++/src/KniDeviceList.cpp b/Pcap++/src/KniDeviceList.cpp index e588cd81b9..36a0856639 100644 --- a/Pcap++/src/KniDeviceList.cpp +++ b/Pcap++/src/KniDeviceList.cpp @@ -1,24 +1,22 @@ -#if defined(USE_DPDK) && defined(__linux__) - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModuleKniDevice +#define LOG_MODULE PcapLogModuleKniDevice -# include -# include +#include +#include -# include "KniDeviceList.h" -# include "Logger.h" -# include "SystemUtils.h" +#include "KniDeviceList.h" +#include "Logger.h" +#include "SystemUtils.h" -# include -# include +#include +#include -# ifndef MAX_KNI_DEVICES +#ifndef MAX_KNI_DEVICES // This value have no meaning in current DPDK implementation (ver >= 18.11) // In older versions have literal meaning -# define MAX_KNI_DEVICES 4 -# endif +# define MAX_KNI_DEVICES 4 +#endif namespace pcpp { @@ -54,15 +52,15 @@ namespace pcpp m_Initialized = false; return; } -# if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(18, 11, 0, 0) if (rte_kni_init(MAX_KNI_DEVICES) < 0) { PCPP_LOG_ERROR("Failed to initialize DPDK KNI module"); m_Initialized = false; } -# else +#else rte_kni_init(MAX_KNI_DEVICES); -# endif +#endif } KniDeviceList::~KniDeviceList() @@ -143,11 +141,11 @@ namespace pcpp KniDeviceList::KniCallbackVersion KniDeviceList::callbackVersion() { -# if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(17, 11, 0, 0) return KniDeviceList::CALLBACKS_NEW; -# else +#else return KniDeviceList::CALLBACKS_OLD; -# endif +#endif } bool KniDeviceList::isCallbackSupported(const KniCallbackType cbType) @@ -161,16 +159,14 @@ namespace pcpp case KniDeviceList::CALLBACK_MAC: /* fall through */ case KniDeviceList::CALLBACK_PROMISC: -# if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) +#if RTE_VERSION >= RTE_VERSION_NUM(18, 2, 0, 0) return true; -# else +#else return false; -# endif +#endif } return false; } } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* defined(USE_DPDK) && defined(__linux__) */ diff --git a/Pcap++/src/LinuxNicInformationSocket.cpp b/Pcap++/src/LinuxNicInformationSocket.cpp index a70db5e341..f75d1d8c36 100644 --- a/Pcap++/src/LinuxNicInformationSocket.cpp +++ b/Pcap++/src/LinuxNicInformationSocket.cpp @@ -1,21 +1,19 @@ -#ifdef __linux__ +#define LOG_MODULE UndefinedLogModule -# define LOG_MODULE UndefinedLogModule +#include "Logger.h" +#include "LinuxNicInformationSocket.h" -# include "Logger.h" -# include "LinuxNicInformationSocket.h" +#include +#include +#include +#include +#include -# include -# include -# include -# include -# include +#include +#include +#include -# include -# include -# include - -# define INVALID_SOCKET_VALUE (-1) +#define INVALID_SOCKET_VALUE (-1) namespace pcpp { @@ -71,4 +69,3 @@ namespace pcpp return true; } } // namespace pcpp -#endif /* __linux__ */ diff --git a/Pcap++/src/MBufRawPacket.cpp b/Pcap++/src/MBufRawPacket.cpp index 8994671100..fc271f0d64 100644 --- a/Pcap++/src/MBufRawPacket.cpp +++ b/Pcap++/src/MBufRawPacket.cpp @@ -1,26 +1,24 @@ -#ifdef USE_DPDK - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModuleMBufRawPacket +#define LOG_MODULE PcapLogModuleMBufRawPacket -# define __STDC_LIMIT_MACROS -# define __STDC_FORMAT_MACROS +#define __STDC_LIMIT_MACROS +#define __STDC_FORMAT_MACROS -# include "rte_mbuf.h" -# include "rte_mempool.h" -# include "rte_errno.h" +#include "rte_mbuf.h" +#include "rte_mempool.h" +#include "rte_errno.h" -# include "MBufRawPacket.h" -# include "Logger.h" -# include "DpdkDevice.h" -# ifdef USE_DPDK_KNI -# include "KniDevice.h" -# endif +#include "MBufRawPacket.h" +#include "Logger.h" +#include "DpdkDevice.h" +#ifdef USE_DPDK_KNI +# include "KniDevice.h" +#endif -# include -# include -# include +#include +#include +#include namespace pcpp { @@ -70,12 +68,12 @@ namespace pcpp return init(device->m_MBufMempool); } -# ifdef USE_DPDK_KNI +#ifdef USE_DPDK_KNI bool MBufRawPacket::init(KniDevice* device) { return init(device->m_MBufMempool); } -# endif +#endif bool MBufRawPacket::initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool) { @@ -104,12 +102,12 @@ namespace pcpp return initFromRawPacket(rawPacket, device->m_MBufMempool); } -# ifdef USE_DPDK_KNI +#ifdef USE_DPDK_KNI bool MBufRawPacket::initFromRawPacket(const RawPacket* rawPacket, KniDevice* device) { return initFromRawPacket(rawPacket, device->m_MBufMempool); } -# endif +#endif MBufRawPacket::MBufRawPacket(const MBufRawPacket& other) { @@ -345,5 +343,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* USE_DPDK */ diff --git a/Pcap++/src/PcapRemoteDevice.cpp b/Pcap++/src/PcapRemoteDevice.cpp index 3b020aba5e..e4e037df17 100644 --- a/Pcap++/src/PcapRemoteDevice.cpp +++ b/Pcap++/src/PcapRemoteDevice.cpp @@ -1,10 +1,8 @@ -#if defined(_WIN32) +#define LOG_MODULE PcapLogModuleRemoteDevice -# define LOG_MODULE PcapLogModuleRemoteDevice - -# include "PcapRemoteDevice.h" -# include "Logger.h" -# include "pcap.h" +#include "PcapRemoteDevice.h" +#include "Logger.h" +#include "pcap.h" namespace pcpp { @@ -99,5 +97,3 @@ namespace pcpp } } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/src/PcapRemoteDeviceList.cpp b/Pcap++/src/PcapRemoteDeviceList.cpp index 4ad2ac4f42..368529789a 100644 --- a/Pcap++/src/PcapRemoteDeviceList.cpp +++ b/Pcap++/src/PcapRemoteDeviceList.cpp @@ -1,15 +1,13 @@ -#if defined(_WIN32) +#define LOG_MODULE PcapLogModuleRemoteDevice -# define LOG_MODULE PcapLogModuleRemoteDevice - -# include "PcapRemoteDeviceList.h" -# include "Logger.h" -# include "IpUtils.h" -# include "PcapUtils.h" -# include "IpAddressUtils.h" -# include "pcap.h" -# include -# include +#include "PcapRemoteDeviceList.h" +#include "Logger.h" +#include "IpUtils.h" +#include "PcapUtils.h" +#include "IpAddressUtils.h" +#include "pcap.h" +#include +#include namespace pcpp { @@ -239,5 +237,3 @@ namespace pcpp } } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/src/PfRingDevice.cpp b/Pcap++/src/PfRingDevice.cpp index 3850501352..8a945a9c20 100644 --- a/Pcap++/src/PfRingDevice.cpp +++ b/Pcap++/src/PfRingDevice.cpp @@ -1,19 +1,17 @@ -#ifdef USE_PF_RING - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModulePfRingDevice +#define LOG_MODULE PcapLogModulePfRingDevice -# include "PfRingDevice.h" -# include "EthLayer.h" -# include "VlanLayer.h" -# include "Logger.h" -# include -# include -# include -# include +#include "PfRingDevice.h" +#include "EthLayer.h" +#include "VlanLayer.h" +#include "Logger.h" +#include +#include +#include +#include -# define DEFAULT_PF_RING_SNAPLEN 1600 +#define DEFAULT_PF_RING_SNAPLEN 1600 namespace pcpp { @@ -760,7 +758,7 @@ namespace pcpp uint8_t flushTxAsUint = (flushTxQueues ? 1 : 0); -# define MAX_TRIES 5 +#define MAX_TRIES 5 int tries = 0; int res = 0; @@ -903,5 +901,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* USE_PF_RING */ diff --git a/Pcap++/src/PfRingDeviceList.cpp b/Pcap++/src/PfRingDeviceList.cpp index 1b9dae42f5..be41d07be8 100644 --- a/Pcap++/src/PfRingDeviceList.cpp +++ b/Pcap++/src/PfRingDeviceList.cpp @@ -1,17 +1,15 @@ -#ifdef USE_PF_RING - // GCOVR_EXCL_START -# define LOG_MODULE PcapLogModulePfRingDevice +#define LOG_MODULE PcapLogModulePfRingDevice -# include -# include -# include "PfRingDeviceList.h" -# include "SystemUtils.h" -# include "DeviceUtils.h" -# include "Logger.h" -# include "pcap.h" -# include "pfring.h" +#include +#include +#include "PfRingDeviceList.h" +#include "SystemUtils.h" +#include "DeviceUtils.h" +#include "Logger.h" +#include "pcap.h" +#include "pfring.h" namespace pcpp { @@ -136,5 +134,3 @@ namespace pcpp } // namespace pcpp // GCOVR_EXCL_STOP - -#endif /* USE_PF_RING */ diff --git a/Pcap++/src/WinPcapLiveDevice.cpp b/Pcap++/src/WinPcapLiveDevice.cpp index efe736ffe8..94f20f2cd3 100644 --- a/Pcap++/src/WinPcapLiveDevice.cpp +++ b/Pcap++/src/WinPcapLiveDevice.cpp @@ -1,11 +1,9 @@ -#if defined(_WIN32) +#define LOG_MODULE PcapLogModuleWinPcapLiveDevice -# define LOG_MODULE PcapLogModuleWinPcapLiveDevice - -# include "WinPcapLiveDevice.h" -# include "Logger.h" -# include "TimespecTimeval.h" -# include "pcap.h" +#include "WinPcapLiveDevice.h" +#include "Logger.h" +#include "TimespecTimeval.h" +#include "pcap.h" namespace pcpp { @@ -139,5 +137,3 @@ namespace pcpp } } // namespace pcpp - -#endif // _WIN32 diff --git a/Pcap++/src/XdpDevice.cpp b/Pcap++/src/XdpDevice.cpp index 1ebca1cdb2..d1f9e99f75 100644 --- a/Pcap++/src/XdpDevice.cpp +++ b/Pcap++/src/XdpDevice.cpp @@ -1,4 +1,5 @@ #define LOG_MODULE PcapLogModuleXdpDevice + #include "XdpDevice.h" #include "GeneralUtils.h" #include "Logger.h"