control

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: AGPL-3.0 Imports: 54 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultNatTimeout = 3 * time.Minute
	DnsNatTimeout     = 17 * time.Second // RFC 5452
	MaxRetry          = 2
)
View Source
const (
	MaxDnsLookupDepth = 3
)
View Source
const (
	TcpSniffBufSize = 4096
)

Variables

View Source
var (
	CheckBatchUpdateFeatureOnce sync.Once
	SimulateBatchUpdate         bool
	SimulateBatchUpdateLpmTrie  bool
)
View Source
var (
	UnspecifiedAddressA    = netip.MustParseAddr("0.0.0.0")
	UnspecifiedAddressAAAA = netip.MustParseAddr("::")
)
View Source
var DefaultUdpEndpointPool = NewUdpEndpointPool()
View Source
var (
	UnsupportedQuestionTypeError = fmt.Errorf("unsupported question type")
)

Functions

func BpfMapBatchDelete added in v0.2.0

func BpfMapBatchDelete(m *ebpf.Map, keys interface{}) (n int, err error)

BpfMapBatchDelete deletes keys and ignores ErrKeyNotExist.

func BpfMapBatchUpdate

func BpfMapBatchUpdate(m *ebpf.Map, keys interface{}, values interface{}, opts *ebpf.BatchOptions) (n int, err error)

func CheckIpforward

func CheckIpforward(ifname string) error

func CheckSendRedirects

func CheckSendRedirects(ifname string) error

func ChooseNatTimeout

func ChooseNatTimeout(data []byte, sniffDns bool) (dmsg *dnsmessage.Msg, timeout time.Duration)

func FormatDnsRsc

func FormatDnsRsc(ans []dnsmessage.RR) string

func FormatL4Proto

func FormatL4Proto(l4proto uint8) string

func GenerateObjects

func GenerateObjects(output string)

func Mac2String

func Mac2String(mac []uint8) string

func ParseAddrHdr

func ParseAddrHdr(data []byte) (hdr *bpfDstRoutingResult, dataOffset int, err error)

func ParseFixedDomainTtl added in v0.2.0

func ParseFixedDomainTtl(ks []config.KeyableString) (map[string]int, error)

func ParsePortRange

func ParsePortRange(b []byte) (portStart, portEnd uint16)

func ProcessName2String

func ProcessName2String(pname []uint8) string

func QtypeToString added in v0.2.1

func QtypeToString(qtype uint16) string

func RefineAddrPortToShow

func RefineAddrPortToShow(addrPort netip.AddrPort) (srcToShow string)

func RefineSourceToShow

func RefineSourceToShow(src netip.AddrPort, dst netip.Addr, lanWanFlag consts.LanWanFlag) (srcToShow string)

func RelayTCP

func RelayTCP(lConn, rConn netproxy.Conn) (err error)

func RetrieveOriginalDest

func RetrieveOriginalDest(oob []byte) netip.AddrPort

func SetForwarding added in v0.1.4

func SetForwarding(ifname string, val string)

func SetIpv4forward added in v0.1.4

func SetIpv4forward(val string) error

func SetSendRedirects added in v0.1.4

func SetSendRedirects(ifname string, val string)

Types

type ControlPlane

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

func NewControlPlane

func NewControlPlane(
	log *logrus.Logger,
	_bpf interface{},
	dnsCache map[string]*DnsCache,
	tagToNodeList map[string][]string,
	groups []config.Group,
	routingA *config.Routing,
	global *config.Global,
	dnsConfig *config.Dns,
	externGeoDataDirs []string,
) (*ControlPlane, error)

func (*ControlPlane) ChooseDialTarget

func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip.AddrPort, domain string) (dialTarget string, shouldReroute bool, dialIp bool)

func (*ControlPlane) CloneDnsCache added in v0.1.2

func (c *ControlPlane) CloneDnsCache() map[string]*DnsCache

func (*ControlPlane) Close

func (c *ControlPlane) Close() (err error)

func (*ControlPlane) EjectBpf

func (c *ControlPlane) EjectBpf() *bpfObjects

EjectBpf will resect bpf from destroying life-cycle of control plane.

func (*ControlPlane) InjectBpf

func (c *ControlPlane) InjectBpf(bpf *bpfObjects)

func (*ControlPlane) ListenAndServe

func (c *ControlPlane) ListenAndServe(readyChan chan<- bool, port uint16) (listener *Listener, err error)

func (*ControlPlane) Route

func (c *ControlPlane) Route(src, dst netip.AddrPort, domain string, l4proto consts.L4ProtoType, routingResult *bpfRoutingResult) (outboundIndex consts.OutboundIndex, mark uint32, must bool, err error)

func (*ControlPlane) RouteDialTcp added in v0.2.0

func (c *ControlPlane) RouteDialTcp(p *RouteDialParam) (conn netproxy.Conn, err error)

func (*ControlPlane) Serve

func (c *ControlPlane) Serve(readyChan chan<- bool, listener *Listener) (err error)

type DialOption added in v0.2.2

type DialOption struct {
	Target   string
	Dialer   *dialer.Dialer
	Outbound *ob.DialerGroup
	Network  string
}

type DnsCache

type DnsCache struct {
	DomainBitmap     []uint32
	Answer           []dnsmessage.RR
	Deadline         time.Time
	OriginalDeadline time.Time // This field is not impacted by `fixed_domain_ttl`.
}

func (*DnsCache) FillInto

func (c *DnsCache) FillInto(req *dnsmessage.Msg)

func (*DnsCache) IncludeAnyIp added in v0.1.8

func (c *DnsCache) IncludeAnyIp() bool

func (*DnsCache) IncludeIp

func (c *DnsCache) IncludeIp(ip netip.Addr) bool

type DnsController

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

func NewDnsController

func NewDnsController(routing *dns.Dns, option *DnsControllerOption) (c *DnsController, err error)

func (*DnsController) Handle_

func (c *DnsController) Handle_(dnsMessage *dnsmessage.Msg, req *udpRequest) (err error)

func (*DnsController) LookupDnsRespCache

func (c *DnsController) LookupDnsRespCache(cacheKey string, ignoreFixedTtl bool) (cache *DnsCache)

func (*DnsController) LookupDnsRespCache_

func (c *DnsController) LookupDnsRespCache_(msg *dnsmessage.Msg, cacheKey string, ignoreFixedTtl bool) (resp []byte)

LookupDnsRespCache_ will modify the msg in place.

func (*DnsController) NormalizeAndCacheDnsResp_ added in v0.2.2

func (c *DnsController) NormalizeAndCacheDnsResp_(msg *dnsmessage.Msg) (err error)

NormalizeAndCacheDnsResp_ handle DNS resp in place.

func (*DnsController) RemoveDnsRespCache added in v0.1.6

func (c *DnsController) RemoveDnsRespCache(cacheKey string)

func (*DnsController) UpdateDnsCacheDeadline added in v0.2.0

func (c *DnsController) UpdateDnsCacheDeadline(host string, dnsTyp uint16, answers []dnsmessage.RR, deadline time.Time) (err error)

func (*DnsController) UpdateDnsCacheTtl added in v0.2.0

func (c *DnsController) UpdateDnsCacheTtl(host string, dnsTyp uint16, answers []dnsmessage.RR, ttl int) (err error)

type DnsControllerOption

type DnsControllerOption struct {
	Log                 *logrus.Logger
	CacheAccessCallback func(cache *DnsCache) (err error)
	CacheRemoveCallback func(cache *DnsCache) (err error)
	NewCache            func(fqdn string, answers []dnsmessage.RR, deadline time.Time, originalDeadline time.Time) (cache *DnsCache, err error)
	BestDialerChooser   func(req *udpRequest, upstream *dns.Upstream) (*dialArgument, error)
	IpVersionPrefer     int
	FixedDomainTtl      map[string]int
}

type IpVersionPrefer added in v0.1.6

type IpVersionPrefer int
const (
	IpVersionPrefer_No IpVersionPrefer = 0
	IpVersionPrefer_4  IpVersionPrefer = 4
	IpVersionPrefer_6  IpVersionPrefer = 6
)

type Listener

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

func (*Listener) Close

func (l *Listener) Close() error

type ProgField

type ProgField struct {
	Name string
	Ebpf string
}

type RouteDialParam added in v0.2.0

type RouteDialParam struct {
	Outbound    consts.OutboundIndex
	Domain      string
	Mac         [6]uint8
	ProcessName [16]uint8
	Src         netip.AddrPort
	Dest        netip.AddrPort
	Mark        uint32
}

type RoutingMatcher

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

func (*RoutingMatcher) Match

func (m *RoutingMatcher) Match(
	sourceAddr []byte,
	destAddr []byte,
	sourcePort uint16,
	destPort uint16,
	ipVersion consts.IpVersionType,
	l4proto consts.L4ProtoType,
	domain string,
	processName [16]uint8,
	mac []byte,
) (outboundIndex consts.OutboundIndex, mark uint32, must bool, err error)

Match is modified from kern/tproxy.c; please keep sync.

type RoutingMatcherBuilder

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

func NewRoutingMatcherBuilder

func NewRoutingMatcherBuilder(log *logrus.Logger, rules []*config_parser.RoutingRule, outboundName2Id map[string]uint8, bpf *bpfObjects, fallback config.FunctionOrString) (b *RoutingMatcherBuilder, err error)

func (*RoutingMatcherBuilder) BuildKernspace

func (b *RoutingMatcherBuilder) BuildKernspace(log *logrus.Logger) (err error)

func (*RoutingMatcherBuilder) BuildUserspace

func (b *RoutingMatcherBuilder) BuildUserspace() (matcher *RoutingMatcher, err error)

type RscWrapper

type RscWrapper struct {
	Rsc dnsmessage.RR
}

func (RscWrapper) String

func (w RscWrapper) String() string

type UdpEndpoint

type UdpEndpoint struct {
	NatTimeout time.Duration

	Dialer   *dialer.Dialer
	Outbound *outbound.DialerGroup
	// contains filtered or unexported fields
}

func (*UdpEndpoint) Close

func (ue *UdpEndpoint) Close() error

func (*UdpEndpoint) WriteTo

func (ue *UdpEndpoint) WriteTo(b []byte, addr string) (int, error)

type UdpEndpointOptions

type UdpEndpointOptions struct {
	Handler    UdpHandler
	NatTimeout time.Duration
	// GetTarget is useful only if the underlay does not support Full-cone.
	GetDialOption func() (option *DialOption, err error)
}

type UdpEndpointPool

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

UdpEndpointPool is a full-cone udp conn pool

func NewUdpEndpointPool

func NewUdpEndpointPool() *UdpEndpointPool

func (*UdpEndpointPool) GetOrCreate

func (p *UdpEndpointPool) GetOrCreate(lAddr netip.AddrPort, createOption *UdpEndpointOptions) (udpEndpoint *UdpEndpoint, isNew bool, err error)

func (*UdpEndpointPool) Remove

func (p *UdpEndpointPool) Remove(lAddr netip.AddrPort, udpEndpoint *UdpEndpoint) (err error)

type UdpHandler

type UdpHandler func(data []byte, from netip.AddrPort) error

type WriteCloser

type WriteCloser interface {
	CloseWrite() error
}

Jump to

Keyboard shortcuts

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