mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-30 05:25:35 +00:00
71029cea2d
This updates all source files to use a new standard header for copyright and license declaration. Notably, copyright no longer includes a date, and we now use the standard SPDX-License-Identifier header. This commit was done almost entirely mechanically with perl, and then some minimal manual fixes. Updates #6865 Signed-off-by: Will Norris <will@tailscale.com>
55 lines
1.1 KiB
Go
55 lines
1.1 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
package tstun
|
|
|
|
import (
|
|
"io"
|
|
"os"
|
|
|
|
"github.com/tailscale/wireguard-go/tun"
|
|
)
|
|
|
|
type fakeTUN struct {
|
|
evchan chan tun.Event
|
|
closechan chan struct{}
|
|
}
|
|
|
|
// NewFake returns a tun.Device that does nothing.
|
|
func NewFake() tun.Device {
|
|
return &fakeTUN{
|
|
evchan: make(chan tun.Event),
|
|
closechan: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
func (t *fakeTUN) File() *os.File {
|
|
panic("fakeTUN.File() called, which makes no sense")
|
|
}
|
|
|
|
func (t *fakeTUN) Close() error {
|
|
close(t.closechan)
|
|
close(t.evchan)
|
|
return nil
|
|
}
|
|
|
|
func (t *fakeTUN) Read(out [][]byte, sizes []int, offset int) (int, error) {
|
|
<-t.closechan
|
|
return 0, io.EOF
|
|
}
|
|
|
|
func (t *fakeTUN) Write(b [][]byte, n int) (int, error) {
|
|
select {
|
|
case <-t.closechan:
|
|
return 0, ErrClosed
|
|
default:
|
|
}
|
|
return 1, nil
|
|
}
|
|
|
|
func (t *fakeTUN) Flush() error { return nil }
|
|
func (t *fakeTUN) MTU() (int, error) { return 1500, nil }
|
|
func (t *fakeTUN) Name() (string, error) { return "FakeTUN", nil }
|
|
func (t *fakeTUN) Events() <-chan tun.Event { return t.evchan }
|
|
func (t *fakeTUN) BatchSize() int { return 1 }
|