device: further add, revise API for on-demand configuration of peers
Updates tailscale/tailscale#17858 Updates tailscale/corp#35603 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
e924a91e99
commit
f69b24781e
5 changed files with 220 additions and 12 deletions
|
|
@ -57,6 +57,11 @@ type Peer struct {
|
|||
sync.Mutex // protects against concurrent Start/Stop, and fields below
|
||||
|
||||
allowedIPs []netip.Prefix
|
||||
|
||||
// testAllowedIP, if non-nil, is used to test whether the peer is
|
||||
// allowed to send a packet from the given IP address. It can be read
|
||||
// without locking, but must be set with the state mutex locked.
|
||||
testAllowedIP atomic.Pointer[func(netip.Addr) bool]
|
||||
}
|
||||
|
||||
queue struct {
|
||||
|
|
@ -138,7 +143,12 @@ func (p *Peer) SetAllowedIPs(allowedIPs []netip.Prefix) {
|
|||
return
|
||||
}
|
||||
p.device.allowedips.setPeerPrefixes(p, allowedIPs)
|
||||
p.state.allowedIPs = slices.Clone(allowedIPs) // avoid retaining caller's slice
|
||||
|
||||
allowedIPs = slices.Clone(allowedIPs) // avoid retaining caller's slice
|
||||
p.state.allowedIPs = allowedIPs
|
||||
|
||||
f := mkIPInCIDRsTestFunc(allowedIPs)
|
||||
p.state.testAllowedIP.Store(&f)
|
||||
}
|
||||
|
||||
// SendBuffers sends buffers to peer. WireGuard packet data in each element of
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue