Skip to content

add lneto as an alternative to gvisor in netstack package#149

Open
soypat wants to merge 1 commit into
WireGuard:masterfrom
umyas:master
Open

add lneto as an alternative to gvisor in netstack package#149
soypat wants to merge 1 commit into
WireGuard:masterfrom
umyas:master

Conversation

@soypat

@soypat soypat commented Jul 1, 2026

Copy link
Copy Markdown

Main API changes:

  • go.mod version 1.23 -> 1.24. go tidy forces this version, likely needed for using lneto due to the use of testing.B.Loop :/
  • CreateNetTUN selects a stack based on build tag
    • CreateNetTUNGvisor by default is wrapped (New API)
    • CreateNetTUNLneto is called instead with build tag wglneto
  • Added netstackdebug build tag for debugging. I'm not particularily vouching for this to be included, was useful for debugging. We can remove it if is not desired.

Added following interfaces to replace gvisor types. Stack is now an interface instead of a struct to better document what is needed to implement a networking stack for use in wireguard.

// Stack is the backend-specific primitive set that [Net] delegates to. Both the
// gvisor netTun and the lneto stack implement it. Higher-level conveniences
// (the *net.TCPAddr/*net.UDPAddr/*PingAddr overloads, generic Dial/DialContext,
// LookupHost) live once on [Net] and are written in terms of these primitives.
type Stack interface {
	DialContextTCPAddrPort(ctx context.Context, addr netip.AddrPort) (TCPConn, error)
	DialTCPAddrPort(addr netip.AddrPort) (TCPConn, error)
	ListenTCPAddrPort(addr netip.AddrPort) (TCPListener, error)
	DialUDPAddrPort(laddr, raddr netip.AddrPort) (UDPConn, error)
	ListenUDPAddrPort(laddr netip.AddrPort) (UDPConn, error)
	DialPingAddr(laddr, raddr netip.Addr) (PingConn, error)
	ListenPingAddr(laddr netip.Addr) (PingConn, error)
	LookupContextHost(ctx context.Context, host string) ([]string, error)
}

// TCPConn is the connection type returned by the TCP dial methods. gvisor's
// *gonet.TCPConn and lneto's TCP connection both satisfy it.
type TCPConn interface {
	Close() error
	CloseRead() error
	CloseWrite() error
	LocalAddr() net.Addr
	Read(b []byte) (int, error)
	RemoteAddr() net.Addr
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
	Write(b []byte) (int, error)
}

// UDPConn is the connection type returned by the UDP dial/listen methods.
type UDPConn interface {
	Close() error
	LocalAddr() net.Addr
	Read(b []byte) (int, error)
	ReadFrom(b []byte) (int, net.Addr, error)
	RemoteAddr() net.Addr
	SetDeadline(t time.Time) error
	SetReadDeadline(t time.Time) error
	SetWriteDeadline(t time.Time) error
	Write(b []byte) (int, error)
	WriteTo(b []byte, addr net.Addr) (int, error)
}

// TCPListener is the listener type returned by the TCP listen methods.
type TCPListener interface {
	Accept() (net.Conn, error)
	Addr() net.Addr
	Close() error
	Shutdown()
}

// PingConn is the ICMP "ping" connection returned by the ping methods. It is both a
// [net.Conn] (Read/Write against the dialed peer) and supports addressed I/O via
// ReadFrom/WriteTo. The gvisor backend returns a concrete implementation; the lneto
// backend does not implement ping and returns an error.
type PingConn interface {
	net.Conn
	ReadFrom(p []byte) (int, net.Addr, error)
	WriteTo(p []byte, addr net.Addr) (int, error)
}

@soypat soypat changed the title add lneto add lneto as an alternative to gvisor in netstack package Jul 1, 2026
Signed-off-by: Patricio Whittingslow <graded.sp@gmail.com>
@soypat

soypat commented Jul 10, 2026

Copy link
Copy Markdown
Author

@zx2c4 Let me know what I can do to help this along :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant