MCPcopy Create free account
hub / github.com/encodeous/nylon / RoutineTUNEventReader

Method RoutineTUNEventReader

polyamide/device/tun.go:16–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14const DefaultMTU = 1420
15
16func (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}

Callers 1

NewDeviceFunction · 0.80

Implementers 4

NativeTunpolyamide/tun/tun_linux.go
netTunpolyamide/tun/netstack/tun.go
chTunpolyamide/tun/tuntest/tuntest.go
fakeTUNDeviceSizedpolyamide/device/device_test.go

Calls 5

UpMethod · 0.95
DownMethod · 0.95
SwapMethod · 0.80
EventsMethod · 0.65
MTUMethod · 0.65

Tested by

no test coverage detected