net/pcap: build on Windows
Subsystems (2)
cover net/pcap: build on Windows
Most modern and actively maintained distribution of libpcap for Windows is Npcap
(https://nmap.org/npcap). It is free (as in "free beer") and open-source, but Npcap redistribution with commercial products may be limited by its license.
Npcap can be installed anywhere, so a new Meson option is provided to find it:
meson -Dpcap_sdk=C:\Npcap -Dexamples=skeleton build
Example of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe `
--vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" `
--vdev "eth_pcap1,tx_pcap=capture.pcap"Implementation in "pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.
There are no release notes for 21.05 yet, will send update after they appear.
Dmitry Kozlyuk (6):
eal: add internal API for current time net/pcap: fix format string
net/pcap: move OS-dependent code to separate files net/pcap: add libpcap wrappers
config: discover libpcap on Windows net/pcap: build on Windows
config/meson.build | 21 +-
drivers/net/pcap/meson.build | 17 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 251 ++++++------------
drivers/net/pcap/pcap_osdep.c | 122 +++++++++
drivers/net/pcap/pcap_osdep.h | 72 +++++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 ++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++
drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++
lib/librte_eal/include/rte_time.h | 17 ++
lib/librte_eal/rte_eal_exports.def | 1 +
lib/librte_eal/unix/eal_unix_timer.c | 13 +
lib/librte_eal/version.map | 1 +
lib/librte_eal/windows/eal_timer.c | 20 +-
meson_options.txt | 6 +-
14 files changed, 584 insertions(+), 176 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (88%)
create mode 100644 drivers/net/pcap/pcap_osdep.c
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.c
create mode 100644 drivers/net/pcap/pcap_osdep_windows.cSignature · 1 line
2.29.2
PATCH 1/6 eal: add internal API for current time
Many PMDs use POSIX gettimeofday(). Add rte_time_get_us() function to obtain current time with microsecond precision on all platforms.
--- lib/librte_eal/include/rte_time.h | 17 +++++++++++++++++ lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/unix/eal_unix_timer.c | 13 +++++++++++++ lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_timer.c | 20 +++++++++++++++++++- 5 files changed, 51 insertions(+), 1 deletion(-)
lib/librte_eal/include/rte_time.h +17 -0
@@ -8,6 +8,8 @@#include <stdint.h> #include <time.h> +#include <rte_compat.h> +#define NSEC_PER_SEC 1000000000L/**
@@ -98,4 +100,19 @@ rte_ns_to_timespec(uint64_t nsec) return ts; } +/* Point of time with microsecond precision. */ +struct rte_time_us { +int64_t sec;/**< Number of whole seconds. */ +int64_t usec;/**< Fractional part of second in [0, 999999]. */ +}; + +/** +* Get current system time. +* +* @param now +* Receives current system time. +*/ +__rte_internal +void rte_time_get_us(struct rte_time_us *now); +#endif /* _RTE_TIME_H_ */
lib/librte_eal/rte_eal_exports.def +1 -0
@@ -334,3 +334,4 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + rte_time_get_us
lib/librte_eal/unix/eal_unix_timer.c +13 -0
@@ -4,7 +4,10 @@#include <time.h> +#include <sys/time.h> +#include <rte_cycles.h> +#include <rte_time.h> void rte_delay_us_sleep (unsigned int us)
@@ -27,3 +30,13 @@ rte_delay_us_sleep(unsigned int us) ind =1 - ind; } } + +void +rte_time_get_us (struct rte_time_us *now) +{ +struct timeval sys; + +gettimeofday (&sys,NULL ); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +}
lib/librte_eal/version.map +1 -0
@@ -421,4 +421,5 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_time_get_us; };
lib/librte_eal/windows/eal_timer.c +19 -1
@@ -9,6 +9,7 @@#include <rte_cycles.h> #include <rte_eal.h> #include <rte_errno.h> +#include <rte_time.h> #include "eal_private.h" #define US_PER_SEC 1E6
@@ -85,10 +86,27 @@ get_tsc_freq(void)return RTE_ALIGN_MUL_NEAR (tsc_hz,CYC_PER_10MHZ ); } -int rte_eal_timer_init (void ) {set_tsc_freq ();return 0 ; } + +void +rte_time_get_us (struct rte_time_us *now) +{ +/* 100ns ticks from 1601-01-01 to 1970-01-01 */ +static const uint64_t EPOCH =116444736000000000ULL ; +static const uint64_t TICKS_PER_USEC =10 ; +static const uint64_t USEC_PER_SEC =1000000 ; + +FILETIME ft; +uint64_t ticks, sec; + +GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + sec = (ticks -EPOCH ) / (TICKS_PER_USEC *USEC_PER_SEC ); + now->sec = sec; + now->usec = (ticks - sec *USEC_PER_SEC ) /TICKS_PER_USEC ; +}
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH 1/6] eal: add internal API for current time
Calculation of usec value is incorrect - 'ticks' is not adjusted for epoch, whereas 'sec' has been, also subtraction has mismatched units - ticks in 100ns and sec * USEC_PER_SEC in usecs.
Quoted 5 lines · Dmitry Kozlyuk
lib/librte_eal/windows/eal_timer.c +5
-0+GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + sec = (ticks -EPOCH ) / (TICKS_PER_USEC *USEC_PER_SEC ); + now->sec = sec; + now->usec = (ticks - sec *USEC_PER_SEC ) /TICKS_PER_USEC ;
Re: [dpdk-dev] [PATCH 1/6] eal: add internal API for current time
Quoted 2 lines
Calculation of usec value is incorrect - 'ticks' is not adjusted for epoch, whereas 'sec' has been, also subtraction has mismatched units - ticks in 100ns and sec *
USEC_PER_SECin usecs.
Ignore - fixed in later version which I hadn't spotted.
PATCH 2/6 net/pcap: fix format string
In reply to Dmitry KozlyukUse PRIu32 for uint32_t (found by -Wformat with Clang on Windows).
--- drivers/net/pcap/rte_eth_pcap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/pcap/rte_eth_pcap.c +1 -1
@@ -827,7 +827,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_pkt_count =count_packets_in_pcap (pcap, pcap_q); -snprintf (ring_name,sizeof (ring_name),"PCAP_RING%" PRIu16, +snprintf (ring_name,sizeof (ring_name),"PCAP_RING%" PRIu32, ring_number); pcap_q->pkts = rte_ring_create(ring_name,
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH 2/6] net/pcap: fix format string
Quoted 3 lines
Use PRIu32 for
uint32_t(found by -Wformat with Clang on Windows).
PATCH 3/6 net/pcap: move OS-dependent code to separate files
In reply to Dmitry KozlyukPCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. In preparation to add Windows-specific part and libpcap wrapper, extract OS-independent interface and move implementations to separate files. Rename rte_eth_pcap.c to pcap_ethdev.c for consistency with the rest of DPDK.
---
drivers/net/pcap/meson.build | 5 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 88 ++-----------------
drivers/net/pcap/pcap_osdep.h | 17 ++++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++++
5 files changed, 130 insertions(+), 81 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.cdrivers/net/pcap/meson.build +4 -1
@@ -11,5 +11,8 @@ if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif -sources = files('rte_eth_pcap.c') +sources = files( + 'pcap_ethdev.c', + 'pcap_osdep_@[email protected]'.format(exec_env), +) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c renamed from drivers/net/pcap/rte_eth_pcap.c +8 -80
122 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#ifndef _RTE_PCAP_OSDEP_ +#define _RTE_PCAP_OSDEP_ + +#include <rte_ether.h> + +/* +* Interface manipulation is always OS-specific. +*/ + +int osdep_iface_index_get (const char *name); +int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c new file +59 -0
59 lines not on this page · raw message
drivers/net/pcap/pcap_osdep_linux.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 4/6 net/pcap: add libpcap wrappers
In reply to Dmitry Kozlyuklibpcap headers can expose OS headers. On Windows, system networking headers are incompatible with DPDK ones, causing multiple name clashes. API of libpcap itself involves a non-standard u_char type.
Add a limited set of trivial libpcap wrappers, so that libpcap headers are not included directly by OS-independent PMD code. Use EAL types and functions for time instead of POSIX ones.
--- drivers/net/pcap/meson.build | 1 + drivers/net/pcap/pcap_ethdev.c | 157 +++++++++++++++++---------------- drivers/net/pcap/pcap_osdep.c | 122 +++++++++++++++++++++++++ drivers/net/pcap/pcap_osdep.h | 50 +++++++++++ 4 files changed, 252 insertions(+), 78 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep.c
drivers/net/pcap/meson.build +1 -0
@@ -13,6 +13,7 @@ if not dpdk_conf.has('RTE_PORT_PCAP') endif sources = files( 'pcap_ethdev.c', + 'pcap_osdep.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c +79 -78
402 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.c new file +122 -0
122 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h +50 -0
60 lines not on this page · raw message
Signature · 1 line
2.29.2
PATCH 5/6 config: discover libpcap on Windows
In reply to Dmitry KozlyukWinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.
--- config/meson.build | 21 ++++++++++++++++++--- meson_options.txt | 6 ++++-- 2 files changed, 22 insertions(+), 5 deletions(-)
config/meson.build +18 -3
@@ -178,9 +178,24 @@ if not pcap_dep.found() # pcap got a pkg-config file only in 1.9.0 pcap_dep = cc.find_library('pcap', required: false) endif -if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) - dpdk_conf.set('RTE_PORT_PCAP', 1) - dpdk_extra_ldflags += '-lpcap' +if is_windows + # npcap SDK can be installed anywhere + pcap_sdk = get_option('pcap_sdk') + if pcap_sdk != '' + pcap_ldflags = ['-L@0@/Lib/x64'.format(pcap_sdk), '-lwpcap'] + pcap_dep = declare_dependency( + compile_args: ['-I@0@/Include'.format(pcap_sdk)], + link_args: pcap_ldflags) + endif + if pcap_dep.found() + dpdk_conf.set('RTE_PORT_PCAP', 1) + dpdk_extra_ldflags += pcap_ldflags + endif +else + if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) + dpdk_conf.set('RTE_PORT_PCAP', 1) + dpdk_extra_ldflags += '-lpcap' + endif endif # for clang 32-bit compiles we need libatomic for 64-bit atomic ops
meson_options.txt +4 -2
@@ -10,6 +10,8 @@ option('enable_docs', type: 'boolean', value: false, description: 'build documentation') option('enable_kmods', type: 'boolean', value: false, description: 'build kernel modules') +option('enable_trace_fp', type: 'boolean', value: false, + description: 'enable fast path trace points.') option('examples', type: 'string', value: '', description: 'Comma-separated list of examples to build by default') option('flexran_sdk', type: 'string', value: '',
@@ -28,8 +30,8 @@ option('max_lcores', type: 'integer', value: 128, description: 'maximum number of cores/threads supported by EAL') option('max_numa_nodes', type: 'integer', value: 32, description: 'maximum number of NUMA nodes supported by EAL') -option('enable_trace_fp', type: 'boolean', value: false, - description: 'enable fast path trace points.') +option('pcap_sdk', type: 'string', value: '', + description: 'Path to libpcap SDK used on Windows') option('tests', type: 'boolean', value: true, description: 'build unit tests') option('use_hpet', type: 'boolean', value: false,
Signature · 1 line
2.29.2
PATCH 6/6 net/pcap: build on Windows
In reply to Dmitry KozlyukImplement OS-dependent functions and enable PMD build on Windows.
--- drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 4 - drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.c
drivers/net/pcap/meson.build +5 -6
@@ -1,19 +1,18 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endif
drivers/net/pcap/pcap_ethdev.c +0 -4
@@ -127,10 +127,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static int eth_pcap_rx_jumbo (struct rte_mempool *mb_pool,struct rte_mbuf *mbuf,const uint8_t *data,uint16_t data_len)
drivers/net/pcap/pcap_osdep.h +5 -0
@@ -8,6 +8,11 @@#include <rte_ether.h> #include <rte_time.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +/* * Interface manipulation is always OS-specific. */
drivers/net/pcap/pcap_osdep_windows.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.29.2
v2 cover net/pcap: build on Windows
In reply to Dmitry KozlyukMost modern and actively maintained distribution of libpcap for Windows is Npcap
(https://nmap.org/npcap). It is free (as in "free beer") and open-source, but Npcap redistribution with commercial products may be limited by its license.
Npcap can be installed anywhere, so a new Meson option is provided to find it:
meson -Dpcap_sdk=C:\Npcap -Dexamples=skeleton build
Example of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe `
--vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" `
--vdev "eth_pcap1,tx_pcap=capture.pcap"Implementation in "pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.
There are no release notes for 21.05 yet, will send update after they appear.
v2: fix microsecond calculation on Windows in patch 1/6.
Dmitry Kozlyuk (6):
eal: add internal API for current time net/pcap: fix format string
net/pcap: move OS-dependent code to separate files net/pcap: add libpcap wrappers
config: discover libpcap on Windows net/pcap: build on Windows
config/meson.build | 21 +-
drivers/net/pcap/meson.build | 17 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 251 ++++++------------
drivers/net/pcap/pcap_osdep.c | 122 +++++++++
drivers/net/pcap/pcap_osdep.h | 72 +++++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 ++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++
drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++
lib/librte_eal/include/rte_time.h | 17 ++
lib/librte_eal/rte_eal_exports.def | 1 +
lib/librte_eal/unix/eal_unix_timer.c | 13 +
lib/librte_eal/version.map | 1 +
lib/librte_eal/windows/eal_timer.c | 21 +-
meson_options.txt | 6 +-
14 files changed, 585 insertions(+), 176 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (88%)
create mode 100644 drivers/net/pcap/pcap_osdep.c
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.c
create mode 100644 drivers/net/pcap/pcap_osdep_windows.cSignature · 1 line
2.29.2
PATCH v2 1/6 eal: add internal API for current time
Many PMDs use POSIX gettimeofday(). Add rte_time_get_us() function to obtain current time with microsecond precision on all platforms.
--- lib/librte_eal/include/rte_time.h | 17 +++++++++++++++++ lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/unix/eal_unix_timer.c | 13 +++++++++++++ lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_timer.c | 21 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-)
lib/librte_eal/include/rte_time.h +17 -0
@@ -8,6 +8,8 @@#include <stdint.h> #include <time.h> +#include <rte_compat.h> +#define NSEC_PER_SEC 1000000000L/**
@@ -98,4 +100,19 @@ rte_ns_to_timespec(uint64_t nsec) return ts; } +/* Point of time with microsecond precision. */ +struct rte_time_us { +int64_t sec;/**< Number of whole seconds. */ +int64_t usec;/**< Fractional part of second in [0, 999999]. */ +}; + +/** +* Get current system time. +* +* @param now +* Receives current system time. +*/ +__rte_internal +void rte_time_get_us(struct rte_time_us *now); +#endif /* _RTE_TIME_H_ */
lib/librte_eal/rte_eal_exports.def +1 -0
@@ -334,3 +334,4 @@ EXPORTS rte_mem_map rte_mem_page_size rte_mem_unmap + rte_time_get_us
lib/librte_eal/unix/eal_unix_timer.c +13 -0
@@ -4,7 +4,10 @@#include <time.h> +#include <sys/time.h> +#include <rte_cycles.h> +#include <rte_time.h> void rte_delay_us_sleep (unsigned int us)
@@ -27,3 +30,13 @@ rte_delay_us_sleep(unsigned int us) ind =1 - ind; } } + +void +rte_time_get_us (struct rte_time_us *now) +{ +struct timeval sys; + +gettimeofday (&sys,NULL ); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +}
lib/librte_eal/version.map +1 -0
@@ -421,4 +421,5 @@ INTERNAL { rte_mem_map; rte_mem_page_size; rte_mem_unmap; + rte_time_get_us; };
lib/librte_eal/windows/eal_timer.c +20 -1
@@ -9,6 +9,7 @@#include <rte_cycles.h> #include <rte_eal.h> #include <rte_errno.h> +#include <rte_time.h> #include "eal_private.h" #define US_PER_SEC 1E6
@@ -85,10 +86,28 @@ get_tsc_freq(void)return RTE_ALIGN_MUL_NEAR (tsc_hz,CYC_PER_10MHZ ); } -int rte_eal_timer_init (void ) {set_tsc_freq ();return 0 ; } + +void +rte_time_get_us (struct rte_time_us *now) +{ +/* 100ns ticks from 1601-01-01 to 1970-01-01 */ +static const uint64_t EPOCH =116444736000000000ULL ; +static const uint64_t TICKS_PER_USEC =10 ; +static const uint64_t USEC_PER_SEC =1000000 ; + +FILETIME ft; +uint64_t ticks, sec; + +GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + ticks -=EPOCH ; + sec = ticks / (TICKS_PER_USEC *USEC_PER_SEC ); + now->sec = sec; + now->usec = ticks /TICKS_PER_USEC - sec *USEC_PER_SEC ; +}
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
Quoted 4 lines
Many PMDs use POSIX
gettimeofday(). Addrte_time_get_us()function to obtain current time with microsecond precision on all platforms.
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
In reply to Dmitry KozlyukQuoted 12 lines · Dmitry Kozlyuk
Many PMDs use POSIX
gettimeofday(). Addrte_time_get_us()function to obtain current time with microsecond precision on all platforms.Signed-off-by Dmitry Kozlyuk <[email protected]>--- lib/librte_eal/include/rte_time.h | 17 +++++++++++++++++ lib/librte_eal/rte_eal_exports.def | 1 + lib/librte_eal/unix/eal_unix_timer.c | 13 +++++++++++++ lib/librte_eal/version.map | 1 + lib/librte_eal/windows/eal_timer.c | 21 ++++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-)
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
In reply to Dmitry Kozlyuk14/02/2021 03:16, Dmitry Kozlyuk:
Quoted 2 lines
Many PMDs use POSIX
gettimeofday(). Addrte_time_get_us()function to obtain current time with microsecond precision on all platforms.
Please could you replace the current use of gettimeofday?
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
In reply to Dmitry Kozlyuklib/librte_eal/unix/eal_unix_timer.c rte_delay_us_sleep(unsigned int us) · line 42
Quoted 8 lines · On Sun, 14 Feb 2021 05:16:11 +0300 Dmitry Kozlyuk <[email protected]>…
lib/librte_eal/unix/eal_unix_timer.c +8
-0+rte_time_get_us(struct rte_time_us *now) +{ +struct timeval sys; + +gettimeofday (&sys,NULL ); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +}
Why would drivers want the default (wall clock) time instead of using monotonic clock. The wall clock gets changed by NTP and that is rarely what you want except for the case of log messages.
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
2021-03-16 11:59 (UTC-0700), Stephen Hemminger:
Quoted 15 lines
lib/librte_eal/unix/eal_unix_timer.c rte_delay_us_sleep(unsigned int us) · line 42
Quoted 8 lines · On Sun, 14 Feb 2021 05:16:11 +0300 Dmitry Kozlyuk <[email protected]>…
lib/librte_eal/unix/eal_unix_timer.c +8
-0+rte_time_get_us(struct rte_time_us *now) +{ +struct timeval sys; + +gettimeofday (&sys,NULL ); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +}Why would drivers want the default (wall clock) time instead of using monotonic clock. The wall clock gets changed by NTP and that is rarely what you want except for the case of log messages.
* gettimeofday() is mostly used to measure time (tests, hns3 PMD), so you're right, monotonic clock is what that code really needs.
* ena PMD uses gettimeofday() with pthread_cond_timedwait() without calling pthread_cond_setclock(), which is a bug, I believe.
* hns3 PMD actually uses gettimeofday() for logs.
For wall clock time there is C11 timespec_get(), so I agree this API should be changed to monotonic, thanks.
Re: [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time
Quoted 20 lines
From: dev [mailto:[email protected]] On Behalf Of Dmitry Kozlyuk
Sent: Tuesday, March 16, 2021 9:08 PM2021-03-16 11:59 (UTC-0700), Stephen Hemminger:
Quoted 15 lines
lib/librte_eal/unix/eal_unix_timer.c rte_delay_us_sleep(unsigned int us) · line 42
Quoted 8 lines · On Sun, 14 Feb 2021 05:16:11 +0300 Dmitry Kozlyuk <[email protected]>…
lib/librte_eal/unix/eal_unix_timer.c +8
-0+rte_time_get_us(struct rte_time_us *now) +{ +struct timeval sys; + +gettimeofday (&sys,NULL ); + now->sec = sys.tv_sec; + now->usec = sys.tv_usec; +}Why would drivers want the default (wall clock) time instead of using monotonic clock. The wall clock gets changed by NTP and that is rarely what you want except for the case of log messages.
Quoted 3 lines
*
gettimeofday()is mostly used to measure time (tests, hns3 PMD), so you're
right, monotonic clock is what that code really needs.
If using monotonic time here, we don't need a struct. A single 64 bit integer counting microseconds can hold thousands of years.
Quoted 10 lines
* ena PMD uses
gettimeofday()withpthread_cond_timedwait()without callingpthread_cond_setclock(), which is a bug, I believe.* hns3 PMD actually uses
gettimeofday()for logs.For wall clock time there is C11
timespec_get(), so I agree this API should
be changed to monotonic, thanks.
PATCH v2 2/6 net/pcap: fix format string
In reply to Dmitry KozlyukUse PRIu32 for uint32_t (found by -Wformat with Clang on Windows).
--- drivers/net/pcap/rte_eth_pcap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/pcap/rte_eth_pcap.c +1 -1
@@ -827,7 +827,7 @@ eth_rx_queue_setup(struct rte_eth_dev *dev, pcap_pkt_count =count_packets_in_pcap (pcap, pcap_q); -snprintf (ring_name,sizeof (ring_name),"PCAP_RING%" PRIu16, +snprintf (ring_name,sizeof (ring_name),"PCAP_RING%" PRIu32, ring_number); pcap_q->pkts = rte_ring_create(ring_name,
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 2/6] net/pcap: fix format string
Quoted 6 lines · Dmitry Kozlyuk
Use PRIu32 for
uint32_t(found by -Wformat with Clang on Windows).Fixes a3f5252e5cbd ("net/pcap: enable infinitely Rx a pcap file")Signed-off-by Dmitry Kozlyuk <[email protected]>
Ferruh Yigit
AppliedRe: [dpdk-dev] [dpdk-stable] [PATCH v2 2/6] net/pcap: fix format string
Quoted 9 lines · Ferruh Yigit
Quoted 6 lines · Dmitry Kozlyuk
Use PRIu32 for
uint32_t(found by -Wformat with Clang on Windows).Fixes a3f5252e5cbd ("net/pcap: enable infinitely Rx a pcap file")Signed-off-by Dmitry Kozlyuk <[email protected]>Acked-by Ferruh Yigit <[email protected]>
This is trivial fix and not directly related to the patchset, let me merge it and get out of way, in next version you don't need to include this patch.
Applied to dpdk-next-net/main, thanks.
PATCH v2 3/6 net/pcap: move OS-dependent code to separate files
In reply to Dmitry KozlyukPCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. In preparation to add Windows-specific part and libpcap wrapper, extract OS-independent interface and move implementations to separate files. Rename rte_eth_pcap.c to pcap_ethdev.c for consistency with the rest of DPDK.
---
drivers/net/pcap/meson.build | 5 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 88 ++-----------------
drivers/net/pcap/pcap_osdep.h | 17 ++++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++++
5 files changed, 130 insertions(+), 81 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.cdrivers/net/pcap/meson.build +4 -1
@@ -11,5 +11,8 @@ if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif -sources = files('rte_eth_pcap.c') +sources = files( + 'pcap_ethdev.c', + 'pcap_osdep_@[email protected]'.format(exec_env), +) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c renamed from drivers/net/pcap/rte_eth_pcap.c +8 -80
122 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#ifndef _RTE_PCAP_OSDEP_ +#define _RTE_PCAP_OSDEP_ + +#include <rte_ether.h> + +/* +* Interface manipulation is always OS-specific. +*/ + +int osdep_iface_index_get (const char *name); +int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c new file +59 -0
59 lines not on this page · raw message
drivers/net/pcap/pcap_osdep_linux.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 3/6] net/pcap: move OS-dependent code to separate files
Quoted 7 lines · Dmitry Kozlyuk
PCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. In preparation to add Windows-specific part and libpcap wrapper, extract OS-independent interface and move implementations to separate files. Rename
rte_eth_pcap.ctopcap_ethdev.cfor consistency with the rest of DPDK.Signed-off-by Dmitry Kozlyuk <[email protected]>
<...>
drivers/net/pcap/pcap_osdep_freebsd.c line 20
Quoted 5 lines
drivers/net/pcap/pcap_osdep_freebsd.c new file +5
-0+int +osdep_iface_index_get (const char *name) +{ +return if_nametoindex (name); +}
The 'osdep_iface_index_get' wrapper is not required for this patch and can be done in patch 6/6, but OK to have here to make the switch clear.
Re: [dpdk-dev] [PATCH v2 3/6] net/pcap: move OS-dependent code to separate files
2021-02-25 14:51, Ferruh Yigit:
Quoted 11 lines · Dmitry Kozlyuk
Quoted 7 lines
PCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. In preparation to add Windows-specific part and libpcap wrapper, extract OS-independent interface and move implementations to separate files. Rename
rte_eth_pcap.ctopcap_ethdev.cfor consistency with the rest of DPDK.Signed-off-by Dmitry Kozlyuk <[email protected]><...>
Quoted 9 lines
drivers/net/pcap/pcap_osdep_freebsd.c line 20
Quoted 5 lines
drivers/net/pcap/pcap_osdep_freebsd.c new file +5
-0+int +osdep_iface_index_get (const char *name) +{ +return if_nametoindex (name); +}The '
osdep_iface_index_get' wrapper is not required for this patch and can be done in patch 6/6, but OK to have here to make the switch clear.
Yes, it was my intention to keep Windows patches separate.
PATCH v2 4/6 net/pcap: add libpcap wrappers
In reply to Dmitry Kozlyuklibpcap headers can expose OS headers. On Windows, system networking headers are incompatible with DPDK ones, causing multiple name clashes. API of libpcap itself involves a non-standard u_char type.
Add a limited set of trivial libpcap wrappers, so that libpcap headers are not included directly by OS-independent PMD code. Use EAL types and functions for time instead of POSIX ones.
--- drivers/net/pcap/meson.build | 1 + drivers/net/pcap/pcap_ethdev.c | 157 +++++++++++++++++---------------- drivers/net/pcap/pcap_osdep.c | 122 +++++++++++++++++++++++++ drivers/net/pcap/pcap_osdep.h | 50 +++++++++++ 4 files changed, 252 insertions(+), 78 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep.c
drivers/net/pcap/meson.build +1 -0
@@ -13,6 +13,7 @@ if not dpdk_conf.has('RTE_PORT_PCAP') endif sources = files( 'pcap_ethdev.c', + 'pcap_osdep.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c +79 -78
402 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.c new file +122 -0
122 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h +50 -0
60 lines not on this page · raw message
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Quoted 8 lines · Dmitry Kozlyuk
libpcap headers can expose OS headers. On Windows, system networking headers are incompatible with DPDK ones, causing multiple name clashes. API of libpcap itself involves a non-standard
u_chartype.Add a limited set of trivial libpcap wrappers, so that libpcap headers are not included directly by OS-independent PMD code. Use EAL types and functions for time instead of POSIX ones.
It is not nice to duplicate the pcap struct and macros and have dpdk versions of them, it may have long term maintanance issues too.
What are the clashes in question?
If they are macros, can the issue solved after undefining some after including 'pcap.h'?
And at the end of the day, shouldn't we need to resolve these clashes globally since we may hit same things with other PMDs or libraries as we enable them. I am for a global solution instead of these changes in pcap, but I guess question is how possible that global solution is..
Quoted 1 line
Signed-off-by Dmitry Kozlyuk <[email protected]>
<...>
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-02-25 14:59, Ferruh Yigit:
Quoted 15 lines · Dmitry Kozlyuk
Quoted 8 lines
libpcap headers can expose OS headers. On Windows, system networking headers are incompatible with DPDK ones, causing multiple name clashes. API of libpcap itself involves a non-standard
u_chartype.Add a limited set of trivial libpcap wrappers, so that libpcap headers are not included directly by OS-independent PMD code. Use EAL types and functions for time instead of POSIX ones.
It is not nice to duplicate the pcap struct and macros and have dpdk versions of them, it may have long term maintanance issues too.
What are the clashes in question?
Quoted 7 lines
If they are macros, can the issue solved after undefining some after including '
pcap.h'?And at the end of the day, shouldn't we need to resolve these clashes globally since we may hit same things with other PMDs or libraries as we enable them. I am for a global solution instead of these changes in pcap, but I guess question is how possible that global solution is..
Your comment made me revise Windows EAL networking shims. Surprisingly, if changed to expose Windows networking headers (specifically, <ws2tcpip.h>) with some additions (but no hacks), they create no issues to any existing code.
The only workaround remaining is #undef s_addr in <rte_ether.h>.
So maybe this commit can be dropped, if Windows EAL networking headers be reworked in the following way:
#if defined min #define USER_EXPLICITLY_WANTS_WINDOWS_H #endif #include <ws2tcpip.h> /* hide definitions that break portable code, * e.g. it had to be done once already for i40e */ #ifndef USER_EXPLICITLY_WANTS_WINDOWS_H #undef min, max, ... #endif #define what's missing from Windows headers, e.g. IPPROTO_SCTP
+ Windows maintainers, Nick Connolly, and Jie Zhou to discuss.
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Quoted 25 lines
Your comment made me revise Windows EAL networking shims. Surprisingly, if changed to expose Windows networking headers (specifically, <
ws2tcpip.h>) with some additions (but no hacks), they create no issues to any existing code.The only workaround remaining is
#undef s_addrin <rte_ether.h>.So maybe this commit can be dropped, if Windows EAL networking headers be reworked in the following way:
#if defined min #define USER_EXPLICITLY_WANTS_WINDOWS_H #endif #include <ws2tcpip.h> /* hide definitions that break portable code, * e.g. it had to be done once already for i40e */ #ifndef USER_EXPLICITLY_WANTS_WINDOWS_H #undef min, max, ... #endif #define what's missing from Windows headers, e.g. IPPROTO_SCTP
Quoted 1 line
+ Windows maintainers, Nick Connolly, and Jie Zhou to discuss.
In my opinion, there are long term maintenance issues either way round.
Wrapping the system headers hides the details and keeps the code 'clean', but has to work with multiple compiler environments and versions of the headers - not always straightforward. Wrapping libpcap involves code changes that need to be maintained.
For SPDK, changing the code wasn't really an option, so I had to go with wrapping the headers. It's worked out ok so far. To make it a bit cleaner I turned off as much as possible from Windows.h with #define NO*. Supporting both clang and MinGW caused a few issues (e.g. MinGW has mswsock.h), but they are solvable.
./inc/sys/socket.h and ./inc/wpdk/windows.h in https://github.com/wpdp/wpdk
show an example of what might need wrapping in the general case.
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-02-25 20:31, Nick Connolly:
Quoted 22 lines
Quoted 22 lines
Your comment made me revise Windows EAL networking shims. Surprisingly, if changed to expose Windows networking headers (specifically, <
ws2tcpip.h>) with some additions (but no hacks), they create no issues to any existing code.The only workaround remaining is
#undef s_addrin <rte_ether.h>.So maybe this commit can be dropped, if Windows EAL networking headers be reworked in the following way:
#if defined min #define USER_EXPLICITLY_WANTS_WINDOWS_H #endif #include <ws2tcpip.h> /* hide definitions that break portable code, * e.g. it had to be done once already for i40e */ #ifndef USER_EXPLICITLY_WANTS_WINDOWS_H #undef min, max, ... #endif
Quoted 8 lines
Quoted 3 lines
#define what's missing from Windows headers, e.g. IPPROTO_SCTP+ Windows maintainers, Nick Connolly, and Jie Zhou to discuss.
In my opinion, there are long term maintenance issues either way round.
Wrapping the system headers hides the details and keeps the code 'clean', but has to work with multiple compiler environments and versions of the headers - not always straightforward.
You're probably right.
We had an exchange with Tyler, let me quote:
[DmitryK]
Quoted 3 lines
I'm pretty sure no DPDK header really needs anything beyond standard C, but one exception: intrinsic functions for vector instructions. Struct
in_addr? An oversight, there'srte_ether_addr, should berte_ip_addr.
Here's a complete list of offending files included from public headers, with comments on usage:
POSIX
netinet/in.h
netinet/ip6.h
netinet/ip.h
cmdline: struct in_addr, struct in6_addr, 6 constants
net: ditto
security: ditto
pthread.h
eal: not used
ethdev: pthread_mutex_t flow_ops_mutex;
sched.h
eal: cpu_set_t
telemetry: rte_cpuset_t (not used?)
sys/types.h
ehtdev: not needed (FILE?)
net: not needed
mbuf: ditto
pci: ditto
security: ditto
sched: ditto
Unix
sys/queue.h
(acl, eal, hash, lpm, mempool, pci, ring, table,
bus/{fslmc,pci,vdev,vmbus}, net/{memif,tap})
multiprocessing
Thread-related stuff will go away as rte_thread.h expands. Network headers are not much needed, as you can see above. Other headers mostly not needed or can be replaced with standard ones.
Replacing in_addr with and rte_ip_addr will break API, but not ABI, because it's essentially the same thing. We can define new types conditionally, as it was done for struct cmdline, if need be.
Complete removal of non-standard dependencies in headers is within a grasp. Then we can remove shims and include whatever needed.
Thoughts?
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Quoted 4 lines
Complete removal of non-standard dependencies in headers is within a grasp. Then we can remove shims and include whatever needed.
Thoughts?
Sounds good. A couple of 'gotchas' that I've come across (but may not be an issue for DPDK):
* Memory allocation / free that spans a dll boundary (see earlier email).
* posix_memalign is unfortunately specified as using free(), so we'll either have to modify the calls to rte_posix_memalign / rte_free_memalign (which means code analysis to find which free calls need changing), or wrapper free() to distinguish the two types of memory somehow. I 'solved' this for SPDK by using posix_memalign for everything and I have a vague recollection that the mingw libc does something similar.
* Sockets are unfortunately specified as using close(). This is probably easy to address by rte_ wrapping all socket calls.
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-03-01 21:43, Nick Connolly:
Quoted 7 lines
Quoted 3 lines
Complete removal of non-standard dependencies in headers is within a grasp. Then we can remove shims and include whatever needed.
Thoughts?Sounds good. A couple of 'gotchas' that I've come across (but may not be an issue for DPDK):
* Memory allocation / free that spans a dll boundary (see earlier email).
Not sure which email you mean, could you give a link?
Quoted 7 lines
*
posix_memalignis unfortunately specified as usingfree(), so we'll either have to modify the calls torte_posix_memalign/rte_free_memalign(which means code analysis to find which free calls need changing), or wrapperfree()to distinguish the two types of memory somehow. I 'solved' this for SPDK by usingposix_memalignfor everything and I have a vague recollection that the mingw libc does something similar.
Is posix_memalign() used more extensively in SPDK? In DPDK, it's 2 PMDs:
* mlx5 PMD uses _aligned_malloc/_aligned_free on Windows;
* dpaax (PMD family) uses posix_memalign() to allocate pages.
There are "malloc" and "alloc_size" attributes that can help code analysis.
Quoted 2 lines
* Sockets are unfortunately specified as using
close(). This is probably easy to address byrte_wrapping all socket calls.
Which public DPDK APIs operate on sockets?
I don't like the idea of wrapping APIs like sockets or files. (Yes, we're discussing libpcap API wrappers in this thread, but we already agreed they are a mistake and they were internal in the first place.)
I drafted what I was talking about: adding address types and removing shims:
* librte_net/rte_ip.h then includes <netinet/ip.h> or <ws2tcpip.h> conditionally for AF_xxx, IPPROTO_xxx, and a few other constants. That's probably OK, there are similar places for Linux/FreeBSD differences, e.g. in <rte_endian.h>.
* Some IPPROTO_xxx constants are missing on Windows, so rte_ip.h has to provide them. I hope Mirosoft will add them to system headers one day.
* It affects cmdline (mostly), ethdev, security, crypto/dpaax.
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-03-02 02:05, Dmitry Kozlyuk:
Quoted 10 lines
2021-03-01 21:43, Nick Connolly:
Quoted 7 lines
Quoted 3 lines
Complete removal of non-standard dependencies in headers is within a grasp. Then we can remove shims and include whatever needed.
Thoughts?Sounds good. A couple of 'gotchas' that I've come across (but may not be an issue for DPDK):
* Memory allocation / free that spans a dll boundary (see earlier email).
Not sure which email you mean, could you give a link?
There it is:
https://mails.dpdk.org/archives/dev/2021-February/200105.html
Yes, of course malloc/free shall be both on either library or caller site.
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
In reply to Dmitry KozlyukQuoted 1 line
Is
posix_memalign()used more extensively in SPDK? In DPDK, it's 2 PMDs:
Yes, there are about 80 references. A lot are in ISA-L where they are #defined to _aligned_malloc and can be ignored, but there still several in the rest of the code.
Quoted 4 lines
Quoted 2 lines
* Sockets are unfortunately specified as using
close(). This is probably easy to address byrte_wrapping all socket calls.Which public DPDK APIs operate on sockets?
I don't like the idea of wrapping APIs like sockets or files.
I'm not sure about use in public APIs - I'd hope none do. I was thinking about 'internal' use. The tricky issue here is that on Linux/FreeBSD socket() returns a small integer file descriptor whereas Windows returns a SOCKET type (which is a UINT_PTR and so larger than the 'int' that an fd occupies). In practice it looks as though SOCKET usually returns a small integer, but as far as I can see from the documentation it depends on the software stack that is in use. Even if it's a small integer, I don't think it has any correlation to the file descriptor table in the crt, which means that calls to read/write/close will all need to be handled so that they work.
Quoted 10 lines
(Yes, we're discussing libpcap API wrappers in this thread, but we already agreed they are a mistake and they were internal in the first place.)
I drafted what I was talking about: adding address types and removing shims:
*
librte_net/rte_ip.hthen includes <netinet/ip.h> or <ws2tcpip.h> conditionally forAF_xxx,IPPROTO_xxx, and a few other constants. That's probably OK, there are similar places for Linux/FreeBSD differences, e.g. in <rte_endian.h>.
Quoted 4 lines
* Some
IPPROTO_xxxconstants are missing on Windows, sorte_ip.hhas to provide them. I hope Mirosoft will add them to system headers one day.* It affects cmdline (mostly), ethdev, security,
crypto/dpaax.
Sounds good - well done!
Regards,
Nick
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-03-02 11:22, Nick Connolly:
Quoted 4 lines
Quoted 1 line
Is
posix_memalign()used more extensively in SPDK? In DPDK, it's 2 PMDs:Yes, there are about 80 references. A lot are in ISA-L where they are #defined to
_aligned_mallocand can be ignored, but there still several in the rest of the code.
I think portable code should try sticking to C11 aligned_malloc(). BTW, _aligned_malloc (with "_") only supports power-of-2 alignment.
There's a related passage in MSVC blog:
Due to the nature of the Windows heap, aligned_alloc support is missing. The alternative is to use _aligned_malloc.
https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
* Sockets are unfortunately specified as using
close(). This is probably easy to address byrte_wrapping all socket calls.Which public DPDK APIs operate on sockets?
I don't like the idea of wrapping APIs like sockets or files.I'm not sure about use in public APIs - I'd hope none do. I was thinking about 'internal' use.
This is important (even more so for SPDK, I suspect), however, I'd like to focus on public API first.
Quoted 7 lines
Quoted 7 lines
I drafted what I was talking about: adding address types and removing shims:
*
librte_net/rte_ip.hthen includes <netinet/ip.h> or <ws2tcpip.h> conditionally forAF_xxx,IPPROTO_xxx, and a few other constants. That's probably OK, there are similar places for Linux/FreeBSD differences, e.g. in <rte_endian.h>.
Quoted 5 lines
Quoted 4 lines
* Some
IPPROTO_xxxconstants are missing on Windows, sorte_ip.hhas to provide them. I hope Mirosoft will add them to system headers one day.* It affects cmdline (mostly), ethdev, security,
crypto/dpaax.Sounds good - well done!
...or not :)
If we can't help including <ws2tcpip.h>/<netinet/ip.h> from public headers, might as well use struct in_addr, just replace #include <netinet/ip.h> with #include <rte_ip.h> everywhere.
The only remaining issue will be s_addr macro on Windows that conflicts with struct rte_ether_addr field s_addr. I don't know a better solution than renaming s_addr to src_addr in DPDK (OTOH, it will be consistent with struct rte_ipvX_hdr field naming).
Ferruh, what do you think?
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Quoted 45 lines · Dmitry Kozlyuk
2021-03-02 11:22, Nick Connolly:
Quoted 4 lines
Quoted 1 line
Is
posix_memalign()used more extensively in SPDK? In DPDK, it's 2 PMDs:Yes, there are about 80 references. A lot are in ISA-L where they are #defined to
_aligned_mallocand can be ignored, but there still several in the rest of the code.I think portable code should try sticking to C11
aligned_malloc(). BTW,_aligned_malloc(with "_") only supports power-of-2 alignment.There's a related passage in MSVC blog:
Due to the nature of the Windows heap,
aligned_allocsupport is missing. The alternative is to use_aligned_malloc.https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
* Sockets are unfortunately specified as using
close(). This is probably easy to address byrte_wrapping all socket calls.Which public DPDK APIs operate on sockets?
I don't like the idea of wrapping APIs like sockets or files.I'm not sure about use in public APIs - I'd hope none do. I was thinking about 'internal' use.
This is important (even more so for SPDK, I suspect), however, I'd like to focus on public API first.
Quoted 7 lines
Quoted 7 lines
I drafted what I was talking about: adding address types and removing shims:
*
librte_net/rte_ip.hthen includes <netinet/ip.h> or <ws2tcpip.h> conditionally forAF_xxx,IPPROTO_xxx, and a few other constants. That's probably OK, there are similar places for Linux/FreeBSD differences, e.g. in <rte_endian.h>.Quoted 5 lines
Quoted 4 lines
* Some
IPPROTO_xxxconstants are missing on Windows, sorte_ip.hhas to provide them. I hope Mirosoft will add them to system headers one day.* It affects cmdline (mostly), ethdev, security,
crypto/dpaax.Sounds good - well done!
...or not :)
If we can't help including <ws2tcpip.h>/<netinet/ip.h> from public headers, might as well use
struct in_addr, just replace#include <netinet/ip.h>with#include <rte_ip.h>everywhere.
Quoted 7 lines
The only remaining issue will be
s_addrmacro on Windows that conflicts withstruct rte_ether_addrfields_addr. I don't know a better solution than renamings_addrtosrc_addrin DPDK (OTOH, it will be consistent withstruct rte_ipvX_hdrfield naming).Ferruh, what do you think?
No problem on the chosen name, that will work fine, but the 'struct rte_eth_addr' is public struct, we can't rename it without breaking the user applications.
Still it is possible to rename public struct, but it is a long process, need to send a deprecation notice and wait for next LTS, 21.11.
Ethernet header already has following, doesn't it help:
#undef s_addr /* Defined in winsock2.h included in windows.h. */
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-03-03 16:47, Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 16 lines
Quoted 11 lines
If we can't help including <ws2tcpip.h>/<netinet/ip.h> from public headers, might as well use
struct in_addr, just replace#include <netinet/ip.h>with#include <rte_ip.h>everywhere.The only remaining issue will be
s_addrmacro on Windows that conflicts withstruct rte_ether_addrfields_addr. I don't know a better solution than renamings_addrtosrc_addrin DPDK (OTOH, it will be consistent withstruct rte_ipvX_hdrfield naming).Ferruh, what do you think?
No problem on the chosen name, that will work fine, but the 'struct
rte_eth_addr' is public struct, we can't rename it without breaking the user applications.
Quoted 5 lines
Still it is possible to rename public struct, but it is a long process, need to send a deprecation notice and wait for next LTS, 21.11.
Ethernet header already has following, doesn't it help:
#undefs_addr/* Defined inwinsock2.hincluded inwindows.h. */
It helps until you do the following:
#include <winsock2.h> /* #define s_addr S_un.S_addr */ #include <rte_ether.h> /* #undef s_addr */ struct in_addr a; a.s_addr = 0; /* ERROR, `s_addr` has been defined to do that */
Or the following:
#include <rte_ether.h> #include <winsock2.h> struct rte_ether_hdr eh; eh.s_addr.addr_bytes[0] = 0; /* ERROR: `addr_s` is a macro */
If you swap include order in each case, it compiles, i.e . code is fragile. Shims redefine struct in_addr and we're trying to get rid of them anyway.
Here's a solution that always works, however ugly it looks. It defines struct rte_ether_hdr for Windows such that s_addr macro works for it if defined. We can keep it until 21.11, then remove it and rename fields. In return, we can remove networking shims and workarounds immediately.
S_un.S_addr part of struct in_addr is documented, and thus is unlikely to ever change:
https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-in_addr
lib/librte_net/rte_ether.h +24 -4
@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */
@@ -257,6 +253,8 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +#if !definedRTE_EXEC_ENV_WINDOWS || defined __DOXYGEN__ +/** * Ethernet header: Contains the destination address, source address * and frame type.
@@ -267,6 +265,28 @@ struct rte_ether_hdr {uint16_t ether_type;/**< Frame type. */ } __rte_aligned(2); +#else + +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif + +struct rte_ether_hdr { +struct rte_ether_addr d_addr;/**< Destination address. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_un; + } S_addr; + }; + uint16_t ether_type; /**< Frame type. */ +}__rte_aligned (2 ); + +#pragma pop_macro("s_addr") +#endif +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Quoted 35 lines · Dmitry Kozlyuk
2021-03-03 16:47, Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 16 lines
Quoted 11 lines
If we can't help including <ws2tcpip.h>/<netinet/ip.h> from public headers, might as well use
struct in_addr, just replace#include <netinet/ip.h>with#include <rte_ip.h>everywhere.The only remaining issue will be
s_addrmacro on Windows that conflicts withstruct rte_ether_addrfields_addr. I don't know a better solution than renamings_addrtosrc_addrin DPDK (OTOH, it will be consistent withstruct rte_ipvX_hdrfield naming).Ferruh, what do you think?
No problem on the chosen name, that will work fine, but the 'struct
rte_eth_addr' is public struct, we can't rename it without breaking the user applications.Quoted 5 lines
Still it is possible to rename public struct, but it is a long process, need to send a deprecation notice and wait for next LTS, 21.11.
Ethernet header already has following, doesn't it help:
#undefs_addr/* Defined inwinsock2.hincluded inwindows.h. */It helps until you do the following:
#include <winsock2.h> /* #define s_addr S_un.S_addr */ #include <rte_ether.h> /* #undef s_addr */ struct in_addr a; a.s_addr = 0; /* ERROR, `s_addr` has been defined to do that */Or the following:
Quoted 9 lines
#include <rte_ether.h> #include <winsock2.h> struct rte_ether_hdr eh; eh.s_addr.addr_bytes[0] = 0; /* ERROR: `addr_s` is a macro */If you swap include order in each case, it compiles, i.e . code is fragile. Shims redefine
struct in_addrand we're trying to get rid of them anyway.
Got it, thanks for clarification.
Quoted 6 lines
Here's a solution that always works, however ugly it looks. It defines
struct rte_ether_hdrfor Windows such thats_addrmacro works for it if defined. We can keep it until 21.11, then remove it and rename fields. In return, we can remove networking shims and workarounds immediately.
Agree it looks ugly :), but I am OK with above plan.
You need to send a deprecation notice for this. We can discuss there if 'd_addr' also should be renamed for consistency, or leave with the workaround instead of rename ...
Quoted 31 lines
S_un.S_addrpart ofstruct in_addris documented, and thus is unlikely to ever change:https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-in_addr
lib/librte_net/rte_ether.h +2
-4@@ -23,10 +23,6 @@ extern "C" {#include <rte_mbuf.h> #include <rte_byteorder.h> -#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */ -#undef s_addr/* Defined in winsock2.h included in windows.h. */ -#endif -#define RTE_ETHER_ADDR_LEN 6/**< Length of Ethernet address. */ #define RTE_ETHER_TYPE_LEN 2/**< Length of Ethernet type field. */ #define RTE_ETHER_CRC_LEN 4/**< Length of Ethernet CRC. */ @@ -257,6 +253,8 @@ __rte_experimentalint rte_ether_unformat_addr (const char *str,struct rte_ether_addr *eth_addr); +#if !definedRTE_EXEC_ENV_WINDOWS || defined __DOXYGEN__ +/** * Ethernet header: Contains the destination address, source address * and frame type.
lib/librte_net/rte_ether.h struct rte_ether_hdr { · line 273
Quoted 9 lines
lib/librte_net/rte_ether.h +6
-0@@ -267,6 +265,28 @@ struct rte_ether_hdr { uint16_t ether_type; /**< Frame type. */ }__rte_aligned (2 ); +#else + +#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif
I guess this needs to be as following, in case this header included before the windows header:
#ifdef s_addr
#pragma push_macro("s_addr")
#undef s_addr
#endif
Quoted 20 lines
lib/librte_net/rte_ether.h +16
-0+ +struct rte_ether_hdr { +struct rte_ether_addr d_addr;/**< Destination address. */ + RTE_STD_C11 + union { +struct rte_ether_addr s_addr;/**< Source address. */ +struct { +struct rte_ether_addr S_un; + } S_addr; + }; +uint16_t ether_type;/**< Frame type. */ +} __rte_aligned(2); + +#pragma pop_macro("s_addr") +#endif +/** * Ethernet VLAN Header. * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
2021-03-03 19:30, Ferruh Yigit:
Quoted 3 lines · Dmitry Kozlyuk
Quoted 2 lines
2021-03-03 16:47, Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 8 lines
lib/librte_net/rte_ether.h struct rte_ether_hdr { · line 273
Quoted 4 lines
lib/librte_net/rte_ether.h +4
-0+#pragma push_macro("s_addr") +#ifdef s_addr +#undef s_addr +#endif I guess this needs to be as following, in case this header included before the windows header:
Quoted 4 lines
#ifdef
s_addr
#pragmapush_macro("s_addr")
#undefs_addr
#endif
It actually works both ways.
I used #ifdef inside so that #pragma pop_macro doesn't need its own guard.
PATCH v2 5/6 config: discover libpcap on Windows
In reply to Dmitry KozlyukWinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.
--- config/meson.build | 21 ++++++++++++++++++--- meson_options.txt | 6 ++++-- 2 files changed, 22 insertions(+), 5 deletions(-)
config/meson.build +18 -3
@@ -178,9 +178,24 @@ if not pcap_dep.found() # pcap got a pkg-config file only in 1.9.0 pcap_dep = cc.find_library('pcap', required: false) endif -if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) - dpdk_conf.set('RTE_PORT_PCAP', 1) - dpdk_extra_ldflags += '-lpcap' +if is_windows + # npcap SDK can be installed anywhere + pcap_sdk = get_option('pcap_sdk') + if pcap_sdk != '' + pcap_ldflags = ['-L@0@/Lib/x64'.format(pcap_sdk), '-lwpcap'] + pcap_dep = declare_dependency( + compile_args: ['-I@0@/Include'.format(pcap_sdk)], + link_args: pcap_ldflags) + endif + if pcap_dep.found() + dpdk_conf.set('RTE_PORT_PCAP', 1) + dpdk_extra_ldflags += pcap_ldflags + endif +else + if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) + dpdk_conf.set('RTE_PORT_PCAP', 1) + dpdk_extra_ldflags += '-lpcap' + endif endif # for clang 32-bit compiles we need libatomic for 64-bit atomic ops
meson_options.txt +4 -2
@@ -10,6 +10,8 @@ option('enable_docs', type: 'boolean', value: false, description: 'build documentation') option('enable_kmods', type: 'boolean', value: false, description: 'build kernel modules') +option('enable_trace_fp', type: 'boolean', value: false, + description: 'enable fast path trace points.') option('examples', type: 'string', value: '', description: 'Comma-separated list of examples to build by default') option('flexran_sdk', type: 'string', value: '',
@@ -28,8 +30,8 @@ option('max_lcores', type: 'integer', value: 128, description: 'maximum number of cores/threads supported by EAL') option('max_numa_nodes', type: 'integer', value: 32, description: 'maximum number of NUMA nodes supported by EAL') -option('enable_trace_fp', type: 'boolean', value: false, - description: 'enable fast path trace points.') +option('pcap_sdk', type: 'string', value: '', + description: 'Path to libpcap SDK used on Windows') option('tests', type: 'boolean', value: true, description: 'build unit tests') option('use_hpet', type: 'boolean', value: false,
Signature · 1 line
2.29.2
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
Quoted 3 lines · Dmitry Kozlyuk
WinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.
I am not sure if it is OK to add a meson option for this, can't we use the default path?
And does this mean we will need to add an option for each dependent library in Windows? If not, why pcap is special?
Quoted 1 line
Signed-off-by Dmitry Kozlyuk <[email protected]>
<...>
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
2021-02-25 15:02, Ferruh Yigit:
Quoted 10 lines · Dmitry Kozlyuk
Quoted 3 lines
WinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.I am not sure if it is OK to add a meson option for this, can't we use the default path?
And does this mean we will need to add an option for each dependent library in Windows? If not, why pcap is special?
There are some meson options for SDK paths already. Are they exceptions?
IMO, explicit specification is better because it allows switching dependency versions and library distributions.
I understand that consensus it to keep build matrix size at minimum, but options to specify SDK path don't change the number of variants what can be found.
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
Quoted 6 lines · Dmitry Kozlyuk
2021-02-25 15:02, Ferruh Yigit:
Quoted 5 lines · Dmitry Kozlyuk
Quoted 3 lines
WinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.
Quoted 8 lines
Quoted 5 lines
I am not sure if it is OK to add a meson option for this, can't we use the default path?
And does this mean we will need to add an option for each dependent library in Windows? If not, why pcap is special?
There are some meson options for SDK paths already. Are they exceptions?
Right now, yes, they are exceptions, but there is work underway to remove them and just replace them with use of pkg-config. Is there some automatic path discovery mechanism on windows, similar to pkg-config, that can be used rather than having to add explicit dependency paths?
/bruce
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
2021-02-25 16:33, Bruce Richardson:
Quoted 13 lines · Dmitry Kozlyuk
Quoted 12 lines
2021-02-25 15:02, Ferruh Yigit:
Quoted 10 lines · Dmitry Kozlyuk
Quoted 3 lines
WinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.I am not sure if it is OK to add a meson option for this, can't we use the default path?
And does this mean we will need to add an option for each dependent library in Windows? If not, why pcap is special?
Quoted 6 lines
Quoted 2 lines
There are some meson options for SDK paths already. Are they exceptions?
Right now, yes, they are exceptions, but there is work underway to remove them and just replace them with use of pkg-config. Is there some automatic path discovery mechanism on windows, similar to pkg-config, that can be used rather than having to add explicit dependency paths?
pkg-config itself works on Windows if installed and given a PKG_CONFIG_PATH.
Npcap doesn't provide a .pc file, despite libpcap commit 4f6b2b99 having it. Another quirk is that library is named libpcap.a/wpcap.lib on Unix/Windows. I can just handle the name difference and assume it's in the search path.
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
25/02/2021 18:42, Dmitry Kozlyuk:
Quoted 16 lines
2021-02-25 16:33, Bruce Richardson:
Quoted 15 lines · Dmitry Kozlyuk
Quoted 14 lines
2021-02-25 15:02, Ferruh Yigit:
Quoted 10 lines · Dmitry Kozlyuk
Quoted 3 lines
WinPcap or Npcap, can be installed anywhere.
Add a Meson option to specify SDK path.I am not sure if it is OK to add a meson option for this, can't we use the default path?
And does this mean we will need to add an option for each dependent library in Windows? If not, why pcap is special?
There are some meson options for SDK paths already. Are they exceptions?
Quoted 8 lines
Quoted 4 lines
Right now, yes, they are exceptions, but there is work underway to remove them and just replace them with use of pkg-config. Is there some automatic path discovery mechanism on windows, similar to pkg-config, that can be used rather than having to add explicit dependency paths?
pkg-config itself works on Windows if installed and given a
PKG_CONFIG_PATH.Npcap doesn't provide a .pc file, despite libpcap commit
4f6b2b99having it.
Please work with them to provide a .pc.
Quoted 2 lines
Another quirk is that library is named libpcap.a/wpcap.lib on Unix/Windows. I can just handle the name difference and assume it's in the search path.
Yes please avoid adding a meson option for a path.
Re: [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows
2021-03-16 10:16 (UTC+0100), Thomas Monjalon:
Quoted 5 lines
25/02/2021 18:42, Dmitry Kozlyuk:
Quoted 4 lines
2021-02-25 16:33, Bruce Richardson:
Quoted 3 lines · Dmitry Kozlyuk
Quoted 2 lines
2021-02-25 15:02, Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 5 lines
Quoted 3 lines
pkg-config itself works on Windows if installed and given a
PKG_CONFIG_PATH.Npcap doesn't provide a .pc file, despite libpcap commit
4f6b2b99having it.Please work with them to provide a .pc.
Good idea, but I can't tell how soon they do'll it.
Quoted 4 lines
Quoted 2 lines
Another quirk is that library is named libpcap.a/wpcap.lib on Unix/Windows. I can just handle the name difference and assume it's in the search path.
Yes please avoid adding a meson option for a path.
I have v3 that relies on search paths only with just a library name fixup. It's blocked by [2] and, transitively, by [1].
[1]: http://patchwork.dpdk.org/project/dpdk/list/?series=15513
[1]: http://patchwork.dpdk.org/project/dpdk/list/?series=15640
PATCH v2 6/6 net/pcap: build on Windows
In reply to Dmitry KozlyukImplement OS-dependent functions and enable PMD build on Windows.
--- drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 4 - drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 10 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.c
drivers/net/pcap/meson.build +5 -6
@@ -1,19 +1,18 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endif
drivers/net/pcap/pcap_ethdev.c +0 -4
@@ -127,10 +127,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static int eth_pcap_rx_jumbo (struct rte_mempool *mb_pool,struct rte_mbuf *mbuf,const uint8_t *data,uint16_t data_len)
drivers/net/pcap/pcap_osdep.h +5 -0
@@ -8,6 +8,11 @@#include <rte_ether.h> #include <rte_time.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +/* * Interface manipulation is always OS-specific. */
drivers/net/pcap/pcap_osdep_windows.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.29.2
v3 cover net/pcap: build on Windows
In reply to Dmitry KozlyukNOTE: dependency patches are requirements, CI may fail.
Most modern and actively maintained distribution of libpcap for Windows is Npcap [1]. It currently doesn't provide a pkg-config file [2]. By default it is installed to C:\Program Files\Npcap and can be located using standard environment variables [3]:
$env:C_INCLUDE_PATH += ";C:\Program Files\Npcap"
$env:LIBRARY_PATH += ";C:\Program Files\Npcap\Lib\x64" # MinGW
$env:LINK += ' /LIBPATH:"C:\Program Files\Npcap\Lib\x64"' # ClangThe following libpcap.pc also works if placed in PKG_CONFIG_PATH:
prefix="C:/Program Files/Npcap"
Name: libpcap
Version: 1.10
Description: Platform-independent network traffic capture library
Cflags: -I${prefix}/Include
Libs: -L${prefix}/Lib/x64 -lwpcapExample of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe `
--vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" `
--vdev "eth_pcap1,tx_pcap=capture.pcap"Interface name can be obtained as follows, with Wireshark installed:
& "C:\Program Files\Wireshark\tshark.exe" -D
Implementation in "pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.
[1]: https://nmap.org/npcap
[2]: https://github.com/nmap/npcap/issues/299
[3]: https://mesonbuild.com/Reference-manual.html#compiler-object
Depends-on: series-15801 ("eal/windows: do not expose POSIX symbols")
Depends-on: patch-89639 ("[v2,3/3] meson: remove unnecessary explicit link to libpcap")
v3:
* Use environment and pkg-config to locate libpcap (Bruce).
* Use C11 timespec_get() instead of EAL wrapper.
* Drop libpcap wrappers in net/pcap (Ferruh).
Dmitry Kozlyuk (3):
eal/windows: add timespec_get shim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
config/meson.build | 3 +-
doc/guides/rel_notes/release_21_05.rst | 4 +
drivers/net/pcap/meson.build | 16 +--
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 109 +++-------------
drivers/net/pcap/pcap_osdep.h | 18 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++
.../windows/include/rte_os_internal.h | 32 +++++
9 files changed, 303 insertions(+), 98 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.c
create mode 100644 drivers/net/pcap/pcap_osdep_windows.cSignature · 1 line
2.29.3
PATCH v3 1/3 eal/windows: add timespec_get shim for MinGW
MinGW-w64 does not currently implement C11 timespec_get. Add an internal shim until this is fixed on MinGW side.
--- .../windows/include/rte_os_internal.h | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+)
lib/librte_eal/windows/include/rte_os_internal.h +32 -0
@@ -3,7 +3,10 @@#ifndef _RTE_OS_INTERNAL_H_#define _RTE_OS_INTERNAL_H_ +#include <time.h> +#include <rte_os.h> +#include <rte_windows.h> /** * @file
@@ -33,4 +36,33 @@#define IPPROTO_SCTP 132#endif +#ifdef RTE_TOOLCHAIN_GCC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get (struct timespec *now,int base) +{ +/* 100ns ticks from 1601-01-01 to 1970-01-01 */ +static const uint64_t EPOCH =116444736000000000ULL ; +static const uint64_t TICKS_PER_SEC =10000000 ; +static const uint64_t NS_PER_TICK =100 ; + +FILETIME ft; +uint64_t ticks; + +if (base !=TIME_UTC ) +return 0 ; + +GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + ticks -=EPOCH ; + now->tv_sec = ticks /TICKS_PER_SEC ; + now->tv_nsec = (ticks - now->tv_sec *TICKS_PER_SEC ) *NS_PER_TICK ; +return base; +} + +#define timespec_get (ts, base) rte_timespec_get(ts, base) + +#endif /* RTE_TOOLCHAIN_GCC */ #endif /* _RTE_OS_INTERNAL_H_ */
Signature · 1 line
2.29.3
PATCH v3 2/3 net/pcap: move OS-dependent code to separate files
In reply to Dmitry KozlyukPCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. This PMD also depends on POSIX bits, namely gettimeofday() and NAME_MAX.
Move OS-dependent code to separate files.
Replace POSIX bits with DPDK equivalents.
Rename rte_eth_pcap.c to pcap_ethdev.c, like it is in most other PMDs.
---
drivers/net/pcap/meson.build | 5 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 105 ++++--------------
drivers/net/pcap/pcap_osdep.h | 13 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 ++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
5 files changed, 137 insertions(+), 87 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.cdrivers/net/pcap/meson.build +4 -1
@@ -11,5 +11,8 @@ if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif -sources = files('rte_eth_pcap.c') +sources = files( + 'pcap_ethdev.c', + 'pcap_osdep_@[email protected]'.format(exec_env), +) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c renamed from drivers/net/pcap/rte_eth_pcap.c +19 -86
171 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#ifndef _RTE_PCAP_OSDEP_ +#define _RTE_PCAP_OSDEP_ + +#include <rte_ether.h> + +int osdep_iface_index_get (const char *name); +int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c new file +59 -0
59 lines not on this page · raw message
drivers/net/pcap/pcap_osdep_linux.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.29.3
PATCH v3 3/3 net/pcap: build on Windows
In reply to Dmitry KozlyukImplement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions.
--- config/meson.build | 3 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 4 - drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 +++++++++++++++++++++++++ 6 files changed, 134 insertions(+), 11 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.c
config/meson.build +2 -1
@@ -179,7 +179,8 @@ endif pcap_dep = dependency('libpcap', required: false, method: 'pkg-config') if not pcap_dep.found() # pcap got a pkg-config file only in 1.9.0 - pcap_dep = cc.find_library('pcap', required: false) + pcap_lib = is_windows ? 'wpcap' : 'pcap' + pcap_dep = cc.find_library(pcap_lib, required: false) endif if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) dpdk_conf.set('RTE_PORT_PCAP', 1)
doc/guides/rel_notes/release_21_05.rst +4 -0
@@ -101,6 +101,10 @@ New Features * Added command to display Rx queue used descriptor count. ``show port (port_id) rxq (queue_id) desc used count`` +* **Enabled libpcap-based PMD on Windows.** + + A libpcap distribution, such as Npcap or WinPcap, is required to run the PMD. + Removed Items -------------
drivers/net/pcap/meson.build +5 -6
@@ -1,18 +1,17 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endif
drivers/net/pcap/pcap_ethdev.c +0 -4
@@ -142,10 +142,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static struct queue_missed_stat *queue_missed_stat_update (struct rte_eth_dev *dev,unsigned int qid) {
drivers/net/pcap/pcap_osdep.h +5 -0
@@ -7,6 +7,11 @@#include <rte_ether.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac);
drivers/net/pcap/pcap_osdep_windows.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.29.3
Quoted 34 lines · Dmitry Kozlyuk
NOTE: dependency patches are requirements, CI may fail.
Most modern and actively maintained distribution of libpcap for Windows is Npcap [1]. It currently doesn't provide a pkg-config file [2]. By default it is installed to C:\Program Files\Npcap and can be located using standard environment variables [3]:
$env:C_INCLUDE_PATH += ";C:\Program Files\Npcap" $env:LIBRARY_PATH += ";C:\Program Files\Npcap\Lib\x64" # MinGW $env:LINK += ' /LIBPATH:"C:\Program Files\Npcap\Lib\x64"' # ClangThe following libpcap.pc also works if placed in
PKG_CONFIG_PATH:prefix="C:/Program Files/Npcap" Name: libpcap Version: 1.10 Description: Platform-independent network traffic capture library Cflags: -I${prefix}/Include Libs: -L${prefix}/Lib/x64 -lwpcapExample of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe ` --vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" ` --vdev "eth_pcap1,tx_pcap=capture.pcap"Interface name can be obtained as follows, with Wireshark installed:
& "C:\Program Files\Wireshark\tshark.exe" -D
Implementation in "
pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.
Quoted 7 lines
[1]: https://nmap.org/npcap
[2]: https://github.com/nmap/npcap/issues/299
[3]: https://mesonbuild.com/Reference-manual.html#compiler-objectDepends-on: series-15801 ("eal/windows: do not expose POSIX symbols")
Depends-on: patch-89639 ("[v2,3/3] meson: remove unnecessary explicit link to libpcap")
Hi Dmitry,
What is the status of the dependent patches, are they merged?
Quoted 26 lines
v3:
* Use environment and pkg-config to locate libpcap (Bruce).
* Use C11timespec_get()instead of EAL wrapper.
* Drop libpcap wrappers in net/pcap (Ferruh).Dmitry Kozlyuk (3):
eal/windows: addtimespec_getshim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on Windowsconfig/meson.build | 3 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 16 +-- .../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 109 +++------------- drivers/net/pcap/pcap_osdep.h | 18 +++ drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++ drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++ drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++ .../windows/include/rte_os_internal.h | 32 +++++ 9 files changed, 303 insertions(+), 98 deletions(-)rename
drivers/net/pcap/{rte_eth_pcap.c=>pcap_ethdev.c} (95%) create mode 100644drivers/net/pcap/pcap_osdep.hcreate mode 100644drivers/net/pcap/pcap_osdep_freebsd.ccreate mode 100644drivers/net/pcap/pcap_osdep_linux.ccreate mode 100644drivers/net/pcap/pcap_osdep_windows.c
2021-04-09 11:51 (UTC+0100), Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 7 lines
Quoted 3 lines
Depends-on: series-15801 ("eal/windows: do not expose POSIX symbols")
Depends-on: patch-89639 ("[v2,3/3] meson: remove unnecessary explicit link to libpcap")Hi Dmitry,
What is the status of the dependent patches, are they merged?
Hi Ferruh,
Not yet, but reviews are progressing.
series-15801 has some acks and no pending changes, probably close to merge. AFAIK, Thomas is now reviewing patch-89639 to improve its description. This series will need a v4 for trivial rebase and to trigger a CI run.
Quoted 9 lines · Dmitry Kozlyuk
2021-04-09 11:51 (UTC+0100), Ferruh Yigit:
Quoted 1 line · Dmitry Kozlyuk
[...]
Quoted 6 lines
Quoted 3 lines
Depends-on: series-15801 ("eal/windows: do not expose POSIX symbols")
Depends-on: patch-89639 ("[v2,3/3] meson: remove unnecessary explicit link to libpcap")Hi Dmitry,
Quoted 9 lines
Quoted 1 line
What is the status of the dependent patches, are they merged?
Hi Ferruh,
Not yet, but reviews are progressing.
series-15801 has some acks and no pending changes, probably close to merge. AFAIK, Thomas is now reviewing patch-89639 to improve its description. This series will need a v4 for trivial rebase and to trigger a CI run.
Thanks Dmitry, cc'ed Thomas.
v4 cover net/pcap: build on Windows
In reply to Dmitry KozlyukMost modern and actively maintained distribution of libpcap for Windows is Npcap [1]. It currently doesn't provide a pkg-config file [2]. By default it is installed to C:\Program Files\Npcap and can be located using standard environment variables [3]:
$env:C_INCLUDE_PATH += ";C:\Program Files\Npcap"
$env:LIBRARY_PATH += ";C:\Program Files\Npcap\Lib\x64" # MinGW
$env:LINK += ' /LIBPATH:"C:\Program Files\Npcap\Lib\x64"' # ClangThe following libpcap.pc also works if placed in PKG_CONFIG_PATH:
prefix="C:/Program Files/Npcap"
Name: libpcap
Version: 1.10
Description: Platform-independent network traffic capture library
Cflags: -I${prefix}/Include
Libs: -L${prefix}/Lib/x64 -lwpcapExample of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe `
--vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" `
--vdev "eth_pcap1,tx_pcap=capture.pcap"Interface name can be obtained as follows, with Wireshark installed:
& "C:\Program Files\Wireshark\tshark.exe" -D
Implementation in "pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.
[1]: https://nmap.org/npcap
[2]: https://github.com/nmap/npcap/issues/299
[3]: https://mesonbuild.com/Reference-manual.html#compiler-object
v4:
* Change libpcap discovery to work without dependent patch.
* Fix memory leak in osdep_iface_mac_get (in v3, actually).
* rte_os_internal.h -> rte_os_shim.h in patch 3/3.
Dmitry Kozlyuk (3):
eal/windows: add timespec_get shim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
config/meson.build | 5 +-
doc/guides/rel_notes/release_21_05.rst | 4 +
drivers/net/pcap/meson.build | 16 +--
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 109 +++-------------
drivers/net/pcap/pcap_osdep.h | 18 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++
lib/librte_eal/windows/include/rte_os_shim.h | 32 +++++
9 files changed, 304 insertions(+), 99 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.c
create mode 100644 drivers/net/pcap/pcap_osdep_windows.cSignature · 1 line
2.29.3
PATCH v4 1/3 eal/windows: add timespec_get shim for MinGW
MinGW-w64 does not currently implement C11 timespec_get. Add an internal shim until this is fixed on MinGW side.
--- lib/librte_eal/windows/include/rte_os_shim.h | 32 ++++++++++++++++++++ 1 file changed, 32 insertions(+)
lib/librte_eal/windows/include/rte_os_shim.h +32 -0
@@ -3,7 +3,10 @@#ifndef _RTE_OS_SHIM_#define _RTE_OS_SHIM_ +#include <time.h> +#include <rte_os.h> +#include <rte_windows.h> /** * @file
@@ -33,4 +36,33 @@#define IPPROTO_SCTP 132#endif +#ifdef RTE_TOOLCHAIN_GCC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get (struct timespec *now,int base) +{ +/* 100ns ticks from 1601-01-01 to 1970-01-01 */ +static const uint64_t EPOCH =116444736000000000ULL ; +static const uint64_t TICKS_PER_SEC =10000000 ; +static const uint64_t NS_PER_TICK =100 ; + +FILETIME ft; +uint64_t ticks; + +if (base !=TIME_UTC ) +return 0 ; + +GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + ticks -=EPOCH ; + now->tv_sec = ticks /TICKS_PER_SEC ; + now->tv_nsec = (ticks - now->tv_sec *TICKS_PER_SEC ) *NS_PER_TICK ; +return base; +} + +#define timespec_get (ts, base) rte_timespec_get(ts, base) + +#endif /* RTE_TOOLCHAIN_GCC */ #endif /* _RTE_OS_SHIM_ */
Signature · 1 line
2.29.3
PATCH v4 2/3 net/pcap: move OS-dependent code to separate files
In reply to Dmitry KozlyukPCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. This PMD also depends on POSIX bits, namely gettimeofday() and NAME_MAX.
Move OS-dependent code to separate files.
Replace POSIX bits with DPDK equivalents.
Rename rte_eth_pcap.c to pcap_ethdev.c, like it is in most other PMDs.
---
drivers/net/pcap/meson.build | 5 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 104 +++---------------
drivers/net/pcap/pcap_osdep.h | 13 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 ++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
5 files changed, 136 insertions(+), 87 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.cdrivers/net/pcap/meson.build +4 -1
@@ -11,5 +11,8 @@ if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif -sources = files('rte_eth_pcap.c') +sources = files( + 'pcap_ethdev.c', + 'pcap_osdep_@[email protected]'.format(exec_env), +) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c renamed from drivers/net/pcap/rte_eth_pcap.c +18 -86
170 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#ifndef _RTE_PCAP_OSDEP_ +#define _RTE_PCAP_OSDEP_ + +#include <rte_ether.h> + +int osdep_iface_index_get (const char *name); +int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c new file +59 -0
59 lines not on this page · raw message
drivers/net/pcap/pcap_osdep_linux.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.29.3
PATCH v4 3/3 net/pcap: build on Windows
In reply to Dmitry KozlyukImplement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions.
---
Tyler, IIRC you were reviewing the code?
This patch is the most important one but surprisingly has no acks.
--- config/meson.build | 5 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 5 +- drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 +++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.c
config/meson.build +3 -2
@@ -182,13 +182,14 @@ endif # check for pcap pcap_dep = dependency('libpcap', required: false, method: 'pkg-config') +pcap_lib = is_windows ? 'wpcap' : 'pcap' if not pcap_dep.found() # pcap got a pkg-config file only in 1.9.0 - pcap_dep = cc.find_library('pcap', required: false) + pcap_dep = cc.find_library(pcap_lib, required: false) endif if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) dpdk_conf.set('RTE_PORT_PCAP', 1) - dpdk_extra_ldflags += '-lpcap' + dpdk_extra_ldflags += '-l@0@'.format(pcap_lib) endif # for clang 32-bit compiles we need libatomic for 64-bit atomic ops
doc/guides/rel_notes/release_21_05.rst +4 -0
@@ -174,6 +174,10 @@ New Features * Added command to display Rx queue used descriptor count. ``show port (port_id) rxq (queue_id) desc used count`` +* **Enabled libpcap-based PMD on Windows.** + + A libpcap distribution, such as Npcap or WinPcap, is required to run the PMD. + Removed Items -------------
drivers/net/pcap/meson.build +5 -6
@@ -1,18 +1,17 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endif
drivers/net/pcap/pcap_ethdev.c +1 -4
@@ -15,6 +15,7 @@#include <rte_malloc.h> #include <rte_mbuf.h> #include <rte_bus_vdev.h> +#include <rte_os_shim.h> #include "pcap_osdep.h"
@@ -141,10 +142,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static struct queue_missed_stat *queue_missed_stat_update (struct rte_eth_dev *dev,unsigned int qid) {
drivers/net/pcap/pcap_osdep.h +5 -0
@@ -7,6 +7,11 @@#include <rte_ether.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac);
drivers/net/pcap/pcap_osdep_windows.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.29.3
Quoted 4 lines · Dmitry Kozlyuk
Implement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions.
Signed-off-by Dmitry Kozlyuk <[email protected]>
Quoted 242 lines
---
Tyler, IIRC you were reviewing the code?
This patch is the most important one but surprisingly has no acks.--- config/meson.build | 5 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 5 +- drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 +++++++++++++++++++++++++ 6 files changed, 136 insertions(+), 12 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.cconfig/meson.build +3
-2@@ -182,13 +182,14 @@ endif # check for pcap pcap_dep = dependency('libpcap', required: false, method: 'pkg-config') +pcap_lib = is_windows ? 'wpcap' : 'pcap' if not pcap_dep.found() # pcap got a pkg-config file only in 1.9.0 - pcap_dep = cc.find_library('pcap', required: false) + pcap_dep = cc.find_library(pcap_lib, required: false) endif if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) dpdk_conf.set('RTE_PORT_PCAP', 1) - dpdk_extra_ldflags += '-lpcap' + dpdk_extra_ldflags += '-l@0@'.format(pcap_lib) endif # for clang 32-bit compiles we need libatomic for 64-bit atomic opsdoc/guides/rel_notes/release_21_05.rst +4
-0@@ -174,6 +174,10 @@ New Features * Added command to display Rx queue used descriptor count. ``show port (port_id) rxq (queue_id) desc used count`` +* **Enabled libpcap-based PMD on Windows.** + + A libpcap distribution, such as Npcap or WinPcap, is required to run the PMD. + Removed Items -------------drivers/net/pcap/meson.build +5
-6@@ -1,18 +1,17 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endifdrivers/net/pcap/pcap_ethdev.c +1
-4@@ -15,6 +15,7 @@#include <rte_malloc.h> #include <rte_mbuf.h> #include <rte_bus_vdev.h> +#include <rte_os_shim.h> #include "pcap_osdep.h" @@ -141,10 +142,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static struct queue_missed_stat *queue_missed_stat_update (struct rte_eth_dev *dev,unsigned int qid) {drivers/net/pcap/pcap_osdep.h +5
-0@@ -7,6 +7,11 @@#include <rte_ether.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac);drivers/net/pcap/pcap_osdep_windows.c new file +118
-0@@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#include <winsock2.h> +#include <iphlpapi.h> +#include <strsafe.h> + +#include "pcap_osdep.h" + +/* +* Given a device name like "\Device\NPF_{GUID}" extract the "{GUID}" part. +* Return NULL if "{GUID}" part is not found. +*/ +static const char * +iface_guid (const char *name) +{ +static const size_t GUID_LENGTH =32 +4 ;/* 16 hex bytes + 4 dashes */ + +const char *ob, *cb; + + ob =strchr (name,'{' ); +if (ob ==NULL ) +return NULL ; + + cb =strchr (ob,'}' ); +if (cb ==NULL || cb - ob !=GUID_LENGTH +1 )/* + 1 opening '{' */ +return NULL ; + +return ob; +} + +/* +* libpcap takes device names like "\Device\NPF_{GUID}", +* GetAdapterIndex() takes interface names like "\DEVICE\TCPIP_{GUID}". +* Try to convert, fall back to original device name. +*/ +int +osdep_iface_index_get (const char *device_name) +{ +WCHAR adapter_name[MAX_ADAPTER_NAME_LENGTH ]; +const char *guid; +ULONG index; +DWORD ret; + + guid =iface_guid (device_name); +if (guid !=NULL ) +StringCbPrintfW (adapter_name,sizeof (adapter_name), +L"\\DEVICE\\TCPIP_%S" , guid); +else +StringCbPrintfW (adapter_name,sizeof (adapter_name), +L"%S" , device_name); + + ret =GetAdapterIndex (adapter_name, &index); +if (ret !=NO_ERROR ) { +PMD_LOG (ERR ,"GetAdapterIndex(%S) = %lu\n" , adapter_name, ret); +return -1 ; + } + +return index; +} + +/* +* libpcap takes device names like "\Device\NPF_{GUID}", +* GetAdaptersAddresses() returns names in "{GUID}" form. +* Try to extract GUID from device name, fall back to original device name. +*/ +int +osdep_iface_mac_get (const char *device_name,struct rte_ether_addr *mac) +{ +IP_ADAPTER_ADDRESSES *info =NULL , *cur =NULL ; +ULONG size, sys_ret; +const char *adapter_name; +int ret =-1 ; + + sys_ret =GetAdaptersAddresses (AF_UNSPEC ,0 ,NULL ,NULL , &size); +if (sys_ret !=ERROR_BUFFER_OVERFLOW ) { +PMD_LOG (ERR ,"GetAdapterAddresses() = %lu, expected %lu\n" , + sys_ret,ERROR_BUFFER_OVERFLOW ); +return -1 ; + } + + info = (IP_ADAPTER_ADDRESSES *)malloc (size); +if (info ==NULL ) { +PMD_LOG (ERR ,"Cannot allocate adapter address info\n" ); +return -1 ; + } + + sys_ret =GetAdaptersAddresses (AF_UNSPEC ,0 ,NULL , info, &size); +if (sys_ret !=ERROR_SUCCESS ) { +PMD_LOG (ERR ,"GetAdapterAddresses() = %lu\n" , sys_ret); +free (info); +return -1 ; + } + + adapter_name =iface_guid (device_name); +if (adapter_name ==NULL ) + adapter_name = device_name; + +for (cur = info; cur !=NULL ; cur = cur->Next) { +if (strcmp (cur->AdapterName, adapter_name) ==0 ) { +if (cur->PhysicalAddressLength !=RTE_ETHER_ADDR_LEN ) { +PMD_LOG (ERR ,"Physical address length: want %u, got %lu" , +RTE_ETHER_ADDR_LEN , + cur->PhysicalAddressLength); +break ; + } + +memcpy (mac->addr_bytes, cur->PhysicalAddress, +RTE_ETHER_ADDR_LEN ); + ret =0 ; +break ; + } + } + +free (info); +return ret; +}Signature · 1 line
2.29.3
Quoted 41 lines · Dmitry Kozlyuk
Most modern and actively maintained distribution of libpcap for Windows is Npcap [1]. It currently doesn't provide a pkg-config file [2]. By default it is installed to C:\Program Files\Npcap and can be located using standard environment variables [3]:
$env:C_INCLUDE_PATH += ";C:\Program Files\Npcap" $env:LIBRARY_PATH += ";C:\Program Files\Npcap\Lib\x64" # MinGW $env:LINK += ' /LIBPATH:"C:\Program Files\Npcap\Lib\x64"' # ClangThe following libpcap.pc also works if placed in
PKG_CONFIG_PATH:prefix="C:/Program Files/Npcap" Name: libpcap Version: 1.10 Description: Platform-independent network traffic capture library Cflags: -I${prefix}/Include Libs: -L${prefix}/Lib/x64 -lwpcapExample of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe ` --vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" ` --vdev "eth_pcap1,tx_pcap=capture.pcap"Interface name can be obtained as follows, with Wireshark installed:
& "C:\Program Files\Wireshark\tshark.exe" -D
Implementation in "
pcap_osdep_windows.c" does some guesswork to convert between variants of an interface name. Microsoft experts and interested users, please take a look and/or give it a try in your environment.[1]: https://nmap.org/npcap
[2]: https://github.com/nmap/npcap/issues/299
[3]: https://mesonbuild.com/Reference-manual.html#compiler-objectv4:
* Change libpcap discovery to work without dependent patch.
* Fix memory leak inosdep_iface_mac_get(in v3, actually).
*rte_os_internal.h->rte_os_shim.hin patch 3/3.
Quoted 5 lines
Dmitry Kozlyuk (3):
eal/windows: addtimespec_getshim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
Hi Dmitry,
Since the dependent patches merged, I checked/tested the set and it looks good to me, pcap patch already has my review tag.
But not able to test the pcap on Windows. Because if Windows & eal part of the patch, I am delegating it to Thomas in patchwork.
Quoted 16 lines
config/meson.build | 5 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 16 +-- .../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 109 +++------------- drivers/net/pcap/pcap_osdep.h | 18 +++ drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++ drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++ drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++ lib/librte_eal/windows/include/rte_os_shim.h | 32 +++++ 9 files changed, 304 insertions(+), 99 deletions(-)rename
drivers/net/pcap/{rte_eth_pcap.c=>pcap_ethdev.c} (95%) create mode 100644drivers/net/pcap/pcap_osdep.hcreate mode 100644drivers/net/pcap/pcap_osdep_freebsd.ccreate mode 100644drivers/net/pcap/pcap_osdep_linux.ccreate mode 100644drivers/net/pcap/pcap_osdep_windows.c
Quoted 4 lines
Dmitry Kozlyuk (3):
eal/windows: addtimespec_getshim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
Compilation is failing on FreeBSD 11:
http://mails.dpdk.org/archives/test-report/2021-April/188997.html
implicit declaration of function 'timespec_get' is invalid in C99 use of undeclared identifier 'TIME_UTC'
It should be fixed by including time.h
I cannot reproduce the issue with FreeBSD 12.
2021-04-21 00:20 (UTC+0200), Thomas Monjalon:
Quoted 11 lines
Quoted 4 lines
Dmitry Kozlyuk (3):
eal/windows: addtimespec_getshim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on WindowsCompilation is failing on FreeBSD 11:
http://mails.dpdk.org/archives/test-report/2021-April/188997.html
implicit declaration of function 'timespec_get' is invalid in C99 use of undeclared identifier 'TIME_UTC'It should be fixed by including
time.h
No, FreeBSD 11 is missing timespec_get indeed.
Quoted 1 line
I cannot reproduce the issue with FreeBSD 12.
After adding a FreeBSD 11 shim and rebasing over "main" I get another error unrelated to the patch.
It seems FreeBSD 11 is missing pthread_setname_np() as well.
[11/1847] Compiling C object lib/librte_telemetry.a.p/telemetry_telemetry.c.o../src/lib/telemetry/telemetry.c:445:2: warning: implicit declaration of function 'pthread_setname_np' is invalid in C99 [-Wimplicit-function-declaration]
pthread_setname_np(t_old, "telemetry-v1");
^
../src/lib/telemetry/telemetry.c:474:2: warning: implicit declaration of function 'pthread_setname_np' is invalid in C99 [-Wimplicit-function-declaration]
pthread_setname_np(t_new, "telemetry-v2");
^2 warnings generated.
[60/1847] Linking target lib/librte_telemetry.so.21.2
FAILED: lib/librte_telemetry.so.21.2
cc -o lib/librte_telemetry.so.21.2 lib/librte_telemetry.a.p/telemetry_telemetry.c.o lib/librte_telemetry.a.p/telemetry_telemetry_data.c.o lib/librte_telemetry.a.p/telemetry_telemetry_legacy.c.o -Wl,--as-needed -Wl,--no-undefined -Wl,-O1 -shared -fPIC -Wl,--start-group -Wl,-soname,librte_telemetry.so.21 -Wl,--no-as-needed -pthread -lm -lexecinfo -Wl,--end-group -Wl,--version-script=/tmp/src/lib/telemetry/version.map lib/librte_telemetry.a.p/telemetry_telemetry.c.o: In function `rte_telemetry_init':
telemetry.c:(.text.internal+0x15a): undefined reference to `pthread_setname_np'
telemetry.c:(.text.internal+0x24d): undefined reference to `pthread_setname_np'
cc: error: linker command failed with exit code 1 (use -v to see invocation)
21/04/2021 16:53, Dmitry Kozlyuk:
Quoted 21 lines
2021-04-21 00:20 (UTC+0200), Thomas Monjalon:
Quoted 11 lines
Quoted 4 lines
Dmitry Kozlyuk (3):
eal/windows: addtimespec_getshim for MinGW net/pcap: move OS-dependent code to separate files net/pcap: build on WindowsCompilation is failing on FreeBSD 11:
http://mails.dpdk.org/archives/test-report/2021-April/188997.html
implicit declaration of function 'timespec_get' is invalid in C99 use of undeclared identifier 'TIME_UTC'It should be fixed by including
time.hNo, FreeBSD 11 is missing
timespec_getindeed.Quoted 1 line
I cannot reproduce the issue with FreeBSD 12.
After adding a FreeBSD 11 shim and rebasing over "main" I get another error unrelated to the patch.
It seems FreeBSD 11 is missingpthread_setname_np()as well.
Quoted 7 lines
[11/1847] Compiling C object
lib/librte_telemetry.a.p/telemetry_telemetry.c.o../src/lib/telemetry/telemetry.c:445:2: warning: implicit declaration of function 'pthread_setname_np' is invalid in C99 [-Wimplicit-function-declaration]pthread_setname_np(t_old, "telemetry-v1"); ^ ../src/lib/telemetry/telemetry.c:474:2: warning: implicit declaration of function 'pthread_setname_np' is invalid in C99 [-Wimplicit-function-declaration] pthread_setname_np(t_new, "telemetry-v2"); ^
Sorry, that's because I've merged a patch which is failing with FreeBSD < 12.2 and I missed the CI report.
I am fixing with this patch:
https://patches.dpdk.org/project/dpdk/patch/[email protected]/
v5 cover net/pcap: build on Windows
In reply to Dmitry KozlyukMost modern and actively maintained distribution of libpcap for Windows is Npcap [1]. It currently doesn't provide a pkg-config file [2]. By default it is installed to C:\Program Files\Npcap and can be located using standard environment variables [3]:
$env:C_INCLUDE_PATH += ";C:\Program Files\Npcap"
$env:LIBRARY_PATH += ";C:\Program Files\Npcap\Lib\x64" # MinGW
$env:LINK += ' /LIBPATH:"C:\Program Files\Npcap\Lib\x64"' # ClangThe following libpcap.pc also works if placed in PKG_CONFIG_PATH:
prefix="C:/Program Files/Npcap"
Name: libpcap
Version: 1.10
Description: Platform-independent network traffic capture library
Cflags: -I${prefix}/Include
Libs: -L${prefix}/Lib/x64 -lwpcapExample of collecting packets from an interface to a file:
.\build\examples\dpdk-skeleton.exe `
--vdev "eth_pcap0,iface=\Device\NPF_{DDD48985-A77C-4FC9-AF48-61E547C8797E}" `
--vdev "eth_pcap1,tx_pcap=capture.pcap"Interface name can be obtained as follows, with Wireshark installed:
& "C:\Program Files\Wireshark\tshark.exe" -D
[1]: https://nmap.org/npcap
[2]: https://github.com/nmap/npcap/issues/299
[3]: https://mesonbuild.com/Reference-manual.html#compiler-object
v5:
* Add timespec_get() shim for FreeBSD < 12.2 (CI, Thomas).
Dmitry Kozlyuk (3):
eal: add timespec_get shim
net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
config/meson.build | 9 +-
doc/guides/rel_notes/release_21_05.rst | 4 +
drivers/net/pcap/meson.build | 16 +--
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 109 +++-------------
drivers/net/pcap/pcap_osdep.h | 18 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 +++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
drivers/net/pcap/pcap_osdep_windows.c | 118 ++++++++++++++++++
lib/eal/freebsd/include/rte_os_shim.h | 17 +++
lib/eal/windows/include/rte_os_shim.h | 32 +++++
10 files changed, 323 insertions(+), 101 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.c
create mode 100644 drivers/net/pcap/pcap_osdep_windows.cSignature · 1 line
2.29.3
PATCH v5 1/3 eal: add timespec_get shim
C11 timespec_get() is not provided on some platforms:
* MinGW-w64 does not currently implement it [1].
* FreeBSD 11 with Clang 10.0.0 does not provide it.
Add internal shims to Windows and FreeBSD EALs. For Windows, it can be removed after [1] is fixed.
[1]: https://sourceforge.net/p/mingw-w64/mailman/message/37224689/
--- lib/eal/freebsd/include/rte_os_shim.h | 17 ++++++++++++++ lib/eal/windows/include/rte_os_shim.h | 32 +++++++++++++++++++++++++++ 2 files changed, 49 insertions(+)
lib/eal/freebsd/include/rte_os_shim.h +17 -0
@@ -3,6 +3,8 @@#ifndef _RTE_OS_SHIM_#define _RTE_OS_SHIM_ +#include <time.h> +#include <rte_os.h> /**
@@ -11,4 +13,19 @@* Provides semi-standard OS facilities by convenient names. */ +#ifndef TIME_UTC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get (struct timespec *now,int base) +{ +if (base !=TIME_UTC ||clock_gettime (CLOCK_REALTIME , now) <0 ) +return 0 ; +return base; +} + +#define timespec_get (ts, base) rte_timespec_get(ts, base) + +#endif /* !defined TIME_UTC */ #endif /* _RTE_OS_SHIM_ */
lib/eal/windows/include/rte_os_shim.h +32 -0
@@ -3,7 +3,10 @@#ifndef _RTE_OS_SHIM_#define _RTE_OS_SHIM_ +#include <time.h> +#include <rte_os.h> +#include <rte_windows.h> /** * @file
@@ -33,4 +36,33 @@#define IPPROTO_SCTP 132#endif +#ifdef RTE_TOOLCHAIN_GCC + +#define TIME_UTC 1 + +static inline int +rte_timespec_get (struct timespec *now,int base) +{ +/* 100ns ticks from 1601-01-01 to 1970-01-01 */ +static const uint64_t EPOCH =116444736000000000ULL ; +static const uint64_t TICKS_PER_SEC =10000000 ; +static const uint64_t NS_PER_TICK =100 ; + +FILETIME ft; +uint64_t ticks; + +if (base !=TIME_UTC ) +return 0 ; + +GetSystemTimePreciseAsFileTime (&ft); + ticks = ((uint64_t )ft.dwHighDateTime <<32 ) | ft.dwLowDateTime; + ticks -=EPOCH ; + now->tv_sec = ticks /TICKS_PER_SEC ; + now->tv_nsec = (ticks - now->tv_sec *TICKS_PER_SEC ) *NS_PER_TICK ; +return base; +} + +#define timespec_get (ts, base) rte_timespec_get(ts, base) + +#endif /* RTE_TOOLCHAIN_GCC */ #endif /* _RTE_OS_SHIM_ */
Signature · 1 line
2.29.3
PATCH v5 2/3 net/pcap: move OS-dependent code to separate files
In reply to Dmitry KozlyukPCAP PMD queries interface information differently for Linux and FreeBSD, OS-specific code is guarded by #ifdef. This PMD also depends on POSIX bits, namely gettimeofday() and NAME_MAX.
Move OS-dependent code to separate files.
Replace POSIX bits with DPDK equivalents.
Rename rte_eth_pcap.c to pcap_ethdev.c, like it is in most other PMDs.
---
drivers/net/pcap/meson.build | 5 +-
.../pcap/{rte_eth_pcap.c => pcap_ethdev.c} | 104 +++---------------
drivers/net/pcap/pcap_osdep.h | 13 +++
drivers/net/pcap/pcap_osdep_freebsd.c | 59 ++++++++++
drivers/net/pcap/pcap_osdep_linux.c | 42 +++++++
5 files changed, 136 insertions(+), 87 deletions(-)
rename drivers/net/pcap/{rte_eth_pcap.c => pcap_ethdev.c} (95%)
create mode 100644 drivers/net/pcap/pcap_osdep.h
create mode 100644 drivers/net/pcap/pcap_osdep_freebsd.c
create mode 100644 drivers/net/pcap/pcap_osdep_linux.cdrivers/net/pcap/meson.build +4 -1
@@ -11,5 +11,8 @@ if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif -sources = files('rte_eth_pcap.c') +sources = files( + 'pcap_ethdev.c', + 'pcap_osdep_@[email protected]'.format(exec_env), +) ext_deps += pcap_dep
drivers/net/pcap/pcap_ethdev.c renamed from drivers/net/pcap/rte_eth_pcap.c +18 -86
170 lines not on this page · raw message
drivers/net/pcap/pcap_osdep.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2021 Dmitry Kozlyuk +*/ + +#ifndef _RTE_PCAP_OSDEP_ +#define _RTE_PCAP_OSDEP_ + +#include <rte_ether.h> + +int osdep_iface_index_get (const char *name); +int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac); + +#endif
drivers/net/pcap/pcap_osdep_freebsd.c new file +59 -0
59 lines not on this page · raw message
drivers/net/pcap/pcap_osdep_linux.c new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.29.3
PATCH v5 3/3 net/pcap: build on Windows
In reply to Dmitry KozlyukImplement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions.
--- config/meson.build | 9 +- doc/guides/rel_notes/release_21_05.rst | 4 + drivers/net/pcap/meson.build | 11 ++- drivers/net/pcap/pcap_ethdev.c | 5 +- drivers/net/pcap/pcap_osdep.h | 5 ++ drivers/net/pcap/pcap_osdep_windows.c | 118 +++++++++++++++++++++++++ 6 files changed, 138 insertions(+), 14 deletions(-) create mode 100644 drivers/net/pcap/pcap_osdep_windows.c
config/meson.build +5 -4
@@ -180,13 +180,14 @@ endif # check for pcap pcap_dep = dependency('libpcap', required: false, method: 'pkg-config') +pcap_lib = is_windows ? 'wpcap' : 'pcap' if not pcap_dep.found() - # pcap got a pkg-config file only in 1.9.0 - pcap_dep = cc.find_library('pcap', required: false) + # pcap got a pkg-config file only in 1.9.0 + pcap_dep = cc.find_library(pcap_lib, required: false) endif if pcap_dep.found() and cc.has_header('pcap.h', dependencies: pcap_dep) - dpdk_conf.set('RTE_PORT_PCAP', 1) - dpdk_extra_ldflags += '-lpcap' + dpdk_conf.set('RTE_PORT_PCAP', 1) + dpdk_extra_ldflags += '-l@0@'.format(pcap_lib) endif # for clang 32-bit compiles we need libatomic for 64-bit atomic ops
doc/guides/rel_notes/release_21_05.rst +4 -0
@@ -235,6 +235,10 @@ New Features * Added support for crypto adapter forward mode in octeontx2 event and crypto device driver. +* **Enabled libpcap-based PMD on Windows.** + + A libpcap distribution, such as Npcap or WinPcap, is required to run the PMD. + Removed Items -------------
drivers/net/pcap/meson.build +5 -6
@@ -1,18 +1,17 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - if not dpdk_conf.has('RTE_PORT_PCAP') build = false reason = 'missing dependency, "libpcap"' endif + sources = files( 'pcap_ethdev.c', 'pcap_osdep_@[email protected]'.format(exec_env), ) + ext_deps += pcap_dep +if is_windows + ext_deps += cc.find_library('iphlpapi', required: true) +endif
drivers/net/pcap/pcap_ethdev.c +1 -4
@@ -16,6 +16,7 @@#include <rte_mbuf.h> #include <rte_mbuf_dyn.h> #include <rte_bus_vdev.h> +#include <rte_os_shim.h> #include "pcap_osdep.h"
@@ -142,10 +143,6 @@ static struct rte_eth_link pmd_link = {RTE_LOG_REGISTER (eth_pcap_logtype, pmd.net.pcap,NOTICE ); -#define PMD_LOG(level, fmt, args...) \ - rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ - "%s(): " fmt "\n", __func__, ##args) -static struct queue_missed_stat *queue_missed_stat_update (struct rte_eth_dev *dev,unsigned int qid) {
drivers/net/pcap/pcap_osdep.h +5 -0
@@ -7,6 +7,11 @@#include <rte_ether.h> +#define PMD_LOG(level, fmt, args...) \ + rte_log(RTE_LOG_ ## level, eth_pcap_logtype, \ + "%s(): " fmt "\n", __func__, ##args) +extern int eth_pcap_logtype; +int osdep_iface_index_get (const char *name);int osdep_iface_mac_get (const char *name,struct rte_ether_addr *mac);
drivers/net/pcap/pcap_osdep_windows.c new file +118 -0
118 lines not on this page · raw message
Signature · 1 line
2.29.3
Thomas Monjalon
AppliedQuoted 4 lines
Dmitry Kozlyuk (3):
eal: addtimespec_getshim
net/pcap: move OS-dependent code to separate files net/pcap: build on Windows
Unfortunately the CI testing FreeBSD 11 is not running on this series, but I feel it's OK to be part of the 21.05-rc1.
Applied, thanks