From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48816 invoked by alias); 18 Jun 2019 15:34:06 -0000 Mailing-List: contact glibc-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: , Sender: glibc-cvs-owner@sourceware.org List-Subscribe: Received: (qmail 48785 invoked by uid 9014); 18 Jun 2019 15:34:06 -0000 Date: Tue, 18 Jun 2019 15:34:00 -0000 Message-ID: <20190618153406.48784.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zack Weinberg To: glibc-cvs@sourceware.org Subject: =?utf-8?q?=5Bglibc/zack/no-nested-includes=5D_Don=E2=80=99t_include_sys/t?= =?utf-8?q?ypes=2Eh_from_POSIX_headers_=282/n=29=3A_net=2C_netinet?= X-Act-Checkin: glibc X-Git-Author: Zack Weinberg X-Git-Refname: refs/heads/zack/no-nested-includes X-Git-Oldrev: b54843a67a873ef2a00aec83f2ec4e82d1bc86db X-Git-Newrev: 353b8eff84e9a356cbd494a177eeb81f5aca56c9 X-SW-Source: 2019-q2/txt/msg00447.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=353b8eff84e9a356cbd494a177eeb81f5aca56c9 commit 353b8eff84e9a356cbd494a177eeb81f5aca56c9 Author: Zack Weinberg 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 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 or 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 +#include #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 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 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 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 -#include +#include __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 -#include #include +#include +#include __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 +# include +# include # include -# include 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 -#ifdef __USE_MISC -# include -# include -#endif - - /* Length of interface name. */ #define IF_NAMESIZE 16 @@ -38,6 +32,8 @@ struct if_nameindex #ifdef __USE_MISC +# include /* 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 - . */ - -#ifndef _NET_IF_H - -#define _NET_IF_H 1 -#include - - -__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 - -__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 */