socks5

package
v0.20.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 24, 2026 License: MPL-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NoAuthHandshake added in v0.20.0

func NoAuthHandshake(rw io.ReadWriter) error

NoAuthHandshake runs the auth negotiation with an exit node that expects it (protocol.Socks5PacketMethod): it offers no auth, as the client has been authenticated locally.

func Pipe added in v0.20.0

func Pipe(conn net.Conn, target io.ReadWriter)

Pipe copies data both ways between the SOCKS client and the target until both directions are done.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(listenAddr string, username, password string, awlPrefixes []netip.Prefix) (*Client, error)

NewClient starts the SOCKS5 listener. awlPrefixes are the awl subnets, IPv4 and IPv6, which the client connects to itself (see bypassTarget).

func (*Client) Addr added in v0.20.0

func (c *Client) Addr() net.Addr

Addr returns the address the listener is bound to.

func (*Client) Close

func (c *Client) Close() error

func (*Client) ConnsChan

func (c *Client) ConnsChan() <-chan net.Conn

func (*Client) HandleLocalAuth added in v0.17.0

func (c *Client) HandleLocalAuth(conn net.Conn) error

HandleLocalAuth performs the SOCKS5 auth negotiation locally. It reads the version byte and offered methods, then delegates to the configured authenticator.

func (*Client) ServeConn added in v0.20.0

func (c *Client) ServeConn(ctx context.Context, conn net.Conn, forward ForwardFunc) error

ServeConn serves a connection from ConnsChan: it runs the auth negotiation and reads the request. It connects to a target on this host or in the awl network itself, see bypassTarget, and passes other requests to forward.

func (*Client) SetBypassLocalAwl added in v0.20.0

func (c *Client) SetBypassLocalAwl(enabled bool)

SetBypassLocalAwl is for tests: with the bypass off, every target goes to the exit node, localhost included.

type ExitNodeRule added in v0.20.0

type ExitNodeRule struct {
	// contains filtered or unexported fields
}

ExitNodeRule keeps the exit node's own host and network from its peers. It refuses:

  • loopback and the unspecified address (0.0.0.0, ::), which the OS also connects to the local host;
  • the LAN, CGNAT and link-local ranges (see privatenet), the latter including the cloud metadata address 169.254.169.254;
  • multicast;
  • the awl subnets: the exit node's peers are not the client's.

The address is checked after the name is resolved, and the connection goes to that same address, so a name resolving to a refused address is refused too. The exit node's own public addresses are allowed: its peers reach its services through its awl address anyway.

func (*ExitNodeRule) Allow added in v0.20.0

func (r *ExitNodeRule) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool)

type ForwardFunc added in v0.20.0

type ForwardFunc func(ctx context.Context, conn net.Conn, rawReq []byte) error

ForwardFunc passes a request the client does not handle itself to the exit node. rawReq is the request as the SOCKS client sent it, already read from conn. An error means nothing has been sent to the SOCKS client yet.

type Logger

type Logger struct {
	// contains filtered or unexported fields
}

func NewLogger

func NewLogger() *Logger

func (*Logger) Printf

func (l *Logger) Printf(format string, v ...interface{})

type ReadWriterConnWrapper

type ReadWriterConnWrapper struct {
	io.ReadWriteCloser
}

ReadWriterConnWrapper is used for socks5

func (ReadWriterConnWrapper) LocalAddr

func (c ReadWriterConnWrapper) LocalAddr() net.Addr

func (ReadWriterConnWrapper) RemoteAddr

func (c ReadWriterConnWrapper) RemoteAddr() net.Addr

func (ReadWriterConnWrapper) SetDeadline

func (c ReadWriterConnWrapper) SetDeadline(time.Time) error

func (ReadWriterConnWrapper) SetReadDeadline

func (c ReadWriterConnWrapper) SetReadDeadline(time.Time) error

func (ReadWriterConnWrapper) SetWriteDeadline

func (c ReadWriterConnWrapper) SetWriteDeadline(time.Time) error

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(dialControl func(network, address string, c syscall.RawConn) error, awlPrefixes []netip.Prefix) *Server

NewServer constructs the SOCKS5 exit-node server. dialControl, when non-nil, is applied to every outbound connection the server opens to the real destination — it is the same socket-marking callback used for libp2p sockets (sockmark). This keeps SOCKS5 exit-node traffic going out the host's physical NIC, independent of whether this node is itself a VPN gateway client (whose 0.0.0.0/0-via-TUN default route would otherwise capture these sockets). Marking unconditionally is safe: when gateway mode is off there is no matching fwmark ip-rule, so the kernel ignores the mark — mirroring how libp2p sockets are marked at all times (see application.go). A nil dialControl yields a plain context-aware dialer. Connecting to the destination times out after dialTimeout.

awlPrefixes are the awl subnets, IPv4 and IPv6, which the exit node does not proxy to (see ExitNodeRule).

TODO(socks5-udp): UDP ASSOCIATE is effectively unsupported today (we serve only libp2p streams via ServeConn; haxii's UDP relay starts only inside Serve(), and BindIP is a fake 127.0.0.1). If it is ever enabled, note that haxii creates its UDP sockets directly (net.ListenUDP / net.DialUDP in udp.go) — bypassing config.Dial and therefore this marking, on every platform. Those sockets would need their own dialControl-style hook, otherwise UDP relay traffic loops into the VPN gateway tunnel.

func (*Server) SendServerFailureReply

func (s *Server) SendServerFailureReply(conn io.ReadWriter) error

func (*Server) ServeConn

func (s *Server) ServeConn(ioConn io.ReadWriteCloser) error

ServeConn is only used in tests. TODO: refactor tests

func (*Server) ServeStreamConn

func (s *Server) ServeStreamConn(stream network.Stream) error

func (*Server) ServeStreamConnNoAuth added in v0.17.0

func (s *Server) ServeStreamConnNoAuth(stream network.Stream) error

func (*Server) SetRulesEnabled added in v0.20.0

func (s *Server) SetRulesEnabled(enabled bool)

SetRulesEnabled is for tests: with the rules off, the server proxies to any address, local ones included. Names in .awl are still refused.

type StreamConnWrapper

type StreamConnWrapper struct {
	network.Stream
}

StreamConnWrapper is used for socks5

func (StreamConnWrapper) Close

func (c StreamConnWrapper) Close() error

func (StreamConnWrapper) LocalAddr

func (c StreamConnWrapper) LocalAddr() net.Addr

func (StreamConnWrapper) RemoteAddr

func (c StreamConnWrapper) RemoteAddr() net.Addr

type UpdatableRule

type UpdatableRule struct {
	// contains filtered or unexported fields
}

func NewUpdatableRule

func NewUpdatableRule(rule socks5.RuleSet) *UpdatableRule

func (*UpdatableRule) Allow

func (r *UpdatableRule) Allow(ctx context.Context, req *socks5.Request) (context.Context, bool)

func (*UpdatableRule) SetRule

func (r *UpdatableRule) SetRule(rule socks5.RuleSet)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL