From a476b1fa0732501b02bd995169654d337fb7b09a Mon Sep 17 00:00:00 2001 From: JackDoan Date: Tue, 28 Apr 2026 10:56:57 -0500 Subject: [PATCH] Remove WriteFromSelf --- inside.go | 4 ++-- overlay/overlaytest/noop.go | 4 ---- overlay/tio/tio.go | 13 ++----------- overlay/tio/tio_poll_linux.go | 4 ---- overlay/tun_android.go | 4 ---- overlay/tun_darwin.go | 4 ---- overlay/tun_disabled.go | 4 ---- overlay/tun_freebsd.go | 4 ---- overlay/tun_ios.go | 4 ---- overlay/tun_netbsd.go | 4 ---- overlay/tun_openbsd.go | 4 ---- overlay/tun_tester.go | 4 ---- overlay/tun_windows.go | 4 ---- overlay/user.go | 4 +--- 14 files changed, 5 insertions(+), 60 deletions(-) diff --git a/inside.go b/inside.go index 2b0ad70c..e528e892 100644 --- a/inside.go +++ b/inside.go @@ -38,7 +38,7 @@ func (f *Interface) consumeInsidePacket(packet []byte, fwPacket *firewall.Packet // routes packets from the Nebula addr to the Nebula addr through the Nebula // TUN device. if immediatelyForwardToSelf { - _, err := f.readers[q].WriteFromSelf(packet) + _, err := f.readers[q].Write(packet) if err != nil { f.l.Error("Failed to forward to tun", "error", err) } @@ -157,7 +157,7 @@ func (f *Interface) rejectInside(packet []byte, out []byte, q int) { return } - _, err := f.readers[q].WriteFromSelf(out) + _, err := f.readers[q].Write(out) if err != nil { f.l.Error("Failed to write to tun", "error", err) } diff --git a/overlay/overlaytest/noop.go b/overlay/overlaytest/noop.go index 99ef4d15..10886511 100644 --- a/overlay/overlaytest/noop.go +++ b/overlay/overlaytest/noop.go @@ -39,10 +39,6 @@ func (NoopTun) Write([]byte) (int, error) { return 0, nil } -func (NoopTun) WriteFromSelf(p []byte) (int, error) { - return 0, nil -} - func (NoopTun) SupportsMultiqueue() bool { return false } diff --git a/overlay/tio/tio.go b/overlay/tio/tio.go index 792083ab..94240d06 100644 --- a/overlay/tio/tio.go +++ b/overlay/tio/tio.go @@ -23,21 +23,12 @@ type Queue interface { // Read returns one or more packets. The returned slices are borrowed // from the Queue's internal buffer and are only valid until the next // Read or Close on this Queue - callers must encrypt or copy each - // slice before the next call. Not safe for concurrent Reads; exactly - // one goroutine per Queue reads. + // slice before the next call. Not safe for concurrent Reads. Read() ([][]byte, error) // Write emits a single packet on the plaintext (outside→inside) - // delivery path. May run concurrently with WriteFromSelf on the same - // Queue, but not with itself. + // delivery path. Not safe for concurrent Writes. Write(p []byte) (int, error) - - // WriteFromSelf writes a single packet that originated from the inside - // path (reject replies or self-forward) using scratch state distinct - // from Write, so it can run concurrently with Write on the same Queue - // without a data race. On backends without a shared-scratch Write, a - // trivial delegation to Write is acceptable. - WriteFromSelf(p []byte) (int, error) } // GSOWriter is implemented by Queues that can emit a TCP TSO superpacket diff --git a/overlay/tio/tio_poll_linux.go b/overlay/tio/tio_poll_linux.go index 17fb73de..21ae1336 100644 --- a/overlay/tio/tio_poll_linux.go +++ b/overlay/tio/tio_poll_linux.go @@ -162,7 +162,3 @@ func (t *Poll) Close() error { return err } - -func (t *Poll) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} diff --git a/overlay/tun_android.go b/overlay/tun_android.go index b68dfcd5..c2342556 100644 --- a/overlay/tun_android.go +++ b/overlay/tun_android.go @@ -43,10 +43,6 @@ func (t *tun) Write(p []byte) (int, error) { return t.rwc.Write(p) } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.rwc.Write(p) -} - func (t *tun) Close() error { return t.rwc.Close() } diff --git a/overlay/tun_darwin.go b/overlay/tun_darwin.go index 9a4b70e6..b4254b05 100644 --- a/overlay/tun_darwin.go +++ b/overlay/tun_darwin.go @@ -525,10 +525,6 @@ func (t *tun) Read() ([][]byte, error) { return t.batchRet[:], nil } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} - // Write is only valid for single threaded use func (t *tun) Write(from []byte) (int, error) { buf := t.out diff --git a/overlay/tun_disabled.go b/overlay/tun_disabled.go index 5daa4797..12f8b883 100644 --- a/overlay/tun_disabled.go +++ b/overlay/tun_disabled.go @@ -108,10 +108,6 @@ func (t *disabledTun) Write(b []byte) (int, error) { return len(b), nil } -func (t *disabledTun) WriteFromSelf(b []byte) (int, error) { - return t.Write(b) -} - func (t *disabledTun) SupportsMultiqueue() bool { return true } diff --git a/overlay/tun_freebsd.go b/overlay/tun_freebsd.go index 980c3efb..90beb557 100644 --- a/overlay/tun_freebsd.go +++ b/overlay/tun_freebsd.go @@ -168,10 +168,6 @@ func (t *tun) Read() ([][]byte, error) { return t.batchRet[:], nil } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} - func (t *tun) readOne(to []byte) (int, error) { // first 4 bytes is protocol family, in network byte order var head [4]byte diff --git a/overlay/tun_ios.go b/overlay/tun_ios.go index 65dc0edc..44607eb2 100644 --- a/overlay/tun_ios.go +++ b/overlay/tun_ios.go @@ -45,10 +45,6 @@ func (t *tun) Write(p []byte) (int, error) { return t.rwc.Write(p) } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.rwc.Write(p) -} - func (t *tun) Close() error { return t.rwc.Close() } diff --git a/overlay/tun_netbsd.go b/overlay/tun_netbsd.go index 8275b754..4a0f502f 100644 --- a/overlay/tun_netbsd.go +++ b/overlay/tun_netbsd.go @@ -80,10 +80,6 @@ func (t *tun) Read() ([][]byte, error) { return t.batchRet[:], nil } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} - func (t *tun) Readers() []tio.Queue { return []tio.Queue{t} } diff --git a/overlay/tun_openbsd.go b/overlay/tun_openbsd.go index 8c16b977..2369a7c2 100644 --- a/overlay/tun_openbsd.go +++ b/overlay/tun_openbsd.go @@ -73,10 +73,6 @@ func (t *tun) Read() ([][]byte, error) { return t.batchRet[:], nil } -func (t *tun) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} - var deviceNameRE = regexp.MustCompile(`^tun[0-9]+$`) func newTunFromFd(_ *config.C, _ *slog.Logger, _ int, _ []netip.Prefix) (*tun, error) { diff --git a/overlay/tun_tester.go b/overlay/tun_tester.go index 22bc9f5c..95d13b39 100644 --- a/overlay/tun_tester.go +++ b/overlay/tun_tester.go @@ -128,10 +128,6 @@ func (t *TestTun) Write(b []byte) (n int, err error) { return len(b), nil } -func (t *TestTun) WriteFromSelf(b []byte) (int, error) { - return t.Write(b) -} - func (t *TestTun) Close() error { if t.closed.CompareAndSwap(false, true) { close(t.rxPackets) diff --git a/overlay/tun_windows.go b/overlay/tun_windows.go index c99d259f..80cb7fa0 100644 --- a/overlay/tun_windows.go +++ b/overlay/tun_windows.go @@ -50,10 +50,6 @@ func (t *winTun) Read() ([][]byte, error) { return t.batchRet[:], nil } -func (t *winTun) WriteFromSelf(p []byte) (int, error) { - return t.Write(p) -} - func newTunFromFd(_ *config.C, _ *slog.Logger, _ int, _ []netip.Prefix) (Device, error) { return nil, fmt.Errorf("newTunFromFd not supported in Windows") } diff --git a/overlay/user.go b/overlay/user.go index fcb1ee51..be6b327b 100644 --- a/overlay/user.go +++ b/overlay/user.go @@ -88,9 +88,7 @@ func (d *UserDevice) Pipe() (*io.PipeReader, *io.PipeWriter) { func (d *UserDevice) Write(p []byte) (n int, err error) { return d.inboundWriter.Write(p) } -func (d *UserDevice) WriteFromSelf(p []byte) (n int, err error) { - return d.Write(p) -} + func (d *UserDevice) Close() error { d.inboundWriter.Close() d.outboundWriter.Close()