Added padding

Added plaintext padding and fixed default interface MTU
This commit is contained in:
Mathias Hall-Andersen
2017-07-15 16:27:59 +02:00
parent b21c82e32d
commit dd4da93749
4 changed files with 77 additions and 17 deletions

View File

@@ -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()