diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2018-02-09 18:56:00 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2018-02-09 18:56:00 +0100 |
commit | b461343171726d99df20bfc4b4741f0fad0c95e0 (patch) | |
tree | 1ce014fb41a75fe66801d19879c665b652fdf756 /tun_linux.go | |
parent | 51a6001bb92c2af95415ad631344be98e54da18c (diff) |
Started migration to sub-packages
Diffstat (limited to 'tun_linux.go')
-rw-r--r-- | tun_linux.go | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/tun_linux.go b/tun_linux.go index daa2462..4585b13 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -7,6 +7,7 @@ import ( "encoding/binary" "errors" "fmt" + "git.zx2c4.com/wireguard-go/internal/events" "golang.org/x/net/ipv6" "golang.org/x/sys/unix" "net" @@ -52,10 +53,10 @@ const ( type NativeTun struct { fd *os.File - index int32 // if index - name string // name of interface - errors chan error // async error handling - events chan TUNEvent // device related events + index int32 // if index + name string // name of interface + errors chan error // async error handling + events chan events.Event // device related events } func (tun *NativeTun) File() *os.File { @@ -71,9 +72,9 @@ func (tun *NativeTun) RoutineHackListener() { _, err := unix.Write(fd, nil) switch err { case unix.EINVAL: - tun.events <- TUNEventUp + tun.events <- events.NewEvent(TUNEventUp) case unix.EIO: - tun.events <- TUNEventDown + tun.events <- events.NewEvent(TUNEventDown) default: } time.Sleep(time.Second / 10) @@ -118,14 +119,14 @@ func (tun *NativeTun) RoutineNetlinkListener() { } if info.Flags&unix.IFF_RUNNING != 0 { - tun.events <- TUNEventUp + tun.events <- events.NewEvent(TUNEventUp) } if info.Flags&unix.IFF_RUNNING == 0 { - tun.events <- TUNEventDown + tun.events <- events.NewEvent(TUNEventDown) } - tun.events <- TUNEventMTUUpdate + tun.events <- events.NewEvent(TUNEventMTUUpdate) default: remain = remain[hdr.Len:] @@ -288,7 +289,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { } } -func (tun *NativeTun) Events() chan TUNEvent { +func (tun *NativeTun) Events() chan events.Event { return tun.events } @@ -300,7 +301,7 @@ func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) { device := &NativeTun{ fd: fd, name: name, - events: make(chan TUNEvent, 5), + events: make(chan events.Event, 5), errors: make(chan error, 5), } @@ -357,7 +358,7 @@ func CreateTUN(name string) (TUNDevice, error) { device := &NativeTun{ fd: fd, name: newName, - events: make(chan TUNEvent, 5), + events: make(chan events.Event, 5), errors: make(chan error, 5), } |