From dd4da93749fd9a8a231942a6b75ad137cc308e02 Mon Sep 17 00:00:00 2001 From: Mathias Hall-Andersen Date: Sat, 15 Jul 2017 16:27:59 +0200 Subject: Added padding Added plaintext padding and fixed default interface MTU --- src/device.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'src/device.go') diff --git a/src/device.go b/src/device.go index a15961a..4981f51 100644 --- a/src/device.go +++ b/src/device.go @@ -4,10 +4,12 @@ import ( "net" "runtime" "sync" + "sync/atomic" + "time" ) type Device struct { - mtu int + mtu int32 log *Logger // collection of loggers for levels idCounter uint // for assigning debug ids to peers fwMark uint32 @@ -118,6 +120,7 @@ func NewDevice(tun TUNDevice, logLevel int) *Device { } go device.RoutineBusyMonitor() + go device.RoutineMTUUpdater(tun) go device.RoutineWriteToTUN(tun) go device.RoutineReadFromTUN(tun) go device.RoutineReceiveIncomming() @@ -126,6 +129,18 @@ func NewDevice(tun TUNDevice, logLevel int) *Device { return device } +func (device *Device) RoutineMTUUpdater(tun TUNDevice) { + logError := device.log.Error + for ; ; time.Sleep(time.Second) { + mtu, err := tun.MTU() + if err != nil { + logError.Println("Failed to load updated MTU of device:", err) + continue + } + atomic.StoreInt32(&device.mtu, int32(mtu)) + } +} + func (device *Device) LookupPeer(pk NoisePublicKey) *Peer { device.mutex.RLock() defer device.mutex.RUnlock() -- cgit v1.2.3