Files
nebula/localaddrs.go
T
JackDoanandClaude Fable 5.1 fcc6008a78 Enumerate Android interfaces without anet
anet's only reason to need -ldflags=-checklinkname=0 is a pair of
//go:linkname pulls that refresh the IPv6 zone caches inside net and
x/net after it enumerates interfaces. localAddrs never resolves a zone
and drops link-local addresses anyway, so nebula was paying for that
flag, and disabling the linker's check for the whole binary, for
nothing it used.

Replace the dependency with the part of anet that matters: an
RTM_GETADDR dump on a netlink socket that is never bound, and
SIOCGIFNAME to name each index. Both are permitted to Android apps,
and it is the same path Bionic's getifaddrs takes for app UIDs. It is
built only for android; every other platform, Linux included, keeps
net.Interfaces.

One dump yields every interface with its addresses, so reshape the
seam to a single enumerator returning localInterface values with a
deferred Addrs. Android hands back what it already has; every other
platform still only asks for the addresses of interfaces the allow
list accepts.

Take the bind-free path unconditionally on android. The sepolicy is
keyed to the app's target SDK rather than the OS release, detecting
either needs cgo, and the path is valid on every release.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01B15ivF2aJUtLFdqJ4iz6zs
2026-09-14 13:26:20 -05:00

19 lines
324 B
Go

//go:build !android
package nebula
import "net"
func localInterfaces() ([]localInterface, error) {
ifaces, err := net.Interfaces()
if err != nil {
return nil, err
}
out := make([]localInterface, len(ifaces))
for n, i := range ifaces {
out[n] = localInterface{Name: i.Name, Addrs: i.Addrs}
}
return out, nil
}