From 1e2c3e5a3c1463cb8c7ec92d74aa739587b6642f Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Wed, 8 Feb 2023 10:42:07 -0800 Subject: [PATCH] tun: guard Device.Events() against chan writes Signed-off-by: Jordan Whited Signed-off-by: Jason A. Donenfeld --- tun/netstack/tun.go | 2 +- tun/tun.go | 2 +- tun/tun_darwin.go | 2 +- tun/tun_freebsd.go | 2 +- tun/tun_linux.go | 2 +- tun/tun_openbsd.go | 2 +- tun/tun_windows.go | 2 +- tun/tuntest/tuntest.go | 8 ++++---- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index 25486a6..37c879d 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -109,7 +109,7 @@ func (tun *netTun) File() *os.File { return nil } -func (tun *netTun) Events() chan tun.Event { +func (tun *netTun) Events() <-chan tun.Event { return tun.events } diff --git a/tun/tun.go b/tun/tun.go index 7b26af0..01051b9 100644 --- a/tun/tun.go +++ b/tun/tun.go @@ -24,6 +24,6 @@ type Device interface { Flush() error // flush all previous writes to the device MTU() (int, error) // returns the MTU of the device Name() (string, error) // fetches and returns the current name - Events() chan Event // returns a constant channel of events related to the device + Events() <-chan Event // returns a constant channel of events related to the device Close() error // stops the device and closes the event channel } diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go index a04bad4..7411a69 100644 --- a/tun/tun_darwin.go +++ b/tun/tun_darwin.go @@ -213,7 +213,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan Event { +func (tun *NativeTun) Events() <-chan Event { return tun.events } diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go index a8ebb34..42431aa 100644 --- a/tun/tun_freebsd.go +++ b/tun/tun_freebsd.go @@ -329,7 +329,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan Event { +func (tun *NativeTun) Events() <-chan Event { return tun.events } diff --git a/tun/tun_linux.go b/tun/tun_linux.go index 6275399..25dbc07 100644 --- a/tun/tun_linux.go +++ b/tun/tun_linux.go @@ -376,7 +376,7 @@ func (tun *NativeTun) Read(buf []byte, offset int) (n int, err error) { return } -func (tun *NativeTun) Events() chan Event { +func (tun *NativeTun) Events() <-chan Event { return tun.events } diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go index ee8cf5a..e7fd79c 100644 --- a/tun/tun_openbsd.go +++ b/tun/tun_openbsd.go @@ -200,7 +200,7 @@ func (tun *NativeTun) File() *os.File { return tun.tunFile } -func (tun *NativeTun) Events() chan Event { +func (tun *NativeTun) Events() <-chan Event { return tun.events } diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 751ad21..d5abb14 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -102,7 +102,7 @@ func (tun *NativeTun) File() *os.File { return nil } -func (tun *NativeTun) Events() chan Event { +func (tun *NativeTun) Events() <-chan Event { return tun.events } diff --git a/tun/tuntest/tuntest.go b/tun/tuntest/tuntest.go index 4e61df5..b143c76 100644 --- a/tun/tuntest/tuntest.go +++ b/tun/tuntest/tuntest.go @@ -138,10 +138,10 @@ func (t *chTun) Write(data []byte, offset int) (int, error) { const DefaultMTU = 1420 -func (t *chTun) Flush() error { return nil } -func (t *chTun) MTU() (int, error) { return DefaultMTU, nil } -func (t *chTun) Name() (string, error) { return "loopbackTun1", nil } -func (t *chTun) Events() chan tun.Event { return t.c.events } +func (t *chTun) Flush() error { return nil } +func (t *chTun) MTU() (int, error) { return DefaultMTU, nil } +func (t *chTun) Name() (string, error) { return "loopbackTun1", nil } +func (t *chTun) Events() <-chan tun.Event { return t.c.events } func (t *chTun) Close() error { t.Write(nil, -1) return nil