mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-04 20:09:03 +00:00
tailcfg,all: add/plumb Node.IsJailed
This adds a new bool that can be sent down from control to do jailing on the client side. Previously this would only be done from control by modifying the packet filter we sent down to clients. This would result in a lot of additional work/CPU on control, we could instead just do this on the client. This has always been a TODO which we keep putting off, might as well do it now. Updates tailscale/corp#19623 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
@@ -71,6 +71,9 @@ type Server struct {
|
||||
// by the specified node.
|
||||
nodeSubnetRoutes map[key.NodePublic][]netip.Prefix
|
||||
|
||||
// peerIsJailed is the set of peers that are jailed for a node.
|
||||
peerIsJailed map[key.NodePublic]map[key.NodePublic]bool // node => peer => isJailed
|
||||
|
||||
// masquerades is the set of masquerades that should be applied to
|
||||
// MapResponses sent to clients. It is keyed by the requesting nodes
|
||||
// public key, and then the peer node's public key. The value is the
|
||||
@@ -379,6 +382,20 @@ type MasqueradePair struct {
|
||||
NodeMasqueradesAs netip.Addr
|
||||
}
|
||||
|
||||
// SetJailed sets b to be jailed when it is a peer of a.
|
||||
func (s *Server) SetJailed(a, b key.NodePublic, jailed bool) {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.peerIsJailed == nil {
|
||||
s.peerIsJailed = map[key.NodePublic]map[key.NodePublic]bool{}
|
||||
}
|
||||
if s.peerIsJailed[a] == nil {
|
||||
s.peerIsJailed[a] = map[key.NodePublic]bool{}
|
||||
}
|
||||
s.peerIsJailed[a][b] = jailed
|
||||
s.updateLocked("SetJailed", s.nodeIDsLocked(0))
|
||||
}
|
||||
|
||||
// SetMasqueradeAddresses sets the masquerade addresses for the server.
|
||||
// See MasqueradePair for more details.
|
||||
func (s *Server) SetMasqueradeAddresses(pairs []MasqueradePair) {
|
||||
@@ -945,6 +962,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
|
||||
|
||||
s.mu.Lock()
|
||||
nodeMasqs := s.masquerades[node.Key]
|
||||
jailed := maps.Clone(s.peerIsJailed[node.Key])
|
||||
s.mu.Unlock()
|
||||
for _, p := range s.AllNodes() {
|
||||
if p.StableID == node.StableID {
|
||||
@@ -957,6 +975,7 @@ func (s *Server) MapResponse(req *tailcfg.MapRequest) (res *tailcfg.MapResponse,
|
||||
p.SelfNodeV4MasqAddrForThisPeer = ptr.To(masqIP)
|
||||
}
|
||||
}
|
||||
p.IsJailed = jailed[p.Key]
|
||||
|
||||
s.mu.Lock()
|
||||
peerAddress := s.masquerades[p.Key][node.Key]
|
||||
|
||||
Reference in New Issue
Block a user