Skip to contentSkip to conversation

uapi: fix linux/if_pppol2tp.h userspace compilation errors

PATCH Superseded Dmitry V. Levin 2 participants 5 messages Feb 14, 2017 – Feb 15, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 uapi: fix linux/if_pppol2tp.h userspace compilation errors

Move inclusion of <linux/l2tp.h> before <linux/in.h> to fix userspace compilation errors like this:

In file included from /usr/include/linux/l2tp.h:12:0,

                 from /usr/include/linux/if_pppol2tp.h:21,

/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

Fixes 47c3e7783be4 ("net: l2tp: deprecate PPPOL2TP_MSG_* in favour of L2TP_MSG_*")
---
 include/uapi/linux/if_pppol2tp.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/uapi/linux/if_pppol2tp.h +1 -1
index 6418c4d..54a404e 100644
@@ -16,9 +16,9 @@
 #define _UAPI__LINUX_IF_PPPOL2TP_H
 
 #include <linux/types.h>
+#include <linux/l2tp.h>
 #include <linux/in.h>
 #include <linux/in6.h>
-#include <linux/l2tp.h>
 
 /* Structure used to connect() the socket to a particular tunnel UDP
  * socket over IPv4.
Signature · 1 line
ldv
maintainer
#1 lore raw

From: "Dmitry V. Levin" <[email protected]>
Date: Tue, 14 Feb 2017 13:33:53 +0300

Quoted 3 lines

In file included from /usr/include/linux/l2tp.h:12:0,

                 from /usr/include/linux/if_pppol2tp.h:21,

/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

This is protected properly by __UAPI_DEF_IN_ADDR, so whichever gets included first makes the definition.

This whole thing is designed so that if GLIBC headers are included first, __UAPI_DEF_IN_ADDR will be defined to zero, therefore linux/in.h won't try to make the definition. Otherwise it will.

The facility should not be so fragile that we have to play all kinds of header ordering games. We would be imposing the same strange rules on userspace applications including these headers which is completely unacceptable.

So if the facility isn't working correctly, let's fix that instead of fidgeting with include ordering all over the tree.

Thanks.

#2 lore raw
Quoted 10 lines · David Miller

From: "Dmitry V. Levin" <[email protected]>
Date: Tue, 14 Feb 2017 13:33:53 +0300

Quoted 3 lines

In file included from /usr/include/linux/l2tp.h:12:0,

                 from /usr/include/linux/if_pppol2tp.h:21,

/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

This is protected properly by __UAPI_DEF_IN_ADDR, so whichever gets included first makes the definition.

Quoted 8 lines

This whole thing is designed so that if GLIBC headers are included first, __UAPI_DEF_IN_ADDR will be defined to zero, therefore linux/in.h won't try to make the definition. Otherwise it will.

The facility should not be so fragile that we have to play all kinds of header ordering games. We would be imposing the same strange rules on userspace applications including these headers which is completely unacceptable.

The facility is so fragile that netinet/in.h cannot be included after linux/in.h:

$ gcc -S -o/dev/null -xc /dev/null -include /usr/include/linux/in.h -include /usr/include/netinet/in.h
In file included from <command-line>:32:0:
/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'
 struct in_addr
        ^~~~~~~
In file included from <command-line>:32:0:
/usr/include/linux/in.h:84:8: note: originally defined here
 struct in_addr {
        ^~~~~~~
Quoted 2 lines

So if the facility isn't working correctly, let's fix that instead of fidgeting with include ordering all over the tree.

I don't mind if the whole facility will get fixed someday.
My humble objective was just to fix the regression introduced in v4.10-rc1 by commit 47c3e7783be4.

Signature · 1 line
ldv
#3 lore raw

PATCH v2 1/1 uapi: fix linux/if_pppol2tp.h userspace compilation errors

Because of <linux/libc-compat.h> interface limitations, <netinet/in.h> provided by libc cannot be included after <linux/in.h>, therefore any header that includes <netinet/in.h> cannot be included after <linux/in.h>.

Change uapi/linux/l2tp.h, the last uapi header that includes <netinet/in.h>, to include <linux/in.h> and <linux/in6.h> instead of <netinet/in.h> and use __SOCK_SIZE__ instead of sizeof(struct sockaddr) the same way as uapi/linux/in.h does, to fix linux/if_pppol2tp.h userspace compilation errors like this:

In file included from /usr/include/linux/l2tp.h:12:0,

                 from /usr/include/linux/if_pppol2tp.h:21,

/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

Fixes 47c3e7783be4 ("net: l2tp: deprecate PPPOL2TP_MSG_* in favour of L2TP_MSG_*")

---
v2: change uapi/linux/l2tp.h to fix <linux/if_pppol2tp.h>

 include/uapi/linux/l2tp.h | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
include/uapi/linux/l2tp.h +3 -4
index 85ddb74..b23c191 100644
@@ -9,9 +9,8 @@
 
 #include <linux/types.h>
 #include <linux/socket.h>
-#ifndef __KERNEL__
-#include <netinet/in.h>
-#endif
+#include <linux/in.h>
+#include <linux/in6.h>
 
 #define IPPROTO_L2TP		115
 
@@ -31,7 +30,7 @@ struct sockaddr_l2tpip {
 	__u32		l2tp_conn_id;	/* Connection ID of tunnel */
 
 	/* Pad to size of `struct sockaddr'. */
-	unsigned char	__pad[sizeof(struct sockaddr) -
+	unsigned char	__pad[__SOCK_SIZE__ -
 			      sizeof(__kernel_sa_family_t) -
 			      sizeof(__be16) - sizeof(struct in_addr) -
 			      sizeof(__u32)];
Signature · 1 line
ldv
maintainer
#4 lore raw

From: "Dmitry V. Levin" <[email protected]>
Date: Wed, 15 Feb 2017 05:23:26 +0300

Quoted 10 lines

Because of <linux/libc-compat.h> interface limitations, <netinet/in.h> provided by libc cannot be included after <linux/in.h>, therefore any header that includes <netinet/in.h> cannot be included after <linux/in.h>.

Change uapi/linux/l2tp.h, the last uapi header that includes <netinet/in.h>, to include <linux/in.h> and <linux/in6.h> instead of <netinet/in.h> and use __SOCK_SIZE__ instead of sizeof(struct sockaddr) the same way as uapi/linux/in.h does, to fix linux/if_pppol2tp.h userspace compilation errors like this:

Quoted 8 lines

In file included from /usr/include/linux/l2tp.h:12:0,

                 from /usr/include/linux/if_pppol2tp.h:21,

/usr/include/netinet/in.h:31:8: error: redefinition of 'struct in_addr'

Fixes 47c3e7783be4 ("net: l2tp: deprecate PPPOL2TP_MSG_* in favour of L2TP_MSG_*")

---
v2: change uapi/linux/l2tp.h to fix <linux/if_pppol2tp.h>

This looks a lot better.

Applied and queued up for -stable, thanks.