diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-15 16:27:59 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2017-07-15 16:27:59 +0200 |
commit | dd4da93749fd9a8a231942a6b75ad137cc308e02 (patch) | |
tree | 187c4d0257e4216ea332cd09d19f6b50041b0791 /src/device.go | |
parent | b21c82e32d955e15d846aed87535b6d728ab1d0b (diff) |
Added padding
Added plaintext padding and fixed default interface MTU
Diffstat (limited to 'src/device.go')
-rw-r--r-- | src/device.go | 17 |
1 files changed, 16 insertions, 1 deletions
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() |