net: work around s_addr macro on Windows

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.

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
Acked-by: Ranjit Menon <ranjit.menon@intel.com>
Acked-by: Olivier Matz <olivier.matz@6wind.com>
This commit is contained in:
Dmitry Kozlyuk 2021-04-11 01:47:31 +03:00 committed by Thomas Monjalon
parent 45d62067c2
commit 6c068dbd9f

View File

@ -23,10 +23,6 @@ extern "C" {
#include <rte_mbuf.h> #include <rte_mbuf.h>
#include <rte_byteorder.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_ADDR_LEN 6 /**< Length of Ethernet address. */
#define RTE_ETHER_TYPE_LEN 2 /**< Length of Ethernet type field. */ #define RTE_ETHER_TYPE_LEN 2 /**< Length of Ethernet type field. */
#define RTE_ETHER_CRC_LEN 4 /**< Length of Ethernet CRC. */ #define RTE_ETHER_CRC_LEN 4 /**< Length of Ethernet CRC. */
@ -257,16 +253,34 @@ __rte_experimental
int int
rte_ether_unformat_addr(const char *str, struct rte_ether_addr *eth_addr); 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 * Ethernet header: Contains the destination address, source address
* and frame type. * and frame type.
*/ */
struct rte_ether_hdr { struct rte_ether_hdr {
struct rte_ether_addr d_addr; /**< Destination address. */ struct rte_ether_addr d_addr; /**< Destination address. */
struct rte_ether_addr s_addr; /**< Source address. */ RTE_STD_C11
uint16_t ether_type; /**< Frame type. */ 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); } __rte_aligned(2);
#pragma pop_macro("s_addr")
/** /**
* Ethernet VLAN Header. * Ethernet VLAN Header.
* Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type * Contains the 16-bit VLAN Tag Control Identifier and the Ethernet type