control

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2023 License: AGPL-3.0 Imports: 51 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 (
	SuspectedRushAnswerError     = fmt.Errorf("suspected DNS rush-answer")
	UnsupportedQuestionTypeError = fmt.Errorf("unsupported question type")
)
View Source
var DefaultUdpEndpointPool = NewUdpEndpointPool()

Functions

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.Message, timeout time.Duration)

func EnsureAdditionalOpt

func EnsureAdditionalOpt(dm *dnsmessage.Message, isReqAdd bool) (bool, error)

EnsureAdditionalOpt makes sure there is additional record OPT in the request.

func FlipDnsQuestionCase

func FlipDnsQuestionCase(dm *dnsmessage.Message)

FlipDnsQuestionCase is used to reduce dns pollution.

func FormatDnsRsc

func FormatDnsRsc(ans []dnsmessage.Resource) string

func FormatL4Proto

func FormatL4Proto(l4proto uint8) string

func GenerateObjects

func GenerateObjects(output string)

func Mac2String

func Mac2String(mac []uint8) string

func MagicNetwork

func MagicNetwork(network string, mark uint32) string

func ParseAddrHdr

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

func ParsePortRange

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

func ProcessName2String

func ProcessName2String(pname []uint8) 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

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,
) (*ControlPlane, error)

func (*ControlPlane) ChooseDialTarget

func (c *ControlPlane) ChooseDialTarget(outbound consts.OutboundIndex, dst netip.AddrPort, domain string) (dialTarget string, dialMode consts.DialMode)

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, err error)

func (*ControlPlane) Serve

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

type DnsCache

type DnsCache struct {
	DomainBitmap []uint32
	Answers      []dnsmessage.Resource
	Deadline     time.Time
}

func (*DnsCache) FillInto

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

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) DnsRespHandler

func (c *DnsController) DnsRespHandler(data []byte, validateRushAns bool) (newMsg *dnsmessage.Message, err error)

DnsRespHandler handle DNS resp.

func (*DnsController) DnsRespHandlerFactory

func (c *DnsController) DnsRespHandlerFactory(validateRushAnsFunc func(from netip.AddrPort) bool) func(data []byte, from netip.AddrPort) (msg *dnsmessage.Message, err error)

func (*DnsController) Handle_

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

func (*DnsController) LookupDnsRespCache

func (c *DnsController) LookupDnsRespCache(domain string, t dnsmessage.Type) (cache *DnsCache)

func (*DnsController) LookupDnsRespCache_

func (c *DnsController) LookupDnsRespCache_(msg *dnsmessage.Message) (resp []byte)

LookupDnsRespCache_ will modify the msg in place.

func (*DnsController) UpdateDnsCache

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

type DnsControllerOption

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

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 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, 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(lpmArrayMap *ebpf.Map) (matcher *RoutingMatcher, err error)

type RscWrapper

type RscWrapper struct {
	Rsc dnsmessage.Resource
}

func (RscWrapper) String

func (w RscWrapper) String() string

type UdpEndpoint

type UdpEndpoint struct {
	NatTimeout time.Duration

	Dialer *dialer.Dialer
	// 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
	Dialer     *dialer.Dialer
	// Network is useful for MagicNetwork
	Network string
	// Target is useful only if the underlay does not support Full-cone.
	Target string
}

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