filter

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Copyright (c) 2025 Tobias Schäfer. All rights reserved. Licensed under the MIT License, see LICENSE file in the project root for details.

Copyright (c) 2025 Tobias Schäfer. All rights reserved. Licensed under the MIT License, see LICENSE file in the project root for details.

Copyright (c) 2025 Tobias Schäfer. All rights reserved. Licensed under the MIT License, see LICENSE file in the project root for details.

Copyright (c) 2025 Tobias Schäfer. All rights reserved. Licensed under the MIT License, see LICENSE file in the project root for details.

Copyright (c) 2025 Tobias Schäfer. All rights reserved. Licensed under the MIT License, see LICENSE file in the project root for details.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action added in v1.0.0

type Action int

Action represents the action to take when a rule matches

const (
	ActionLog Action = iota
	ActionDrop
)

func (Action) String added in v1.0.0

func (a Action) String() string

type AddressPredicate added in v1.0.0

type AddressPredicate struct {
	Direction string   // source, destination
	Addresses []string // IP addresses or CIDR
	Ports     []uint16 // optional ports
}

AddressPredicate matches IP addresses or CIDR ranges

type AnyPredicate added in v1.0.0

type AnyPredicate struct{}

AnyPredicate matches any event (catch-all)

type BinaryExpr added in v1.0.0

type BinaryExpr struct {
	Op    BinaryOp
	Left  ExprNode
	Right ExprNode
}

BinaryExpr represents a binary expression (AND, OR)

type BinaryOp added in v1.0.0

type BinaryOp int
const (
	OpAnd BinaryOp = iota
	OpOr
)

type CompiledRule added in v1.0.0

type CompiledRule struct {
	Rule      *Rule
	Predicate PredicateFunc
	RuleText  string
}

CompiledRule represents a parsed and compiled filter rule

type ExprNode added in v1.0.0

type ExprNode interface {
	// contains filtered or unexported methods
}

ExprNode represents a node in the expression AST

type Filter

type Filter struct {
	Rules []CompiledRule
}

Filter represents a compiled set of filter rules

func NewFilter added in v1.0.0

func NewFilter(ruleStrings []string) (*Filter, error)

NewFilter creates a new DSL-based filter from rule strings

func (*Filter) Evaluate added in v1.0.0

func (f *Filter) Evaluate(event conntrack.Event) (bool, bool, int)

Evaluate evaluates the filter against an event Returns: (matched bool, shouldLog bool, matchedRuleIndex int) If no rule matches, returns (false, true, -1) for log-by-default policy

type Lexer added in v1.0.0

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

func NewLexer added in v1.0.0

func NewLexer(input string) *Lexer

func (*Lexer) NextToken added in v1.0.0

func (l *Lexer) NextToken() (Token, error)

type NetworkPredicate added in v1.0.0

type NetworkPredicate struct {
	Direction string   // source, destination
	Networks  []string // LOCAL, PRIVATE, PUBLIC, MULTICAST
}

NetworkPredicate matches network types

type Parser added in v1.0.0

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

func NewParser added in v1.0.0

func NewParser(input string) (*Parser, error)

func (*Parser) ParseRule added in v1.0.0

func (p *Parser) ParseRule() (*Rule, error)

ParseRule parses a complete rule: action expression

type PortPredicate added in v1.0.0

type PortPredicate struct {
	Direction string   // source, destination
	Ports     []uint16 // port numbers or ranges
}

PortPredicate matches ports

type Predicate added in v1.0.0

type Predicate interface {
	ExprNode
	// contains filtered or unexported methods
}

Predicate represents a base predicate

type PredicateFunc added in v1.0.0

type PredicateFunc func(event conntrack.Event) bool

PredicateFunc is a function that evaluates a predicate against an event

func Compile added in v1.0.0

func Compile(expr ExprNode) (PredicateFunc, error)

Compile compiles an expression AST into a predicate function

type ProtocolPredicate added in v1.0.0

type ProtocolPredicate struct {
	Protocols []string // TCP, UDP
}

ProtocolPredicate matches protocols

type Rule added in v1.0.0

type Rule struct {
	Action Action
	Expr   ExprNode
}

Rule represents a complete filter rule

type Token added in v1.0.0

type Token struct {
	Type  TokenType
	Value string
	Pos   int
}

type TokenType added in v1.0.0

type TokenType int
const (
	TokenEOF TokenType = iota
	TokenIdent
	TokenNumber
	TokenComma
	TokenDash
	TokenSlash
	TokenColon
	TokenDot
	TokenLParen
	TokenRParen
	TokenAnd
	TokenOr
	TokenNot
	TokenLog
	TokenDrop
	TokenEventType
	TokenProtocol
	TokenSource
	TokenDestination
	TokenAddress
	TokenNetwork
	TokenPort
	TokenOn
	TokenAny
)

type TypePredicate added in v1.0.0

type TypePredicate struct {
	Types []string // NEW, UPDATE, DESTROY
}

TypePredicate matches event types

type UnaryExpr added in v1.0.0

type UnaryExpr struct {
	Op   UnaryOp
	Expr ExprNode
}

UnaryExpr represents a unary expression (NOT)

type UnaryOp added in v1.0.0

type UnaryOp int
const (
	OpNot UnaryOp = iota
)

Jump to

Keyboard shortcuts

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