Skip to content

Commit

Permalink
Remove ifdef inside cpp and format (seladb#1587)
Browse files Browse the repository at this point in the history
* Remove ifdef inside cpp

* Proper indent file

* More fix

* same for headers
  • Loading branch information
clementperon authored Sep 24, 2024
1 parent 26ced48 commit 4417695
Show file tree
Hide file tree
Showing 16 changed files with 309 additions and 363 deletions.
4 changes: 2 additions & 2 deletions Pcap++/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
10 changes: 3 additions & 7 deletions Pcap++/header/PcapRemoteDevice.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

#if defined(_WIN32)

# include <vector>
# include <memory>
# include "PcapLiveDevice.h"
#include <vector>
#include <memory>
#include "PcapLiveDevice.h"

/// @file

Expand Down Expand Up @@ -160,5 +158,3 @@ namespace pcpp
};

} // namespace pcpp

#endif // _WIN32
12 changes: 4 additions & 8 deletions Pcap++/header/PcapRemoteDeviceList.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#pragma once

#if defined(_WIN32)

# include <memory>
# include "IpAddress.h"
# include "PcapRemoteDevice.h"
# include "DeprecationUtils.h"
#include <memory>
#include "IpAddress.h"
#include "PcapRemoteDevice.h"
#include "DeprecationUtils.h"

/// @file

Expand Down Expand Up @@ -222,5 +220,3 @@ namespace pcpp
};

} // namespace pcpp

#endif // _WIN32
6 changes: 1 addition & 5 deletions Pcap++/header/WinPcapLiveDevice.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#pragma once

#if defined(_WIN32)

/// @file

# include "PcapLiveDevice.h"
#include "PcapLiveDevice.h"

/**
* \namespace pcpp
Expand Down Expand Up @@ -76,5 +74,3 @@ namespace pcpp
};

} // namespace pcpp

#endif // _WIN32
216 changes: 106 additions & 110 deletions Pcap++/src/DpdkDevice.cpp
Original file line number Diff line number Diff line change
@@ -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 <string>
# include <stdint.h>
# include <unistd.h>

# 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 <string>
#include <stdint.h>
#include <unistd.h>

#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
{
Expand All @@ -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] = {
Expand All @@ -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, &etherAddr);
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]);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -1541,5 +1539,3 @@ namespace pcpp
} // namespace pcpp

// GCOVR_EXCL_STOP

#endif /* USE_DPDK */
Loading

0 comments on commit 4417695

Please sign in to comment.