filter

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2026 License: MIT Imports: 16 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_ASPATH_LEN              // AS_PATH length
	ATTR_ASPATH_HOPS             // AS_PATH unique hop count (ignore prepending)
	ATTR_NEXTHOP                 // NEXT_HOP attribute
	ATTR_ORIGIN                  // ORIGIN attribute (IGP/EGP/INCOMPLETE)
	ATTR_MED                     // MULTI_EXIT_DISC attribute
	ATTR_LOCALPREF               // LOCAL_PREF attribute
	ATTR_COMM                    // COMMUNITY attribute
	ATTR_COMM_EXT                // EXTENDED_COMMUNITY attribute
	ATTR_COMM_LARGE              // LARGE_COMMUNITY attribute
	ATTR_OTC                     // OTC attribute (Only To Customer, RFC 9234)
	ATTR_DIR                     // message direction (L/R)
	ATTR_SEQ                     // message sequence number
	ATTR_TIME                    // message timestamp
	ATTR_JSON                    // generic JSON path extractor
	ATTR_JATTR                   // attribute-specific JSON extractor
)

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

ClearCache 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) Set added in v0.17.1

func (ev *Eval) Set(m *msg.Msg, kv *xsync.Map[string, any], caps caps.Caps, tags map[string]string) *Eval

Set sets the Msg and Pipe context together, for convenience.

func (*Eval) SetMsg

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

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) *Eval

SetPipe sets the optional, read-only Pipe context, in a way that 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_PRESENT Op = iota // attribute exists? (no value)
	OP_EQ                // ==
	OP_LT                // <
	OP_LE                // <=
	OP_GT                // >
	OP_GE                // >=
	OP_LIKE              // ~ (match)
)

type Res added in v0.18.0

type Res = int8
const (
	RES_FALSE  Res = -1 // evaluated to false
	RES_ABSENT Res = 0  // referenced attribute not found
	RES_TRUE   Res = 1  // evaluated to true
)

Jump to

Keyboard shortcuts

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