shortcut

package module
v0.0.0-...-bf59a13 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2021 License: Apache-2.0 Imports: 7 Imported by: 2

README

Go

shortcut

Provides the ability to check if target address belongs to IP ranges known to be unblocked, in which case there is the possibility to send traffic directly. Alternatively or in addition, include IP ranges known to be blocked or to indicate DNS poisoning.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Method

type Method int
const (
	// Proxy indicates traffic to this domain/IP should be proxied.
	Proxy Method = iota

	// Direct indicates traffic to this domain/IP should be routed directly.
	Direct

	// Unknown indicates shortcut has no opinion about the routing for this domain/IP.
	Unknown
)

type Shortcut

type Shortcut interface {
	// RouteMethod checks if the address should be routed directly or should
	// be proxied, or whether the ideal method is unknown.
	RouteMethod(ctx context.Context, addr string) (Method, net.IP)
	// SetResolver sets a custom resolver to replace the system default.
	SetResolver(r func(ctx context.Context, addr string) (net.IP, error))
}

func New

func New(ipv4DirectSubnets, ipv6DirectSubnets, ipv4ProxySubnets, ipv6ProxySubnets []string) Shortcut

New creates a new shortcut from the subnets for both direct and proxied traffic.

func NewFromReader

func NewFromReader(v4Direct, v6Direct, v4Proxy, v6Proxy io.Reader) Shortcut

NewFromReader is a helper to create shortcut from readers. The content should be in CIDR format, one entry per line.

type SortList

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

func NewSortList

func NewSortList(subnets []string) *SortList

NewSortList creates a shortcut list from a list of CIDR subnets in "a.b.c.d/24" or "2001:db8::/32" format. Each subnet string in one list should be in the same format, i.e., IPv4 only or IPv6 only, but not mixed.

func (*SortList) Contains

func (l *SortList) Contains(ip net.IP) bool

Contains checks if the ip belongs to one of the subnets in the list. Note that the byte length of ip should match the format of the subnets, i.e., call To4() before checking against an IPv4 list, and To16() for an IPv6 list.

Jump to

Keyboard shortcuts

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