net/pcap: build on Windows
Implement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions. Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
This commit is contained in:
parent
436c089a52
commit
b5674be414
@ -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_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
|
||||
|
@ -177,6 +177,10 @@ New Features
|
||||
|
||||
* **Enabled vmxnet3 PMD on Windows.**
|
||||
|
||||
* **Enabled libpcap-based PMD on Windows.**
|
||||
|
||||
A libpcap distribution, such as Npcap or WinPcap, is required to run the PMD.
|
||||
|
||||
* **Updated the AF_XDP driver.**
|
||||
|
||||
* Added support for preferred busy polling.
|
||||
|
@ -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_@0@.c'.format(exec_env),
|
||||
)
|
||||
|
||||
ext_deps += pcap_dep
|
||||
if is_windows
|
||||
ext_deps += cc.find_library('iphlpapi', required: true)
|
||||
endif
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
118
drivers/net/pcap/pcap_osdep_windows.c
Normal file
118
drivers/net/pcap/pcap_osdep_windows.c
Normal file
@ -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;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user