ipn/ipnlocal: fix peerapi6 port being report as 0 in netstack mode

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-04-01 22:04:46 -07:00
parent 9f105d3968
commit 6266cf8e36
2 changed files with 17 additions and 21 deletions

View File

@@ -1327,7 +1327,7 @@ func (b *LocalBackend) getPeerAPIPortForTSMPPing(ip netaddr.IP) (port uint16, ok
defer b.mu.Unlock()
for _, pln := range b.peerAPIListeners {
if pln.ip.BitLen() == ip.BitLen() {
return uint16(pln.Port()), true
return uint16(pln.port), true
}
}
return 0, false
@@ -1341,7 +1341,7 @@ func (b *LocalBackend) peerAPIServicesLocked() (ret []tailcfg.Service) {
}
ret = append(ret, tailcfg.Service{
Proto: proto,
Port: uint16(pln.Port()),
Port: uint16(pln.port),
})
}
return ret
@@ -1556,13 +1556,12 @@ func (b *LocalBackend) initPeerAPIListener() {
ln: ln, // nil for 2nd+ on netstack
lb: b,
}
var port int
if skipListen {
port = b.peerAPIListeners[0].Port()
pln.port = b.peerAPIListeners[0].port
} else {
port = pln.Port()
pln.port = ln.Addr().(*net.TCPAddr).Port
}
pln.urlStr = "http://" + net.JoinHostPort(a.IP.String(), strconv.Itoa(port))
pln.urlStr = "http://" + net.JoinHostPort(a.IP.String(), strconv.Itoa(pln.port))
b.logf("peerapi: serving on %s", pln.urlStr)
go pln.serve()
b.peerAPIListeners = append(b.peerAPIListeners, pln)