|
|
@ -60,7 +60,6 @@ var addH2C func(*http.Server)
|
|
|
|
type peerAPIServer struct {
|
|
|
|
type peerAPIServer struct {
|
|
|
|
b *LocalBackend
|
|
|
|
b *LocalBackend
|
|
|
|
rootDir string // empty means file receiving unavailable
|
|
|
|
rootDir string // empty means file receiving unavailable
|
|
|
|
selfNode *tailcfg.Node
|
|
|
|
|
|
|
|
knownEmpty atomic.Bool
|
|
|
|
knownEmpty atomic.Bool
|
|
|
|
resolver *resolver.Resolver
|
|
|
|
resolver *resolver.Resolver
|
|
|
|
|
|
|
|
|
|
|
@ -514,10 +513,17 @@ func (pln *peerAPIListener) ServeConn(src netip.AddrPort, c net.Conn) {
|
|
|
|
c.Close()
|
|
|
|
c.Close()
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nm := pln.lb.NetMap()
|
|
|
|
|
|
|
|
if nm == nil || nm.SelfNode == nil {
|
|
|
|
|
|
|
|
logf("peerapi: no netmap")
|
|
|
|
|
|
|
|
c.Close()
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
h := &peerAPIHandler{
|
|
|
|
h := &peerAPIHandler{
|
|
|
|
ps: pln.ps,
|
|
|
|
ps: pln.ps,
|
|
|
|
isSelf: pln.ps.selfNode.User == peerNode.User,
|
|
|
|
isSelf: nm.SelfNode.User == peerNode.User,
|
|
|
|
remoteAddr: src,
|
|
|
|
remoteAddr: src,
|
|
|
|
|
|
|
|
selfNode: nm.SelfNode,
|
|
|
|
peerNode: peerNode,
|
|
|
|
peerNode: peerNode,
|
|
|
|
peerUser: peerUser,
|
|
|
|
peerUser: peerUser,
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -535,6 +541,7 @@ type peerAPIHandler struct {
|
|
|
|
ps *peerAPIServer
|
|
|
|
ps *peerAPIServer
|
|
|
|
remoteAddr netip.AddrPort
|
|
|
|
remoteAddr netip.AddrPort
|
|
|
|
isSelf bool // whether peerNode is owned by same user as this node
|
|
|
|
isSelf bool // whether peerNode is owned by same user as this node
|
|
|
|
|
|
|
|
selfNode *tailcfg.Node // this node; always non-nil
|
|
|
|
peerNode *tailcfg.Node // peerNode is who's making the request
|
|
|
|
peerNode *tailcfg.Node // peerNode is who's making the request
|
|
|
|
peerUser tailcfg.UserProfile // profile of peerNode
|
|
|
|
peerUser tailcfg.UserProfile // profile of peerNode
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -552,7 +559,7 @@ func (h *peerAPIHandler) validateHost(r *http.Request) error {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
hostIPPfx := netip.PrefixFrom(ap.Addr(), ap.Addr().BitLen())
|
|
|
|
hostIPPfx := netip.PrefixFrom(ap.Addr(), ap.Addr().BitLen())
|
|
|
|
if !slices.Contains(h.ps.selfNode.Addresses, hostIPPfx) {
|
|
|
|
if !slices.Contains(h.selfNode.Addresses, hostIPPfx) {
|
|
|
|
return fmt.Errorf("%v not found in self addresses", hostIPPfx)
|
|
|
|
return fmt.Errorf("%v not found in self addresses", hostIPPfx)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
@ -778,14 +785,7 @@ func (h *peerAPIHandler) canPutFile() bool {
|
|
|
|
// canDebug reports whether h can debug this node (goroutines, metrics,
|
|
|
|
// canDebug reports whether h can debug this node (goroutines, metrics,
|
|
|
|
// magicsock internal state, etc).
|
|
|
|
// magicsock internal state, etc).
|
|
|
|
func (h *peerAPIHandler) canDebug() bool {
|
|
|
|
func (h *peerAPIHandler) canDebug() bool {
|
|
|
|
// Reread the selfNode as it may have changed since the peerAPIServer
|
|
|
|
if !slices.Contains(h.selfNode.Capabilities, tailcfg.CapabilityDebug) {
|
|
|
|
// was created.
|
|
|
|
|
|
|
|
// TODO(maisem): handle this in other places too.
|
|
|
|
|
|
|
|
nm := h.ps.b.NetMap()
|
|
|
|
|
|
|
|
if nm == nil || nm.SelfNode == nil {
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if !slices.Contains(nm.SelfNode.Capabilities, tailcfg.CapabilityDebug) {
|
|
|
|
|
|
|
|
// This node does not expose debug info.
|
|
|
|
// This node does not expose debug info.
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|