diff options
Diffstat (limited to 'tun.go')
-rw-r--r-- | tun.go | 14 |
1 files changed, 8 insertions, 6 deletions
@@ -1,14 +1,13 @@ package main import ( + "git.zx2c4.com/wireguard-go/internal/events" "os" "sync/atomic" ) const DefaultMTU = 1420 -type TUNEvent int - const ( TUNEventUp = 1 << iota TUNEventDown @@ -21,7 +20,7 @@ type TUNDevice interface { Write([]byte, int) (int, error) // writes a packet to the device (without any additional headers) MTU() (int, error) // returns the MTU of the device Name() string // returns the current name - Events() chan TUNEvent // returns a constant channel of events related to the device + Events() chan events.Event // returns a constant channel of events related to the device Close() error // stops the device and closes the event channel } @@ -30,7 +29,8 @@ func (device *Device) RoutineTUNEventReader() { logError := device.log.Error for event := range device.tun.device.Events() { - if event&TUNEventMTUUpdate != 0 { + + if event.Contains(TUNEventMTUUpdate) { mtu, err := device.tun.device.MTU() old := atomic.LoadInt32(&device.tun.mtu) if err != nil { @@ -45,14 +45,16 @@ func (device *Device) RoutineTUNEventReader() { } } - if event&TUNEventUp != 0 && !device.isUp.Get() { + if event.Contains(TUNEventUp) && !device.isUp.Get() { logInfo.Println("Interface set up") device.Up() } - if event&TUNEventDown != 0 && device.isUp.Get() { + if event.Contains(TUNEventDown) && device.isUp.Get() { logInfo.Println("Interface set down") device.Down() } + + event.Processed() } } |