device: don't track device interface state in RoutineTUNEventReader

We already track this state elsewhere. No need to duplicate.
The cost of calling changeState is negligible.

Signed-off-by: Josh Bleecher Snyder <josh@tailscale.com>
This commit is contained in:
Josh Bleecher Snyder 2021-01-21 09:26:14 -08:00
parent 675ff32e6c
commit d840445e9b

View file

@ -15,7 +15,6 @@ import (
const DefaultMTU = 1420 const DefaultMTU = 1420
func (device *Device) RoutineTUNEventReader() { func (device *Device) RoutineTUNEventReader() {
setUp := false
device.log.Verbosef("Routine: event worker - started") device.log.Verbosef("Routine: event worker - started")
for event := range device.tun.device.Events() { for event := range device.tun.device.Events() {
@ -40,15 +39,13 @@ func (device *Device) RoutineTUNEventReader() {
} }
} }
if event&tun.EventUp != 0 && !setUp { if event&tun.EventUp != 0 {
device.log.Verbosef("Interface set up") device.log.Verbosef("Interface up requested")
setUp = true
device.Up() device.Up()
} }
if event&tun.EventDown != 0 && setUp { if event&tun.EventDown != 0 {
device.log.Verbosef("Interface set down") device.log.Verbosef("Interface down requested")
setUp = false
device.Down() device.Down()
} }
} }