Skip to contentSkip to conversation

eal/windows: do not expose POSIX symbols

PATCH Superseded Dmitry Kozlyuk 13 participants 132 messages Feb 20, 2021 – Apr 29, 2021 Page 2 of 2

Subsystems (2)
lore
Share & tools
lore
#126 lore raw

PATCH v10 2/4 eal: make OS shims internal

In reply to Dmitry Kozlyuk

DPDK code often relies on functions and macros that are not standard C, but are found on all platforms, even if by slightly different names. Windows <rte_os.h> provided macros or inline definitions for such symbols. However, when placed in public header, these symbols were unnecessarily exposed, breaking consumer POSIX compatibility code.

Move most of the shims to <rte_os_shim.h>, a header to be used instead of <rte_os.h> by internal code. Include it in libraries and PMDs that previously imported shims from <rte_os.h>. Directly replace shims that were only used inside EAL:
* index -> strchr, rindex -> strrchr
* sleep -> rte_delay_us_sleep
* strerror_r -> strerror_s

Remove sleep(3) shim in favour of rte_delay_us_sleep().

---
 drivers/bus/pci/private.h                    |  4 +-
 drivers/bus/vdev/vdev_private.h              |  2 +
 drivers/common/mlx5/mlx5_common.h            |  1 +
 drivers/net/i40e/i40e_ethdev.c               |  1 +
 examples/service_cores/main.c                |  4 +-
 lib/librte_cmdline/cmdline.c                 |  4 --
 lib/librte_cmdline/cmdline_os_windows.c      |  2 -
 lib/librte_cmdline/cmdline_private.h         |  1 +
 lib/librte_cmdline/cmdline_socket.c          |  4 --
 lib/librte_eal/common/eal_common_config.c    |  1 -
 lib/librte_eal/common/eal_common_errno.c     |  4 ++
 lib/librte_eal/common/eal_common_log.c       |  1 +
 lib/librte_eal/common/eal_common_options.c   |  2 +-
 lib/librte_eal/common/eal_common_timer.c     |  4 +-
 lib/librte_eal/common/eal_internal_cfg.h     |  1 +
 lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++++
 lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++++
 lib/librte_eal/windows/eal_hugepages.c       |  1 -
 lib/librte_eal/windows/eal_lcore.c           |  1 -
 lib/librte_eal/windows/eal_memalloc.c        |  1 -
 lib/librte_eal/windows/include/rte_os.h      | 62 ++------------------
 lib/librte_eal/windows/include/rte_os_shim.h | 28 +++++++++
 lib/librte_ethdev/ethdev_private.h           |  2 +
 lib/librte_kvargs/rte_kvargs.c               |  1 +
 24 files changed, 82 insertions(+), 78 deletions(-)
 create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h
 create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h
drivers/bus/pci/private.h +3 -1
index f566943f5e..4cd9d14ec7 100644
@@ -7,8 +7,10 @@
 
 #include <stdbool.h>
 #include <stdio.h>
-#include <rte_pci.h>
+
 #include <rte_bus_pci.h>
+#include <rte_os_shim.h>
+#include <rte_pci.h>
 
 extern struct rte_pci_bus rte_pci_bus;
 
drivers/bus/vdev/vdev_private.h +2 -0
index ba6dc48ff3..e683f5f133 100644
@@ -5,6 +5,8 @@
 #ifndef _VDEV_PRIVATE_H_
 #define _VDEV_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
drivers/common/mlx5/mlx5_common.h +1 -0
index 327374fdcf..f3c6beb23b 100644
@@ -14,6 +14,7 @@
 #include <rte_kvargs.h>
 #include <rte_devargs.h>
 #include <rte_bitops.h>
+#include <rte_os_shim.h>
 
 #include "mlx5_prm.h"
 #include "mlx5_devx_cmds.h"
drivers/net/i40e/i40e_ethdev.c +1 -0
index c03e4a0a4b..ea5d384283 100644
@@ -27,6 +27,7 @@
 #include <rte_tailq.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_prototype.h"
examples/service_cores/main.c +2 -2
index c7c792810d..0b3d8c8073 100644
@@ -209,10 +209,10 @@ main(int argc, char **argv)
 		apply_profile(i);
 		printf("\n==> Profile: %s\n\n", profiles[i].name);
 
-		sleep(1);
+		rte_delay_us_sleep(1 * US_PER_S);
 		rte_service_dump(stdout, UINT32_MAX);
 
-		sleep(5);
+		rte_delay_us_sleep(5 * US_PER_S);
 		rte_service_dump(stdout, UINT32_MAX);
 
 		i++;
lib/librte_cmdline/cmdline.c +0 -4
index 79ea5f98c8..49770869bb 100644
@@ -18,10 +18,6 @@
 
 #include "cmdline_private.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define write _write
-#endif
-
 static void
 cmdline_valid_buffer(struct rdline *rdl, const char *buf,
 		     __rte_unused unsigned int size)
lib/librte_cmdline/cmdline_os_windows.c +0 -2
index e9585c9eea..73ed9ba290 100644
@@ -4,8 +4,6 @@
 
 #include <io.h>
 
-#include <rte_os.h>
-
 #include "cmdline_private.h"
 
 /* Missing from some MinGW-w64 distributions. */
lib/librte_cmdline/cmdline_private.h +1 -0
index a8a6ee9e69..a87c45275c 100644
@@ -8,6 +8,7 @@
 #include <stdarg.h>
 
 #include <rte_common.h>
+#include <rte_os_shim.h>
 #ifdef RTE_EXEC_ENV_WINDOWS
 #include <rte_windows.h>
 #endif
lib/librte_cmdline/cmdline_socket.c +0 -4
index 0fe1497008..998e8ade25 100644
@@ -16,10 +16,6 @@
 #include "cmdline_private.h"
 #include "cmdline_socket.h"
 
-#ifdef RTE_EXEC_ENV_WINDOWS
-#define open _open
-#endif
-
 struct cmdline *
 cmdline_file_new(cmdline_parse_ctx_t *ctx, const char *prompt, const char *path)
 {
lib/librte_eal/common/eal_common_config.c +0 -1
index 56d09dda7f..1c4c4dd585 100644
@@ -3,7 +3,6 @@
  */
 #include <string.h>
 
-#include <rte_os.h>
 #include <rte_string_fns.h>
 
 #include "eal_private.h"
lib/librte_eal/common/eal_common_errno.c +4 -0
index 2a10fb823f..f86802705a 100644
@@ -15,6 +15,10 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 
+#ifdef RTE_EXEC_ENV_WINDOWS
+#define strerror_r(errnum, buf, buflen) strerror_s(buf, buflen, errnum)
+#endif
+
 RTE_DEFINE_PER_LCORE(int, _rte_errno);
 
 const char *
lib/librte_eal/common/eal_common_log.c +1 -0
index bed83a402a..cedf9f0894 100644
@@ -13,6 +13,7 @@
 
 #include <rte_eal.h>
 #include <rte_log.h>
+#include <rte_os_shim.h>
 #include <rte_per_lcore.h>
 
 #include "eal_log.h"
lib/librte_eal/common/eal_common_options.c +1 -1
index 2951b1aca2..66f9114715 100644
@@ -1959,7 +1959,7 @@ eal_check_common_options(struct internal_config *internal_cfg)
 		RTE_LOG(ERR, EAL, "Invalid length of --" OPT_MBUF_POOL_OPS_NAME" option\n");
 		return -1;
 	}
-	if (index(eal_get_hugefile_prefix(), '%') != NULL) {
+	if (strchr(eal_get_hugefile_prefix(), '%') != NULL) {
 		RTE_LOG(ERR, EAL, "Invalid char, '%%', in --"OPT_FILE_PREFIX" "
 			"option\n");
 		return -1;
lib/librte_eal/common/eal_common_timer.c +2 -2
index 71e0bd035a..86f8429847 100644
@@ -47,9 +47,9 @@ estimate_tsc_freq(void)
 #define CYC_PER_10MHZ 1E7
 	RTE_LOG(WARNING, EAL, "WARNING: TSC frequency estimated roughly"
 		" - clock timings may be less accurate.\n");
-	/* assume that the sleep(1) will sleep for 1 second */
+	/* assume that the rte_delay_us_sleep() will sleep for 1 second */
 	uint64_t start = rte_rdtsc();
-	sleep(1);
+	rte_delay_us_sleep(US_PER_S);
 	/* Round up to 10Mhz. 1E7 ~ 10Mhz */
 	return RTE_ALIGN_MUL_NEAR(rte_rdtsc() - start, CYC_PER_10MHZ);
 }
lib/librte_eal/common/eal_internal_cfg.h +1 -0
index 51dbe86e2b..d6c0470eb8 100644
@@ -11,6 +11,7 @@
 #define EAL_INTERNAL_CFG_H
 
 #include <rte_eal.h>
+#include <rte_os_shim.h>
 #include <rte_pci_dev_feature_defs.h>
 
 #include "eal_thread.h"
lib/librte_eal/freebsd/include/rte_os_shim.h new file +14 -0
new file mode 100644
index 0000000000..1e85229ca9
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/linux/include/rte_os_shim.h new file +14 -0
new file mode 100644
index 0000000000..1e85229ca9
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/eal_hugepages.c +0 -1
index 83a3d0ffc6..b007dceb39 100644
@@ -6,7 +6,6 @@
 #include <rte_log.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_filesystem.h"
lib/librte_eal/windows/eal_lcore.c +0 -1
index a85149be95..476c2d2bdf 100644
@@ -9,7 +9,6 @@
 #include <rte_common.h>
 #include <rte_debug.h>
 #include <rte_lcore.h>
-#include <rte_os.h>
 
 #include "eal_private.h"
 #include "eal_thread.h"
lib/librte_eal/windows/eal_memalloc.c +0 -1
index 85a9712cea..4459d59b1a 100644
@@ -3,7 +3,6 @@
  */
 
 #include <rte_errno.h>
-#include <rte_os.h>
 
 #include "eal_internal_cfg.h"
 #include "eal_memalloc.h"
lib/librte_eal/windows/include/rte_os.h +4 -58

76 lines not on this page · raw message

lib/librte_eal/windows/include/rte_os_shim.h new file +28 -0
new file mode 100644
index 0000000000..edd9a1082c
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: BSD-3-Clause */
+
+#ifndef _RTE_OS_SHIM_
+#define _RTE_OS_SHIM_
+
+#include <rte_os.h>
+
+/**
+ * @file
+ * @internal
+ * Provides semi-standard OS facilities by convenient names.
+ */
+
+#ifndef PATH_MAX
+#define PATH_MAX _MAX_PATH
+#endif
+
+#define strdup(str) _strdup(str)
+#define strtok_r(str, delim, saveptr) strtok_s(str, delim, saveptr)
+#define strncasecmp(s1, s2, count) _strnicmp(s1, s2, count)
+
+#define open(path, flags, ...) _open(path, flags, ##__VA_ARGS__)
+#define read(fd, buf, n) _read(fd, buf, n)
+#define write(fd, buf, n) _write(fd, buf, n)
+#define close(fd) _close(fd)
+#define unlink(path) _unlink(path)
+
+#endif /* _RTE_OS_SHIM_ */
lib/librte_ethdev/ethdev_private.h +2 -0
index 220ddd4408..9bb0879538 100644
@@ -5,6 +5,8 @@
 #ifndef _ETH_PRIVATE_H_
 #define _ETH_PRIVATE_H_
 
+#include <rte_os_shim.h>
+
 #include "rte_ethdev.h"
 
 #ifdef __cplusplus
lib/librte_kvargs/rte_kvargs.c +1 -0
index 4cce8e953b..38e9d5c1ca 100644
@@ -7,6 +7,7 @@
 #include <stdlib.h>
 #include <stdbool.h>
 
+#include <rte_os_shim.h>
 #include <rte_string_fns.h>
 
 #include "rte_kvargs.h"
Signature · 1 line
2.29.3
#127 lore raw

PATCH v10 3/4 net: work around s_addr macro on Windows

In reply to Dmitry Kozlyuk

Windows Sockets headers contain #define s_addr S_un.S_addr, which conflicts with definition of s_addr field of struct rte_ether_hdr. Prieviously s_addr was undefined in <rte_ether.h>, which had been breaking access to s_addr field of struct in_addr, so some DPDK and Windows headers could not be included in one file.

Renaming of struct rte_ether_hdr is planned:
https://mails.dpdk.org/archives/dev/2021-March/201444.html

Temporarily disable s_addr macro around struct rte_ether_hdr definition to avoid conflict. Place source MAC address in both s_addr and S_un.S_addr fields, so that access works either directly or through the macro as defined in Windows headers.

---
 lib/librte_net/rte_ether.h | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
lib/librte_net/rte_ether.h +20 -6
index 060b63fc9b..a303c24a8c 100644
@@ -23,10 +23,6 @@ extern "C" {
 #include <rte_mbuf.h>
 #include <rte_byteorder.h>
 
-#ifdef RTE_EXEC_ENV_WINDOWS /* Workaround conflict with rte_ether_hdr. */
-#undef s_addr /* Defined in winsock2.h included in windows.h. */
-#endif
-
 #define RTE_ETHER_ADDR_LEN  6 /**< Length of Ethernet address. */
 #define RTE_ETHER_TYPE_LEN  2 /**< Length of Ethernet type field. */
 #define RTE_ETHER_CRC_LEN   4 /**< Length of Ethernet CRC. */
@@ -257,16 +253,34 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+/* Windows Sockets headers contain `#define s_addr S_un.S_addr`.
+ * Temporarily disable this macro to avoid conflict at definition.
+ * Place source MAC address in both `s_addr` and `S_un.S_addr` fields,
+ * so that access works either directly or through the macro.
+ */
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
  */
 struct rte_ether_hdr {
 	struct rte_ether_addr d_addr; /**< Destination address. */
-	struct rte_ether_addr s_addr; /**< Source address. */
-	uint16_t ether_type;      /**< Frame type. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_addr;
+		} S_un; /**< Do not use directly; use s_addr instead.*/
+	};
+	uint16_t ether_type; /**< Frame type. */
 } __rte_aligned(2);
 
+#pragma pop_macro("s_addr")
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type
Signature · 1 line
2.29.3
#128 lore raw

PATCH v10 4/4 net: provide IP-related API on any OS

In reply to Dmitry Kozlyuk

Users of <rte_ip.h> relied on it to provide IP-related defines, like IPPROTO_* constants, but still had to include POSIX headers for inet_pton() and other standard IP-related facilities.

Extend <rte_ip.h> so that it is a single header to gain access to IP-related facilities on any OS. Use it to replace POSIX includes in components enabled on Windows. Move missing constants from Windows networking shim to OS shim header and include it where needed.

Remove Windows networking shim that is no longer needed.

---
 drivers/net/i40e/i40e_fdir.c                 |  1 +
 drivers/net/mlx5/mlx5.h                      |  1 -
 drivers/net/mlx5/mlx5_flow.c                 |  4 +--
 drivers/net/mlx5/mlx5_flow.h                 |  3 +-
 drivers/net/mlx5/mlx5_mac.c                  |  1 -
 examples/cmdline/commands.c                  |  5 ---
 examples/cmdline/parse_obj_list.c            |  2 --
 examples/flow_filtering/main.c               |  1 -
 examples/l2fwd/main.c                        |  1 -
 examples/link_status_interrupt/main.c        |  1 -
 lib/librte_cmdline/cmdline.c                 |  1 -
 lib/librte_cmdline/cmdline_parse.c           |  2 --
 lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 ----
 lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
 lib/librte_eal/windows/include/arpa/inet.h   | 30 ----------------
 lib/librte_eal/windows/include/netinet/in.h  | 38 --------------------
 lib/librte_eal/windows/include/netinet/ip.h  | 10 ------
 lib/librte_eal/windows/include/rte_os_shim.h |  8 +++++
 lib/librte_eal/windows/include/sys/socket.h  | 24 -------------
 lib/librte_ethdev/rte_ethdev.c               | 12 +++----
 lib/librte_ethdev/rte_ethdev_core.h          |  1 -
 lib/librte_net/rte_ip.h                      |  7 ++++
 lib/librte_net/rte_net.c                     |  1 +
 24 files changed, 24 insertions(+), 144 deletions(-)
 delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/in.h
 delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h
 delete mode 100644 lib/librte_eal/windows/include/sys/socket.h
drivers/net/i40e/i40e_fdir.c +1 -0
index da089baa4d..22e6e34640 100644
@@ -22,6 +22,7 @@
 #include <rte_sctp.h>
 #include <rte_hash_crc.h>
 #include <rte_bitmap.h>
+#include <rte_os_shim.h>
 
 #include "i40e_logs.h"
 #include "base/i40e_type.h"
drivers/net/mlx5/mlx5.h +0 -1
index 0f69f9d125..bac8bc0377 100644
@@ -10,7 +10,6 @@
 #include <stdbool.h>
 #include <stdint.h>
 #include <limits.h>
-#include <netinet/in.h>
 #include <sys/queue.h>
 
 #include <rte_pci.h>
drivers/net/mlx5/mlx5_flow.c +1 -3
index c347f8130e..0f1a9c5ed9 100644
@@ -3,12 +3,11 @@
  * Copyright 2016 Mellanox Technologies, Ltd
  */
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
 #include <stdbool.h>
+#include <sys/queue.h>
 
 #include <rte_common.h>
 #include <rte_ether.h>
@@ -8241,4 +8240,3 @@ mlx5_release_tunnel_hub(__rte_unused struct mlx5_dev_ctx_shared *sh,
 {
 }
 #endif /* HAVE_IBV_FLOW_DV_SUPPORT */
-
drivers/net/mlx5/mlx5_flow.h +1 -2
index ec673c29ab..1ee5a9eb15 100644
@@ -5,11 +5,10 @@
 #ifndef RTE_PMD_MLX5_FLOW_H_
 #define RTE_PMD_MLX5_FLOW_H_
 
-#include <netinet/in.h>
-#include <sys/queue.h>
 #include <stdalign.h>
 #include <stdint.h>
 #include <string.h>
+#include <sys/queue.h>
 
 #include <rte_alarm.h>
 #include <rte_mtr.h>
drivers/net/mlx5/mlx5_mac.c +0 -1
index a7946f7756..19981d26d8 100644
@@ -8,7 +8,6 @@
 #include <string.h>
 #include <inttypes.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_ether.h>
 #include <ethdev_driver.h>
examples/cmdline/commands.c +0 -5
index f43eacfbad..9ce8ef389f 100644
@@ -8,12 +8,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
-#include <stdarg.h>
 #include <errno.h>
-#include <netinet/in.h>
-#ifdef RTE_EXEC_ENV_FREEBSD
-#include <sys/socket.h>
-#endif
 
 #include <cmdline_rdline.h>
 #include <cmdline_parse.h>
examples/cmdline/parse_obj_list.c +0 -2
index b04adbea58..959bcd1452 100644
@@ -6,11 +6,9 @@
 
 #include <stdio.h>
 #include <inttypes.h>
-#include <stdarg.h>
 #include <errno.h>
 #include <ctype.h>
 #include <string.h>
-#include <netinet/in.h>
 
 #include <cmdline_parse.h>
 #include <cmdline_parse_ipaddr.h>
examples/flow_filtering/main.c +0 -1
index 93523d625b..bc28468f17 100644
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
examples/l2fwd/main.c +0 -1
index 3377b08322..be5bf7bc90 100644
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
examples/link_status_interrupt/main.c +0 -1
index f1653b4fb8..8ca3586e05 100644
@@ -9,7 +9,6 @@
 #include <inttypes.h>
 #include <sys/types.h>
 #include <sys/queue.h>
-#include <netinet/in.h>
 #include <setjmp.h>
 #include <stdarg.h>
 #include <ctype.h>
lib/librte_cmdline/cmdline.c +0 -1
index 49770869bb..a176d15130 100644
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
lib/librte_cmdline/cmdline_parse.c +0 -2
index fe366841cd..f5cc934782 100644
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
lib/librte_cmdline/cmdline_parse_etheraddr.c +0 -6
index 5cb10de321..433b828a72 100644
@@ -5,13 +5,7 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
-#include <sys/types.h>
 
 #include <rte_string_fns.h>
 #include <rte_ether.h>
lib/librte_cmdline/cmdline_parse_ipaddr.c +0 -6
index f8dbdf204c..5e278c963f 100644
@@ -6,14 +6,8 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <stdarg.h>
-#include <inttypes.h>
-#include <ctype.h>
 #include <string.h>
 #include <errno.h>
-#include <arpa/inet.h>
-#include <netinet/in.h>
-#include <sys/socket.h>
 
 #include <rte_string_fns.h>
 
lib/librte_cmdline/cmdline_parse_ipaddr.h +1 -1
index 0ba81647bc..0118c31d44 100644
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
lib/librte_eal/windows/include/arpa/inet.h deleted +0 -30
deleted file mode 100644
index 96b6984383..0000000000
@@ -1,30 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _ARPA_INET_H_
-#define _ARPA_INET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <netinet/in.h>
-#include <sys/socket.h>
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-int
-inet_pton(int af, const char *src, void *dst);
-
-/* defined in ws2_32.dll */
-__attribute__((stdcall))
-const char *
-inet_ntop(int af, const void *src, char *dst, socklen_t size);
-
-#endif /* _ARPA_INET_H_ */
lib/librte_eal/windows/include/netinet/in.h deleted +0 -38
deleted file mode 100644
index 6455b9ba51..0000000000
@@ -1,38 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IN_H_
-#define _IN_H_
-
-#include <stdint.h>
-#include <sys/socket.h>
-
-#define IPPROTO_IP         0
-#define IPPROTO_HOPOPTS    0
-#define IPPROTO_ICMP       1
-#define IPPROTO_IPIP       4
-#define IPPROTO_TCP        6
-#define IPPROTO_UDP       17
-#define IPPROTO_IPV6      41
-#define IPPROTO_ROUTING   43
-#define IPPROTO_FRAGMENT  44
-#define IPPROTO_GRE       47
-#define IPPROTO_ESP       50
-#define IPPROTO_AH        51
-#define IPPROTO_ICMPV6    58
-#define IPPROTO_NONE      59
-#define IPPROTO_DSTOPTS   60
-#define IPPROTO_SCTP     132
-
-#define INET6_ADDRSTRLEN 46
-
-struct in_addr {
-	uint32_t s_addr;
-};
-
-struct in6_addr {
-	uint8_t s6_addr[16];
-};
-
-#endif
lib/librte_eal/windows/include/netinet/ip.h deleted +0 -10
deleted file mode 100644
index 2126498797..0000000000
@@ -1,10 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright 2020 Mellanox Technologies, Ltd
- */
-
-#ifndef _IP_H_
-#define _IP_H_
-
-#define IPVERSION 4
-
-#endif
lib/librte_eal/windows/include/rte_os_shim.h +8 -0
index edd9a1082c..f40fb62d1d 100644
@@ -25,4 +25,12 @@
 #define close(fd) _close(fd)
 #define unlink(path) _unlink(path)
 
+#define IPVERSION	4
+
+#define IPPROTO_IPIP	4
+#define IPPROTO_GRE	47
+#ifdef RTE_TOOLCHAIN_GCC
+#define IPPROTO_SCTP	132
+#endif
+
 #endif /* _RTE_OS_SHIM_ */
lib/librte_eal/windows/include/sys/socket.h deleted +0 -24
deleted file mode 100644
index 9536cf8e62..0000000000
@@ -1,24 +0,0 @@
-/* SPDX-License-Identifier: BSD-3-Clause
- * Copyright (c) 2020 Dmitry Kozlyuk
- */
-
-#ifndef _SYS_SOCKET_H_
-#define _SYS_SOCKET_H_
-
-/**
- * @file
- *
- * Compatibility header
- *
- * Although symbols declared here are present on Windows,
- * including <winsock2.h> would expose too much macros breaking common code.
- */
-
-#include <stddef.h>
-
-#define AF_INET  2
-#define AF_INET6 23
-
-typedef size_t socklen_t;
-
-#endif /* _SYS_SOCKET_H_ */
lib/librte_ethdev/rte_ethdev.c +4 -8
index 0419500fc3..c73d263c2f 100644
@@ -2,18 +2,14 @@
  * Copyright(c) 2010-2017 Intel Corporation
  */
 
-#include <sys/types.h>
-#include <sys/queue.h>
 #include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
 #include <errno.h>
+#include <inttypes.h>
 #include <stdbool.h>
 #include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
 
 #include <rte_byteorder.h>
 #include <rte_log.h>
lib/librte_ethdev/rte_ethdev_core.h +0 -1
index 918a34ed1f..4679d948fa 100644
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
lib/librte_net/rte_ip.h +7 -0
index b59c4d67a3..8c189009b0 100644
@@ -16,9 +16,16 @@
  */
 
 #include <stdint.h>
+
+#ifdef RTE_EXEC_ENV_WINDOWS
+#include <ws2tcpip.h>
+#else
+#include <sys/socket.h>
 #include <sys/types.h>
+#include <arpa/inet.h>
 #include <netinet/in.h>
 #include <netinet/ip.h>
+#endif
 
 #include <rte_byteorder.h>
 #include <rte_mbuf.h>
lib/librte_net/rte_net.c +1 -0
index bfe5003976..d680accc16 100644
@@ -15,6 +15,7 @@
 #include <rte_gre.h>
 #include <rte_mpls.h>
 #include <rte_net.h>
+#include <rte_os_shim.h>
 
 /* get l3 packet type from ip6 next protocol */
 static uint32_t
Signature · 1 line
2.29.3
Acked-by on the v10 series
#129 lore raw
In reply to Dmitry Kozlyuk
Quoted 70 lines · Dmitry Kozlyuk

On Windows, EAL contains two sets of functions and macros for POSIX
compatibility: <rte_os.h> and a networking shim (socket headers). The latter conflicts with system headers and should not exist. Exposing the former from EAL can break consumer own POSIX compatibility layer and is against standards in general. Hide these symbols from external consumers, while keeping them available for DPDK code.

v10:
* Fix examples that build on Windows.
v9:
* Fix missing <rte_os_shim.h> include in rte_common_log.c. (This will happen again. Going to add a checkpatch test after this series is merged.)

Dmitry Kozlyuk (4):
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS

  drivers/bus/pci/private.h                    |  4 +-
  drivers/bus/vdev/vdev_private.h              |  2 +
  drivers/common/mlx5/mlx5_common.h            |  1 +
  drivers/net/i40e/i40e_ethdev.c               |  1 +
  drivers/net/i40e/i40e_fdir.c                 |  1 +
  drivers/net/mlx5/mlx5.h                      |  1 -
  drivers/net/mlx5/mlx5_flow.c                 |  4 +-
  drivers/net/mlx5/mlx5_flow.h                 |  3 +-
  drivers/net/mlx5/mlx5_mac.c                  |  1 -
  examples/cmdline/commands.c                  |  5 --
  examples/cmdline/parse_obj_list.c            |  2 -
  examples/flow_filtering/main.c               |  1 -
  examples/l2fwd/main.c                        |  1 -
  examples/link_status_interrupt/main.c        |  1 -
  examples/service_cores/main.c                |  4 +-
  lib/librte_cmdline/cmdline.c                 |  5 --
  lib/librte_cmdline/cmdline_os_windows.c      |  2 -
  lib/librte_cmdline/cmdline_parse.c           |  2 -
  lib/librte_cmdline/cmdline_parse_etheraddr.c |  6 --
  lib/librte_cmdline/cmdline_parse_ipaddr.c    |  6 --
  lib/librte_cmdline/cmdline_parse_ipaddr.h    |  2 +-
  lib/librte_cmdline/cmdline_private.h         |  1 +
  lib/librte_cmdline/cmdline_socket.c          |  4 -
  lib/librte_eal/common/eal_common_config.c    |  1 -
  lib/librte_eal/common/eal_common_errno.c     |  4 +
  lib/librte_eal/common/eal_common_log.c       |  1 +
  lib/librte_eal/common/eal_common_options.c   |  2 +-
  lib/librte_eal/common/eal_common_timer.c     |  4 +-
  lib/librte_eal/common/eal_internal_cfg.h     |  1 +
  lib/librte_eal/common/eal_private.h          | 11 +++
  lib/librte_eal/freebsd/include/rte_os_shim.h | 14 +++
  lib/librte_eal/linux/include/rte_os_shim.h   | 14 +++
  lib/librte_eal/windows/eal.c                 | 30 +++++++
  lib/librte_eal/windows/eal_hugepages.c       |  1 -
  lib/librte_eal/windows/eal_lcore.c           |  1 -
  lib/librte_eal/windows/eal_memalloc.c        |  1 -
  lib/librte_eal/windows/include/arpa/inet.h   | 30 -------
  lib/librte_eal/windows/include/netinet/in.h  | 38 --------
  lib/librte_eal/windows/include/netinet/ip.h  | 10 ---
  lib/librte_eal/windows/include/rte_os.h      | 92 +-------------------
  lib/librte_eal/windows/include/rte_os_shim.h | 36 ++++++++
  lib/librte_eal/windows/include/sys/socket.h  | 24 -----
  lib/librte_ethdev/ethdev_private.h           |  2 +
  lib/librte_ethdev/rte_ethdev.c               | 12 +--
  lib/librte_ethdev/rte_ethdev_core.h          |  1 -
  lib/librte_kvargs/rte_kvargs.c               |  1 +
  lib/librte_net/rte_ether.h                   | 26 ++++--
  lib/librte_net/rte_ip.h                      |  7 ++
  lib/librte_net/rte_net.c                     |  1 +
  49 files changed, 167 insertions(+), 258 deletions(-)
Quoted 7 lines

create mode 100644 lib/librte_eal/freebsd/include/rte_os_shim.h create mode 100644 lib/librte_eal/linux/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/arpa/inet.h delete mode 100644 lib/librte_eal/windows/include/netinet/in.h delete mode 100644 lib/librte_eal/windows/include/netinet/ip.h create mode 100644 lib/librte_eal/windows/include/rte_os_shim.h delete mode 100644 lib/librte_eal/windows/include/sys/socket.h

Thanks, Dmitry.

#130 lore raw
Quoted 9 lines
Quoted 5 lines

Dmitry Kozlyuk (4):
eal/windows: hide asprintf() shim
eal: make OS shims internal
net: work around s_addr macro on Windows
net: provide IP-related API on any OS

Thanks, Dmitry.

Applied, thanks

Acked-by on the v1 series
#131 lore raw
In reply to Dmitry Kozlyuk
Quoted 52 lines · Dmitry Kozlyuk

On Windows, rte_os.h contains a small POSIX compatibility set of functions and macros. Exposing it from EAL can break consumer own POSIX compatibility layer and is against standards in general.

First define required wrappers, then fix POSIX dependencies in Windows-enabled libraries and drivers, then eliminate POSIX symbols from Windows EAL API. Commits are arranged so that they all compile and are limited in scope; patches 5, 6, 7 can be squashed if needed.

No "Fixes" tags, because it's really an enhancement, preventing issues rather then solving direct ones.

Dmitry Kozlyuk (7):
eal: add wrappers for POSIX string functions
eal: add macro for maximum path length
eal: add sleep API
eal: add asprintf() internal wrapper
lib: remove POSIX dependencies
drivers: remove POSIX dependencies
eal/windows: do not expose POSIX symbols

  doc/guides/rel_notes/release_21_05.rst        |  9 ++
  drivers/bus/pci/private.h                     |  2 +-
  drivers/bus/vdev/vdev.c                       |  4 +-
  drivers/bus/vdev/vdev_params.c                |  3 +-
  drivers/common/mlx5/mlx5_common_pci.c         |  4 +-
  drivers/net/i40e/i40e_ethdev.c                | 56 +++++------
  lib/librte_cmdline/cmdline.c                  |  1 +
  lib/librte_eal/common/eal_common_config.c     |  2 +-
  lib/librte_eal/common/eal_common_dev.c        |  6 +-
  lib/librte_eal/common/eal_common_devargs.c    |  7 +-
  lib/librte_eal/common/eal_common_errno.c      |  4 +
  lib/librte_eal/common/eal_common_fbarray.c    |  8 +-
  lib/librte_eal/common/eal_common_lcore.c      |  2 +-
  lib/librte_eal/common/eal_common_log.c        |  5 +-
  lib/librte_eal/common/eal_common_options.c    | 42 ++++----
  lib/librte_eal/common/eal_common_timer.c      |  5 +-
  lib/librte_eal/common/eal_common_trace.c      |  2 +-
  lib/librte_eal/common/eal_common_trace_ctf.c  |  4 +-
  .../common/eal_common_trace_utils.c           | 13 +--
  lib/librte_eal/common/eal_filesystem.h        |  8 +-
  lib/librte_eal/common/eal_hugepages.h         |  2 +-
  lib/librte_eal/common/eal_internal_cfg.h      |  2 +-
  lib/librte_eal/common/eal_private.h           | 23 +++++
  lib/librte_eal/common/eal_trace.h             |  2 +-
  lib/librte_eal/freebsd/include/rte_os.h       |  6 +-
  lib/librte_eal/include/rte_string_fns.h       | 42 ++++++++
  lib/librte_eal/include/rte_thread.h           | 11 +++
  lib/librte_eal/linux/include/rte_os.h         |  6 +-
  lib/librte_eal/rte_eal_exports.def            |  2 +
  lib/librte_eal/unix/rte_thread.c              |  6 ++
  lib/librte_eal/version.map                    |  3 +
Quoted 9 lines
  lib/librte_eal/windows/eal.c                  | 30 ++++++
  lib/librte_eal/windows/eal_thread.c           |  9 +-
  lib/librte_eal/windows/include/dirent.h       | 21 ++--
  lib/librte_eal/windows/include/rte_os.h       | 99 ++-----------------
  lib/librte_ethdev/rte_class_eth.c             |  2 +-
  lib/librte_ethdev/rte_ethdev.c                |  2 +-
  lib/librte_kvargs/rte_kvargs.c                | 17 ++--
  38 files changed, 266 insertions(+), 206 deletions(-)