All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Tyler Retzlaff <roretzla@linux.microsoft.com>,
	Reshma Pattan <reshma.pattan@intel.com>
Subject: [PATCH v3 8/8] pcapng: windows compatibility
Date: Sun, 19 Feb 2023 09:50:13 -0800	[thread overview]
Message-ID: <20230219175013.10057-9-stephen@networkplumber.org> (raw)
In-Reply-To: <20230219175013.10057-1-stephen@networkplumber.org>

Allow building on Windows, need to provide some comparability
wrappers for writev() and if_nametoindex.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
---
 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..d4b2db773160 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -3,15 +3,18 @@
  */
 
 #include <errno.h>
-#include <net/if.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <sys/uio.h>
 #include <time.h>
 #include <unistd.h>
 
+#ifndef RTE_EXEC_ENV_WINDOWS
+#include <net/if.h>
+#include <sys/uio.h>
+#endif
+
 #include <bus_driver.h>
 #include <rte_common.h>
 #include <rte_cycles.h>
@@ -20,6 +23,7 @@
 #include <rte_ethdev.h>
 #include <rte_ether.h>
 #include <rte_mbuf.h>
+#include <rte_os_shim.h>
 #include <rte_pcapng.h>
 #include <rte_reciprocal.h>
 #include <rte_time.h>
@@ -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
+/* compatiablity wrapper because name is optional */
+#define if_indextoname(ifindex, ifname) NULL
+#endif
+
 static inline void
 pcapng_init(void)
 {
-- 
2.39.1


  parent reply	other threads:[~2023-02-19 17:51 UTC|newest]

Thread overview: 66+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-01  1:44 [PATCH 0/8] Enable building more on Windows Stephen Hemminger
2022-12-01  1:44 ` [PATCH 1/8] net/null: build null PMD " Stephen Hemminger
2022-12-01 23:51   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 2/8] net/ring: build " Stephen Hemminger
2022-12-01 23:52   ` Tyler Retzlaff
2022-12-14 23:18   ` Kadam, Pallavi
2022-12-15  3:22     ` Stephen Hemminger
2022-12-15 17:48       ` Tyler Retzlaff
2022-12-15 18:09         ` Dmitry Kozlyuk
2022-12-01  1:44 ` [PATCH 3/8] lpm: enable " Stephen Hemminger
2022-12-01 23:53   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 4/8] reorder: build " Stephen Hemminger
2022-12-01 23:53   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 5/8] ip_frag: enable " Stephen Hemminger
2022-12-01 23:54   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 6/8] rib: enable " Stephen Hemminger
2022-12-01 23:54   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 7/8] fib: " Stephen Hemminger
2022-12-01 23:54   ` Tyler Retzlaff
2022-12-01  1:44 ` [PATCH 8/8] pcapng: windows compatability Stephen Hemminger
2022-12-01 23:55   ` Tyler Retzlaff
2023-02-07  0:19 ` [PATCH v2 0/8] Enable building more libraries on Windows Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 1/8] net/null: build null PMD " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 2/8] net/ring: build " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 3/8] lpm: enable " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 4/8] reorder: build " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 5/8] ip_frag: enable " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 6/8] rib: enable " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 7/8] fib: " Stephen Hemminger
2023-02-07  0:19   ` [PATCH v2 8/8] pcapng: windows compatibility Stephen Hemminger
2023-02-07 22:13   ` [PATCH v2 0/8] Enable building more libraries on Windows Dmitry Kozlyuk
2023-02-09  9:16     ` David Marchand
2023-02-19 17:50   ` [PATCH v3 " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 1/8] net/null: build null PMD " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 2/8] net/ring: build " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 3/8] lpm: enable " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 4/8] reorder: build " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 5/8] ip_frag: enable " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 6/8] rib: enable " Stephen Hemminger
2023-02-19 17:50     ` [PATCH v3 7/8] fib: " Stephen Hemminger
2023-02-19 17:50     ` Stephen Hemminger [this message]
2023-02-19 23:14   ` [PATCH v4 0/9] Enable building more libraries " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 1/9] net/null: build null PMD " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 2/9] net/ring: build " Stephen Hemminger
2023-03-09 21:10       ` David Marchand
2023-03-09 21:21         ` Stephen Hemminger
2023-03-10  9:34           ` David Marchand
2023-02-19 23:14     ` [PATCH v4 3/9] lpm: enable " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 4/9] reorder: build " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 5/9] ip_frag: enable " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 6/9] rib: enable " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 7/9] fib: " Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 8/9] pcapng: windows compatibility Stephen Hemminger
2023-02-19 23:14     ` [PATCH v4 9/9] table: enable build on Windows Stephen Hemminger
2023-03-06 21:07       ` Tyler Retzlaff
2023-03-10 14:06     ` [PATCH v4 0/9] Enable building more libraries " David Marchand
2023-03-09 21:31 ` [PATCH v5 " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 1/9] net/null: build null PMD " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 2/9] net/ring: build " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 3/9] lpm: enable " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 4/9] reorder: build " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 5/9] ip_frag: enable " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 6/9] rib: enable " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 7/9] fib: " Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 8/9] pcapng: windows compatibility Stephen Hemminger
2023-03-09 21:31   ` [PATCH v5 9/9] table: enable build on Windows Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230219175013.10057-9-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=dev@dpdk.org \
    --cc=reshma.pattan@intel.com \
    --cc=roretzla@linux.microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.