Skip to content

shared: use the scope of a link-local egress address - #4181

Merged
igaw merged 2 commits into
linux-nvme:masterfrom
martin-belanger:net-util-scoped-ipv6
Oct 15, 2026
Merged

igaw merged 2 commits into
linux-nvme:masterfrom
martin-belanger:net-util-scoped-ipv6

Conversation

@martin-belanger

@martin-belanger martin-belanger commented Oct 14, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #4140.

For a link-local traddr without --host-iface, the route lookup in shr_route_get_egress_iface() returned any interface, because every interface has a route to the link-local prefix. The I/O queue count then came from the wrong NIC.

  • For a link-local destination, the interface named by the scope is used, and there is no route query. Without a valid scope, the function fails, and the default queue count applies.
  • The scope can also be an interface index (fe80::1%2), as in the kernel.

NOTE: The first commit fixes a latent strict-aliasing bug in the same file. The scope change made gcc 14 inline differently in the musl release build, and tree-fabrics then failed because two equal IPv4 addresses compared as different.

Tests in test-net-util.c: scope name, scope index, no scope, unknown scope. All four fail without the fix.

Martin Belanger added 2 commits October 14, 2026 15:14
parse_numeric_addr() writes a struct sockaddr_in or sockaddr_in6 into
a struct sockaddr_storage, and sockaddrs_eq() reads it as a struct
sockaddr. This breaks the strict aliasing rule: the compiler may
assume that the write does not change what the read returns.

The bug was latent. An unrelated change in this file made gcc 14
inline differently in a musl release build. The generated code then
compared two equal IPv4 addresses as different.

Access the addresses through a union of the sockaddr types, and copy
the addresses of getifaddrs() into it.

Fixes: 74b5d63 ("libnvme/util: reimplement numeric address helpers without getaddrinfo")
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Every interface has a route to the IPv6 link-local prefix, so the
route lookup for a link-local traddr returns any interface. The I/O
queue count then comes from the wrong NIC.

For a link-local destination, return the interface that the scope
names. Accept an interface index as scope too, as the kernel does.

Fixes: 6153710 ("shared/net-util-linux: add support for retrieving egress netdev")
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
@igaw
igaw merged commit 9e813f5 into linux-nvme:master Oct 15, 2026
32 of 33 checks passed
@igaw

igaw commented Oct 15, 2026

Copy link
Copy Markdown
Collaborator

Looks good. Thanks!

@martin-belanger
martin-belanger deleted the net-util-scoped-ipv6 branch October 15, 2026 10:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants