kernel: improve uapi headers coexistence with musl
[openwrt/openwrt.git] / target / linux / generic / patches-4.0 / 272-uapi-if_ether.h-prevent-redefinition-of-struct-ethhd.patch
1 From fcbb6fed85ea9ff4feb4f1ebd4f0f235fdaf06b6 Mon Sep 17 00:00:00 2001
2 From: David Heidelberger <david.heidelberger@ixit.cz>
3 Date: Mon, 29 Jun 2015 16:53:03 +0200
4 Subject: [PATCH 3/3] uapi/if_ether.h: prevent redefinition of struct ethhdr
5
6 Musl provides its own ethhdr struct definition. Add a guard to prevent
7 its definition of the appropriate musl header has already been included.
8
9 Signed-off-by: John Spencer <maillist-linux@barfooze.de>
10 Tested-by: David Heidelberger <david.heidelberger@ixit.cz>
11 Signed-off-by: Jonas Gorski <jogo@openwrt.org>
12 ---
13 include/uapi/linux/if_ether.h | 3 +++
14 include/uapi/linux/libc-compat.h | 11 +++++++++++
15 2 files changed, 14 insertions(+)
16
17 --- a/include/uapi/linux/if_ether.h
18 +++ b/include/uapi/linux/if_ether.h
19 @@ -22,6 +22,7 @@
20 #define _UAPI_LINUX_IF_ETHER_H
21
22 #include <linux/types.h>
23 +#include <linux/libc-compat.h>
24
25 /*
26 * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble
27 @@ -134,11 +135,13 @@
28 * This is an Ethernet frame header.
29 */
30
31 +#if __UAPI_DEF_ETHHDR
32 struct ethhdr {
33 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */
34 unsigned char h_source[ETH_ALEN]; /* source ether addr */
35 __be16 h_proto; /* packet type ID field */
36 } __attribute__((packed));
37 +#endif
38
39
40 #endif /* _UAPI_LINUX_IF_ETHER_H */
41 --- a/include/uapi/linux/libc-compat.h
42 +++ b/include/uapi/linux/libc-compat.h
43 @@ -51,6 +51,14 @@
44 /* We have included libc headers... */
45 #if !defined(__KERNEL__)
46
47 +/* musl defines the ethhdr struct itself in its netinet/if_ether.h.
48 + * Glibc just includes the kernel header and uses a different guard. */
49 +#if defined(_NETINET_IF_ETHER_H)
50 +#define __UAPI_DEF_ETHHDR 0
51 +#else
52 +#define __UAPI_DEF_ETHHDR 1
53 +#endif
54 +
55 /* Coordinate with libc netinet/in.h header. */
56 #if defined(_NETINET_IN_H)
57
58 @@ -117,6 +125,9 @@
59 * that we need. */
60 #else /* defined(__KERNEL__) */
61
62 +/* Definitions for if_ether.h */
63 +#define __UAPI_DEF_ETHHDR 1
64 +
65 /* Definitions for in.h */
66 #define __UAPI_DEF_IN_ADDR 1
67 #define __UAPI_DEF_IN_IPPROTO 1