mirror of
https://github.com/tailscale/tailscale.git
synced 2025-01-05 23:07:44 +00:00
net/portmapper: don't pick external ports below 1024
Some devices don't let you UPnP portmap a port below 1024, so let's just avoid that range of ports entirely. Updates #7377 Signed-off-by: Andrew Dunham <andrew@du.nham.ca> Change-Id: Ib7603b1c9a019162cdc4fa21744a2cae48bb1d86
This commit is contained in:
parent
69f9c17555
commit
d379a25ae4
@ -124,8 +124,15 @@ func addAnyPortMapping(
|
||||
uint32(leaseDuration.Seconds()),
|
||||
)
|
||||
}
|
||||
for externalPort == 0 {
|
||||
externalPort = uint16(rand.Intn(65535))
|
||||
|
||||
// Some devices don't let clients add a port mapping for privileged
|
||||
// ports (ports below 1024).
|
||||
//
|
||||
// Pick an external port that's greater than 1024 by getting a random
|
||||
// number in [0, 65535 - 1024] and then adding 1024 to it, shifting the
|
||||
// range to [1024, 65535].
|
||||
if externalPort < 1024 {
|
||||
externalPort = uint16(rand.Intn(65535-1024) + 1024)
|
||||
}
|
||||
err = upnp.AddPortMapping(
|
||||
ctx,
|
||||
|
Loading…
x
Reference in New Issue
Block a user