From cbdc9dd0cc902e4914ceaef7c690415e63b5a3f1 Mon Sep 17 00:00:00 2001 From: Anton Litvinov Date: Wed, 14 Feb 2024 16:57:13 +0400 Subject: [PATCH] Release IP address on session stop only for Windows Signed-off-by: Anton Litvinov --- services/wireguard/connection/connection_test.go | 1 + services/wireguard/service/service.go | 5 ++++- services/wireguard/service/service_test.go | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/services/wireguard/connection/connection_test.go b/services/wireguard/connection/connection_test.go index cbc2930b6a..876821b97d 100644 --- a/services/wireguard/connection/connection_test.go +++ b/services/wireguard/connection/connection_test.go @@ -158,6 +158,7 @@ func (mce *mockConnectionEndpoint) ConfigureRoutes(_ net.IP) error { retur func (mce *mockConnectionEndpoint) PeerStats() (wgcfg.Stats, error) { return wgcfg.Stats{LastHandshake: time.Now(), BytesSent: 10, BytesReceived: 11}, nil } +func (mce *mockConnectionEndpoint) ReleaseIP(ip net.IPNet) {} type mockHandshakeWaiter struct { err error diff --git a/services/wireguard/service/service.go b/services/wireguard/service/service.go index b191340306..994f00d3e9 100644 --- a/services/wireguard/service/service.go +++ b/services/wireguard/service/service.go @@ -21,6 +21,7 @@ import ( "encoding/json" "fmt" "net" + "runtime" "sync" "time" @@ -188,7 +189,9 @@ func (m *Manager) ProvideConfig(sessionID string, sessionConfig json.RawMessage, if err := conn.Stop(); err != nil { log.Error().Err(err).Msg("Failed to stop connection endpoint") } - conn.ReleaseIP(config.Consumer.IPAddress) + if runtime.GOOS == "windows" { + conn.ReleaseIP(config.Consumer.IPAddress) + } if err := m.resourcesAllocator.ReleaseIPNet(providerConfig.Subnet); err != nil { log.Error().Err(err).Msg("Failed to release IP network") diff --git a/services/wireguard/service/service_test.go b/services/wireguard/service/service_test.go index ddc53a3fd0..afce97fca6 100644 --- a/services/wireguard/service/service_test.go +++ b/services/wireguard/service/service_test.go @@ -101,6 +101,7 @@ func (mce *mockConnectionEndpoint) ConfigureRoutes(_ net.IP) error { retur func (mce *mockConnectionEndpoint) PeerStats() (wgcfg.Stats, error) { return wgcfg.Stats{LastHandshake: time.Now()}, nil } +func (mce *mockConnectionEndpoint) ReleaseIP(ip net.IPNet) {} func newManagerStub(pub, out, country string) *Manager { dnsHandler, _ := dns.ResolveViaSystem()