From nobody Sat Apr 27 11:57:41 2024 X-Original-To: freebsd-net@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VRSlD6Dnpz5JS4F for ; Sat, 27 Apr 2024 11:57:44 +0000 (UTC) (envelope-from mike@karels.net) Received: from mail2.karels.net (mail2.karels.net [3.19.118.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "freebsd", Issuer "freebsd" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VRSlD3wnmz4ZxC for ; Sat, 27 Apr 2024 11:57:44 +0000 (UTC) (envelope-from mike@karels.net) Authentication-Results: mx1.freebsd.org; none Received: from mail2.karels.net (localhost [IPv6:0:0:0:0:0:0:0:1]) by mail2.karels.net (8.18.1/8.18.1) with ESMTP id 43RBvfei088714; Sat, 27 Apr 2024 06:57:42 -0500 (CDT) (envelope-from mike@karels.net) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=karels.net; s=mail2; t=1714219062; bh=poslSk6EHAklAm+2a0+JG4XeoCAJBdp2hAb0O7Xr660=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eZ9OeJkca7Cdj7LFZ4iupu9JT3ShY0osvwtYR2N/4AWvNHQzTLh13aquyWRa9NpfC iA931Tc0QK3Vmhz5wfRxzNKIgCbMatwpsGoWZS1TQ5jC0uQk3vSgiyjgmapzttGzST vAG3o5sz54ZQViY7BI8CWHGPXfe+CxUTFZ55NBNpJLS5GvEh3Qja8vsrdNAWLeTiLU xj4W0MapsbhhS9ecM44uY2v4Vb3uOwpwrC8np17KY2qyRdjzQloqNseF50fXOvieeU MAplksVEdyRwhnePhqvCZpzWv9Y+0kDb5ugGRXhWk/pCl+YI3C+Vdt2Nhf7kAW9oxn YtYiFd/7MaP3Q== Received: from [10.0.2.130] ([73.62.165.147]) by mail2.karels.net with ESMTPSA id HZUPNzXoLGaIWgEAs/W3XQ (envelope-from ); Sat, 27 Apr 2024 06:57:41 -0500 From: Mike Karels To: Bakul Shah Cc: Warner Losh , FreeBSD Net Subject: Re: Question about netinet6/in6.h Date: Sat, 27 Apr 2024 06:57:41 -0500 X-Mailer: MailMate (1.14r6028) Message-ID: <03AAFE2A-8BCE-4E5E-8510-1D5AB58AC363@karels.net> In-Reply-To: References: <229EB3F8-FB68-461C-BF1F-3B2846510EBA@karels.net> <4AF50212-9141-44FF-937F-A06AF8B15121@karels.net> <54E63C68-2713-4247-A57C-D3AA9C571327@iitbombay.org> List-Id: Networking and TCP/IP with FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-net List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-net@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Spamd-Bar: ---- X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[]; ASN(0.00)[asn:16509, ipnet:3.16.0.0/14, country:US] X-Rspamd-Queue-Id: 4VRSlD3wnmz4ZxC On 26 Apr 2024, at 23:02, Bakul Shah wrote: > On Apr 26, 2024, at 8:41=E2=80=AFPM, Warner Losh wrote= : >> >> >> >> On Fri, Apr 26, 2024, 9:33=E2=80=AFPM Bakul Shah = wrote: >> >> >>> On Apr 26, 2024, at 5:02=E2=80=AFPM, Mike Karels wr= ote: >>> >>> On 26 Apr 2024, at 18:06, Warner Losh wrote: >>> >>>> On Fri, Apr 26, 2024 at 4:21=E2=80=AFPM Mike Karels 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' i= n >>>>> '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 l= oader: >>>>>>> /* >>>>>>> * 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 w= e >>>>> 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). = Oddly, >>>>>> though, the RFCs give an example implementation using that union w= ith >>>>>> different element names (like _S6_u8), and show the one #define. >>>>>> Similarly, POSIX specifies only s6_addr, but it allows other membe= rs >>>>>> 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, especi= ally >>>>>> 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... t= hough >>>> maybe >>>> we should just make it visible when __BSD_VISIBLE is true.... I'll h= ave to >>>> look >>>> closely at what Linux does here... I think they have it always visib= le, or >>>> at least >>>> musl does that (glibc is harder to track down due to the many layers= of >>>> indirection). >>> >>> I thought briefly about __BSD_VISIBLE, but wasn't sure it was necessa= ry. >>> Let me know what you find out. I think it should work either way; in= =2Eh >>> 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 l= ater] >> >> True. In fact c11 and newer doesn't need anything on the command line = here. If it were only in the kernel then I'd chamge it like thay while I = was here... but lots of code in ports will specify c99 + POSIX 2001 and t= o compile there your only hope is this construct.... > > Such defines were typically within #if defined(KERNEL) .. #endif > so non-kld ports shouldn't be referring to them, right?! I don't know if that is typical, but in this case the point is to make it= visible to user level. We don't expect base/ports to do that currently, but imported programs will. Mike