feat(vpn): auto detection of IPv6 support
- `OPENVPN_IPV6` removed - Affects OpenVPN - Use the same mechanism for OpenVPN and Wireguard - Check only once at program start since this is unlikely to change at runtime - Log if IPv6 is supported - Remove `IPv6` boolean from settings structs - Move IPv6 detection as a method on NetLinker
This commit is contained in:
@@ -50,7 +50,7 @@ type OpenVPNProviderSettings struct {
|
||||
//nolint:gocognit,gocyclo
|
||||
func OpenVPNConfig(provider OpenVPNProviderSettings,
|
||||
connection models.Connection,
|
||||
settings settings.OpenVPN) []string {
|
||||
settings settings.OpenVPN, ipv6Supported bool) []string {
|
||||
var lines openvpnConfigLines
|
||||
lines.add("client")
|
||||
lines.add("nobind")
|
||||
@@ -158,7 +158,7 @@ func OpenVPNConfig(provider OpenVPNProviderSettings,
|
||||
lines.add("persist-key")
|
||||
}
|
||||
|
||||
if *settings.IPv6 {
|
||||
if ipv6Supported {
|
||||
lines.add("tun-ipv6")
|
||||
} else {
|
||||
lines.add("pull-filter", "ignore", `"route-ipv6"`)
|
||||
|
||||
@@ -9,11 +9,12 @@ import (
|
||||
)
|
||||
|
||||
func BuildWireguardSettings(connection models.Connection,
|
||||
userSettings settings.Wireguard) (settings wireguard.Settings) {
|
||||
userSettings settings.Wireguard, ipv6Supported bool) (settings wireguard.Settings) {
|
||||
settings.PrivateKey = *userSettings.PrivateKey
|
||||
settings.PublicKey = connection.PubKey
|
||||
settings.PreSharedKey = *userSettings.PreSharedKey
|
||||
settings.InterfaceName = userSettings.Interface
|
||||
settings.IPv6 = &ipv6Supported
|
||||
|
||||
const rulePriority = 101 // 100 is to receive external connections
|
||||
settings.RulePriority = rulePriority
|
||||
|
||||
@@ -16,9 +16,10 @@ func Test_BuildWireguardSettings(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
testCases := map[string]struct {
|
||||
connection models.Connection
|
||||
userSettings settings.Wireguard
|
||||
settings wireguard.Settings
|
||||
connection models.Connection
|
||||
userSettings settings.Wireguard
|
||||
ipv6Supported bool
|
||||
settings wireguard.Settings
|
||||
}{
|
||||
"some settings": {
|
||||
connection: models.Connection{
|
||||
@@ -35,6 +36,7 @@ func Test_BuildWireguardSettings(t *testing.T) {
|
||||
},
|
||||
Interface: "wg1",
|
||||
},
|
||||
ipv6Supported: true,
|
||||
settings: wireguard.Settings{
|
||||
InterfaceName: "wg1",
|
||||
PrivateKey: "private",
|
||||
@@ -49,6 +51,7 @@ func Test_BuildWireguardSettings(t *testing.T) {
|
||||
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||
},
|
||||
RulePriority: 101,
|
||||
IPv6: boolPtr(true),
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -59,7 +62,7 @@ func Test_BuildWireguardSettings(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
settings := BuildWireguardSettings(testCase.connection,
|
||||
testCase.userSettings)
|
||||
testCase.userSettings, testCase.ipv6Supported)
|
||||
|
||||
assert.Equal(t, testCase.settings, settings)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user