filter

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrEmpty     = fmt.Errorf("empty filter")
	ErrExpr      = fmt.Errorf("invalid expression")
	ErrUnmatched = fmt.Errorf("unmatched parentheses")
	ErrAttr      = fmt.Errorf("invalid attribute")
	ErrIndex     = fmt.Errorf("invalid index")
	ErrOp        = fmt.Errorf("invalid operator")
	ErrValue     = fmt.Errorf("invalid value")
	ErrOpValue   = fmt.Errorf("operator needs value")
	ErrLogic     = fmt.Errorf("expecting logical operator")
)

Functions

This section is empty.

Types

type Attr

type Attr = int
const (
	ATTR_EXPR       Attr = iota // sub-expression in value (nested)
	ATTR_TAG                    // message tag (from pipe context)
	ATTR_TYPE                   // BGP message type
	ATTR_AF                     // address family / subsequent address family
	ATTR_REACH                  // reachable prefixes
	ATTR_UNREACH                // unreachable prefixes
	ATTR_PREFIX                 // prefix, either reachable or unreachable
	ATTR_ASPATH                 // AS_PATH attribute
	ATTR_NEXTHOP                // NEXT_HOP attribute
	ATTR_COMM                   // COMMUNITY attribute
	ATTR_COMM_EXT               // EXTENDED_COMMUNITY attribute
	ATTR_COMM_LARGE             // LARGE_COMMUNITY attribute
)

type Eval

type Eval struct {
	Msg *msg.Msg // message being evaluated

	PipeKV   *xsync.Map[string, any] // pipe key-value store (can be nil)
	PipeCaps caps.Caps               // pipe capabilities (can be nil)
	PipeTags map[string]string       // pipe message tags (can be nil)
	// contains filtered or unexported fields
}

Eval efficiently evaluates Filters against a given Msg.

func NewEval

func NewEval(use_cache bool) *Eval

NewEval creates a new Eval instance. The SetMsg method must be called before use.

func (*Eval) ClearCache

func (ev *Eval) ClearCache()

Clear resets the cache to match the current Msg version.

func (*Eval) Run

func (ev *Eval) Run(f *Filter) (result bool)

Run evaluates given Filter f against the current message.

func (*Eval) SetMsg

func (ev *Eval) SetMsg(m *msg.Msg)

SetMsg sets the Msg to be evaluated, and clears the Pipe context. It must be called before using the Run method.

func (*Eval) SetPipe

func (ev *Eval) SetPipe(kv *xsync.Map[string, any], caps caps.Caps, tags map[string]string)

SetPipe sets the optional, read-only Pipe context, in a way that hopefully avoids a cyclic import vs. the pipe package.

type Expr

type Expr struct {
	Filter *Filter // root filter, must be non-nil
	String string  // raw expression string
	Types  bool    // allow message types other than UPDATE?

	Not  bool  // negate the final result of this expression?
	And  bool  // apply logical AND with the next expression? (if false, apply OR)
	Next *Expr // next expression (nil means last)

	Attr Attr // attribute
	Idx  any  // index inside the attribute (eg. int(0) if aspath[0])
	Op   Op   // operator
	Val  any  // value to use (string, int, regexp, etc OR *Expr if nested)
}

Expr represents an expression like <attribute> <operator> <value>, optionally linked with the next expression using a logical AND or OR.

type Filter

type Filter struct {
	// raw filter string, eg:
	// !(UPDATE && (origin == 39282 || aspath[0] < 1000) && com ~ "11:22")
	String string

	// the first parsed expression in the filter
	First *Expr
}

Filter represents a BGP message filter, compiled from a string representation.

func NewFilter

func NewFilter(filter string) (*Filter, error)

type Op

type Op = int
const (
	OP_TRUE Op = iota // is true? (no value)
	OP_EQ             // ==
	OP_LT             // <
	OP_LE             // <=
	OP_GT             // >
	OP_GE             // >=
	OP_LIKE           // ~ (match)
)

Jump to

Keyboard shortcuts

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