DPDK patches and discussions
 help / color / mirror / Atom feed
From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: Ferruh Yigit <ferruh.yigit@intel.com>,
	Tyler Retzlaff <roretzla@microsoft.com>
Cc: Nick Connolly <nick.connolly@mayadata.io>,
	dev@dpdk.org, Mike Wells <mike.wells@telchemy.com>,
	Narcisa Ana Maria Vasile <navasile@linux.microsoft.com>,
	Dmitry Malloy <dmitrym@microsoft.com>,
	Pallavi Kadam <pallavi.kadam@intel.com>,
	Jie Zhou <jizh@linux.microsoft.com>
Subject: Re: [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers
Date: Wed, 3 Mar 2021 21:19:20 +0300	[thread overview]
Message-ID: <20210303211920.59ad403d@sovereign> (raw)
In-Reply-To: <e742d4a5-41c7-d78b-e6e2-d2be853c6e92@intel.com>

2021-03-03 16:47, Ferruh Yigit:
> On 3/3/2021 4:32 PM, Dmitry Kozlyuk wrote:
[...]
> > If we can't help including <ws2tcpip.h>/<netinet/ip.h> from public headers,
> > might as well use `struct in_addr`, just replace `#include <netinet/ip.h>`
> > with `#include <rte_ip.h>` everywhere.
> > 
> > The only remaining issue will be `s_addr` macro on Windows that conflicts with
> > `struct rte_ether_addr` field `s_addr`. I don't know a better solution than
> > renaming `s_addr` to `src_addr` in DPDK (OTOH, it will be consistent with
> > `struct rte_ipvX_hdr` field naming).
> > 
> > Ferruh, what do you think?
> >   
> 
> No problem on the chosen name, that will work fine, but the 'struct 
> rte_eth_addr' is public struct, we can't rename it without breaking the user 
> applications.
> 
> Still it is possible to rename public struct, but it is a long process, need to 
> send a deprecation notice and wait for next LTS, 21.11.
> 
> Ethernet header already has following, doesn't it help:
> #undef s_addr /* Defined in winsock2.h included in windows.h. */

It helps until you do the following:

	#include <winsock2.h>	/* #define s_addr S_un.S_addr */
	#include <rte_ether.h>	/* #undef s_addr */

	struct in_addr a;
	a.s_addr = 0; /* ERROR, `s_addr` has been defined to do that */

Or the following:

	#include <rte_ether.h>
	#include <winsock2.h>

	struct rte_ether_hdr eh;
	eh.s_addr.addr_bytes[0] = 0;	/* ERROR: `addr_s` is a macro */

If you swap include order in each case, it compiles, i.e . code is fragile.
Shims redefine `struct in_addr` and we're trying to get rid of them anyway.


Here's a solution that always works, however ugly it looks. It defines
`struct rte_ether_hdr` for Windows such that `s_addr` macro works for it if
defined. We can keep it until 21.11, then remove it and rename fields. In
return, we can remove networking shims and workarounds immediately.

`S_un.S_addr` part of `struct in_addr` is documented, and thus is unlikely to
ever change:

	https://docs.microsoft.com/en-us/windows/win32/api/winsock2/ns-winsock2-in_addr


diff --git a/lib/librte_net/rte_ether.h b/lib/librte_net/rte_ether.h
index 060b63fc9..67d340bb2 100644
--- a/lib/librte_net/rte_ether.h
+++ b/lib/librte_net/rte_ether.h
@@ -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,6 +253,8 @@ __rte_experimental
 int
 rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr);
 
+#if !defined RTE_EXEC_ENV_WINDOWS || defined __DOXYGEN__
+
 /**
  * Ethernet header: Contains the destination address, source address
  * and frame type.
@@ -267,6 +265,28 @@ struct rte_ether_hdr {
 	uint16_t ether_type;      /**< Frame type. */
 } __rte_aligned(2);
 
+#else
+
+#pragma push_macro("s_addr")
+#ifdef s_addr
+#undef s_addr
+#endif
+
+struct rte_ether_hdr {
+	struct rte_ether_addr d_addr; /**< Destination address. */
+	RTE_STD_C11
+	union {
+		struct rte_ether_addr s_addr; /**< Source address. */
+		struct {
+			struct rte_ether_addr S_un;
+		} S_addr;
+	};
+	uint16_t ether_type; /**< Frame type. */
+} __rte_aligned(2);
+
+#pragma pop_macro("s_addr")
+#endif
+
 /**
  * Ethernet VLAN Header.
  * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type

  reply	other threads:[~2021-03-03 18:19 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-14  1:20 [dpdk-dev] [PATCH 0/6] net/pcap: build on Windows Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 1/6] eal: add internal API for current time Dmitry Kozlyuk
2021-03-01 22:31   ` Nick Connolly
2021-03-01 22:36     ` Nick Connolly
2021-02-14  1:20 ` [dpdk-dev] [PATCH 2/6] net/pcap: fix format string Dmitry Kozlyuk
2021-03-01 22:33   ` Nick Connolly
2021-02-14  1:20 ` [dpdk-dev] [PATCH 3/6] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 4/6] net/pcap: add libpcap wrappers Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 5/6] config: discover libpcap on Windows Dmitry Kozlyuk
2021-02-14  1:20 ` [dpdk-dev] [PATCH 6/6] net/pcap: build " Dmitry Kozlyuk
2021-02-14  2:16 ` [dpdk-dev] [PATCH v2 0/6] " Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 1/6] eal: add internal API for current time Dmitry Kozlyuk
2021-03-01 22:39     ` Nick Connolly
2021-03-05 17:50     ` Jie Zhou
2021-03-16  9:18     ` Thomas Monjalon
2021-03-16 18:59     ` Stephen Hemminger
2021-03-16 20:07       ` Dmitry Kozlyuk
2021-03-17  9:50         ` Morten Brørup
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 2/6] net/pcap: fix format string Dmitry Kozlyuk
2021-02-25 14:45     ` Ferruh Yigit
2021-03-02 11:48       ` [dpdk-dev] [dpdk-stable] " Ferruh Yigit
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 3/6] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-02-25 14:51     ` Ferruh Yigit
2021-02-25 16:05       ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 4/6] net/pcap: add libpcap wrappers Dmitry Kozlyuk
2021-02-25 14:59     ` Ferruh Yigit
2021-02-25 19:04       ` Dmitry Kozlyuk
2021-02-25 20:31         ` Nick Connolly
2021-02-25 23:10           ` Dmitry Kozlyuk
2021-03-01 21:43             ` Nick Connolly
2021-03-01 23:05               ` Dmitry Kozlyuk
2021-03-01 23:23                 ` Dmitry Kozlyuk
2021-03-02 11:22                 ` Nick Connolly
2021-03-03 16:32                   ` Dmitry Kozlyuk
2021-03-03 16:47                     ` Ferruh Yigit
2021-03-03 18:19                       ` Dmitry Kozlyuk [this message]
2021-03-03 19:30                         ` Ferruh Yigit
2021-03-03 23:03                           ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 5/6] config: discover libpcap on Windows Dmitry Kozlyuk
2021-02-25 15:02     ` Ferruh Yigit
2021-02-25 16:04       ` Dmitry Kozlyuk
2021-02-25 16:33         ` Bruce Richardson
2021-02-25 17:42           ` Dmitry Kozlyuk
2021-03-16  9:16             ` Thomas Monjalon
2021-03-16  9:37               ` Dmitry Kozlyuk
2021-02-14  2:16   ` [dpdk-dev] [PATCH v2 6/6] net/pcap: build " Dmitry Kozlyuk
2021-03-24  0:50   ` [dpdk-dev] [PATCH v3 0/3] " Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 1/3] eal/windows: add timespec_get shim for MinGW Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-03-24  0:50     ` [dpdk-dev] [PATCH v3 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-09 10:51     ` [dpdk-dev] [PATCH v3 0/3] " Ferruh Yigit
2021-04-09 11:03       ` Dmitry Kozlyuk
2021-04-09 11:24         ` Ferruh Yigit
2021-04-15 22:10     ` [dpdk-dev] [PATCH v4 " Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 1/3] eal/windows: add timespec_get shim for MinGW Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-04-15 22:10       ` [dpdk-dev] [PATCH v4 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-19 21:05         ` Tyler Retzlaff
2021-04-16 17:22       ` [dpdk-dev] [PATCH v4 0/3] " Ferruh Yigit
2021-04-20 22:20       ` Thomas Monjalon
2021-04-21 14:53         ` Dmitry Kozlyuk
2021-04-21 18:12           ` Thomas Monjalon
2021-04-21 19:33       ` [dpdk-dev] [PATCH v5 " Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 1/3] eal: add timespec_get shim Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 2/3] net/pcap: move OS-dependent code to separate files Dmitry Kozlyuk
2021-04-21 19:33         ` [dpdk-dev] [PATCH v5 3/3] net/pcap: build on Windows Dmitry Kozlyuk
2021-04-21 21:54         ` [dpdk-dev] [PATCH v5 0/3] " Thomas Monjalon

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=20210303211920.59ad403d@sovereign \
    --to=dmitry.kozliuk@gmail.com \
    --cc=dev@dpdk.org \
    --cc=dmitrym@microsoft.com \
    --cc=ferruh.yigit@intel.com \
    --cc=jizh@linux.microsoft.com \
    --cc=mike.wells@telchemy.com \
    --cc=navasile@linux.microsoft.com \
    --cc=nick.connolly@mayadata.io \
    --cc=pallavi.kadam@intel.com \
    --cc=roretzla@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).