mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-07 00:34:42 +00:00
ipn/ipnlocal: send peerapi port(s) in Hostinfo.Services
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
12ae2d73b3
commit
9659ab81e0
@ -1330,25 +1330,47 @@ func (b *LocalBackend) SetPrefs(newp *ipn.Prefs) {
|
|||||||
b.send(ipn.Notify{Prefs: newp})
|
b.send(ipn.Notify{Prefs: newp})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *LocalBackend) peerAPIServicesLocked() (ret []tailcfg.Service) {
|
||||||
|
for _, pln := range b.peerAPIListeners {
|
||||||
|
proto := tailcfg.ServiceProto("peerapi4")
|
||||||
|
if pln.ip.Is6() {
|
||||||
|
proto = "peerapi6"
|
||||||
|
}
|
||||||
|
ret = append(ret, tailcfg.Service{
|
||||||
|
Proto: proto,
|
||||||
|
Port: uint16(pln.Port()),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return ret
|
||||||
|
}
|
||||||
|
|
||||||
// doSetHostinfoFilterServices calls SetHostinfo on the controlclient,
|
// doSetHostinfoFilterServices calls SetHostinfo on the controlclient,
|
||||||
// possibly after mangling the given hostinfo.
|
// possibly after mangling the given hostinfo.
|
||||||
//
|
//
|
||||||
// TODO(danderson): we shouldn't be mangling hostinfo here after
|
// TODO(danderson): we shouldn't be mangling hostinfo here after
|
||||||
// painstakingly constructing it in twelvety other places.
|
// painstakingly constructing it in twelvety other places.
|
||||||
func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) {
|
func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) {
|
||||||
hi2 := *hi
|
b.mu.Lock()
|
||||||
|
cc := b.c
|
||||||
|
if cc == nil {
|
||||||
|
// Control client isn't up yet.
|
||||||
|
b.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
peerAPIServices := b.peerAPIServicesLocked()
|
||||||
|
b.mu.Unlock()
|
||||||
|
|
||||||
|
// Make a shallow copy of hostinfo so we can mutate
|
||||||
|
// at the Service field.
|
||||||
|
hi2 := *hi // shallow copy
|
||||||
if !b.shouldUploadServices() {
|
if !b.shouldUploadServices() {
|
||||||
hi2.Services = []tailcfg.Service{}
|
hi2.Services = []tailcfg.Service{}
|
||||||
}
|
}
|
||||||
|
// Don't mutate hi.Service's underlying array. Append to
|
||||||
b.mu.Lock()
|
// the slice with no free capacity.
|
||||||
cli := b.c
|
c := len(hi2.Services)
|
||||||
b.mu.Unlock()
|
hi2.Services = append(hi2.Services[:c:c], peerAPIServices...)
|
||||||
|
cc.SetHostinfo(&hi2)
|
||||||
// b.c might not be started yet
|
|
||||||
if cli != nil {
|
|
||||||
cli.SetHostinfo(&hi2)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NetMap returns the latest cached network map received from
|
// NetMap returns the latest cached network map received from
|
||||||
@ -1490,6 +1512,7 @@ func (b *LocalBackend) initPeerAPIListener() {
|
|||||||
}
|
}
|
||||||
pln := &peerAPIListener{
|
pln := &peerAPIListener{
|
||||||
ps: ps,
|
ps: ps,
|
||||||
|
ip: a.IP,
|
||||||
ln: ln,
|
ln: ln,
|
||||||
lb: b,
|
lb: b,
|
||||||
}
|
}
|
||||||
|
@ -80,6 +80,7 @@ func (s *peerAPIServer) listen(ip netaddr.IP, ifState *interfaces.State) (ln net
|
|||||||
|
|
||||||
type peerAPIListener struct {
|
type peerAPIListener struct {
|
||||||
ps *peerAPIServer
|
ps *peerAPIServer
|
||||||
|
ip netaddr.IP
|
||||||
ln net.Listener
|
ln net.Listener
|
||||||
lb *LocalBackend
|
lb *LocalBackend
|
||||||
urlStr string
|
urlStr string
|
||||||
|
Loading…
x
Reference in New Issue
Block a user