Skip to content

Commit

Permalink
fix default mtu handling
Browse files Browse the repository at this point in the history
  • Loading branch information
h44z committed Dec 18, 2020
1 parent 6fd4089 commit ec60dd1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions internal/server/usermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,9 @@ func (u *UserManager) validateOrCreateDevice(dev wgtypes.Device, ipAddresses []s
device.Mtu = 0
device.PersistentKeepalive = 16 // Default
device.IPsStr = strings.Join(ipAddresses, ", ")
if mtu == wireguard.WireGuardDefaultMTU {
mtu = 0
}
device.Mtu = mtu

res := u.db.Create(&device)
Expand Down
4 changes: 3 additions & 1 deletion internal/wireguard/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/milosgajdos/tenus"
)

const WireGuardDefaultMTU = 1420

func (m *Manager) GetIPAddress() ([]string, error) {
wgInterface, err := tenus.NewLinkFrom(m.Cfg.DeviceName)
if err != nil {
Expand Down Expand Up @@ -107,7 +109,7 @@ func (m *Manager) SetMTU(mtu int) error {
}

if mtu == 0 {
mtu = 1420 // WireGuard default MTU
mtu = WireGuardDefaultMTU
}

if err := wgInterface.SetLinkMTU(mtu); err != nil {
Expand Down

0 comments on commit ec60dd1

Please sign in to comment.