Skip to content

Commit

Permalink
Skip IPv6 Servers if VPN_IPV6_SERVER is set to off
Browse files Browse the repository at this point in the history
  • Loading branch information
Félix Pratt committed Oct 31, 2024
1 parent 9aacf42 commit 51a865c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion internal/provider/utils/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"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 {
Expand Down Expand Up @@ -38,6 +39,14 @@ func GetConnection(provider string,
randSource rand.Source) (
connection models.Connection, err error,
) {
// Use reader.BoolPtr to check the VPN_IPV6_SERVER environment variable
vpnIPv6ServerPtr := reader.BoolPtr("VPN_IPV6_SERVER")
useIPv6 := ipv6Supported // Default to system IPv6 support

if vpnIPv6ServerPtr != nil && !*vpnIPv6ServerPtr {
useIPv6 = false // Disable IPv6 if the environment variable is set to "off"
}

servers, err := storage.FilterServers(provider, selection)
if err != nil {
return connection, fmt.Errorf("filtering servers: %w", err)
Expand All @@ -50,7 +59,8 @@ func GetConnection(provider string,
connections := make([]models.Connection, 0, len(servers))
for _, server := range servers {
for _, ip := range server.IPs {
if !ipv6Supported && ip.Is6() {
// Skip IPv6 addresses if IPv6 is unsupported or explicitly disabled
if !useIPv6 && ip.Is6() {
continue
}

Expand Down

0 comments on commit 51a865c

Please sign in to comment.