Merge "Use the canonical idiom for sockaddr_storage." into main am: bb261225e0 am: 3f5aaa8812 am: 4b694b6969

Original change: https://android-review.googlesource.com/c/platform/bionic/+/2852650

Change-Id: I70804a869978bd6f27482530af7446a2cc57b33b
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Elliott Hughes 2023-12-08 16:28:27 +00:00 committed by Automerger Merge Worker
commit c608e57893
11 changed files with 96 additions and 63 deletions

View file

@ -0,0 +1,57 @@
/*
* Copyright (C) 2023 The Android Open Source Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * 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.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS 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
* COPYRIGHT OWNER 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.
*/
#pragma once
/**
* @file bits/sockaddr_storage.h
* @brief The `sockaddr_storage` struct.
*/
#include <sys/cdefs.h>
#include <bits/sa_family_t.h>
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
/**
* [sockaddr_storage](https://man7.org/linux/man-pages/man3/sockaddr.3type.html)
* is a structure large enough to contain any other `sockaddr_*` type, used to
* pass socket addresses without needing to know what kind of socket address
* you're passing.
*/
struct sockaddr_storage {
union {
struct {
sa_family_t ss_family;
char __data[128 - sizeof(sa_family_t)];
};
void* __align;
};
};
#pragma clang diagnostic pop

View file

@ -33,20 +33,10 @@
#include <sys/cdefs.h>
#include <sys/socket.h>
// Include linux/socket.h first to trigger the header guard without
// the__kernel_sockaddr_storage define, so its definition uses the
// kernel name.
#include <linux/socket.h>
// Redefine __kernel_sockaddr_storage to sockaddr_storage so that
// the structs defined in linux/in.h use the sockaddr_storage defined
// in sys/sockets.h.
#define __kernel_sockaddr_storage sockaddr_storage
#include <linux/in.h>
#undef __kernel_sockaddr_storage
#include <linux/in6.h>
#include <linux/ipv6.h>
#include <linux/socket.h>
__BEGIN_DECLS

View file

@ -39,6 +39,7 @@
#include <linux/types.h>
#include <linux/compiler.h>
#include <bits/sockaddr_storage.h>
#include <bits/sa_family_t.h>
__BEGIN_DECLS
@ -72,15 +73,6 @@ struct sockaddr {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"
struct sockaddr_storage {
union {
struct {
sa_family_t ss_family;
char __data[128 - sizeof(sa_family_t)];
};
void* __align;
};
};
struct linger {
int l_onoff;

View file

@ -1247,8 +1247,8 @@ class BlockList(object):
# Add an include for the structure to be removed of the form:
# #include <bits/STRUCT_NAME.h>
struct_token = b.tokens[i + 1]
if not structs[struct_token.id]:
extra_includes.add("<bits/%s.h>" % struct_token.id)
if struct_token.id in structs and structs[struct_token.id]:
extra_includes.add("<%s>" % structs[struct_token.id])
# Search forward for the end of the structure.
# Very simple search, look for } and ; tokens.

View file

@ -28,23 +28,23 @@ kernel_known_macros = {
}
# This is the set of known kernel data structures we want to remove from
# the final headers. If the map value is False, that means that in
# addition to removing the structure, add an #include <bits/STRUCT.h>
# to the file.
# the final headers. If the map value is non-empty, that means that in
# addition to removing the structure, add a #include to the file.
kernel_structs_to_remove = {
# Remove the structures since they are still the same as
# Remove these structures since they are still the same as
# timeval, itimerval.
"__kernel_old_timeval": True,
"__kernel_old_itimerval": True,
"__kernel_old_timeval": None,
"__kernel_old_itimerval": None,
# Replace all of the below structures with #include <bits/STRUCT.h>
"epoll_event": False,
"flock": False,
"flock64": False,
"in_addr": False,
"ip_mreq_source": False,
"ip_msfilter": False,
"tcphdr": False,
"timespec": False,
"__kernel_sockaddr_storage": "bits/sockaddr_storage.h",
"epoll_event": "bits/epoll_event.h",
"flock": "bits/flock.h",
"flock64": "bits/flock64.h",
"in_addr": "bits/in_addr.h",
"ip_mreq_source": "bits/ip_mreq_source.h",
"ip_msfilter": "bits/ip_msfilter.h",
"tcphdr": "bits/tcphdr.h",
"timespec": "bits/timespec.h",
}
# define to true if you want to remove all defined(CONFIG_FOO) tests
@ -92,6 +92,8 @@ kernel_token_replacements = {
"__kernel_old_timeval": "timeval",
# Do the same for __kernel_old_itimerval as for timeval.
"__kernel_old_itimerval": "itimerval",
# Do the same for __kernel_sockaddr_storage.
"__kernel_sockaddr_storage": "sockaddr_storage",
# Replace __packed with __attribute__((__packed__)) to avoid depending
# on sys/cdefs.h
"__packed": "__attribute__((__packed__))",

View file

@ -148,32 +148,32 @@ struct ip_mreqn {
#define IP_MSFILTER_SIZE(numsrc) (sizeof(struct ip_msfilter) - sizeof(__u32) + (numsrc) * sizeof(__u32))
struct group_req {
__u32 gr_interface;
struct __kernel_sockaddr_storage gr_group;
struct sockaddr_storage gr_group;
};
struct group_source_req {
__u32 gsr_interface;
struct __kernel_sockaddr_storage gsr_group;
struct __kernel_sockaddr_storage gsr_source;
struct sockaddr_storage gsr_group;
struct sockaddr_storage gsr_source;
};
struct group_filter {
union {
struct {
__u32 gf_interface_aux;
struct __kernel_sockaddr_storage gf_group_aux;
struct sockaddr_storage gf_group_aux;
__u32 gf_fmode_aux;
__u32 gf_numsrc_aux;
struct __kernel_sockaddr_storage gf_slist[1];
struct sockaddr_storage gf_slist[1];
};
struct {
__u32 gf_interface;
struct __kernel_sockaddr_storage gf_group;
struct sockaddr_storage gf_group;
__u32 gf_fmode;
__u32 gf_numsrc;
struct __kernel_sockaddr_storage gf_slist_flex[];
struct sockaddr_storage gf_slist_flex[];
};
};
};
#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct __kernel_sockaddr_storage) + (numsrc) * sizeof(struct __kernel_sockaddr_storage))
#define GROUP_FILTER_SIZE(numsrc) (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) + (numsrc) * sizeof(struct sockaddr_storage))
#endif
#if __UAPI_DEF_IN_PKTINFO
struct in_pktinfo {

View file

@ -163,13 +163,13 @@ struct mptcp_subflow_addrs {
struct sockaddr sa_local;
struct sockaddr_in sin_local;
struct sockaddr_in6 sin6_local;
struct __kernel_sockaddr_storage ss_local;
struct sockaddr_storage ss_local;
};
union {
struct sockaddr sa_remote;
struct sockaddr_in sin_remote;
struct sockaddr_in6 sin6_remote;
struct __kernel_sockaddr_storage ss_remote;
struct sockaddr_storage ss_remote;
};
};
struct mptcp_subflow_info {

View file

@ -205,7 +205,7 @@ struct rds_get_mr_args {
__u64 flags;
};
struct rds_get_mr_for_dest_args {
struct __kernel_sockaddr_storage dest_addr;
struct sockaddr_storage dest_addr;
struct rds_iovec vec;
__u64 cookie_addr;
__u64 flags;

View file

@ -6,17 +6,9 @@
*/
#ifndef _UAPI_LINUX_SOCKET_H
#define _UAPI_LINUX_SOCKET_H
#include <bits/sockaddr_storage.h>
#define _K_SS_MAXSIZE 128
typedef unsigned short __kernel_sa_family_t;
struct __kernel_sockaddr_storage {
union {
struct {
__kernel_sa_family_t ss_family;
char __data[_K_SS_MAXSIZE - sizeof(unsigned short)];
};
void * __align;
};
};
#define SOCK_SNDBUF_LOCK 1
#define SOCK_RCVBUF_LOCK 2
#define SOCK_BUF_LOCK_MASK (SOCK_SNDBUF_LOCK | SOCK_RCVBUF_LOCK)

View file

@ -202,7 +202,7 @@ enum {
#define TCP_MD5SIG_FLAG_PREFIX 0x1
#define TCP_MD5SIG_FLAG_IFINDEX 0x2
struct tcp_md5sig {
struct __kernel_sockaddr_storage tcpm_addr;
struct sockaddr_storage tcpm_addr;
__u8 tcpm_flags;
__u8 tcpm_prefixlen;
__u16 tcpm_keylen;

View file

@ -76,7 +76,7 @@ struct rdma_ucm_bind {
__u32 id;
__u16 addr_size;
__u16 reserved;
struct __kernel_sockaddr_storage addr;
struct sockaddr_storage addr;
};
struct rdma_ucm_resolve_ip {
struct sockaddr_in6 src_addr;
@ -90,8 +90,8 @@ struct rdma_ucm_resolve_addr {
__u16 src_size;
__u16 dst_size;
__u32 reserved;
struct __kernel_sockaddr_storage src_addr;
struct __kernel_sockaddr_storage dst_addr;
struct sockaddr_storage src_addr;
struct sockaddr_storage dst_addr;
};
struct rdma_ucm_resolve_route {
__u32 id;
@ -125,8 +125,8 @@ struct rdma_ucm_query_addr_resp {
__u16 pkey;
__u16 src_size;
__u16 dst_size;
struct __kernel_sockaddr_storage src_addr;
struct __kernel_sockaddr_storage dst_addr;
struct sockaddr_storage src_addr;
struct sockaddr_storage dst_addr;
__u32 ibdev_index;
__u32 reserved1;
};
@ -213,7 +213,7 @@ struct rdma_ucm_join_mcast {
__u32 id;
__u16 addr_size;
__u16 join_flags;
struct __kernel_sockaddr_storage addr;
struct sockaddr_storage addr;
};
struct rdma_ucm_get_event {
__aligned_u64 response;