ipn/ipnlocal: send peerapi port(s) in Hostinfo.Services

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1612/head
Brad Fitzpatrick 3 years ago
parent 12ae2d73b3
commit 9659ab81e0

@ -1330,25 +1330,47 @@ func (b *LocalBackend) SetPrefs(newp *ipn.Prefs) {
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,
// possibly after mangling the given hostinfo.
//
// TODO(danderson): we shouldn't be mangling hostinfo here after
// painstakingly constructing it in twelvety other places.
func (b *LocalBackend) doSetHostinfoFilterServices(hi *tailcfg.Hostinfo) {
hi2 := *hi
if !b.shouldUploadServices() {
hi2.Services = []tailcfg.Service{}
}
b.mu.Lock()
cli := b.c
cc := b.c
if cc == nil {
// Control client isn't up yet.
b.mu.Unlock()
return
}
peerAPIServices := b.peerAPIServicesLocked()
b.mu.Unlock()
// b.c might not be started yet
if cli != nil {
cli.SetHostinfo(&hi2)
// Make a shallow copy of hostinfo so we can mutate
// at the Service field.
hi2 := *hi // shallow copy
if !b.shouldUploadServices() {
hi2.Services = []tailcfg.Service{}
}
// Don't mutate hi.Service's underlying array. Append to
// the slice with no free capacity.
c := len(hi2.Services)
hi2.Services = append(hi2.Services[:c:c], peerAPIServices...)
cc.SetHostinfo(&hi2)
}
// NetMap returns the latest cached network map received from
@ -1490,6 +1512,7 @@ func (b *LocalBackend) initPeerAPIListener() {
}
pln := &peerAPIListener{
ps: ps,
ip: a.IP,
ln: ln,
lb: b,
}

@ -80,6 +80,7 @@ func (s *peerAPIServer) listen(ip netaddr.IP, ifState *interfaces.State) (ln net
type peerAPIListener struct {
ps *peerAPIServer
ip netaddr.IP
ln net.Listener
lb *LocalBackend
urlStr string

Loading…
Cancel
Save