Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Apr 2024 20:33:03 -0700
From:      Bakul Shah <bakul@iitbombay.org>
To:        Mike Karels <mike@karels.net>
Cc:        Warner Losh <imp@bsdimp.com>, FreeBSD Net <freebsd-net@freebsd.org>
Subject:   Re: Question about netinet6/in6.h
Message-ID:  <54E63C68-2713-4247-A57C-D3AA9C571327@iitbombay.org>
In-Reply-To: <4AF50212-9141-44FF-937F-A06AF8B15121@karels.net>
References:  <CANCZdfrDTktpyW9Ad=3-K9qnVYmY_wCnrmyizvgwJktVfHfV3Q@mail.gmail.com> <229EB3F8-FB68-461C-BF1F-3B2846510EBA@karels.net> <AA706B2F-1C77-47B7-915E-6574E1F3654C@karels.net> <CANCZdfrtxsGKKn3bzaWRDhYphYb0DuZ7VTOWeTbR_8X980u_1A@mail.gmail.com> <4AF50212-9141-44FF-937F-A06AF8B15121@karels.net>

next in thread | previous in thread | raw e-mail | index | archive | help


> On Apr 26, 2024, at 5:02=E2=80=AFPM, Mike Karels <mike@karels.net> =
wrote:
>=20
> On 26 Apr 2024, at 18:06, Warner Losh wrote:
>=20
>> On Fri, Apr 26, 2024 at 4:21=E2=80=AFPM Mike Karels <mike@karels.net> =
wrote:
>>=20
>>> On 26 Apr 2024, at 15:49, Mike Karels wrote:
>>>=20
>>>> On 26 Apr 2024, at 15:01, Warner Losh wrote:
>>>>=20
>>>>> This has to be a FAQ
>>>>>=20
>>>>> I'm porting a program from Linux, I often see an error like:
>>>>> ./test/mock-ifaddrs.c:95:19: error: no member named 's6_addr32' in
>>> 'struct
>>>>> in6_addr'
>>>>>   95 |                 ipv6->sin6_addr.s6_addr32[3] =3D 0;
>>>>>      |                 ~~~~~~~~~~~~~~~ ^
>>>>> but yet, we kinda define them, but only for the kernel and boot =
loader:
>>>>> /*
>>>>> * IPv6 address
>>>>> */
>>>>> struct in6_addr {
>>>>>        union {
>>>>>                uint8_t         __u6_addr8[16];
>>>>>                uint16_t        __u6_addr16[8];
>>>>>                uint32_t        __u6_addr32[4];
>>>>>        } __u6_addr;                    /* 128-bit IP6 address */
>>>>> };
>>>>>=20
>>>>> #define s6_addr   __u6_addr.__u6_addr8
>>>>> #if defined(_KERNEL) || defined(_STANDALONE) /* XXX nonstandard */
>>>>> #define s6_addr8  __u6_addr.__u6_addr8
>>>>> #define s6_addr16 __u6_addr.__u6_addr16
>>>>> #define s6_addr32 __u6_addr.__u6_addr32
>>>>> #endif
>>>>>=20
>>>>> I'm wondering if anybody why it's like that? git blame suggests we
>>> imported
>>>>> that from kame, with
>>>>> only tweaks by people that are now deceased*.*
>>>>>=20
>>>>> Why not just expose them?
>>>>=20
>>>> Looks like only s6_addr is specified in the RFCs (2553 and 3493).  =
Oddly,
>>>> though, the RFCs give an example implementation using that union =
with
>>>> different element names (like _S6_u8), and show the one #define.
>>>> Similarly, POSIX specifies only s6_addr, but it allows other =
members
>>>> of the structure, so I don't see a problem with exposing them all =
even
>>>> in a POSIX environment.
>>>>=20
>>>> I would have no objection to exposing all four definitions, =
especially
>>>> if Linux apps use them.
>>>=20
>>> I put the change, along with an explanatory comment, in
>>> https://reviews.freebsd.org/D44979.  Comments welcome.
>>>=20
>>=20
>> Thanks! I was testing a similar change, but I like yours better... =
though
>> maybe
>> we should just make it visible when __BSD_VISIBLE is true.... I'll =
have to
>> look
>> closely at what Linux does here... I think they have it always =
visible, or
>> at least
>> musl does that (glibc is harder to track down due to the many layers =
of
>> indirection).
>=20
> I thought briefly about __BSD_VISIBLE, but wasn't sure it was =
necessary.
> Let me know what you find out.  I think it should work either way; =
in.h
> includes cdefs.h, so it's guaranteed to have been included.

If the -ms-extensions option is used with gcc or clang, this ugliness =
can
go away as you can have nested anonymous unions or -structs and their =
fields
can be referenced as if they're directly in the parent struct/union.

[IIRC this was present in Plan9 C from very early on. Also in C11 or =
later]=



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?54E63C68-2713-4247-A57C-D3AA9C571327>