]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: guard Device.Events() against chan writes
authorJordan Whited <jordan@tailscale.com>
Wed, 8 Feb 2023 18:42:07 +0000 (10:42 -0800)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 9 Feb 2023 15:35:58 +0000 (12:35 -0300)
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tun/netstack/tun.go
tun/tun.go
tun/tun_darwin.go
tun/tun_freebsd.go
tun/tun_linux.go
tun/tun_openbsd.go
tun/tun_windows.go
tun/tuntest/tuntest.go

index 25486a60ea2414afb306598c08a674f68b13aef7..37c879d56f68515094fd5f15907281b7c9b3620a 100644 (file)
@@ -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
 }
 
index 7b26af069778d81e980511043acb9775b28f2d9c..01051b938e1ae1d3ae39303424a8a1b3058af1b4 100644 (file)
@@ -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
 }
index a04bad46b29a092f7c09387d3c08baca054850b2..7411a694637ea5968d71f5de6d38a4912049d4d6 100644 (file)
@@ -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
 }
 
index a8ebb340dd11d0a1f0c9ee913ee11dcc2fe68235..42431aa3ee3a21dc0aee1b3595ec1833954a1f67 100644 (file)
@@ -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
 }
 
index 6275399839ae1f0c04eb4a7ab0335c4a6816e5c8..25dbc0749b82ee641ddd6e315082f13d300addc9 100644 (file)
@@ -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
 }
 
index ee8cf5a89ab226b0b69b3a9d656817ff4e35a059..e7fd79c5b0045a8625ddb8b4fa7233d7a1e83f1c 100644 (file)
@@ -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
 }
 
index 751ad210bf8fedb55de5f52d6296752a05741c09..d5abb148981db7f0121244f842d0bddd5cf19077 100644 (file)
@@ -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
 }
 
index 4e61df52a10b3067d1999341a318bec37380f29e..b143c76a46217a9a9f963c47021049a961638836 100644 (file)
@@ -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