public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Zack Weinberg <zack@sourceware.org>
To: glibc-cvs@sourceware.org
Subject: [glibc/zack/no-nested-includes] Don’t include sys/types.h from POSIX headers (2/n): net, netinet
Date: Tue, 18 Jun 2019 15:34:00 -0000	[thread overview]
Message-ID: <20190618153406.48784.qmail@sourceware.org> (raw)

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="us-ascii", Size: 12875 bytes --]

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=353b8eff84e9a356cbd494a177eeb81f5aca56c9

commit 353b8eff84e9a356cbd494a177eeb81f5aca56c9
Author: Zack Weinberg <zackw@panix.com>
Date:   Wed May 22 09:32:46 2019 -0400

    Don’t include sys/types.h from POSIX headers (2/n): net, netinet
    
    This patch changes net/if.h, netinet/in_systm.h, netinet/ip.h, and
    netinet/tcp.h to avoid including sys/types.h and/or stdint.h.  They
    primarily wanted these headers for the uintN_t types; all of them
    except net/if.h now include <bits/stdint-uintn.h> instead, which means
    they expose the uintN_t types.  We could go further and have them use
    __uintN_t types instead but I’m not sure that would be better.
    
    None of these headers are supposed to include <sys/socket.h> or
    <netinet/in.h> either, but they all need struct sockaddr and/or
    struct sockaddr_in.  I am not sure whether I will get to that in
    this patch series.
    
    While I was at it, I noticed that all of these headers exist only in
    sysdeps/generic and sysdeps/gnu.  This means they aren’t really
    system-dependent and can be repatriated to the directories that
    install them.
    
    	* sysdeps/generic/netinet/in_systm.h: Rename to
    	inet/netinet/in_systm.h.  Include bits/stdint-uintn.h,
    	not sys/types.h or stdint.h.
    	* sysdeps/generic/netinet/ip.h: Rename to
    	inet/netinet/ip.h.  Include bits/stdint-uintn.h and
    	bits/endian.h, not sys/types.h.
    	* sysdeps/gnu/netinet/tcp.h: Rename to
    	inet/netinet/tcp.h. Include bits/stdint-uintn.h and
    	bits/endian.h, not sys/types.h or stdint.h.
    	* sydeps/gnu/net/if.h: Rename to socket/net/if.h.
    	Don’t include sys/types.h.
    
    	* include/net/if.h: Include socket/net/if.h, rather than
    	whatever the next net/if.h on the include path is.
    	* include/netinet/in_systm.h, include/netinet/ip.h
    	* include/netinet/tcp.h: New trivial wrappers.
    
    	* sysdeps/generic/net/if.h: Delete, never used.
    	* sysdeps/generic/netinet/tcp.h: Delete, never used.
    
    	* scripts/check-obsolete-constructs.py (HEADER_ALLOWED_INCLUDES): Update.

Diff:
---
 include/net/if.h                             |   2 +-
 include/netinet/in_systm.h                   |   1 +
 include/netinet/ip.h                         |   1 +
 include/netinet/tcp.h                        |   1 +
 {sysdeps/generic => inet}/netinet/in_systm.h |   3 +-
 {sysdeps/generic => inet}/netinet/ip.h       |   3 +-
 {sysdeps/gnu => inet}/netinet/tcp.h          |   4 +-
 scripts/check-obsolete-constructs.py         |   8 +-
 {sysdeps/gnu => socket}/net/if.h             |   8 +-
 sysdeps/generic/net/if.h                     |  49 ------------
 sysdeps/generic/netinet/tcp.h                | 107 ---------------------------
 11 files changed, 14 insertions(+), 173 deletions(-)

diff --git a/include/net/if.h b/include/net/if.h
index 6c4cbc9..2e7af05 100644
--- a/include/net/if.h
+++ b/include/net/if.h
@@ -1,6 +1,6 @@
 #ifndef _NET_IF_H
 
-# include_next <net/if.h>
+#include <socket/net/if.h>
 
 #ifndef _ISOMAC
 libc_hidden_proto (if_nametoindex)
diff --git a/include/netinet/in_systm.h b/include/netinet/in_systm.h
new file mode 100644
index 0000000..7634c9b
--- /dev/null
+++ b/include/netinet/in_systm.h
@@ -0,0 +1 @@
+#include <inet/netinet/in_systm.h>
diff --git a/include/netinet/ip.h b/include/netinet/ip.h
new file mode 100644
index 0000000..da55733
--- /dev/null
+++ b/include/netinet/ip.h
@@ -0,0 +1 @@
+#include <inet/netinet/ip.h>
diff --git a/include/netinet/tcp.h b/include/netinet/tcp.h
new file mode 100644
index 0000000..edba529
--- /dev/null
+++ b/include/netinet/tcp.h
@@ -0,0 +1 @@
+#include <inet/netinet/tcp.h>
diff --git a/sysdeps/generic/netinet/in_systm.h b/inet/netinet/in_systm.h
similarity index 97%
rename from sysdeps/generic/netinet/in_systm.h
rename to inet/netinet/in_systm.h
index 2b3c742..6964aca2 100644
--- a/sysdeps/generic/netinet/in_systm.h
+++ b/inet/netinet/in_systm.h
@@ -19,8 +19,7 @@
 #ifndef _NETINET_IN_SYSTM_H
 #define _NETINET_IN_SYSTM_H 1
 
-#include <sys/types.h>
-#include <stdint.h>
+#include <bits/stdint-uintn.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/generic/netinet/ip.h b/inet/netinet/ip.h
similarity index 99%
rename from sysdeps/generic/netinet/ip.h
rename to inet/netinet/ip.h
index 13b03ff..35f61d1 100644
--- a/sysdeps/generic/netinet/ip.h
+++ b/inet/netinet/ip.h
@@ -19,9 +19,10 @@
 #define __NETINET_IP_H 1
 
 #include <features.h>
-#include <sys/types.h>
 
 #include <netinet/in.h>
+#include <bits/endian.h>
+#include <bits/stdint-uintn.h>
 
 __BEGIN_DECLS
 
diff --git a/sysdeps/gnu/netinet/tcp.h b/inet/netinet/tcp.h
similarity index 99%
rename from sysdeps/gnu/netinet/tcp.h
rename to inet/netinet/tcp.h
index 1a164a9..7b07acc 100644
--- a/sysdeps/gnu/netinet/tcp.h
+++ b/inet/netinet/tcp.h
@@ -85,9 +85,9 @@
 #define TCP_REPAIR_OFF_NO_WP	 -1
 
 #ifdef __USE_MISC
-# include <sys/types.h>
+# include <bits/stdint-uintn.h>
+# include <bits/endian.h>
 # include <sys/socket.h>
-# include <stdint.h>
 
 typedef	uint32_t tcp_seq;
 /*
diff --git a/scripts/check-obsolete-constructs.py b/scripts/check-obsolete-constructs.py
index 4eb293e..6eb366e 100755
--- a/scripts/check-obsolete-constructs.py
+++ b/scripts/check-obsolete-constructs.py
@@ -551,10 +551,9 @@ HEADER_ALLOWED_INCLUDES = {
     #          arpa/inet.h -> netinet/in.h
     "netdb.h":                     [ "netinet/in.h", "rpc/netdb.h" ],
     "arpa/inet.h":                 [ "netinet/in.h" ],
-    "net/if.h":                    [ "sys/socket.h", "sys/types.h" ],
+    "net/if.h":                    [ "sys/socket.h" ],
     "netinet/in.h":                [ "sys/socket.h" ],
-    "netinet/tcp.h":               [ "stdint.h", "sys/socket.h",
-                                     "sys/types.h" ],
+    "netinet/tcp.h":               [ "sys/socket.h" ],
 
     # Nonstandardized top-level headers
     "aliases.h":                   [ "sys/types.h" ],
@@ -667,8 +666,7 @@ HEADER_ALLOWED_INCLUDES = {
     "netinet/if_fddi.h":           [ "stdint.h", "sys/types.h" ],
     "netinet/if_tr.h":             [ "stdint.h", "sys/types.h" ],
     "netinet/igmp.h":              [ "netinet/in.h", "sys/types.h" ],
-    "netinet/in_systm.h":          [ "stdint.h", "sys/types.h" ],
-    "netinet/ip.h":                [ "netinet/in.h", "sys/types.h" ],
+    "netinet/ip.h":                [ "netinet/in.h" ],
     "netinet/ip6.h":               [ "inttypes.h", "netinet/in.h" ],
     "netinet/ip_icmp.h":           [ "netinet/in.h", "netinet/ip.h",
                                      "stdint.h", "sys/types.h" ],
diff --git a/sysdeps/gnu/net/if.h b/socket/net/if.h
similarity index 98%
rename from sysdeps/gnu/net/if.h
rename to socket/net/if.h
index e94ed67..b2fdbf7 100644
--- a/sysdeps/gnu/net/if.h
+++ b/socket/net/if.h
@@ -21,12 +21,6 @@
 
 #include <features.h>
 
-#ifdef __USE_MISC
-# include <sys/types.h>
-# include <sys/socket.h>
-#endif
-
-
 /* Length of interface name.  */
 #define IF_NAMESIZE	16
 
@@ -38,6 +32,8 @@ struct if_nameindex
 
 
 #ifdef __USE_MISC
+# include <sys/socket.h>  /* for struct sockaddr */
+
 /* Standard interface flags. */
 enum
   {
diff --git a/sysdeps/generic/net/if.h b/sysdeps/generic/net/if.h
deleted file mode 100644
index 4af6651..0000000
--- a/sysdeps/generic/net/if.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/* net/if.h -- declarations for inquiring about network interfaces
-   Copyright (C) 2000-2019 Free Software Foundation, Inc.
-   This file is part of the GNU C Library.
-
-   The GNU C Library is free software; you can redistribute it and/or
-   modify it under the terms of the GNU Lesser General Public
-   License as published by the Free Software Foundation; either
-   version 2.1 of the License, or (at your option) any later version.
-
-   The GNU C Library is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   Lesser General Public License for more details.
-
-   You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, see
-   <http://www.gnu.org/licenses/>.  */
-
-#ifndef _NET_IF_H
-
-#define _NET_IF_H	1
-#include <features.h>
-
-
-__BEGIN_DECLS
-
-/* Convert an interface name to an index, and vice versa.  */
-
-extern unsigned int if_nametoindex (const char *__ifname) __THROW;
-extern char *if_indextoname (unsigned int __ifindex, char *__ifname) __THROW;
-
-/* Return a list of all interfaces and their indices.  */
-
-struct if_nameindex
-  {
-    unsigned int if_index;	/* 1, 2, ... */
-    char *if_name;		/* null terminated name: "eth0", ... */
-  };
-
-extern struct if_nameindex *if_nameindex (void) __THROW;
-
-/* Free the data returned from if_nameindex.  */
-
-extern void if_freenameindex (struct if_nameindex *__ptr) __THROW;
-
-__END_DECLS
-
-
-#endif /* net/if.h */
diff --git a/sysdeps/generic/netinet/tcp.h b/sysdeps/generic/netinet/tcp.h
deleted file mode 100644
index 3b59e94..0000000
--- a/sysdeps/generic/netinet/tcp.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 1982, 1986, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *	@(#)tcp.h	8.1 (Berkeley) 6/10/93
- */
-
-#ifndef _NETINET_TCP_H
-#define _NETINET_TCP_H	1
-
-#include <features.h>
-
-__BEGIN_DECLS
-
-typedef	unsigned int	tcp_seq;
-/*
- * TCP header.
- * Per RFC 793, September, 1981.
- */
-struct tcphdr {
-	unsigned short	th_sport;	/* source port */
-	unsigned short	th_dport;	/* destination port */
-	tcp_seq		th_seq;		/* sequence number */
-	tcp_seq		th_ack;		/* acknowledgement number */
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-	unsigned char	th_x2:4,	/* (unused) */
-			th_off:4;	/* data offset */
-#endif
-#if __BYTE_ORDER == __BIG_ENDIAN
-	unsigned char	th_off:4,	/* data offset */
-			th_x2:4;	/* (unused) */
-#endif
-	unsigned char	th_flags;
-#define	TH_FIN	0x01
-#define	TH_SYN	0x02
-#define	TH_RST	0x04
-#define	TH_PUSH	0x08
-#define	TH_ACK	0x10
-#define	TH_URG	0x20
-	unsigned short	th_win;		/* window */
-	unsigned short	th_sum;		/* checksum */
-	unsigned short	th_urp;		/* urgent pointer */
-};
-
-#define	TCPOPT_EOL		0
-#define	TCPOPT_NOP		1
-#define	TCPOPT_MAXSEG		2
-#define TCPOLEN_MAXSEG		4
-#define TCPOPT_WINDOW		3
-#define TCPOLEN_WINDOW		3
-#define TCPOPT_SACK_PERMITTED	4		/* Experimental */
-#define TCPOLEN_SACK_PERMITTED	2
-#define TCPOPT_SACK		5		/* Experimental */
-#define TCPOPT_TIMESTAMP	8
-#define TCPOLEN_TIMESTAMP	10
-#define TCPOLEN_TSTAMP_APPA	(TCPOLEN_TIMESTAMP+2) /* appendix A */
-
-#define TCPOPT_TSTAMP_HDR	\
-    (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
-
-/*
- * Default maximum segment size for TCP.
- * With an IP MSS of 576, this is 536,
- * but 512 is probably more convenient.
- * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
- */
-#define	TCP_MSS	512
-
-#define	TCP_MAXWIN	65535	/* largest value for (unscaled) window */
-
-#define TCP_MAX_WINSHIFT	14	/* maximum window shift */
-
-/*
- * User-settable options (used with setsockopt).
- */
-#define	TCP_NODELAY	0x01	/* don't delay send to coalesce packets */
-#define	TCP_MAXSEG	0x02	/* set maximum segment size */
-
-#define SOL_TCP		6	/* TCP level */
-
-__END_DECLS
-
-#endif /* netinet/tcp.h */


             reply	other threads:[~2019-06-18 15:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 15:34 Zack Weinberg [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-05-26 16:36 Zack Weinberg

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=20190618153406.48784.qmail@sourceware.org \
    --to=zack@sourceware.org \
    --cc=glibc-cvs@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).