summaryrefslogtreecommitdiff
path: root/src/device.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/device.go')
-rw-r--r--src/device.go17
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()