Skip to content

Commit

Permalink
tun: guard Device.Events() against chan writes
Browse files Browse the repository at this point in the history
Signed-off-by: Jordan Whited <[email protected]>
Signed-off-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
jwhited authored and zx2c4 committed Feb 9, 2023
1 parent ebbd4a4 commit 1e2c3e5
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tun/netstack/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tun/tun.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion tun/tun_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tun/tun_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tun/tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tun/tun_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion tun/tun_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
8 changes: 4 additions & 4 deletions tun/tuntest/tuntest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1e2c3e5

Please sign in to comment.