Hotfix: Wireguard WIREGUARD_ADDRESSES setting
This commit is contained in:
@@ -15,15 +15,15 @@ func BuildWireguardSettings(connection models.Connection,
|
|||||||
settings.PreSharedKey = userSettings.PreSharedKey
|
settings.PreSharedKey = userSettings.PreSharedKey
|
||||||
settings.InterfaceName = userSettings.Interface
|
settings.InterfaceName = userSettings.Interface
|
||||||
|
|
||||||
const routePriority = 101 // 100 is to receive external connections
|
const rulePriority = 101 // 100 is to receive external connections
|
||||||
settings.RulePriority = routePriority
|
settings.RulePriority = rulePriority
|
||||||
|
|
||||||
settings.Endpoint = new(net.UDPAddr)
|
settings.Endpoint = new(net.UDPAddr)
|
||||||
settings.Endpoint.IP = make(net.IP, len(connection.IP))
|
settings.Endpoint.IP = make(net.IP, len(connection.IP))
|
||||||
copy(settings.Endpoint.IP, connection.IP)
|
copy(settings.Endpoint.IP, connection.IP)
|
||||||
settings.Endpoint.Port = int(connection.Port)
|
settings.Endpoint.Port = int(connection.Port)
|
||||||
|
|
||||||
for _, address := range settings.Addresses {
|
for _, address := range userSettings.Addresses {
|
||||||
addressCopy := new(net.IPNet)
|
addressCopy := new(net.IPNet)
|
||||||
addressCopy.IP = make(net.IP, len(address.IP))
|
addressCopy.IP = make(net.IP, len(address.IP))
|
||||||
copy(addressCopy.IP, address.IP)
|
copy(addressCopy.IP, address.IP)
|
||||||
|
|||||||
65
internal/provider/utils/wireguard_test.go
Normal file
65
internal/provider/utils/wireguard_test.go
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/qdm12/gluetun/internal/configuration"
|
||||||
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
|
"github.com/qdm12/gluetun/internal/wireguard"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_BuildWireguardSettings(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
testCases := map[string]struct {
|
||||||
|
connection models.Connection
|
||||||
|
userSettings configuration.Wireguard
|
||||||
|
settings wireguard.Settings
|
||||||
|
}{
|
||||||
|
"some settings": {
|
||||||
|
connection: models.Connection{
|
||||||
|
IP: net.IPv4(1, 2, 3, 4),
|
||||||
|
Port: 51821,
|
||||||
|
PubKey: "public",
|
||||||
|
},
|
||||||
|
userSettings: configuration.Wireguard{
|
||||||
|
PrivateKey: "private",
|
||||||
|
PreSharedKey: "pre-shared",
|
||||||
|
Addresses: []*net.IPNet{
|
||||||
|
{IP: net.IPv4(1, 1, 1, 1), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||||
|
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||||
|
},
|
||||||
|
Interface: "wg1",
|
||||||
|
},
|
||||||
|
settings: wireguard.Settings{
|
||||||
|
InterfaceName: "wg1",
|
||||||
|
PrivateKey: "private",
|
||||||
|
PublicKey: "public",
|
||||||
|
PreSharedKey: "pre-shared",
|
||||||
|
Endpoint: &net.UDPAddr{
|
||||||
|
IP: net.IPv4(1, 2, 3, 4),
|
||||||
|
Port: 51821,
|
||||||
|
},
|
||||||
|
Addresses: []*net.IPNet{
|
||||||
|
{IP: net.IPv4(1, 1, 1, 1), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||||
|
{IP: net.IPv4(2, 2, 2, 2), Mask: net.IPv4Mask(255, 255, 255, 255)},
|
||||||
|
},
|
||||||
|
RulePriority: 101,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for name, testCase := range testCases {
|
||||||
|
testCase := testCase
|
||||||
|
t.Run(name, func(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
settings := BuildWireguardSettings(testCase.connection,
|
||||||
|
testCase.userSettings)
|
||||||
|
|
||||||
|
assert.Equal(t, testCase.settings, settings)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user