mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
feat(ipv6): prefer IPv6 endpoints when IPv6 is supported
This commit is contained in:
@@ -2,6 +2,7 @@ package utils
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/configuration/settings"
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
||||||
"github.com/qdm12/gluetun/internal/constants/vpn"
|
"github.com/qdm12/gluetun/internal/constants/vpn"
|
||||||
@@ -75,5 +76,18 @@ func GetConnection(provider string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
slices.SortStableFunc(connections, func(a, b models.Connection) int {
|
||||||
|
aIPv6 := a.IP.Is6()
|
||||||
|
bIPv6 := b.IP.Is6()
|
||||||
|
switch {
|
||||||
|
case aIPv6 && !bIPv6:
|
||||||
|
return -1
|
||||||
|
case !aIPv6 && bIPv6:
|
||||||
|
return 1
|
||||||
|
default:
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
return pickConnection(connections, selection, connPicker)
|
return pickConnection(connections, selection, connPicker)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,8 +124,8 @@ func Test_GetConnection(t *testing.T) {
|
|||||||
VPN: vpn.OpenVPN,
|
VPN: vpn.OpenVPN,
|
||||||
UDP: true,
|
UDP: true,
|
||||||
IPs: []netip.Addr{
|
IPs: []netip.Addr{
|
||||||
netip.IPv6Unspecified(),
|
|
||||||
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
|
netip.AddrFrom4([4]byte{1, 1, 1, 1}),
|
||||||
|
netip.IPv6Unspecified(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user