Skip to content

feat(libc): list each interface's AF_LINK entry in getifaddrs on Linux - #7988

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
MarrasFederico:feat/libc-getifaddrs-link-entries
Oct 20, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
MarrasFederico:feat/libc-getifaddrs-link-entries

Conversation

@MarrasFederico

Copy link
Copy Markdown
Contributor

What

getifaddrs on Linux listed only the host's IPv4 and IPv6 addresses, omitting the per-interface AF_LINK entries that FreeBSD 11.4's getifaddrs.c places before each interface's addresses, and with them the interface index, hardware address, MTU, counters and any interface without an IP address.

  • On Linux each interface now starts with an AF_LINK (18) entry followed by its IPv4 and IPv6 addresses, matching the ordering of FreeBSD 11.4 getifaddrs.c.
  • Its ifa_addr is a FreeBSD 11.4 sockaddr_dl with the host interface index, type (IFT_ETHER 0x6, IFT_LOOP 0x18, IFT_PPP 0x17, or IFT_OTHER 0x1), interface name and hardware address (0 bytes on loopback), sized to at least 54 bytes (8-byte aligned) as FreeBSD 11.4's if_attach_internal in sys/net/if.c sizes it.
  • Its ifa_data is a 152-byte FreeBSD 11.4 if_data filled as if_data_copy in sys/net/if.c fills it: ifi_type, ifi_addrlen, ifi_hdrlen (14 for Ethernet, 0 otherwise), ifi_link_state (LINK_STATE_UP 2 or LINK_STATE_DOWN 1), ifi_datalen (152), ifi_mtu (SIOCGIFMTU), ifi_baudrate (from /sys/class/net/<name>/speed in Mb/s when positive) and the 64-bit packet, error, collision, byte, multicast and drop counters from /sys/class/net/<name>/statistics/*, falling back to the 32-bit rtnl_link_stats counters from getifaddrs when sysfs cannot be read.
  • Fields with no host counterpart (ifi_omcasts, ifi_noproto, ifi_hwassist, ifi_metric, ifi_epoch, ifi_lastchange) are 0 and recorded in docs/dev/debt/libc.md.
  • The Windows code path is unchanged and was not compiled.

Tested

Ubuntu 26.04.1, kernel 7.0.0-38, GCC 15.2.0, Release, full build with BUILD_TESTING=ON. Windows was not compiled (Windows code is unchanged). No title was run.

  • guest_interfaces: checks that each interface's AF_LINK entry precedes its IPv4/IPv6 addresses, verifies sockaddr_dl layout (sdl_len, sdl_family 18, sdl_index against if_nametoindex, sdl_type, sdl_nlen, sdl_alen, sdl_slen, name and hardware address bytes) and if_data layout (ifi_datalen 152, ifi_type, ifi_addrlen, ifi_hdrlen, ifi_link_state, ifi_mtu against SIOCGIFMTU, and nonzero loopback packet/byte counters bounded by sysfs after sending a loopback datagram).
  • Also verified in an isolated network namespace (unshare -rn) with an unaddressed interface and with the rtnl_link_stats counter fallback.
  • Mutation checks: three deliberate errors (wrong ifi_datalen, swapped AF_LINK ordering, wrong sdl_index offset) each make guest_interfaces fail.
  • Full ctest --test-dir build -E '^agc' -j16 --timeout 300 run passes (except guest_sce_net, which aborts on this host as described in test(libSceNet): accept every unusable IPv6 loopback error in guest_sce_net #7987).
  • tools/check_conventions.py --base origin/main passes with zero findings. tools/pr_overlap.py lists only PR test: organize library tests and label CTest suites #6044 on GuestInterfaces.cpp (which moves test files to subdirectories) and open PRs touching unrelated lines of docs/dev/debt/libc.md.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

getifaddrs listed only the host's IPv4 and IPv6 addresses, so the
per-interface AF_LINK entries FreeBSD's getifaddrs puts first were
missing, and with them the interface index, hardware address, MTU and
counters and every interface without an address.

On Linux each interface now starts with an AF_LINK entry, followed by
its addresses, as FreeBSD 11.4's getifaddrs orders them. Its address is
a sockaddr_dl with the host index, type, name and hardware address
(none for a loopback), sized as FreeBSD's if_attach sizes it. Its
ifa_data is a 152-byte FreeBSD if_data filled as if_data_copy fills it:
type, address and header length, link state, MTU, speed and the host's
packet, byte, error, drop and multicast counters from sysfs, or the
host list's 32-bit counters when sysfs cannot be read. Fields with no
host equivalent are 0 and listed in the debt entry. Windows is
unchanged.
@github-actions

github-actions Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 5021 docs/dev/debt/libc.md
PR 5303 docs/dev/debt/libc.md
PR 6044 core/libs/tests/GuestInterfaces.cpp
PR 6226 docs/dev/debt/libc.md
PR 6469 docs/dev/debt/libc.md
PR 6819 docs/dev/debt/libc.md
PR 7081 docs/dev/debt/libc.md
PR 7332 docs/dev/debt/libc.md
PR 7386 docs/dev/debt/libc.md
PR 7473 docs/dev/debt/libc.md
PR 7715 docs/dev/debt/libc.md

@oneandonlydean oneandonlydean self-assigned this Oct 20, 2026
@oneandonlydean
oneandonlydean merged commit 329b9aa into boykopovar:main Oct 20, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants