@@ -3,11 +3,12 @@ package utils
33import (
44 "fmt"
55 "math/rand"
6+ "os"
7+ "strings"
68
79 "github.com/qdm12/gluetun/internal/configuration/settings"
810 "github.com/qdm12/gluetun/internal/constants/vpn"
911 "github.com/qdm12/gluetun/internal/models"
10- "github.com/qdm12/gosettings/reader"
1112)
1213
1314type ConnectionDefaults struct {
@@ -31,30 +32,17 @@ type Storage interface {
3132 servers []models.Server , err error )
3233}
3334
34- type VPNSettings struct {
35- IPv6Server * bool
36- }
37-
38- // Read method to populate the VPNSettings from the reader
39- func (v * VPNSettings ) read (reader * reader.Reader ) (err error ) {
40- v .IPv6Server , err = reader .BoolPtr ("VPN_IPV6_SERVER" )
41- return err
42- }
43-
4435func GetConnection (provider string ,
4536 storage Storage ,
4637 selection settings.ServerSelection ,
4738 defaults ConnectionDefaults ,
4839 ipv6Supported bool ,
49- randSource rand.Source ,
50- reader * reader.Reader ) (
40+ randSource rand.Source ) (
5141 connection models.Connection , err error ,
5242) {
53- // Create an instance of VPNSettings and read settings
54- var vpnSettings VPNSettings
55- if err := vpnSettings .read (reader ); err != nil {
56- return connection , fmt .Errorf ("reading VPN settings: %w" , err )
57- }
43+ // Read the VPN_IPV6_SERVER environment variable
44+ vpnIPv6Server := os .Getenv ("VPN_IPV6_SERVER" )
45+ skipIPv6Servers := strings .EqualFold (vpnIPv6Server , "off" )
5846
5947 servers , err := storage .FilterServers (provider , selection )
6048 if err != nil {
@@ -68,8 +56,11 @@ func GetConnection(provider string,
6856 connections := make ([]models.Connection , 0 , len (servers ))
6957 for _ , server := range servers {
7058 for _ , ip := range server .IPs {
71- // Skip IPv6 if unsupported or if VPN_IPV6_SERVER is false
72- if ! ipv6Supported || (vpnSettings .IPv6Server != nil && ! * vpnSettings .IPv6Server && ip .Is6 ()) {
59+ if skipIPv6Servers && ip .Is6 () {
60+ continue
61+ }
62+
63+ if ! ipv6Supported && ip .Is6 () {
7364 continue
7465 }
7566
0 commit comments