router

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2025 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrBlocked = errors.New("block")
View Source
var ErrNoHandler = errors.New("no handler")
View Source
var ErrNoHandlerPick = errors.New("no handler picked")
View Source
var ErrNoRule = errors.New("no rule matched")
View Source
var ErrSelectorNotFound = errors.New("selector not found")

Functions

func NewRule

func NewRule(name string, outboundTag, selectorTag string, conditions ...Condition) *rule

func NewUserMatcher

func NewUserMatcher(users []string) *userMatcher

Types

type AllMatcher

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

func (*AllMatcher) Apply

func (m *AllMatcher) Apply(c context.Context, sInfo *session.Info, rw interface{}) (interface{}, bool)

type AppIdMatcher

type AppIdMatcher struct {
	AppSet i.AppSet
}
func ToIndexMatcher(appIds []*configs.AppId) (strmatcher.IndexMatcher, error) {
	indexMatcher := strmatcher.NewMphIndexMatcher()
	for _, appId := range appIds {
		matcher, err := ToStrMatcher(appId)
		if err != nil {
			return nil, err
		}
		indexMatcher.Add(matcher)
	}
	if err := indexMatcher.Build(); err != nil {
		return nil, err
	}
	return indexMatcher, nil
}
func ToStrMatcher(d *configs.AppId) (strmatcher.Matcher, error) {
	lowerValue := strings.ToLower(d.Value)
	switch d.Type {
	case configs.AppId_Exact:
		return strmatcher.Full.New(lowerValue)
	case configs.AppId_Prefix:
		return strmatcher.Prefix.New(lowerValue)
	case configs.AppId_Keyword:
		return strmatcher.Substr.New(lowerValue)
	default:
		return nil, errors.New("unknown domain type")
	}
}

func (*AppIdMatcher) Apply

func (m *AppIdMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type Condition

type Condition interface {
	Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)
}

type ConditionFakeIp

type ConditionFakeIp struct {
}

func (*ConditionFakeIp) Apply

func (m *ConditionFakeIp) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type ConditionProtocol added in v1.0.2

type ConditionProtocol struct {
	Sniffer *sniff.Sniffer
	// contains filtered or unexported fields
}

func (*ConditionProtocol) Apply added in v1.0.2

func (m *ConditionProtocol) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type ConditionTrue

type ConditionTrue struct{}

func (*ConditionTrue) Apply

func (c *ConditionTrue) Apply(ctx context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type ContextWithDNS

type ContextWithDNS struct {
	SessionInfo
	// contains filtered or unexported fields
}

func NewInfoWithDNS

func NewInfoWithDNS(ctx SessionInfo, dns i.IPResolver) *ContextWithDNS

func (*ContextWithDNS) GetTargetIP

func (ctx *ContextWithDNS) GetTargetIP() net.IP

GetTargetIPs overrides original routing.Context's implementation.

type DomainMatcher

type DomainMatcher struct {
	DomainSet i.DomainSet
	SkipSniff bool
	Sniffer   *sniff.Sniffer
}

func (*DomainMatcher) Apply

func (m *DomainMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type InboundTagMatcher

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

func NewInboundTagMatcher

func NewInboundTagMatcher(tags []string) *InboundTagMatcher

func (*InboundTagMatcher) Apply

func (v *InboundTagMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

Apply implements Condition.

type IpMatcher

type IpMatcher struct {
	MatchSourceIp bool
	IpSet         i.IPSet
	IpResolver    i.IPResolver
	Resolve       bool
}

a IpMatcher consists of a list of geoIpMatcher, each geoIpMatcher is created from a geo.GeoIP which corresponds to ips of a specific country.

func (*IpMatcher) Apply

func (m *IpMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type Ipv6Matcher

type Ipv6Matcher struct{}

func (*Ipv6Matcher) Apply

func (m *Ipv6Matcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type NetworkMatcher

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

func NewNetworkMatcher

func NewNetworkMatcher(network []net.Network) NetworkMatcher

func (NetworkMatcher) Apply

func (v NetworkMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

Apply implements Condition.

type PortMatcher

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

func NewPortMatcher

func NewPortMatcher(portRanges []*net.PortRange, onSource bool) *PortMatcher

func (*PortMatcher) Apply

func (m *PortMatcher) Apply(c context.Context, info *session.Info, rw interface{}) (interface{}, bool)

type Router

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

determine a outbound handler for a session

func NewRouter

func NewRouter(config *RouterConfig) (*Router, error)

func (*Router) AddRule

func (r *Router) AddRule(rule *rule)

func (*Router) PickHandler

func (r *Router) PickHandler(ctx context.Context, si *session.Info) (i.Outbound, error)

func (*Router) PickHandlerWithData

func (r *Router) PickHandlerWithData(ctx context.Context, si *session.Info, rw interface{}) (interface{}, i.Outbound, error)

type RouterConfig

type RouterConfig struct {
	*configs.RouterConfig
	GeoHelper       i.GeoHelper
	Selectors       *selector.Selectors
	OutboundManager i.OutboundManager
	IpResolver      i.IPResolver
}

type RouterWrapper

type RouterWrapper struct {
	atomic.Value //*Router
}

func (*RouterWrapper) GetRouter

func (r *RouterWrapper) GetRouter() *Router

func (*RouterWrapper) PickHandler

func (r *RouterWrapper) PickHandler(ctx context.Context, si *session.Info) (i.Outbound, error)

func (*RouterWrapper) PickHandlerWithData

func (r *RouterWrapper) PickHandlerWithData(ctx context.Context, si *session.Info, rw interface{}) (interface{}, i.Outbound, error)

func (*RouterWrapper) UpdateRouter

func (r *RouterWrapper) UpdateRouter(router *Router)

type SessionInfo

type SessionInfo interface {
	// GetInboundTag returns the tag of the inbound the connection was from.
	GetInboundTag() string

	// GetSourcesIPs returns the source IPs bound to the connection.
	GetSourceIPs() net.IP

	// GetSourcePort returns the source port of the connection.
	GetSourcePort() net.Port

	// GetTargetIPs returns the target IP of the connection or resolved IPs of target domain.
	GetTargetIP() net.IP

	// GetTargetPort returns the target port of the connection.
	GetTargetPort() net.Port

	// GetTargetDomain returns the target domain of the connection, if exists.
	GetTargetDomain() string

	// GetNetwork returns the network type of the connection.
	GetNetwork() net.Network

	// GetUser returns the user email from the connection content, if exists.
	GetUser() uuid.UUID

	GetSourceAddr() net.Destination
	GetTargetAddr() net.Destination
	// GetAttributes returns extra attributes from the connection content.
	// GetAttributes() map[string]string
	GetAppId() string
	GetFakeIP() net.IP
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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