mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-08-27 15:36:48 +00:00

There are cases in networking (e.g. wireguard, sctp) where a union is used to provide coverage for either IPv4 or IPv6 network addresses, and they include an embedded "struct sockaddr" as well (for "sa_family" and raw "sa_data" access). The current struct sockaddr contains a flexible array, which means these unions should not be further embedded in other structs because they do not technically have a fixed size (and are generating warnings for the coming -Wflexible-array-not-at-end flag addition). But the future changes to make struct sockaddr a fixed size (i.e. with a 14 byte sa_data member) make the "sa_data" uses with an IPv6 address a potential place for the compiler to get upset about object size mismatches. Therefore, we need a sockaddr that cleanly provides both an sa_family member and an appropriately fixed-sized sa_data member that does not bloat member usage via the potential alternative of sockaddr_storage to cover both IPv4 and IPv6, to avoid unseemly churn in the affected code bases. Introduce sockaddr_inet as a unified structure for holding both IPv4 and IPv6 addresses (i.e. large enough to accommodate sockaddr_in6). The structure is defined in linux/in6.h since its max size is sized based on sockaddr_in6 and provides a more specific alternative to the generic sockaddr_storage for IPv4 with IPv6 address family handling. The "sa_family" member doesn't use the sa_family_t type to avoid needing layer violating header inclusions. Signed-off-by: Kees Cook <kees@kernel.org> Link: https://patch.msgid.link/20250722171836.1078436-1-kees@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
52 lines
1.8 KiB
C
52 lines
1.8 KiB
C
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
/*
|
|
* Types and definitions for AF_INET6
|
|
* Linux INET6 implementation
|
|
*
|
|
* Authors:
|
|
* Pedro Roque <roque@di.fc.ul.pt>
|
|
*
|
|
* Sources:
|
|
* IPv6 Program Interfaces for BSD Systems
|
|
* <draft-ietf-ipngwg-bsd-api-05.txt>
|
|
*
|
|
* Advanced Sockets API for IPv6
|
|
* <draft-stevens-advanced-api-00.txt>
|
|
*/
|
|
#ifndef _LINUX_IN6_H
|
|
#define _LINUX_IN6_H
|
|
|
|
#include <uapi/linux/in6.h>
|
|
|
|
/* Large enough to hold both sockaddr_in and sockaddr_in6. */
|
|
struct sockaddr_inet {
|
|
unsigned short sa_family;
|
|
char sa_data[sizeof(struct sockaddr_in6) -
|
|
sizeof(unsigned short)];
|
|
};
|
|
|
|
/* IPv6 Wildcard Address (::) and Loopback Address (::1) defined in RFC2553
|
|
* NOTE: Be aware the IN6ADDR_* constants and in6addr_* externals are defined
|
|
* in network byte order, not in host byte order as are the IPv4 equivalents
|
|
*/
|
|
extern const struct in6_addr in6addr_any;
|
|
#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } }
|
|
extern const struct in6_addr in6addr_loopback;
|
|
#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
|
|
extern const struct in6_addr in6addr_linklocal_allnodes;
|
|
#define IN6ADDR_LINKLOCAL_ALLNODES_INIT \
|
|
{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
|
|
extern const struct in6_addr in6addr_linklocal_allrouters;
|
|
#define IN6ADDR_LINKLOCAL_ALLROUTERS_INIT \
|
|
{ { { 0xff,2,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
|
|
extern const struct in6_addr in6addr_interfacelocal_allnodes;
|
|
#define IN6ADDR_INTERFACELOCAL_ALLNODES_INIT \
|
|
{ { { 0xff,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } }
|
|
extern const struct in6_addr in6addr_interfacelocal_allrouters;
|
|
#define IN6ADDR_INTERFACELOCAL_ALLROUTERS_INIT \
|
|
{ { { 0xff,1,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
|
|
extern const struct in6_addr in6addr_sitelocal_allrouters;
|
|
#define IN6ADDR_SITELOCAL_ALLROUTERS_INIT \
|
|
{ { { 0xff,5,0,0,0,0,0,0,0,0,0,0,0,0,0,2 } } }
|
|
#endif
|