fix default mtu handling

This commit is contained in:
Christoph Haas 2020-12-18 22:07:55 +01:00
parent 6fd4089766
commit ec60dd136a
2 changed files with 6 additions and 1 deletions

View File

@ -390,6 +390,9 @@ func (u *UserManager) validateOrCreateDevice(dev wgtypes.Device, ipAddresses []s
device.Mtu = 0 device.Mtu = 0
device.PersistentKeepalive = 16 // Default device.PersistentKeepalive = 16 // Default
device.IPsStr = strings.Join(ipAddresses, ", ") device.IPsStr = strings.Join(ipAddresses, ", ")
if mtu == wireguard.WireGuardDefaultMTU {
mtu = 0
}
device.Mtu = mtu device.Mtu = mtu
res := u.db.Create(&device) res := u.db.Create(&device)

View File

@ -7,6 +7,8 @@ import (
"github.com/milosgajdos/tenus" "github.com/milosgajdos/tenus"
) )
const WireGuardDefaultMTU = 1420
func (m *Manager) GetIPAddress() ([]string, error) { func (m *Manager) GetIPAddress() ([]string, error) {
wgInterface, err := tenus.NewLinkFrom(m.Cfg.DeviceName) wgInterface, err := tenus.NewLinkFrom(m.Cfg.DeviceName)
if err != nil { if err != nil {
@ -107,7 +109,7 @@ func (m *Manager) SetMTU(mtu int) error {
} }
if mtu == 0 { if mtu == 0 {
mtu = 1420 // WireGuard default MTU mtu = WireGuardDefaultMTU
} }
if err := wgInterface.SetLinkMTU(mtu); err != nil { if err := wgInterface.SetLinkMTU(mtu); err != nil {