From patchwork Sun Feb 19 23:14:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Hemminger X-Patchwork-Id: 124163 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 0B1A541CE4; Mon, 20 Feb 2023 00:15:08 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7976E42DBF; Mon, 20 Feb 2023 00:14:36 +0100 (CET) Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by mails.dpdk.org (Postfix) with ESMTP id 5035C42D8D for ; Mon, 20 Feb 2023 00:14:28 +0100 (CET) Received: by mail-pj1-f46.google.com with SMTP id o10-20020a17090a744a00b00233ba727724so1258236pjk.1 for ; Sun, 19 Feb 2023 15:14:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=networkplumber-org.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=83D8iYul/29Bw+0iYP33DhWO1Z0u1oDFprj7fb/7FtA=; b=jRhq1YSL0TZVC6iJTPDlWRUb9CMwcFj34S3iiZUjhQ63SeUPC+dT5X5EaGSOgkwdCz /jXPEcPbQ06GZ6fAZU6ImXQ0BifwNUEn876aOJD/LGicirZZvKFiAB26nLXh+0o/fiMm pcpnUXJJPdEDMD0N903O4Hl5pTtcHsiufXoF1DWtcHj2ib5hEMpGTBxyCTnX8wORzq5G 482DcYcMncbh8wxmb1PbiOxA+zrOmG0/qTb39BTUwLbidQ50OBsq6rklCVphS5Vhl6o+ MNxUMs485nwvYpxfi4zxZuI9WYfC+IQL9WqzGifWOH/DJXzAl90PY7OKnpbup3SiGc4F aADQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=83D8iYul/29Bw+0iYP33DhWO1Z0u1oDFprj7fb/7FtA=; b=dO4wc9/lF6OMdDLSB8dsWyrbGyluphCSHFiKeHO1sbiwfRXVwCtTKGi4M1pxjmppXj llsCH0d5QF+CRBOdmkhomK15Zi348YDb5wI/oUPQciLyp9KamKEl1gfnVRAb0UFqjwHJ rO04VXBzvOgNs+fgQZcCrCMHV1UnM9tx2CABqxHstM6VdpSJx5F0c6PzRGqnJM/0+kup aNWXTgGOt4xJy8cOKfmC69hdx578vYJkAYvlNORn7iekzFpQ3fp2tYaNsJRRafbSnOSE edGqpF0qaVsRBwcOJz8ZvxgCOyOitrtCMYf4nx+7qYgxPE4C21wgeePEs+Qdb0QM4Bzx Q+1A== X-Gm-Message-State: AO0yUKUs/HCXLdm+pOSC2/ejRnAo2ppfvIUTcATw9TECCbg/8Rv2v28U VhCQ/jR0g6UJ9/HHJnv8ST7tW2+MfVEWEydUnNM= X-Google-Smtp-Source: AK7set9RHvLAvVnqGqxwA6AmGpsX1v8RFAxSqbEZPP8GLTTrkTb7Rwqd3lqifH1SMca/+sm7a2V51g== X-Received: by 2002:a17:902:da90:b0:19a:a9d8:e49f with SMTP id j16-20020a170902da9000b0019aa9d8e49fmr2781250plx.39.1676848467141; Sun, 19 Feb 2023 15:14:27 -0800 (PST) Received: from hermes.local (204-195-120-218.wavecable.com. [204.195.120.218]) by smtp.gmail.com with ESMTPSA id l10-20020a170902d34a00b00192fe452e17sm683336plk.162.2023.02.19.15.14.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Feb 2023 15:14:26 -0800 (PST) From: Stephen Hemminger To: dev@dpdk.org Cc: Stephen Hemminger , Tyler Retzlaff , Reshma Pattan Subject: [PATCH v4 8/9] pcapng: windows compatibility Date: Sun, 19 Feb 2023 15:14:15 -0800 Message-Id: <20230219231416.22524-9-stephen@networkplumber.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230219231416.22524-1-stephen@networkplumber.org> References: <20230207001937.875608-1-stephen@networkplumber.org> <20230219231416.22524-1-stephen@networkplumber.org> MIME-Version: 1.0 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 Allow building on Windows, need to provide some comparability wrappers for writev() and if_nametoindex. Signed-off-by: Stephen Hemminger Acked-by: Tyler Retzlaff --- lib/pcapng/meson.build | 6 ----- lib/pcapng/rte_pcapng.c | 59 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/lib/pcapng/meson.build b/lib/pcapng/meson.build index da938bbcb733..4549925d41b6 100644 --- a/lib/pcapng/meson.build +++ b/lib/pcapng/meson.build @@ -1,12 +1,6 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2019 Microsoft Corporation -if is_windows - build = false - reason = 'not supported on Windows' - subdir_done() -endif - sources = files('rte_pcapng.c') headers = files('rte_pcapng.h') diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index 65c8c77fa405..3c91fc77644a 100644 --- a/lib/pcapng/rte_pcapng.c +++ b/lib/pcapng/rte_pcapng.c @@ -3,15 +3,18 @@ */ #include -#include #include #include #include #include -#include #include #include +#ifndef RTE_EXEC_ENV_WINDOWS +#include +#include +#endif + #include #include #include @@ -20,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -47,6 +51,57 @@ static struct pcapng_time { struct rte_reciprocal_u64 tsc_hz_inverse; } pcapng_time; + +#ifdef RTE_EXEC_ENV_WINDOWS +/* + * Windows does not have writev() call. + * Emulate this by copying to a new buffer. + * The copy is necessary since pcapng needs to be thread-safe + * and do atomic write operations. + */ + +#define IOV_MAX 128 +struct iovec { + void *iov_base; + size_t iov_len; +}; + +static ssize_t writev(int fd, const struct iovec *iov, int iovcnt) +{ + size_t bytes = 0; + uint8_t *ptr; + void *tmp_buf; + ssize_t ret; + int i; + + for (i = 0; i < iovcnt; i++) + bytes += iov[i].iov_len; + + if (unlikely(bytes == 0)) + return 0; + + tmp_buf = malloc(bytes); + if (unlikely(tmp_buf == NULL)) { + errno = ENOMEM; + return -1; + } + + ptr = tmp_buf; + for (i = 0; i < iovcnt; i++) { + rte_memcpy(ptr, iov[i].iov_base, iov[i].iov_len); + ptr += iov[i].iov_len; + } + + ret = write(fd, tmp_buf, bytes); + free(tmp_buf); + return ret; +} + +#define IF_NAMESIZE 16 +/* compatibility wrapper because name is optional */ +#define if_indextoname(ifindex, ifname) NULL +#endif + static inline void pcapng_init(void) {