Help us shape the future of Go! Take the 2026 Go Developer Survey

inbound

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Overview

Package inbound is the loft client listener: SOCKS5, userspace TUN (ICMP/UDP/TCP), Darwin/Linux DNS and routes, optional overlay IPv6.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AcceptTUNFD

func AcceptTUNFD(ln net.Listener) (int, string, error)

AcceptTUNFD reads one SCM_RIGHTS fd and the utun name from ln.

func JoinDNS

func JoinDNS(ips []net.IP) string

JoinDNS is comma-separated IPv4 for STATUS and logs.

func ListenSOCKS5

func ListenSOCKS5(addr string, d transport.Dialer) (net.Listener, error)

ListenSOCKS5 accepts SOCKS5 CONNECT and UDP ASSOCIATE on addr.

func ListenTUNSock

func ListenTUNSock(path string) (net.Listener, error)

ListenTUNSock binds a unix socket at path (0600) for loft-priv to send a utun fd.

func OverlayCIDR

func OverlayCIDR(overlayIP, tunAddr string) string

OverlayCIDR is Status.IP with the prefix from tun_addr (default /24).

func PacketTUNFromFD

func PacketTUNFromFD(fd int, name string) io.ReadWriteCloser

PacketTUNFromFD is a utun fd as IP ReadWriteCloser (no mux stack). For SSTP.

func ParseDNSList

func ParseDNSList(s string) []net.IP

ParseDNSList reads IPv4 addresses separated by comma, space, or semicolon.

func ResolveDNS

func ResolveDNS(ipcp []net.IP, peer net.IP, extra []net.IP, replace bool) []net.IP

ResolveDNS picks SSTP resolvers the way Windows RAS does: IPCP DNS if the server sent any, else the PPP gateway. extra appends to that list; extra with replace uses only extra.

func SocksOff added in v1.0.4

func SocksOff(addr string) bool

SocksOff is true when addr is empty, off, false, 0, or "-".

func WrapL3 added in v1.0.25

func WrapL3(d transport.Dialer) (transport.Dialer, error)

WrapL3 returns n wrapping d when d carries IP. d is returned unchanged otherwise.

Types

type Device

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

Device is a live TUN. Attach hooks ICMP on each new mux session (metro).

func AttachTUN added in v1.0.15

func AttachTUN(device, cidr string, d transport.Dialer) (*Device, error)

AttachTUN opens an existing TUN by name and runs the userspace stack on it. The kernel address, MTU, DNS, and routes stay with the caller (ConnMan, NetworkManager). Same packet path as StartTUN.

func StartStack

func StartStack(rw io.ReadWriteCloser, name string, d transport.Dialer, overlayIP string) (*Device, error)

StartStack binds an IP packet pipe. Mux fronts get gVisor; l3 splices IP. overlayIP is Status (loft) or the synthetic VLESS address. No OS routes.

func StartTUN

func StartTUN(device, cidr string, killSwitch bool, d transport.Dialer, exclude []string) (*Device, error)

StartTUN brings up a real utun/tun, userspace stack, and optional kill-switch.

func StartTUNFromFD

func StartTUNFromFD(fd int, name string, d transport.Dialer) (*Device, error)

StartTUNFromFD wraps an already-configured utun fd in the userspace stack.

func (*Device) Attach

func (d *Device) Attach(dial transport.Dialer)

Attach hooks ICMP/UDP datagrams on the current mux session, or an L3 IP pump.

func (*Device) Close

func (d *Device) Close() error

Close undoes DNS/routes, stops the stack, and closes the TUN.

type L3Net added in v1.0.25

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

L3Net is a Dialer that opens TCP/UDP on the L3 overlay IP.

func NewL3Net added in v1.0.25

func NewL3Net(d transport.Dialer, pump transport.IPPump) (*L3Net, error)

NewL3Net binds a gVisor IPv4 stack to pump and starts the packet pump.

func (*L3Net) AttachTUN added in v1.0.25

func (n *L3Net) AttachTUN(tun io.ReadWriteCloser)

AttachTUN splices kernel utun packets with the L3 pump.

func (*L3Net) Close added in v1.0.25

func (n *L3Net) Close() error

func (*L3Net) ConnBytes added in v1.0.25

func (n *L3Net) ConnBytes() (uint64, uint64)

func (*L3Net) Done added in v1.0.25

func (n *L3Net) Done() <-chan struct{}

func (*L3Net) ListenUDP added in v1.0.25

func (n *L3Net) ListenUDP() (net.PacketConn, error)

ListenUDP binds one unconnected UDP socket on the overlay.

func (*L3Net) LookupIP4 added in v1.0.25

func (n *L3Net) LookupIP4(host string) (net.IP, error)

LookupIP4 resolves host through the host resolver (debug path).

func (*L3Net) Open added in v1.0.25

func (n *L3Net) Open(target string) (net.Conn, error)

Open dials TCP on the overlay toward target (host:port).

func (*L3Net) Session added in v1.0.25

func (n *L3Net) Session() *mux.Session

func (*L3Net) Swap added in v1.0.25

func (n *L3Net) Swap(d transport.Dialer, pump transport.IPPump)

Swap replaces the CONNECT pump. gVisor, SOCKS, and TUN stay.

type SSTPNet

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

SSTPNet is a transport.Dialer that opens TCP/UDP on the SSTP overlay IP.

func NewSSTPNet

func NewSSTPNet(sess *sstp.Session) (*SSTPNet, error)

NewSSTPNet binds a gVisor IPv4 stack to sess and starts the packet pump.

func (*SSTPNet) ApplyDNS

func (n *SSTPNet) ApplyDNS(extra []net.IP, replace bool)

ApplyDNS sets resolvers: IPCP, else the PPP peer, plus extra. replace with a non-empty extra list skips IPCP and the gateway.

func (*SSTPNet) AttachTUN

func (n *SSTPNet) AttachTUN(tun io.ReadWriteCloser)

AttachTUN splices kernel utun packets with the SSTP session (L3).

func (*SSTPNet) Bytes

func (n *SSTPNet) Bytes() (up, down uint64)

Bytes is overlay IP octets written (up) and read (down) on the PPP session.

func (*SSTPNet) Close

func (n *SSTPNet) Close() error

func (*SSTPNet) DNS

func (n *SSTPNet) DNS() []net.IP

DNS is the resolver list SOCKS/TUN name lookup will use.

func (*SSTPNet) DialUDP

func (n *SSTPNet) DialUDP(addr string) (net.Conn, error)

DialUDP opens one connected UDP socket on the SSTP overlay (SOCKS UDP ASSOCIATE).

func (*SSTPNet) Done

func (n *SSTPNet) Done() <-chan struct{}

func (*SSTPNet) ListenUDP

func (n *SSTPNet) ListenUDP() (net.PacketConn, error)

ListenUDP binds one unconnected UDP socket on the overlay (SOCKS UDP ASSOCIATE).

func (*SSTPNet) LookupIP4

func (n *SSTPNet) LookupIP4(host string) (net.IP, error)

LookupIP4 resolves host through the SSTP DNS servers.

func (*SSTPNet) Open

func (n *SSTPNet) Open(target string) (net.Conn, error)

func (*SSTPNet) OverlayIP

func (n *SSTPNet) OverlayIP() net.IP

OverlayIP is the SSTP-assigned IPv4.

func (*SSTPNet) Session

func (n *SSTPNet) Session() *mux.Session

func (*SSTPNet) SetLog

func (n *SSTPNet) SetLog(fn func(string, ...any))

SetLog prints stack/DNS/TCP traces (loft-front -v, loft-probe -v).

func (*SSTPNet) SetTap

func (n *SSTPNet) SetTap(fn func([]byte))

SetTap sees every inbound IP before demux (ICMP probes).

type SocksGate added in v1.0.4

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

SocksGate holds the current SOCKS5 listener. Set replaces it; a bind error leaves the previous listener running.

func NewSocksGate added in v1.0.4

func NewSocksGate(d transport.Dialer) *SocksGate

NewSocksGate serves SOCKS5 through d. No listen until Set.

func (*SocksGate) Addr added in v1.0.4

func (g *SocksGate) Addr() string

Addr is the current listen address, or empty.

func (*SocksGate) Close added in v1.0.4

func (g *SocksGate) Close() error

Close drops the listener. In-flight SOCKS clients keep the Dialer.

func (*SocksGate) Set added in v1.0.4

func (g *SocksGate) Set(addr string) (bound string, err error)

Set binds addr (host:port). Empty/off closes the listener. On bind failure the previous listen stays up.

Jump to

Keyboard shortcuts

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