Define sockaddr_storage in bionic

Bionic currently renames the kernel's __kernel_sockaddr_storage
to sockaddr_storage.  We would like to reuse the bionic kernel
headers for musl, but musl defines its own sockaddr_storage,
causing redefinition errors when the musl and kernel headers
are both included.

Give bionic its own definition of sockaddr_storage so the kernel
one can be left as __kernel_sockaddr_storage, avoiding the
conflict in musl.

Some of the structs in netinet/in.h contain sockaddr_storage members.
There are definitions in linux/in.h, but they now use the
__kernel_sockaddr_storage naming.  To avoid having to copy the structs
from linux/in.h into netinet/in.h, add some #define hackery to
rename __kernel_sockaddr_storage to sockaddr_storage when including
linux/in.h from netinet/in.h.

Bug: 190084016
Test: m checkbuild
Test: bionic-unit-tests
Change-Id: I8f654511722b3a4a8e0bb146e4418ebcd370305c
This commit is contained in:
Colin Cross 2021-06-29 12:52:26 -07:00
parent a55c81e36e
commit d27506716a
8 changed files with 36 additions and 18 deletions

View file

@ -33,7 +33,18 @@
#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>

View file

@ -31,7 +31,6 @@
#include <sys/cdefs.h>
#include <sys/types.h>
#include <linux/socket.h>
#include <asm/fcntl.h>
#include <asm/socket.h>
@ -71,6 +70,16 @@ struct sockaddr {
char sa_data[14];
};
struct sockaddr_storage {
union {
struct {
sa_family_t ss_family;
char __data[128 - sizeof(sa_family_t)];
};
void* __align;
};
};
struct linger {
int l_onoff;
int l_linger;

View file

@ -89,8 +89,6 @@ kernel_token_replacements = {
"udphdr": "__kernel_udphdr",
# This causes problems when trying to export the headers for the ndk.
"__attribute_const__": "__attribute__((__const__))",
# In this case the kernel tries to keep out of our way, but we're happy to use its definition.
"__kernel_sockaddr_storage": "sockaddr_storage",
# The kernel started using struct __kernel_old_timeval in some places,
# which is the exact same as struct timeval. Replace that name with
# timeval so that kernel structures all use the same named structure.

View file

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

View file

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

View file

@ -20,7 +20,7 @@
#define _UAPI_LINUX_SOCKET_H
#define _K_SS_MAXSIZE 128
typedef unsigned short __kernel_sa_family_t;
struct sockaddr_storage {
struct __kernel_sockaddr_storage {
union {
struct {
__kernel_sa_family_t ss_family;

View file

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

View file

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