Skip to content

ssdp: allow overriding interface address lookup - #195

Merged
anacrolix merged 1 commit into
anacrolix:masterfrom
lieranderl:ssdp-interface-addrs-hook
Nov 11, 2026
Merged

anacrolix merged 1 commit into
anacrolix:masterfrom
lieranderl:ssdp-interface-addrs-hook

Conversation

@lieranderl

Copy link
Copy Markdown
Contributor

Problem

On Android 11+ (API 30+), net.Interface.Addrs() fails for ordinary apps because SELinux denies the netlink RTM_GETADDR request. This is a long-standing Go issue: golang/go#40569.

When that happens, ssdp.Server.Serve returns right after it starts, so the server is never announced and clients can't discover it. The HTTP side keeps working fine. Log from a real device (Android 14, running under Termux):

"wlan0": "route ip+net: netlinkrib: permission denied"
"eth0":  "route ip+net: netlinkrib: permission denied"

The same lookup in the M-SEARCH handler panics on that error. Today it's only unreachable because Serve has already exited.

Listing interfaces isn't a problem, since dms.Server.Interfaces can already be set by the caller (for example from github.com/wlynxg/anet). Looking up the addresses inside ssdp has no such override.

Change

  • ssdp.Server.InterfaceAddrs func(net.Interface) ([]net.Addr, error): optional. When it's nil, net.Interface.Addrs is used, so existing behaviour is unchanged.
  • dms.Server.InterfaceAddrs passes it through to each ssdp.Server.
  • The M-SEARCH handler logs the error and skips the response instead of panicking.
  • CHANGELOG entry under Unreleased.

This adds no Android-specific code or new dependency to dms. A caller on Android would set:

InterfaceAddrs: func(i net.Interface) ([]net.Addr, error) {
	return anet.InterfaceAddrsByInterface(&i)
},

Testing

  • go build ./..., go vet ./ssdp ./dlna/dms and go test ./dlna/... all pass.

  • No behaviour change when the field is unset.

  • On a real device (Android 14, built natively under Termux with Go 1.26.4, ssdp.Server on eth0, with another LAN host listening on 239.255.255.250:1900 for 24 s):

    Serve() NOTIFYs received M-SEARCH reply
    without InterfaceAddrs returns netlinkrib: permission denied immediately 0 none
    with InterfaceAddrs from anet keeps running 12 yes, correct LOCATION

🤖 Generated with Claude Code

net.Interface.Addrs fails with "route ip+net: netlinkrib: permission
denied" on Android 11+ for non-system apps (golang/go#40569), which makes
ssdp.Server.Serve return immediately, so the server is never announced.

Add an optional InterfaceAddrs func to ssdp.Server, passed through from
dms.Server, so callers can supply a working lookup (e.g. wlynxg/anet).
Behaviour is unchanged when it's nil.

Also stop panicking in the M-SEARCH handler when the lookup fails; log
and skip the response instead.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@lieranderl
lieranderl force-pushed the ssdp-interface-addrs-hook branch from dda3619 to 6a01604 Compare October 2, 2026 12:49
@anacrolix
anacrolix merged commit ed8d06b into anacrolix:master Nov 11, 2026
@anacrolix

Copy link
Copy Markdown
Owner

Why don't you also include the anet package and its function on Android?

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