From: Mikko Rapeli <mikko.rapeli@iki.fi>
To: Kamal Mostafa <kamal@canonical.com>
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
kernel-team@lists.ubuntu.com,
Gabriel Laskar <gabriel@lse.epita.fr>,
"David S . Miller" <davem@davemloft.net>
Subject: Re: [PATCH 4.2.y-ckt 53/53] uapi glibc compat: fix compile errors when glibc net/if.h included before linux/if.h
Date: Wed, 25 May 2016 10:22:10 +0300 [thread overview]
Message-ID: <20160525072210.GD26774@lakka.kapsi.fi> (raw)
In-Reply-To: <1464112523-3701-54-git-send-email-kamal@canonical.com>
On Tue, May 24, 2016 at 10:55:23AM -0700, Kamal Mostafa wrote:
> 4.2.8-ckt11 -stable review patch. If anyone has any objections, please let me know.
>
> ---8<------------------------------------------------------------
>
> From: Mikko Rapeli <mikko.rapeli@iki.fi>
>
> [ Upstream commit 4a91cb61bb995e5571098188092e296192309c77 ]
>
> glibc's net/if.h contains copies of definitions from linux/if.h and these
> conflict and cause build failures if both files are included by application
> source code. Changes in uapi headers, which fixed header file dependencies to
> include linux/if.h when it was needed, e.g. commit 1ffad83d, made the
> net/if.h and linux/if.h incompatibilities visible as build failures for
> userspace applications like iproute2 and xtables-addons.
Commit 1ffad83d from me was released in v4.4-rc2. Before that the linux/if.h
conflict with glibc net/if.h was hidden from most users of kernel uapi headers.
IMO, there is no need to backport this fix to kernel trees older than v4.4.
-Mikko
> This patch fixes compile errors when glibc net/if.h is included before
> linux/if.h:
>
> ./linux/if.h:99:21: error: redeclaration of enumerator ‘IFF_NOARP’
> ./linux/if.h:98:23: error: redeclaration of enumerator ‘IFF_RUNNING’
> ./linux/if.h:97:26: error: redeclaration of enumerator ‘IFF_NOTRAILERS’
> ./linux/if.h:96:27: error: redeclaration of enumerator ‘IFF_POINTOPOINT’
> ./linux/if.h:95:24: error: redeclaration of enumerator ‘IFF_LOOPBACK’
> ./linux/if.h:94:21: error: redeclaration of enumerator ‘IFF_DEBUG’
> ./linux/if.h:93:25: error: redeclaration of enumerator ‘IFF_BROADCAST’
> ./linux/if.h:92:19: error: redeclaration of enumerator ‘IFF_UP’
> ./linux/if.h:252:8: error: redefinition of ‘struct ifconf’
> ./linux/if.h:203:8: error: redefinition of ‘struct ifreq’
> ./linux/if.h:169:8: error: redefinition of ‘struct ifmap’
> ./linux/if.h:107:23: error: redeclaration of enumerator ‘IFF_DYNAMIC’
> ./linux/if.h:106:25: error: redeclaration of enumerator ‘IFF_AUTOMEDIA’
> ./linux/if.h:105:23: error: redeclaration of enumerator ‘IFF_PORTSEL’
> ./linux/if.h:104:25: error: redeclaration of enumerator ‘IFF_MULTICAST’
> ./linux/if.h:103:21: error: redeclaration of enumerator ‘IFF_SLAVE’
> ./linux/if.h:102:22: error: redeclaration of enumerator ‘IFF_MASTER’
> ./linux/if.h:101:24: error: redeclaration of enumerator ‘IFF_ALLMULTI’
> ./linux/if.h:100:23: error: redeclaration of enumerator ‘IFF_PROMISC’
>
> The cases where linux/if.h is included before net/if.h need a similar fix in
> the glibc side, or the order of include files can be changed userspace
> code as a workaround.
>
> This change was tested in x86 userspace on Debian unstable with
> scripts/headers_compile_test.sh:
>
> $ make headers_install && \
> cd usr/include && ../../scripts/headers_compile_test.sh -l -k
> ...
> cc -Wall -c -nostdinc -I /usr/lib/gcc/i586-linux-gnu/5/include -I /usr/lib/gcc/i586-linux-gnu/5/include-fixed -I . -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.2uX2zH -I /home/mcfrisk/src/linux-2.6/usr/headers_compile_test_include.2uX2zH/i586-linux-gnu -o /dev/null ./linux/if.h_libc_before_kernel.h
> PASSED libc before kernel test: ./linux/if.h
>
> Reported-by: Jan Engelhardt <jengelh@inai.de>
> Reported-by: Josh Boyer <jwboyer@fedoraproject.org>
> Reported-by: Stephen Hemminger <shemming@brocade.com>
> Reported-by: Waldemar Brodkorb <mail@waldemar-brodkorb.de>
> Cc: Gabriel Laskar <gabriel@lse.epita.fr>
> Signed-off-by: Mikko Rapeli <mikko.rapeli@iki.fi>
> Signed-off-by: David S. Miller <davem@davemloft.net>
> Signed-off-by: Kamal Mostafa <kamal@canonical.com>
> ---
> include/uapi/linux/if.h | 28 +++++++++++++++++++++++++
> include/uapi/linux/libc-compat.h | 44 ++++++++++++++++++++++++++++++++++++++++
> 2 files changed, 72 insertions(+)
>
> diff --git a/include/uapi/linux/if.h b/include/uapi/linux/if.h
> index 9cf2394..752f5dc 100644
> --- a/include/uapi/linux/if.h
> +++ b/include/uapi/linux/if.h
> @@ -19,14 +19,20 @@
> #ifndef _LINUX_IF_H
> #define _LINUX_IF_H
>
> +#include <linux/libc-compat.h> /* for compatibility with glibc */
> #include <linux/types.h> /* for "__kernel_caddr_t" et al */
> #include <linux/socket.h> /* for "struct sockaddr" et al */
> #include <linux/compiler.h> /* for "__user" et al */
>
> +#if __UAPI_DEF_IF_IFNAMSIZ
> #define IFNAMSIZ 16
> +#endif /* __UAPI_DEF_IF_IFNAMSIZ */
> #define IFALIASZ 256
> #include <linux/hdlc/ioctl.h>
>
> +/* For glibc compatibility. An empty enum does not compile. */
> +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 && \
> + __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0
> /**
> * enum net_device_flags - &struct net_device flags
> *
> @@ -68,6 +74,8 @@
> * @IFF_ECHO: echo sent packets. Volatile.
> */
> enum net_device_flags {
> +/* for compatibility with glibc net/if.h */
> +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
> IFF_UP = 1<<0, /* sysfs */
> IFF_BROADCAST = 1<<1, /* volatile */
> IFF_DEBUG = 1<<2, /* sysfs */
> @@ -84,11 +92,17 @@ enum net_device_flags {
> IFF_PORTSEL = 1<<13, /* sysfs */
> IFF_AUTOMEDIA = 1<<14, /* sysfs */
> IFF_DYNAMIC = 1<<15, /* sysfs */
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
> +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
> IFF_LOWER_UP = 1<<16, /* volatile */
> IFF_DORMANT = 1<<17, /* volatile */
> IFF_ECHO = 1<<18, /* volatile */
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
> };
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO != 0 && __UAPI_DEF_IF_NET_DEVICE_FLAGS != 0 */
>
> +/* for compatibility with glibc net/if.h */
> +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS
> #define IFF_UP IFF_UP
> #define IFF_BROADCAST IFF_BROADCAST
> #define IFF_DEBUG IFF_DEBUG
> @@ -105,9 +119,13 @@ enum net_device_flags {
> #define IFF_PORTSEL IFF_PORTSEL
> #define IFF_AUTOMEDIA IFF_AUTOMEDIA
> #define IFF_DYNAMIC IFF_DYNAMIC
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS */
> +
> +#if __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
> #define IFF_LOWER_UP IFF_LOWER_UP
> #define IFF_DORMANT IFF_DORMANT
> #define IFF_ECHO IFF_ECHO
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
>
> #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST|IFF_ECHO|\
> IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT)
> @@ -166,6 +184,8 @@ enum {
> * being very small might be worth keeping for clean configuration.
> */
>
> +/* for compatibility with glibc net/if.h */
> +#if __UAPI_DEF_IF_IFMAP
> struct ifmap {
> unsigned long mem_start;
> unsigned long mem_end;
> @@ -175,6 +195,7 @@ struct ifmap {
> unsigned char port;
> /* 3 bytes spare */
> };
> +#endif /* __UAPI_DEF_IF_IFMAP */
>
> struct if_settings {
> unsigned int type; /* Type of physical device or protocol */
> @@ -200,6 +221,8 @@ struct if_settings {
> * remainder may be interface specific.
> */
>
> +/* for compatibility with glibc net/if.h */
> +#if __UAPI_DEF_IF_IFREQ
> struct ifreq {
> #define IFHWADDRLEN 6
> union
> @@ -223,6 +246,7 @@ struct ifreq {
> struct if_settings ifru_settings;
> } ifr_ifru;
> };
> +#endif /* __UAPI_DEF_IF_IFREQ */
>
> #define ifr_name ifr_ifrn.ifrn_name /* interface name */
> #define ifr_hwaddr ifr_ifru.ifru_hwaddr /* MAC address */
> @@ -249,6 +273,8 @@ struct ifreq {
> * must know all networks accessible).
> */
>
> +/* for compatibility with glibc net/if.h */
> +#if __UAPI_DEF_IF_IFCONF
> struct ifconf {
> int ifc_len; /* size of buffer */
> union {
> @@ -256,6 +282,8 @@ struct ifconf {
> struct ifreq __user *ifcu_req;
> } ifc_ifcu;
> };
> +#endif /* __UAPI_DEF_IF_IFCONF */
> +
> #define ifc_buf ifc_ifcu.ifcu_buf /* buffer address */
> #define ifc_req ifc_ifcu.ifcu_req /* array of structures */
>
> diff --git a/include/uapi/linux/libc-compat.h b/include/uapi/linux/libc-compat.h
> index 7d024ce..d5e38c7 100644
> --- a/include/uapi/linux/libc-compat.h
> +++ b/include/uapi/linux/libc-compat.h
> @@ -51,6 +51,40 @@
> /* We have included glibc headers... */
> #if defined(__GLIBC__)
>
> +/* Coordinate with glibc net/if.h header. */
> +#if defined(_NET_IF_H)
> +
> +/* GLIBC headers included first so don't define anything
> + * that would already be defined. */
> +
> +#define __UAPI_DEF_IF_IFCONF 0
> +#define __UAPI_DEF_IF_IFMAP 0
> +#define __UAPI_DEF_IF_IFNAMSIZ 0
> +#define __UAPI_DEF_IF_IFREQ 0
> +/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0
> +/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
> +#ifndef __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
> +#endif /* __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO */
> +
> +#else /* _NET_IF_H */
> +
> +/* Linux headers included first, and we must define everything
> + * we need. The expectation is that glibc will check the
> + * __UAPI_DEF_* defines and adjust appropriately. */
> +
> +#define __UAPI_DEF_IF_IFCONF 1
> +#define __UAPI_DEF_IF_IFMAP 1
> +#define __UAPI_DEF_IF_IFNAMSIZ 1
> +#define __UAPI_DEF_IF_IFREQ 1
> +/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
> +/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
> +
> +#endif /* _NET_IF_H */
> +
> /* Coordinate with glibc netinet/in.h header. */
> #if defined(_NETINET_IN_H)
>
> @@ -117,6 +151,16 @@
> * that we need. */
> #else /* !defined(__GLIBC__) */
>
> +/* Definitions for if.h */
> +#define __UAPI_DEF_IF_IFCONF 1
> +#define __UAPI_DEF_IF_IFMAP 1
> +#define __UAPI_DEF_IF_IFNAMSIZ 1
> +#define __UAPI_DEF_IF_IFREQ 1
> +/* Everything up to IFF_DYNAMIC, matches net/if.h until glibc 2.23 */
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS 1
> +/* For the future if glibc adds IFF_LOWER_UP, IFF_DORMANT and IFF_ECHO */
> +#define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 1
> +
> /* Definitions for in.h */
> #define __UAPI_DEF_IN_ADDR 1
> #define __UAPI_DEF_IN_IPPROTO 1
> --
> 2.7.4
>
prev parent reply other threads:[~2016-05-25 7:22 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-24 17:54 [4.2.y-ckt stable] Linux 4.2.8-ckt11 stable review Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 01/53] [4.2-stable only] fix backport "IB/security: restrict use of the write() interface" Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 02/53] Revert "usb: hub: do not clear BOS field during reset device" Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 03/53] regulator: s2mps11: Fix invalid selector mask and voltages for buck9 Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 04/53] regmap: spmi: Fix regmap_spmi_ext_read in multi-byte case Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 05/53] ALSA: usb-audio: Quirk for yet another Phoenix Audio devices (v2) Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 06/53] atomic_open(): fix the handling of create_error Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 07/53] drm/i915/bdw: Add missing delay during L3 SQC credit programming Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 08/53] crypto: hash - Fix page length clamping in hash walk Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 09/53] drm/radeon: fix DP link training issue with second 4K monitor Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 10/53] drm/radeon: fix PLL sharing on DCE6.1 (v2) Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 11/53] get_rock_ridge_filename(): handle malformed NM entries Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 12/53] ALSA: hda - Fix white noise on Asus UX501VW headset Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 13/53] Input: max8997-haptic - fix NULL pointer dereference Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 14/53] drm/i915: Bail out of pipe config compute loop on LPT Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 15/53] ALSA: hda - Fix broken reconfig Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 16/53] ALSA: hda - Fix subwoofer pin on ASUS N751 and N551 Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 17/53] vfs: add vfs_select_inode() helper Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 18/53] vfs: rename: check backing inode being equal Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 19/53] ALSA: usb-audio: Yet another Phoneix Audio device quirk Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 20/53] perf/x86: Fix undefined shift on 32-bit kernels Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 21/53] perf/x86/intel/pt: Generate PMI in the STOP region as well Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 22/53] perf/core: Disable the event on a truncated AUX record Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 23/53] tools lib traceevent: Do not reassign parg after collapse_tree() Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 24/53] workqueue: fix rebind bound workers warning Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 25/53] ocfs2: fix posix_acl_create deadlock Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 26/53] nf_conntrack: avoid kernel pointer value leak in slab name Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 27/53] macvtap: segmented packet is consumed Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 28/53] regulator: axp20x: Fix axp22x ldo_io voltage ranges Kamal Mostafa
2016-05-24 17:54 ` [PATCH 4.2.y-ckt 29/53] arm64: bpf: jit JMP_JSET_{X,K} Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 30/53] bridge: fix igmp / mld query parsing Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 31/53] net/mlx4_en: Fix endianness bug in IPV6 csum calculation Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 32/53] net: fec: only clear a queue's work bit if the queue was emptied Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 33/53] tcp: refresh skb timestamp at retransmit time Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 34/53] net/route: enforce hoplimit max value Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 35/53] decnet: Do not build routes to devices without decnet private data Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 36/53] route: do not cache fib route info on local routes with oif Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 37/53] net: use skb_postpush_rcsum instead of own implementations Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 38/53] vlan: pull on __vlan_insert_tag error path and fix csum correction Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 39/53] ipv4/fib: don't warn when primary address is missing if in_dev is dead Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 40/53] bpf: fix double-fdput in replace_map_fd_with_map_ptr() Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 41/53] net_sched: introduce qdisc_replace() helper Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 42/53] net_sched: update hierarchical backlog too Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 43/53] sch_htb: update backlog as well Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 44/53] sch_dsmark: " Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 45/53] netem: Segment GSO packets on enqueue Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 46/53] net: fix infoleak in llc Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 47/53] net: fix infoleak in rtnetlink Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 48/53] VSOCK: do not disconnect socket when peer has shutdown SEND only Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 49/53] net: bridge: fix old ioctl unlocked net device walk Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 50/53] net: fix a kernel infoleak in x25 module Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 51/53] cdc_mbim: apply "NDP to end" quirk to all Huawei devices Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 52/53] soreuseport: fix ordering for mixed v4/v6 sockets Kamal Mostafa
2016-05-24 17:55 ` [PATCH 4.2.y-ckt 53/53] uapi glibc compat: fix compile errors when glibc net/if.h included before linux/if.h Kamal Mostafa
2016-05-25 7:22 ` Mikko Rapeli [this message]
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=20160525072210.GD26774@lakka.kapsi.fi \
--to=mikko.rapeli@iki.fi \
--cc=davem@davemloft.net \
--cc=gabriel@lse.epita.fr \
--cc=kamal@canonical.com \
--cc=kernel-team@lists.ubuntu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®