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 ABB0AA0546; Sun, 14 Feb 2021 02:21:15 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CBE4D22A238; Sun, 14 Feb 2021 02:20:34 +0100 (CET) Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by mails.dpdk.org (Postfix) with ESMTP id 373CE1CC551 for ; Sun, 14 Feb 2021 02:20:30 +0100 (CET) Received: by mail-lf1-f50.google.com with SMTP id m22so5121436lfg.5 for ; Sat, 13 Feb 2021 17:20:30 -0800 (PST) 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=uildSmbz6KhYXk/qQX0T/5BOxbXRmjh+ijouvFYzO/w=; b=gWnrz3DkdKiDY6xT9Z7RQc3TofLTiwWEum4vCsq3RcUcmZoTpT7Tids/1eoBthi/9j HqpGSKTJy6EaEJkglBzD3gXRTwwgdOL0zyRguSSerivfI11dLwcMgj5od6TeqzKgrL1O 2T+HjTXKa1Vn2kit4xEKM/sUY5vbaqSbsn9wiVcTGFX84pQ79NYvTNClOIftsA1/qlf3 +oTir05VUL8wMuOaMfjViMFpeZ3qz10e4GrIVBg+GVQDhKurqLUQ+N6p3GJO7+TlHgPO q3VytfQoO413fXtFU3gw9DxKebS+7MJR4DdykxUmOLdad5spXWIfq1Wq3jyY7Spx3tly KNqA== 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=uildSmbz6KhYXk/qQX0T/5BOxbXRmjh+ijouvFYzO/w=; b=OErN25CKhyCeJaxyqsfJIr6k07zzsaKW4/QCwBYUxzGnw9TcOx9GNTkiEkyKo2YKG9 gUlGFHeSy2vn7EvY58Hkeux8XA51UAUyAqmy2gYudqBgzlWUMLAezHhBvGRt3+xKlitn /cPcOHpbLe6bGvMjC8SvmyjafrkAcDq5b8lgP+qQPd/nzKjtCUIk/DNSJ+xbSn02wLW+ DwN8V17wXh7XEABtARHE72xy7WYdiM4gqIhJ8uwzDm8Wi5GdrQfLjj/VX/ctPD71kMiY EPtGSl71fENyeJgoDi32t9m8ucPXBm/Q0sn/+u+b92yWYltmlFlIAHge6b5dCqOQIT+f MF4Q== X-Gm-Message-State: AOAM530SPEnv1/PY7BsuutCvPfyZPv7iKzLi2iZn1gWIRZxdYXEDeKG6 sx3u1YfCnrRmy9kIHJhO8uEGH3B7a1EO0A== X-Google-Smtp-Source: ABdhPJwjwHzLA4U+LtuctsMyjV7f9ua7MhzIn+sYIUZfX84rOLaxW7kF45eBgTu/MnjQjmuMGyFP/A== X-Received: by 2002:a19:41cd:: with SMTP id o196mr5353549lfa.30.1613265629566; Sat, 13 Feb 2021 17:20:29 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id h11sm2237648lfd.243.2021.02.13.17.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 13 Feb 2021 17:20:29 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Mike Wells , Dmitry Kozlyuk , Ferruh Yigit Date: Sun, 14 Feb 2021 04:20:13 +0300 Message-Id: <20210214012013.23165-7-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210214012013.23165-1-dmitry.kozliuk@gmail.com> References: <20210214012013.23165-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 6/6] 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 PMD build on Windows. Signed-off-by: Dmitry Kozlyuk --- 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 diff --git a/drivers/net/pcap/meson.build b/drivers/net/pcap/meson.build index 9ab95ec3e..614a4e340 100644 --- a/drivers/net/pcap/meson.build +++ b/drivers/net/pcap/meson.build @@ -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_@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 6461213e0..142533c6e 100644 --- a/drivers/net/pcap/pcap_ethdev.c +++ b/drivers/net/pcap/pcap_ethdev.c @@ -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) diff --git a/drivers/net/pcap/pcap_osdep.h b/drivers/net/pcap/pcap_osdep.h index bd00b728a..f7c311ef8 100644 --- a/drivers/net/pcap/pcap_osdep.h +++ b/drivers/net/pcap/pcap_osdep.h @@ -8,6 +8,11 @@ #include #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; + /* * Interface manipulation is always OS-specific. */ diff --git a/drivers/net/pcap/pcap_osdep_windows.c b/drivers/net/pcap/pcap_osdep_windows.c new file mode 100644 index 000000000..d6557ff73 --- /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() = %lu\n", 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); + return -1; + } + + memcpy(mac->addr_bytes, cur->PhysicalAddress, + RTE_ETHER_ADDR_LEN); + ret = 0; + break; + } + } + + free(info); + return ret; +} -- 2.29.2