net: provide IP-related API on any OS
authorDmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Sat, 10 Apr 2021 22:47:32 +0000 (01:47 +0300)
committerThomas Monjalon <thomas@monjalon.net>
Wed, 14 Apr 2021 23:56:43 +0000 (01:56 +0200)
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.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
25 files changed:
drivers/net/i40e/i40e_fdir.c
drivers/net/mlx5/mlx5.h
drivers/net/mlx5/mlx5_flow.c
drivers/net/mlx5/mlx5_flow.h
drivers/net/mlx5/mlx5_mac.c
examples/cmdline/commands.c
examples/cmdline/parse_obj_list.c
examples/flow_filtering/main.c
examples/l2fwd/main.c
examples/link_status_interrupt/main.c
examples/service_cores/main.c
lib/librte_cmdline/cmdline.c
lib/librte_cmdline/cmdline_parse.c
lib/librte_cmdline/cmdline_parse_etheraddr.c
lib/librte_cmdline/cmdline_parse_ipaddr.c
lib/librte_cmdline/cmdline_parse_ipaddr.h
lib/librte_eal/windows/include/arpa/inet.h [deleted file]
lib/librte_eal/windows/include/netinet/in.h [deleted file]
lib/librte_eal/windows/include/netinet/ip.h [deleted file]
lib/librte_eal/windows/include/rte_os_shim.h
lib/librte_eal/windows/include/sys/socket.h [deleted file]
lib/librte_ethdev/rte_ethdev.c
lib/librte_ethdev/rte_ethdev_core.h
lib/librte_net/rte_ip.h
lib/librte_net/rte_net.c

index da089ba..22e6e34 100644 (file)
@@ -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"
index 0f69f9d..bac8bc0 100644 (file)
@@ -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>
index c347f81..0f1a9c5 100644 (file)
@@ -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 */
-
index ec673c2..1ee5a9e 100644 (file)
@@ -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>
index a7946f7..19981d2 100644 (file)
@@ -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>
index f43eacf..9ce8ef3 100644 (file)
@@ -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>
index b04adbe..959bcd1 100644 (file)
@@ -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>
index 93523d6..bc28468 100644 (file)
@@ -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>
index 3377b08..be5bf7b 100644 (file)
@@ -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>
index f1653b4..8ca3586 100644 (file)
@@ -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>
index c7c7928..0b3d8c8 100644 (file)
@@ -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++;
index 4977086..a176d15 100644 (file)
@@ -12,7 +12,6 @@
 #include <inttypes.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <netinet/in.h>
 
 #include <rte_string_fns.h>
 
index fe36684..f5cc934 100644 (file)
@@ -11,8 +11,6 @@
 #include <inttypes.h>
 #include <ctype.h>
 
-#include <netinet/in.h>
-
 #include <rte_string_fns.h>
 
 #include "cmdline_private.h"
index 5cb10de..433b828 100644 (file)
@@ -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>
index f8dbdf2..5e278c9 100644 (file)
@@ -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>
 
index 0ba8164..0118c31 100644 (file)
@@ -8,7 +8,7 @@
 #define _PARSE_IPADDR_H_
 
 #include <cmdline_parse.h>
-#include <netinet/in.h>
+#include <rte_ip.h>
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/lib/librte_eal/windows/include/arpa/inet.h b/lib/librte_eal/windows/include/arpa/inet.h
deleted file mode 100644 (file)
index 96b6984..0000000
+++ /dev/null
@@ -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_ */
diff --git a/lib/librte_eal/windows/include/netinet/in.h b/lib/librte_eal/windows/include/netinet/in.h
deleted file mode 100644 (file)
index 6455b9b..0000000
+++ /dev/null
@@ -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
diff --git a/lib/librte_eal/windows/include/netinet/ip.h b/lib/librte_eal/windows/include/netinet/ip.h
deleted file mode 100644 (file)
index 2126498..0000000
+++ /dev/null
@@ -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
index edd9a10..f40fb62 100644 (file)
 #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_ */
diff --git a/lib/librte_eal/windows/include/sys/socket.h b/lib/librte_eal/windows/include/sys/socket.h
deleted file mode 100644 (file)
index 9536cf8..0000000
+++ /dev/null
@@ -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_ */
index 0419500..c73d263 100644 (file)
@@ -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>
index 918a34e..4679d94 100644 (file)
@@ -6,7 +6,6 @@
 #define _RTE_ETHDEV_CORE_H_
 
 #include <pthread.h>
-#include <sys/types.h>
 
 /**
  * @file
index b59c4d6..8c18900 100644 (file)
  */
 
 #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>
index bfe5003..d680acc 100644 (file)
@@ -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