#21562·tailscale

net/portmapper: UPnP mapping fails with "unexpected host" when the Location URL has no port

Author: RaphaelFakhriCreated Sep 29, 2026Updated Sep 29, 2026
Labelsbugpod/network-features

What is the issue?

getUPnPRootDevice parses the host of the discovery response's Location header with netip.ParseAddrPort. That call fails if the URL leaves out the port, which is legal for the default HTTP port. A router that answers SSDP discovery with Location: http://192.168.1.1/rootDesc.xml is rejected with:

unexpected host "192.168.1.1" in "http://192.168.1.1/rootDesc.xml"

and no UPnP port mapping is created for that gateway.

The same code path repoints a Location that names a different address at the gateway. That step calls net.JoinHostPort(gw.String(), u.Port()), which would produce 192.168.1.1: for a URL without a port.

Steps to reproduce

Call getUPnPRootDevice with meta.Location set to http://192.168.1.1/rootDesc.xml and gw set to 192.168.1.1. The call returns the error above before any request is made.

Expected behavior

The port is optional. The root description is fetched from the gateway, on the given port if there is one and on the scheme's default port otherwise.

Version

Current main.