Skip to content

Commit

Permalink
Release IP address on session stop only for Windows
Browse files Browse the repository at this point in the history
Signed-off-by: Anton Litvinov <[email protected]>
  • Loading branch information
Zensey committed Apr 30, 2024
1 parent 537003d commit ab5ba2e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions services/wireguard/connection/connection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion services/wireguard/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"net"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -189,7 +190,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")
Expand Down
1 change: 1 addition & 0 deletions services/wireguard/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,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()
Expand Down

0 comments on commit ab5ba2e

Please sign in to comment.