Documentation
¶
Index ¶
- type DialContext
- type FilteredNetwork
- func (n *FilteredNetwork) AddAllowedDestination(prefix netip.Prefix)
- func (n *FilteredNetwork) AddAllowedPort(port uint16)
- func (n *FilteredNetwork) AddDeniedDestination(prefix netip.Prefix)
- func (n *FilteredNetwork) AddDeniedPort(port uint16)
- func (n *FilteredNetwork) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (n *FilteredNetwork) Listen(network, address string) (net.Listener, error)
- func (n *FilteredNetwork) ListenPacket(network, address string) (net.PacketConn, error)
- func (n *FilteredNetwork) LookupHost(ctx context.Context, host string) ([]string, error)
- func (n *FilteredNetwork) RemoveAllowedDestination(prefix netip.Prefix)
- func (n *FilteredNetwork) RemoveAllowedPort(port uint16)
- func (n *FilteredNetwork) RemoveDeniedDestination(prefix netip.Prefix)
- func (n *FilteredNetwork) RemoveDeniedPort(port uint16)
- type FilteredNetworkConfig
- type HostNetwork
- func (n *HostNetwork) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (n *HostNetwork) Listen(network, address string) (net.Listener, error)
- func (n *HostNetwork) ListenPacket(network, address string) (net.PacketConn, error)
- func (n *HostNetwork) LookupHost(ctx context.Context, host string) ([]string, error)
- type LoopbackNetwork
- func (n *LoopbackNetwork) DialContext(ctx context.Context, network, addr string) (net.Conn, error)
- func (n *LoopbackNetwork) Listen(network, address string) (net.Listener, error)
- func (n *LoopbackNetwork) ListenPacket(network, address string) (net.PacketConn, error)
- func (n *LoopbackNetwork) LookupHost(ctx context.Context, host string) ([]string, error)
- type NetstackNetwork
- func (n *NetstackNetwork) DialContext(ctx context.Context, network, address string) (net.Conn, error)
- func (n *NetstackNetwork) Listen(network, address string) (net.Listener, error)
- func (n *NetstackNetwork) ListenPacket(network, address string) (net.PacketConn, error)
- func (n *NetstackNetwork) LookupHost(ctx context.Context, host string) ([]string, error)
- type Network
- type ResolveConfig
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DialContext ¶
DialContext is a function that connects to the address on the named network using the provided context.
type FilteredNetwork ¶ added in v0.3.0
type FilteredNetwork struct {
// contains filtered or unexported fields
}
FilteredNetwork is a network that filters connections based on allowed and denied destination prefixes. It forwards connections to the upstream network if the destination is allowed. If the destination is denied, it returns an error.
func Filtered ¶ added in v0.3.0
func Filtered(conf *FilteredNetworkConfig) *FilteredNetwork
Filtered creates a new filtered network with the given configuration.
func (*FilteredNetwork) AddAllowedDestination ¶ added in v0.3.1
func (n *FilteredNetwork) AddAllowedDestination(prefix netip.Prefix)
AddAllowedDestination adds a prefix to the list of allowed destinations.
func (*FilteredNetwork) AddAllowedPort ¶ added in v0.3.3
func (n *FilteredNetwork) AddAllowedPort(port uint16)
AddAllowedPort adds a port to the list of allowed ports.
func (*FilteredNetwork) AddDeniedDestination ¶ added in v0.3.1
func (n *FilteredNetwork) AddDeniedDestination(prefix netip.Prefix)
AddDeniedDestination adds a prefix to the list of denied destinations.
func (*FilteredNetwork) AddDeniedPort ¶ added in v0.3.3
func (n *FilteredNetwork) AddDeniedPort(port uint16)
AddDeniedPort adds a port to the list of denied ports.
func (*FilteredNetwork) DialContext ¶ added in v0.3.0
func (*FilteredNetwork) Listen ¶ added in v0.3.0
func (n *FilteredNetwork) Listen(network, address string) (net.Listener, error)
func (*FilteredNetwork) ListenPacket ¶ added in v0.3.0
func (n *FilteredNetwork) ListenPacket(network, address string) (net.PacketConn, error)
func (*FilteredNetwork) LookupHost ¶ added in v0.3.0
func (*FilteredNetwork) RemoveAllowedDestination ¶ added in v0.3.1
func (n *FilteredNetwork) RemoveAllowedDestination(prefix netip.Prefix)
RemoveAllowedDestination removes a prefix from the list of allowed destinations.
func (*FilteredNetwork) RemoveAllowedPort ¶ added in v0.3.3
func (n *FilteredNetwork) RemoveAllowedPort(port uint16)
RemoveAllowedPort removes a port from the list of allowed ports.
func (*FilteredNetwork) RemoveDeniedDestination ¶ added in v0.3.1
func (n *FilteredNetwork) RemoveDeniedDestination(prefix netip.Prefix)
RemoveDeniedDestination removes a prefix from the list of denied destinations.
func (*FilteredNetwork) RemoveDeniedPort ¶ added in v0.3.3
func (n *FilteredNetwork) RemoveDeniedPort(port uint16)
RemoveDeniedPort removes a port from the list of denied ports.
type FilteredNetworkConfig ¶ added in v0.3.0
type FilteredNetworkConfig struct {
// Allowed destination prefixes.
AllowedDestinations []netip.Prefix
// Denied destination prefixes.
DeniedDestinations []netip.Prefix
// Allowed destination ports.
AllowedPorts []uint16
// Denied destination ports.
DeniedPorts []uint16
// The network to forward connections to.
Upstream Network
}
FilteredNetworkConfig is the configuration for a FilteredNetwork.
type HostNetwork ¶
type HostNetwork struct{}
func Host ¶
func Host() *HostNetwork
Host returns a network implementation that uses the host's network stack.
func (*HostNetwork) DialContext ¶
func (*HostNetwork) Listen ¶
func (n *HostNetwork) Listen(network, address string) (net.Listener, error)
func (*HostNetwork) ListenPacket ¶
func (n *HostNetwork) ListenPacket(network, address string) (net.PacketConn, error)
func (*HostNetwork) LookupHost ¶ added in v0.2.0
type LoopbackNetwork ¶
type LoopbackNetwork struct{}
func Loopback ¶
func Loopback() *LoopbackNetwork
Loopback returns a network that only connects to localhost.
func (*LoopbackNetwork) DialContext ¶
func (*LoopbackNetwork) Listen ¶
func (n *LoopbackNetwork) Listen(network, address string) (net.Listener, error)
func (*LoopbackNetwork) ListenPacket ¶
func (n *LoopbackNetwork) ListenPacket(network, address string) (net.PacketConn, error)
func (*LoopbackNetwork) LookupHost ¶ added in v0.2.0
type NetstackNetwork ¶
type NetstackNetwork struct {
// contains filtered or unexported fields
}
func Netstack ¶
func Netstack(ipstack *stack.Stack, nicID tcpip.NICID, resolveConf *ResolveConfig) *NetstackNetwork
Netstack returns a network that uses the provided netstack stack and NIC ID.
func (*NetstackNetwork) DialContext ¶
func (*NetstackNetwork) Listen ¶
func (n *NetstackNetwork) Listen(network, address string) (net.Listener, error)
func (*NetstackNetwork) ListenPacket ¶
func (n *NetstackNetwork) ListenPacket(network, address string) (net.PacketConn, error)
func (*NetstackNetwork) LookupHost ¶ added in v0.2.0
type Network ¶
type Network interface {
// DialContext connects to the address on the named network using the provided context.
DialContext(ctx context.Context, network, addr string) (net.Conn, error)
// LookupHost looks up the given host using the local resolver.
// It returns a slice of that host's addresses.
LookupHost(ctx context.Context, host string) ([]string, error)
// Listen listens for incoming connections on the network address.
// Known networks are "tcp", "tcp4" (IPv4-only), "tcp6" (IPv6-only).
// If the address is an empty string, Listen listens on all available addresses.
Listen(network, address string) (net.Listener, error)
// ListenPacket listens for incoming packets addressed to the local address.
// Known networks are "udp", "udp4" (IPv4-only), "udp6" (IPv6-only).
ListenPacket(network, address string) (net.PacketConn, error)
}
Network is a simple network abstraction.
type ResolveConfig ¶
type ResolveConfig struct {
// Nameservers is a list of nameservers to use.
// If empty, the system default resolver is used.
Nameservers []string
// SearchDomains is a list of search domains to use.
SearchDomains []string
// NDots is the number of dots in name to trigger absolute lookup.
// Defaults to 1 if nil.
NDots *int
}
ResolveConfig holds the resolver configuration.
func (*ResolveConfig) LookupHost ¶ added in v0.2.0
func (r *ResolveConfig) LookupHost(ctx context.Context, host string, dialContext DialContext) ([]string, error)
LookupHost looks up the given host using the resolver configuration.