Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ func (device *Device) upLocked() error {
device.peers.RLock()
for _, peer := range device.peers.keyMap {
peer.Start()
peer.SendHandshakeInitiation(false)
if peer.persistentKeepaliveInterval.Load() > 0 {
peer.SendKeepalive()
}
Expand All @@ -191,6 +192,20 @@ func (device *Device) upLocked() error {
return nil
}

// DrainPeers expires the current keypairs for all peers, causing each peer to
// immediately initiate a new handshake on the next send attempt. Call this
// before gracefully shutting down or restarting the device so that clients
// re-establish sessions with the new instance quickly rather than waiting up
// to RekeyAfterTime (120 s) for natural expiry.
func (device *Device) DrainPeers() {
device.peers.RLock()
defer device.peers.RUnlock()
for _, peer := range device.peers.keyMap {
peer.ExpireCurrentKeypairs()
}
device.log.Verbosef("DrainPeers: expired keypairs for %d peer(s)", len(device.peers.keyMap))
}

// downLocked attempts to bring the device down.
// The caller must hold device.state.mu and is responsible for updating device.state.state.
func (device *Device) downLocked() error {
Expand Down
11 changes: 11 additions & 0 deletions device/uapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ const (
type Config struct {
BindIpv4 *string
BindIpv6 *string
// Drain, when true, expires all peer keypairs before applying any other
// config changes. Useful for signalling an imminent server restart so that
// clients re-handshake quickly rather than waiting for natural session expiry.
Drain bool

wgtypes.Config
}
Expand Down Expand Up @@ -198,6 +202,13 @@ func (device *Device) IpcSet2(deviceConfig *Config) (err error) {
}
}()

// Drain peers before applying any other changes if requested.

if deviceConfig.Drain {
device.log.Verbosef("UAPI: Draining all peer sessions")
device.DrainPeers()
}

// Configuring Device //

// private key
Expand Down