Documentation
¶
Index ¶
- func NoAuthHandshake(rw io.ReadWriter) error
- func Pipe(conn net.Conn, target io.ReadWriter)
- type Client
- func (c *Client) Addr() net.Addr
- func (c *Client) Close() error
- func (c *Client) ConnsChan() <-chan net.Conn
- func (c *Client) HandleLocalAuth(conn net.Conn) error
- func (c *Client) ServeConn(ctx context.Context, conn net.Conn, forward ForwardFunc) error
- func (c *Client) SetBypassLocalAwl(enabled bool)
- type ExitNodeRule
- type ForwardFunc
- type Logger
- type ReadWriterConnWrapper
- type Server
- func (s *Server) SendServerFailureReply(conn io.ReadWriter) error
- func (s *Server) ServeConn(ioConn io.ReadWriteCloser) error
- func (s *Server) ServeStreamConn(stream network.Stream) error
- func (s *Server) ServeStreamConnNoAuth(stream network.Stream) error
- func (s *Server) SetRulesEnabled(enabled bool)
- type StreamConnWrapper
- type UpdatableRule
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.
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) HandleLocalAuth ¶ added in v0.17.0
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
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
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.
type ForwardFunc ¶ added in v0.20.0
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 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) ServeStreamConnNoAuth ¶ added in v0.17.0
func (*Server) SetRulesEnabled ¶ added in v0.20.0
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 ¶
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) SetRule ¶
func (r *UpdatableRule) SetRule(rule socks5.RuleSet)