mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
be92aa2ac4
- 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
58 lines
1.9 KiB
Go
58 lines
1.9 KiB
Go
package utils
|
|
|
|
import (
|
|
"net/netip"
|
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
|
"github.com/qdm12/gluetun/internal/models"
|
|
"github.com/qdm12/gluetun/internal/wireguard"
|
|
)
|
|
|
|
func BuildWireguardSettings(connection models.Connection,
|
|
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.Implementation = userSettings.Implementation
|
|
if *userSettings.MTU > 0 {
|
|
settings.MTU = *userSettings.MTU
|
|
} else {
|
|
// The default is 1320 which is NOT the wireguard-go default
|
|
// of 1420 because this impacts bandwidth a lot on some
|
|
// VPN providers, see https://github.com/qdm12/gluetun/issues/1650.
|
|
// It has been lowered to 1320 following quite a bit of
|
|
// investigation in the issue: https://github.com/qdm12/gluetun/issues/2533.
|
|
const defaultMTU = 1320
|
|
settings.MTU = defaultMTU
|
|
}
|
|
settings.IPv6 = &ipv6Supported
|
|
|
|
const rulePriority = 101 // 100 is to receive external connections
|
|
settings.RulePriority = rulePriority
|
|
|
|
settings.Endpoint = netip.AddrPortFrom(connection.IP, connection.Port)
|
|
|
|
settings.Addresses = make([]netip.Prefix, 0, len(userSettings.Addresses))
|
|
for _, address := range userSettings.Addresses {
|
|
if !ipv6Supported && address.Addr().Is6() {
|
|
continue
|
|
}
|
|
addressCopy := netip.PrefixFrom(address.Addr(), address.Bits())
|
|
settings.Addresses = append(settings.Addresses, addressCopy)
|
|
}
|
|
|
|
settings.AllowedIPs = make([]netip.Prefix, 0, len(userSettings.AllowedIPs))
|
|
for _, allowedIP := range userSettings.AllowedIPs {
|
|
if !ipv6Supported && allowedIP.Addr().Is6() {
|
|
continue
|
|
}
|
|
settings.AllowedIPs = append(settings.AllowedIPs, allowedIP)
|
|
}
|
|
|
|
settings.PersistentKeepaliveInterval = *userSettings.PersistentKeepaliveInterval
|
|
|
|
return settings
|
|
}
|