public inbox for
 help / color / mirror / Atom feed
From: James Hanley <>
Subject: in6_addr struct union with uint64_t
Date: Fri, 26 Jan 2024 09:57:57 -0500	[thread overview]
Message-ID: <> (raw)

[-- Attachment #1: Type: text/plain, Size: 1533 bytes --]

In a local experiment, I added the union fields __u6_addr64 and
__u6_addr128 for in the in6_addr structure to allow the compiler to
optimize access for the Interface ID of an IPv6 address as applicable using
the EUI-48/64 in IPv6 in the case of the uint64_t and to allow the compiler
to optimize access when comparing, setting, manipulating IPv6 addresses as
a whole with the GCC specific unsigned __int128. Code below modified
from inet/netinet/in.h:

/* IPv6 address */
struct in6_addr
        uint8_t __u6_addr8[16];
        uint16_t __u6_addr16[8];
        uint32_t __u6_addr32[4];
        uint64_t __u6_addr64[2]; // new
        unsigned __int128 __u6_addr128; // new
      } __in6_u;
#define s6_addr                 __in6_u.__u6_addr8
#ifdef __USE_MISC
# define s6_addr16              __in6_u.__u6_addr16
# define s6_addr32              __in6_u.__u6_addr32
# define s6_addr64              __in6_u.__u6_addr64
# define s6_addr128             __in6_u.__u6_addr128
#endif /* !__USE_KERNEL_IPV6_DEFS */

First, is this useful, and is there a standard that prohibits defining
additional union members?

Second, when building, I hit an alignment issue in an assertion check in
resolv/resolv_conf.c comparing sockaddr_in and sockaddr_in6 with the
change.  I assumed I should add "__attribute__((aligned(128)))" ahead of
the struct sockaddr_in definition to force sockaddr_in to align to 128bit,
however, this did not resolve the issue. Any suggestions?

Thanks much,

             reply	other threads:[~2024-01-26 14:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 14:57 James Hanley [this message]
2024-01-26 19:38 ` Florian Weimer
2024-01-29 18:02   ` James Hanley
2024-01-29 19:08     ` Florian Weimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).