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

Merged
MarrasFederico merged 1 commit from upstream-pr/7988 into main 2026-10-20 04:51:28 +00:00
MarrasFederico commented 2026-10-19 17:06:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarrasFederico on 2026-10-19T17:06:25Z.


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 #7987).
  • tools/check_conventions.py --base origin/main passes with zero findings. tools/pr_overlap.py lists only PR #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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4924535290 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7988). Originally posted by [MarrasFederico](https://github.com/MarrasFederico) on 2026-10-19T17:06:25Z. --- ### 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`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/net/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`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/lib/libc/net/getifaddrs.c). - Its `ifa_addr` is a FreeBSD 11.4 [`sockaddr_dl`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/net/if_dl.h) 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`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/net/if.c) sizes it. - Its `ifa_data` is a 152-byte FreeBSD 11.4 [`if_data`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/sys/net/if.h) filled as `if_data_copy` in [`sys/net/if.c`](https://github.com/freebsd/freebsd-src/blob/8c639945a44588f6cfdddfb057bb5aad88735da0/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 <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> 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 #7987). - `tools/check_conventions.py --base origin/main` passes with zero findings. `tools/pr_overlap.py` lists only PR #6044 on `GuestInterfaces.cpp` (which moves test files to subdirectories) and open PRs touching unrelated lines of `docs/dev/debt/libc.md`. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none <!-- #PR, or none --> - [x] Fixes: none <!-- issue it closes as Fixes #N, or none --> - [x] Unblocks: none <!-- title ID and Game bring-up discussion, e.g. PPSA01325 #3232, or none --> - [x] GPUs tested: n/a <!-- for AGC, shader recompiler or VideoOut changes: vendor, model, driver and OS of each GPU the GPU tests ran on; otherwise n/a --> - [x] AI-assisted: yes <!-- yes / no -->
github-actions[bot] commented 2026-10-19 17:33:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T17:33:26Z.


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
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273264951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7988#issuecomment-6273264951). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T17:33:26Z. --- <!-- pr-overlap --> 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](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `docs/dev/debt/libc.md` | | [PR 5303](https://www.github.com/boykopovar/AnyPS5/pull/5303) | `docs/dev/debt/libc.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestInterfaces.cpp` | | [PR 6226](https://www.github.com/boykopovar/AnyPS5/pull/6226) | `docs/dev/debt/libc.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `docs/dev/debt/libc.md` | | [PR 6819](https://www.github.com/boykopovar/AnyPS5/pull/6819) | `docs/dev/debt/libc.md` | | [PR 7081](https://www.github.com/boykopovar/AnyPS5/pull/7081) | `docs/dev/debt/libc.md` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `docs/dev/debt/libc.md` | | [PR 7386](https://www.github.com/boykopovar/AnyPS5/pull/7386) | `docs/dev/debt/libc.md` | | [PR 7473](https://www.github.com/boykopovar/AnyPS5/pull/7473) | `docs/dev/debt/libc.md` | | [PR 7715](https://www.github.com/boykopovar/AnyPS5/pull/7715) | `docs/dev/debt/libc.md` |
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7988
No description provided.