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 ¶
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.
var ErrBlocked = errors.New("egress: destination address not allowed")
ErrBlocked is returned for destinations that are not public unicast addresses.
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
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.
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 BlockNames ¶
BlockNames refuses destinations by name. list is asked on every dial and datagram, so a new list needs no new egress (nil or empty: nothing is blocked, the egress behaves as without this option). A destination given as a domain that the list holds is refused with ErrBlocked before it is resolved. A destination given as an IP address is let through, but the client's first bytes are read for the name: TLS SNI on a TCP connection (the connection is closed, no byte reaches the server) and the QUIC Initial of UDP (its datagrams are dropped). onBlock, if not nil, runs once per connection or UDP session that was blocked, never per packet.
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
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 ¶
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.