()
| 14 | const DefaultMTU = 1420 |
| 15 | |
| 16 | func (device *Device) RoutineTUNEventReader() { |
| 17 | device.Log.Verbosef("Routine: event worker - started") |
| 18 | |
| 19 | for event := range device.tun.device.Events() { |
| 20 | if event&tun.EventMTUUpdate != 0 { |
| 21 | mtu, err := device.tun.device.MTU() |
| 22 | if err != nil { |
| 23 | device.Log.Errorf("Failed to load updated MTU of device: %v", err) |
| 24 | continue |
| 25 | } |
| 26 | if mtu < 0 { |
| 27 | device.Log.Errorf("MTU not updated to negative value: %v", mtu) |
| 28 | continue |
| 29 | } |
| 30 | var tooLarge string |
| 31 | if mtu > MaxContentSize { |
| 32 | tooLarge = fmt.Sprintf(" (too large, capped at %v)", MaxContentSize) |
| 33 | mtu = MaxContentSize |
| 34 | } |
| 35 | old := device.tun.mtu.Swap(int32(mtu)) |
| 36 | if int(old) != mtu { |
| 37 | device.Log.Verbosef("MTU updated: %v%s", mtu, tooLarge) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | if event&tun.EventUp != 0 { |
| 42 | device.Log.Verbosef("Interface up requested") |
| 43 | device.Up() |
| 44 | } |
| 45 | |
| 46 | if event&tun.EventDown != 0 { |
| 47 | device.Log.Verbosef("Interface down requested") |
| 48 | device.Down() |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | device.Log.Verbosef("Routine: event worker - stopped") |
| 53 | } |
no test coverage detected