Files
gluetun/internal/provider/utils/wireguard_test.go
T
Quentin McGaw be92aa2ac4 Path MTU discovery fixes and improvements (#3109)
- Existing option `WIREGUARD_MTU` , if set, disables PMTUD and is used
- New option `PMTUD_ICMP_ADDRESSES=1.1.1.1,8.8.8.8` and `PMTUD_TCP_ADDRESSES=1.1.1.1:443,8.8.8.8:443`
- ICMP PMTUD now targets external-by-default IP addresses
- New TCP PMTUD (binary search only) as a second MTU confirmation and fallback mechanism.
- Force set TCP MSS to MTU - IP header - TCP base header - "magic 20 bytes" 🎆
- Fix #3108
2026-02-14 19:40:34 -05:00

78 lines
2.1 KiB
Go

package utils
import (
"net/netip"
"testing"
"time"
"github.com/qdm12/gluetun/internal/configuration/settings"
"github.com/qdm12/gluetun/internal/models"
"github.com/qdm12/gluetun/internal/wireguard"
"github.com/stretchr/testify/assert"
)
func ptrTo[T any](x T) *T { return &x }
func Test_BuildWireguardSettings(t *testing.T) {
t.Parallel()
testCases := map[string]struct {
connection models.Connection
userSettings settings.Wireguard
ipv6Supported bool
settings wireguard.Settings
}{
"some_settings": {
connection: models.Connection{
IP: netip.AddrFrom4([4]byte{1, 2, 3, 4}),
Port: 51821,
PubKey: "public",
},
userSettings: settings.Wireguard{
PrivateKey: ptrTo("private"),
PreSharedKey: ptrTo("pre-shared"),
Addresses: []netip.Prefix{
netip.PrefixFrom(netip.AddrFrom4([4]byte{1, 1, 1, 1}), 32),
netip.PrefixFrom(netip.AddrFrom16([16]byte{}), 32),
},
AllowedIPs: []netip.Prefix{
netip.PrefixFrom(netip.AddrFrom4([4]byte{2, 2, 2, 2}), 32),
netip.PrefixFrom(netip.AddrFrom16([16]byte{}), 32),
},
PersistentKeepaliveInterval: ptrTo(time.Hour),
Interface: "wg1",
MTU: ptrTo(uint32(1000)),
},
ipv6Supported: false,
settings: wireguard.Settings{
InterfaceName: "wg1",
PrivateKey: "private",
PublicKey: "public",
PreSharedKey: "pre-shared",
Endpoint: netip.AddrPortFrom(netip.AddrFrom4([4]byte{1, 2, 3, 4}), 51821),
Addresses: []netip.Prefix{
netip.PrefixFrom(netip.AddrFrom4([4]byte{1, 1, 1, 1}), 32),
},
AllowedIPs: []netip.Prefix{
netip.PrefixFrom(netip.AddrFrom4([4]byte{2, 2, 2, 2}), 32),
},
PersistentKeepaliveInterval: time.Hour,
RulePriority: 101,
IPv6: boolPtr(false),
MTU: 1000,
},
},
}
for name, testCase := range testCases {
t.Run(name, func(t *testing.T) {
t.Parallel()
settings := BuildWireguardSettings(testCase.connection,
testCase.userSettings, testCase.ipv6Supported)
assert.Equal(t, testCase.settings, settings)
})
}
}