routerule

package
v0.0.0-...-21cfbab Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2023 License: Apache-2.0, Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	GetFailed     = errors.New("netlink get operation failed")
	ConnectFailed = errors.New("connect to netlink failed")
	ListFailed    = errors.New("netlink list operation failed")
	UpdateFailed  = errors.New("netlink update operation failed")

	TableIndexFailed = errors.New("no table index specified")
)

Functions

func RulesMatchSrcFWMark

func RulesMatchSrcFWMark(r, p *Rule) bool

func RulesMatchSrcFWMarkTable

func RulesMatchSrcFWMarkTable(r, p *Rule) bool

Types

type HandleIface

type HandleIface interface {
	SetSocketTimeout(to time.Duration) error
	RuleList(family int) ([]netlink.Rule, error)
	RuleAdd(rule *netlink.Rule) error
	RuleDel(rule *netlink.Rule) error
	Delete()
}

type RouteRules

type RouteRules struct {
	IPVersion int
	// contains filtered or unexported fields
}

RouteRules represents set of routing rules with same ip family. The target of those rules are set of routing tables.

func New

func New(
	ipVersion int,
	tableIndexSet set.Set[int],
	updateFunc RulesMatchFunc,
	removeFunc RulesMatchFunc,
	netlinkTimeout time.Duration,
	newNetlinkHandle func() (HandleIface, error),
	opRecorder logutils.OpRecorder,
) (*RouteRules, error)

func (*RouteRules) Apply

func (r *RouteRules) Apply() error

func (*RouteRules) PrintCurrentRules

func (r *RouteRules) PrintCurrentRules()

func (*RouteRules) QueueResync

func (r *RouteRules) QueueResync()

func (*RouteRules) RemoveRule

func (r *RouteRules) RemoveRule(rule *Rule)

Remove a Rule. Do nothing if Rule not exists depends based on matchForRemove function.

func (*RouteRules) SetRule

func (r *RouteRules) SetRule(rule *Rule)

Set a Rule. Add to activeRules if it does not already exist based on matchForUpdate function.

type Rule

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

Rule is a wrapper structure around netlink rule. Currently it supports FWMark, Source match and table action.

func FromNetlinkRule

func FromNetlinkRule(nlRule *netlink.Rule) *Rule

func NewRule

func NewRule(ipVersion, priority int) *Rule

func (*Rule) Copy

func (r *Rule) Copy() *Rule

func (*Rule) GoToTable

func (r *Rule) GoToTable(index int) *Rule

func (*Rule) LogCxt

func (r *Rule) LogCxt() *log.Entry

func (*Rule) MatchFWMark

func (r *Rule) MatchFWMark(fwmark uint32) *Rule

func (*Rule) MatchFWMarkWithMask

func (r *Rule) MatchFWMarkWithMask(fwmark, mask uint32) *Rule

func (*Rule) MatchSrcAddress

func (r *Rule) MatchSrcAddress(ip net.IPNet) *Rule

func (*Rule) NetLinkRule

func (r *Rule) NetLinkRule() *netlink.Rule

func (*Rule) Not

func (r *Rule) Not() *Rule

type RulesMatchFunc

type RulesMatchFunc func(r, p *Rule) bool

Functions to check if two rules has same matching condition (and table index to go to).

Jump to

Keyboard shortcuts

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