From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 84172A0547; Wed, 21 Apr 2021 21:34:20 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id EBD2041BD8; Wed, 21 Apr 2021 21:34:07 +0200 (CEST) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by mails.dpdk.org (Postfix) with ESMTP id 7E20E41BCB for ; Wed, 21 Apr 2021 21:34:04 +0200 (CEST) Received: by mail-lj1-f182.google.com with SMTP id a36so38196709ljq.8 for ; Wed, 21 Apr 2021 12:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DgYUG1IviLn67bKZvJ8nwlazan1auhfSqBRSHoiZ9ro=; b=aHUSlIvf72VHaT1inM06wBl9DK/vuxAigvtlNZkmCUuE6jqhQTDTEGQW1OJVSeqnFb tGQgRnx8ukB16vW7RvHxTeTN9ITArKWvBgvMlb02eUXfbLgZ97y2aH5rEPBfs46QvMa3 MutHZNrJnO6JS/rUgwmydRxz3JIWgaW6CzGU93x/5MJlHWpJCd+574cFU0d687RGK3fZ zXP5rqpMvAAntIfl6UVOWMJFvhJWID2Ru1MoyB5dtOR7zCU7QN96/O00JDwkj4V8l4xk PNCz+fxLqhYu4//N1F3QxNK5x2hvxqlY6lLIAv1Gge9lO1tCmq3mdhqA5XLID3KaBcw5 H5Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DgYUG1IviLn67bKZvJ8nwlazan1auhfSqBRSHoiZ9ro=; b=e0i1buBUY+BIrcOFIZb8JWgbhvIel0+EchhrRQYPP8TlNlBLgcaC0+9pOTzGSu7XDE +/OvP7YpvTBAwn1X3MLUCGAbZd2NKHu77y2+xGENf33SWXeuock5Kp9jKrZFtd/YMxMr XB457W+VZM6i/UzXjcUQil4J3y1H7NJEdwxn1yrgTrg86dqGs8RdARS3lENZk1ROU1wa IrVYNTUSo9XkAxlVMdXTZXRoOxpyd0uei/Vrs7yAPx6rxqTyFaPErU12MmJSDTM1q6vf 7VGzOvKcph6S9dgwm0qj0/NUVNsJDgiZCL6WA4CwNSccy5xL7K7zvoMreYTTB2BTntkd nsjg== X-Gm-Message-State: AOAM5305XsMTU8xYiuLG84Vz2SE93lbuVli4rIepO7InZdhitgfDQFxX wUIw+NsUsiRUi3gyBhCcCKa4zWpyaLpwDg== X-Google-Smtp-Source: ABdhPJx3oCmcOBYYu7eN7Ih56b2xQWHDcYV4rvhd3bG8FOJy4C+Z7NxRYFho6AQKbbNTbtLRs1mX8w== X-Received: by 2002:a2e:8891:: with SMTP id k17mr8844418lji.11.1619033643621; Wed, 21 Apr 2021 12:34:03 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id p11sm47588lfg.126.2021.04.21.12.34.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Apr 2021 12:34:03 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Dmitry Kozlyuk , Tyler Retzlaff , Bruce Richardson , Ferruh Yigit Date: Wed, 21 Apr 2021 22:33:51 +0300 Message-Id: <20210421193351.1909-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.3 In-Reply-To: <20210421193351.1909-1-dmitry.kozliuk@gmail.com> References: <20210415221055.1575-1-dmitry.kozliuk@gmail.com> <20210421193351.1909-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v5 3/3] net/pcap: build on Windows X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Implement OS-dependent functions and enable build for Windows. Account for different library name in Windows libpcap distributions. Signed-off-by: Dmitry Kozlyuk Acked-by: Tyler Retzlaff --- 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 diff --git a/config/meson.build b/config/meson.build index 9e49abc0f8..d31ddef4e4 100644 --- a/config/meson.build +++ b/config/meson.build @@ -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 diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst index 565e764811..3ba8e5ce7d 100644 --- a/doc/guides/rel_notes/release_21_05.rst +++ b/doc/guides/rel_notes/release_21_05.rst @@ -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 ------------- diff --git a/drivers/net/pcap/meson.build b/drivers/net/pcap/meson.build index d02a98b6f4..eec63a9b08 100644 --- a/drivers/net/pcap/meson.build +++ b/drivers/net/pcap/meson.build @@ -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 diff --git a/drivers/net/pcap/pcap_ethdev.c b/drivers/net/pcap/pcap_ethdev.c index 5ff7339e97..883a0c494a 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -16,6 +16,7 @@ #include #include #include +#include #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) { diff --git a/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h index 9de422ab8d..bf41cba982 100644 --- a/drivers/net/pcap/pcap_osdep.h +++ b/drivers/net/pcap/pcap_osdep.h @@ -7,6 +7,11 @@ #include +#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); diff --git a/drivers/net/pcap/pcap_osdep_windows.c b/drivers/net/pcap/pcap_osdep_windows.c new file mode 100644 index 0000000000..1d398dc7ed --- /dev/null +++ b/drivers/net/pcap/pcap_osdep_windows.c @@ -0,0 +1,118 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright (c) 2021 Dmitry Kozlyuk + */ + +#include +#include +#include + +#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; +} -- 2.29.3