egress

package
v0.1.89 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package egress is the node's direct outbound for Hysteria2 (engine.Egress).

Two jobs the hysteria defaults do not do:

  • Domains are resolved with the node's own resolver list (a RU node must ask Yandex DNS or gosuslugi breaks). Together with the sniffing RequestHook this means the client's own DNS answer is not trusted: a sniffed domain replaces the IP the client sent and the node resolves it. The default outbound would use the system resolver, and its UDP path would call the system resolver once per datagram.
  • Destinations that are not public unicast (loopback, RFC 1918, CGNAT, link-local, cloud metadata, multicast) and every address of this host's own interfaces (v4 and v6, its public IP included: Linux would route that through lo, straight to sshd and the exporters) are refused, so an authenticated VPN user cannot reach the node's own services or its private network. AllowPrivate lifts this for tests and dev.

WARP is this same egress bound to a device: New(dns, WithDevice("mgwarp")), see device.go. Nothing here is WARP-specific.

Index

Constants

This section is empty.

Variables

View Source
var BindIP4 net.IP

BindIP4 is the local IPv4 address of the outgoing UDP sockets; nil, the production value, lets the system choose (all interfaces). Tests set it to loopback in TestMain: a test binary with a wildcard UDP socket makes Windows ask for a firewall rule on each run.

View Source
var ErrBlocked = errors.New("egress: destination address not allowed")

ErrBlocked is returned for destinations that are not public unicast addresses.

View Source
var ErrNoIPv4 = errors.New("egress: no IPv4 address (IPv6 for clients is off on this node)")

ErrNoIPv4 is returned for a destination that has no IPv4 address while the egress is IPv4-only (IPv4OnlyWhen).

Functions

func LookupIPv4 added in v0.1.65

func LookupIPv4(servers []string, host string) (netip.Addr, error)

LookupIPv4 resolves the A record of host with the given resolvers, the way the engines resolve (servers in order, the system resolver when there are none). An IPv4 literal is returned as it is. For callers outside the engines that must not follow AAAA.

Types

type Direct

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

Direct dials the internet from this host. Safe for concurrent use.

func New

func New(resolvers func() []string, opts ...Option) *Direct

New builds the direct egress. resolvers is called per lookup (engine.Env.DNS), so a node settings change needs no restart; "host" or "host:port" entries, tried in order; nil or empty = system resolver.

func (*Direct) CheckUDP

func (d *Direct) CheckUDP(addr string) error

func (*Direct) TCP

func (d *Direct) TCP(addr string) (net.Conn, error)

func (*Direct) UDP

func (d *Direct) UDP(addr string) (engine.EgressUDP, error)

type Option

type Option func(*stage)

Option tunes New.

func AllowPrivate

func AllowPrivate() Option

AllowPrivate permits loopback, private and link-local destinations and the node's own addresses (tests, dev).

func IPv4Only

func IPv4Only() Option

IPv4Only makes the dialer use IPv4 addresses only (hysteria DirectOutboundMode4). The WARP egress sets it while the account has no IPv6 address: new accounts often have none, and a v6 dial would only hang or fail.

func IPv4OnlyWhen added in v0.1.22

func IPv4OnlyWhen(on func() bool) Option

IPv4OnlyWhen makes the egress use IPv4 only while on() returns true, asked on every dial and every datagram ("IPv6 for clients" off on the node: a hoster's IPv6 range may be geolocated in another country). A destination that has only IPv6 addresses is refused with ErrNoIPv4. Connections that are already open keep their address family.

func WithDevice

func WithDevice(name string) Option

WithDevice makes the egress leave through the named network device (SO_BINDTODEVICE on every TCP dialer and UDP socket, Linux only). This is how the WARP egress works: the device is the WARP tunnel, the routing rules of internal/node/warp send anything bound to it into the WARP table, and a missing device or a dead table makes a dial fail instead of falling back to the direct route (fail closed).

The dialer is built on first use and again after a failure, never at construction: the hysteria constructor insists that the device exists right now, and the tunnel can come and go (an agent start, a pause, a link flap). A built dialer keeps working across a re-creation of the device, because the bind is by name. Everything else (node resolver, blocklist) is the same stage as Direct.

Jump to

Keyboard shortcuts

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