Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Apr 2024 17:06:31 -0600
From:      Warner Losh <imp@bsdimp.com>
To:        Mike Karels <mike@karels.net>
Cc:        FreeBSD Net <freebsd-net@freebsd.org>
Subject:   Re: Question about netinet6/in6.h
Message-ID:  <CANCZdfrtxsGKKn3bzaWRDhYphYb0DuZ7VTOWeTbR_8X980u_1A@mail.gmail.com>
In-Reply-To: <AA706B2F-1C77-47B7-915E-6574E1F3654C@karels.net>
References:  <CANCZdfrDTktpyW9Ad=3-K9qnVYmY_wCnrmyizvgwJktVfHfV3Q@mail.gmail.com> <229EB3F8-FB68-461C-BF1F-3B2846510EBA@karels.net> <AA706B2F-1C77-47B7-915E-6574E1F3654C@karels.net>

next in thread | previous in thread | raw e-mail | index | archive | help
--000000000000fe240c061707f464
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

On Fri, Apr 26, 2024 at 4:21=E2=80=AFPM Mike Karels <mike@karels.net> wrote=
:

> On 26 Apr 2024, at 15:49, Mike Karels wrote:
>
> > On 26 Apr 2024, at 15:01, Warner Losh wrote:
> >
> >> This has to be a FAQ
> >>
> >> 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 */
> >> };
> >>
> >> #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
> >>
> >> 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*.*
> >>
> >> Why not just expose them?
> >
> > Looks like only s6_addr is specified in the RFCs (2553 and 3493).  Oddl=
y,
> > 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.
> >
> > I would have no objection to exposing all four definitions, especially
> > if Linux apps use them.
>
> I put the change, along with an explanatory comment, in
> https://reviews.freebsd.org/D44979.  Comments welcome.
>

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).

Warner

--000000000000fe240c061707f464
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div dir=3D"ltr"><br></div><br><div class=3D"gmail_quote">=
<div dir=3D"ltr" class=3D"gmail_attr">On Fri, Apr 26, 2024 at 4:21=E2=80=AF=
PM Mike Karels &lt;<a href=3D"mailto:mike@karels.net">mike@karels.net</a>&g=
t; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0px 0p=
x 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On 26 =
Apr 2024, at 15:49, Mike Karels wrote:<br>
<br>
&gt; On 26 Apr 2024, at 15:01, Warner Losh wrote:<br>
&gt;<br>
&gt;&gt; This has to be a FAQ<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m porting a program from Linux, I often see an error like:<b=
r>
&gt;&gt; ./test/mock-ifaddrs.c:95:19: error: no member named &#39;s6_addr32=
&#39; in &#39;struct<br>
&gt;&gt; in6_addr&#39;<br>
&gt;&gt;=C2=A0 =C2=A0 95 |=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0ipv6-&gt;sin6_addr.s6_addr32[3] =3D 0;<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0|=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=
=A0 =C2=A0 =C2=A0 =C2=A0~~~~~~~~~~~~~~~ ^<br>
&gt;&gt; but yet, we kinda define them, but only for the kernel and boot lo=
ader:<br>
&gt;&gt; /*<br>
&gt;&gt;=C2=A0 * IPv6 address<br>
&gt;&gt;=C2=A0 */<br>
&gt;&gt; struct in6_addr {<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0union {<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uint8=
_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0__u6_addr8[16];<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uint1=
6_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 __u6_addr16[8];<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0uint3=
2_t=C2=A0 =C2=A0 =C2=A0 =C2=A0 __u6_addr32[4];<br>
&gt;&gt;=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0} __u6_addr;=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 /* 128-bit IP6 address */<=
br>
&gt;&gt; };<br>
&gt;&gt;<br>
&gt;&gt; #define s6_addr=C2=A0 =C2=A0__u6_addr.__u6_addr8<br>
&gt;&gt; #if defined(_KERNEL) || defined(_STANDALONE) /* XXX nonstandard */=
<br>
&gt;&gt; #define s6_addr8=C2=A0 __u6_addr.__u6_addr8<br>
&gt;&gt; #define s6_addr16 __u6_addr.__u6_addr16<br>
&gt;&gt; #define s6_addr32 __u6_addr.__u6_addr32<br>
&gt;&gt; #endif<br>
&gt;&gt;<br>
&gt;&gt; I&#39;m wondering if anybody why it&#39;s like that? git blame sug=
gests we imported<br>
&gt;&gt; that from kame, with<br>
&gt;&gt; only tweaks by people that are now deceased*.*<br>
&gt;&gt;<br>
&gt;&gt; Why not just expose them?<br>
&gt;<br>
&gt; Looks like only s6_addr is specified in the RFCs (2553 and 3493).=C2=
=A0 Oddly,<br>
&gt; though, the RFCs give an example implementation using that union with<=
br>
&gt; different element names (like _S6_u8), and show the one #define.<br>
&gt; Similarly, POSIX specifies only s6_addr, but it allows other members<b=
r>
&gt; of the structure, so I don&#39;t see a problem with exposing them all =
even<br>
&gt; in a POSIX environment.<br>
&gt;<br>
&gt; I would have no objection to exposing all four definitions, especially=
<br>
&gt; if Linux apps use them.<br>
<br>
I put the change, along with an explanatory comment, in<br>
<a href=3D"https://reviews.freebsd.org/D44979" rel=3D"noreferrer" target=3D=
"_blank">https://reviews.freebsd.org/D44979</a>.=C2=A0 Comments welcome.<br=
></blockquote><div><br></div><div>Thanks! I was testing a similar change, b=
ut I like yours better... though maybe</div><div>we should just make it vis=
ible when __BSD_VISIBLE is true.... I&#39;ll have to look</div><div>closely=
 at what Linux does here... I think they have it always visible, or at leas=
t</div><div>musl does that (glibc is harder to track down due to the many l=
ayers of indirection).</div><div><br></div><div>Warner<br></div></div></div=
>

--000000000000fe240c061707f464--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CANCZdfrtxsGKKn3bzaWRDhYphYb0DuZ7VTOWeTbR_8X980u_1A>