router

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrRejected = errors.New("rejected")
)

Functions

This section is empty.

Types

type Config added in v1.2.0

type Config struct {
	DisableNameResolutionForIPRules bool               `json:"disableNameResolutionForIPRules"`
	DefaultTCPClientName            string             `json:"defaultTCPClientName"`
	DefaultUDPClientName            string             `json:"defaultUDPClientName"`
	GeoLite2CountryDbPath           string             `json:"geoLite2CountryDbPath"`
	DomainSets                      []domainset.Config `json:"domainSets"`
	Routes                          []RouteConfig      `json:"routes"`
}

Config is the configuration for a Router.

func (*Config) Router added in v1.2.0

func (rc *Config) Router(logger *zap.Logger, resolvers []*dns.Resolver, resolverMap map[string]*dns.Resolver, tcpClientMap map[string]zerocopy.TCPClient, udpClientMap map[string]zerocopy.UDPClient) (*Router, error)

Router creates a router from the RouterConfig.

type Route

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

Route controls where a request is routed.

type RouteConfig

type RouteConfig struct {
	// Name of this route. Used in logs to identify matched routes.
	Name string `json:"name"`

	// Apply this route to "tcp" or "udp" only. If empty, match all requests.
	Network string `json:"network"`

	// Route matched requests to this client. Must not be empty.
	ClientName string `json:"clientName"`

	// When matching a domain target to IP prefixes, use this resolver to resolve the domain name.
	// If unspecified, use all resolvers by order.
	ResolverName string `json:"resolverName"`

	// Match requests from these servers. If empty, match all requests.
	ServerNames []string `json:"serverNames"`

	// Match requests to these domain targets. If empty, match all requests.
	Domains []string `json:"domains"`

	// Match requests to domains in these domain sets. If empty, match all requests.
	DomainSets []string `json:"domainSets"`

	// Match requests to these IP prefixes. If empty, match all requests.
	Prefixes []netip.Prefix `json:"prefixes"`

	// Match requests from these IP prefixes. If empty, match all requests.
	SourcePrefixes []netip.Prefix `json:"sourcePrefixes"`

	// Match requests to these ports. If empty, match all requests.
	Ports []uint16 `json:"ports"`

	// Match requests from these ports. If empty, match all requests.
	SourcePorts []uint16 `json:"sourcePorts"`

	// Match requests to IP addresses in these countries. If empty, match all requests.
	GeoIPCountries []string `json:"geoIPCountries"`

	// Invert domain matching logic. Match requests to all domains except those in Domains or DomainSets.
	InvertDomains bool `json:"invertDomains"`

	// Invert IP prefix matching logic. Match requests to all IP prefixes except those in Prefixes.
	InvertPrefixes bool `json:"invertPrefixes"`

	// Invert port matching logic. Match requests to all ports except those in Ports.
	InvertPorts bool `json:"invertPorts"`

	// Invert source IP prefix matching logic. Match requests from all IP prefixes except those in SourcePrefixes.
	InvertSourcePrefixes bool `json:"invertSourcePrefixes"`

	// Invert source port matching logic. Match requests from all ports except those in SourcePorts.
	InvertSourcePorts bool `json:"invertSourcePorts"`

	// Invert GeoIP country matching logic. Match requests to all IP addresses except those in GeoIPCountries.
	InvertGeoIPCountries bool `json:"invertGeoIPCountries"`
}

RouteConfig is a routing rule.

func (*RouteConfig) Route

func (rc *RouteConfig) Route(allowGeoIP bool, resolverMap map[string]*dns.Resolver, tcpClientMap map[string]zerocopy.TCPClient, udpClientMap map[string]zerocopy.UDPClient, domainSetMap map[string]domainset.DomainSet) (*Route, error)

Route creates a route from the RouteConfig.

type Router

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

Router looks up the destination client for requests received by servers.

func NewRouter

func NewRouter(disableNameResolutionForIPRules bool, geoip *geoip2.Reader, logger *zap.Logger, defaultTCPClient zerocopy.TCPClient, defaultUDPClient zerocopy.UDPClient, routes []*Route, resolvers []*dns.Resolver) *Router

func (*Router) GetTCPClient

func (r *Router) GetTCPClient(serverName string, sourceAddrPort netip.AddrPort, targetAddr conn.Addr) (tcpClient zerocopy.TCPClient, err error)

GetTCPClient returns the zerocopy.TCPClient for a TCP request received by serverName from sourceAddrPort to targetAddr.

func (*Router) GetUDPClient

func (r *Router) GetUDPClient(serverName string, sourceAddrPort netip.AddrPort, targetAddr conn.Addr) (udpClient zerocopy.UDPClient, err error)

GetUDPClient returns the zerocopy.UDPClient for a UDP session received by serverName. The first received packet of the session is from sourceAddrPort to targetAddr.

func (*Router) Stop

func (r *Router) Stop() error

Stop stops the router.

Jump to

Keyboard shortcuts

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