diff --git a/internal/provider/utils/connection.go b/internal/provider/utils/connection.go index c9c049192..5e0c0f637 100644 --- a/internal/provider/utils/connection.go +++ b/internal/provider/utils/connection.go @@ -3,11 +3,12 @@ package utils import ( "fmt" "math/rand" + "os" + "strings" "github.com/qdm12/gluetun/internal/configuration/settings" "github.com/qdm12/gluetun/internal/constants/vpn" "github.com/qdm12/gluetun/internal/models" - "github.com/qdm12/gosettings/reader" ) type ConnectionDefaults struct { @@ -31,30 +32,17 @@ type Storage interface { servers []models.Server, err error) } -type VPNSettings struct { - IPv6Server *bool -} - -// Read method to populate the VPNSettings from the reader -func (v *VPNSettings) read(reader *reader.Reader) (err error) { - v.IPv6Server, err = reader.BoolPtr("VPN_IPV6_SERVER") - return err -} - func GetConnection(provider string, storage Storage, selection settings.ServerSelection, defaults ConnectionDefaults, ipv6Supported bool, - randSource rand.Source, - reader *reader.Reader) ( + randSource rand.Source) ( connection models.Connection, err error, ) { - // Create an instance of VPNSettings and read settings - var vpnSettings VPNSettings - if err := vpnSettings.read(reader); err != nil { - return connection, fmt.Errorf("reading VPN settings: %w", err) - } + // Read the VPN_IPV6_SERVER environment variable + vpnIPv6Server := os.Getenv("VPN_IPV6_SERVER") + skipIPv6Servers := strings.EqualFold(vpnIPv6Server, "off") servers, err := storage.FilterServers(provider, selection) if err != nil { @@ -68,8 +56,11 @@ func GetConnection(provider string, connections := make([]models.Connection, 0, len(servers)) for _, server := range servers { for _, ip := range server.IPs { - // Skip IPv6 if unsupported or if VPN_IPV6_SERVER is false - if !ipv6Supported || (vpnSettings.IPv6Server != nil && !*vpnSettings.IPv6Server && ip.Is6()) { + if skipIPv6Servers && ip.Is6() { + continue + } + + if !ipv6Supported && ip.Is6() { continue }