parser

package
v0.0.0-...-670a255 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Check references: https://man.openbsd.org/pf.conf#EXAMPLES

Index

Constants

View Source
const (
	IPv4Expr    = "(" + `\d{1,3}(\.\d{1,3}){3}` + ")"
	IPv6Expr    = "(" + "::::" + ")"
	AddressExpr = "(" + IPv4Expr + "|" + IPv6Expr + ")"
	IPRange     = "(" + AddressExpr + "-" + AddressExpr + ")"
	CIDR        = "(" + AddressExpr + `/\d{1,3})`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Pass  BooleanSet   `parser:"@('pass')"`
	Match BooleanSet   `parser:"| @('match')"`
	Block *ActionBlock `parser:"| @@"`
}

type ActionBlock

type ActionBlock struct {
	Return *string `parser:"'block' @('return' | 'return-icmp' | 'return-icmp6' | 'return-rst' | 'drop')?"`
}

type ActionBlockReturn

type ActionBlockReturn struct {
	Return string `parser:"@('return' | 'drop')"`
}

type Address

type Address struct {
	IP         *Value[IP]   `parser:"@@"`
	UrpfFailed BooleanSet   `parser:"| @('urpf-failed')"`
	Text       *Value[Text] `parser:"| @@"`
}

type AddressFamily

type AddressFamily struct {
	Is4 BooleanSet `parser:"@('inet') | 'inet6'"`
}

type AfTo

type AfTo struct {
	AddressFamily AddressFamily           `parser:"'af-to' @@"`
	From          ValueOrBraceList[Host]  `parser:"'from' @@"`
	To            *ValueOrBraceList[Host] `parser:"('to' @@)?"`
}

type AnchorRule

type AnchorRule struct {
	Name          Value[Text]                   `parser:"'anchor' @@"`
	Direction     *string                       `parser:"@('in' | 'out')?"`
	OnIfSpec      *IfSpec                       `parser:"('on' @@)?"`
	AddressFamily *AddressFamily                `parser:"@@?"`
	ProtoSpec     *ProtoSpec                    `parser:"@@?"`
	Hosts         *Hosts                        `parser:"@@?"`
	FilterOptions *ValueOrRawList[FilterOption] `parser:"@@?"`
	Body          []*Line                       `parser:"'{' EOL (@@ EOL?)* EOL? '}'"`
}

type AntiSpoofRule

type AntiSpoofRule struct {
	Log           *Log           `parser:"'antispoof' @@?"`
	Quick         BooleanSet     `parser:"@('quick')?"`
	IfSpec        IfSpec         `parser:"'for' @@"`
	AddressFamily *AddressFamily `parser:"@@?"`
	Label         *Label         `parser:"@@?"`
}

type Assignment

type Assignment struct {
	Variable string                    `parser:"@Ident"`
	Value    ValueOrBraceList[Literal] `parser:"'=' @@"`
}

type BinAtTo

type BinAtTo struct {
	To       ValueOrBraceList[Host] `parser:"'binat-to' @@"`
	PortSpec *PortSpec              `parser:"@@?"`
	PoolType *PoolType              `parser:"@@?"`
}

type Binary

type Binary struct {
	Lhs      Value[Number] `parser:"@@"`
	Operator string        `parser:"@(':' | '<>' | '><')"`
	Rhs      Value[Number] `parser:"@@"`
}

type BlockPolicyOption

type BlockPolicyOption struct {
	Policy string `parser:"'block-policy' @('drop' | 'return')"`
}

type BooleanSet

type BooleanSet bool

func (*BooleanSet) Capture

func (b *BooleanSet) Capture(values []string) error

type Comment

type Comment string

func (*Comment) Capture

func (c *Comment) Capture(values []string) error

type Configuration

type Configuration struct {
	Line []*Line `parser:"(@@ EOL?)*"`
}

func ParseContent

func ParseContent[T string | ~[]byte](b T) (conf *Configuration, err error)

func ParseReader

func ParseReader(r io.Reader) (conf *Configuration, err error)

type DebugOption

type DebugOption struct {
	Level string `parser:"'debug' @('urgent' | 'emerg' | 'alert' | 'crit' | 'err' | 'warning' | 'notice' | 'info' | 'debug')"`
}

type DivertTo

type DivertTo struct {
	Host Host `parser:"'divert-to' @@"`
	Port Port `parser:"'port' @@"`
}

type FilterOption

type FilterOption struct {
	User             *User            `parser:"@@"`
	Group            *Group           `parser:"| @@"`
	Flags            *Flags           `parser:"| @@"`
	IcmpType         *IcmpType        `parser:"| @@"`
	IcmpType6        *IcmpType6       `parser:"| @@"`
	Tos              *Tos             `parser:"| ('tos' @@)"`
	State            *State           `parser:"| @@"`
	ScrubOption      *ScrubOptions    `parser:"| ('scrub' '(' @@ ')')"`
	Fragment         BooleanSet       `parser:"| @('fragment')"`
	AllowOpts        BooleanSet       `parser:"| @('allow-opts')"`
	Once             BooleanSet       `parser:"| @('once')"`
	DivertPacketPort *Port            `parser:"| ('divert-packet' @@)"`
	DivertReply      BooleanSet       `parser:"| @('divert-reply')"`
	DivertTo         DivertTo         `parser:"| @@"`
	Label            *Label           `parser:"| @@"`
	Tag              *Tag             `parser:"| @@"`
	Tagged           *Tagged          `parser:"| @@"`
	MaxPacketRate    *MaxPacketRate   `parser:"| @@"`
	SetDelay         *Value[Number]   `parser:"| ('set' 'delay' @@)"`
	SetPrio          *[]Value[Number] `parser:"| ('set' 'prio'  (@@ | '(' @@ (',' @@)* ')' ))"`
	SetQueue         *[]Value[Text]   `parser:"| ('set' 'queue' (@@ | '(' @@ (',' @@)* ')' ))"`
	Rtable           *Value[Number]   `parser:"| ('rtable' @@)"`
	Probability      *Value[Number]   `parser:"| ('probability' @@ '%')"`
	Prio             *Value[Number]   `parser:"| ('prio' @@)"`
	AfTo             *AfTo            `parser:"| @@"`
	BinAtTo          *BinAtTo         `parser:"| @@"`
	RdrTo            *RdrTo           `parser:"| @@"`
	NatTo            *NatTo           `parser:"| @@"`
}

type FingerPrintsOption

type FingerPrintsOption struct {
	Filename Value[Text] `parser:"'fingerprints' @@"`
}

type Flags

type Flags struct {
	Left  []string   `parser:"'flags' @Ident?"`
	Right string     `parser:"'/' (@Ident"`
	Any   BooleanSet `parser:"@('any')? )"`
}

type FlushStateOverloadEntry

type FlushStateOverloadEntry struct {
	Global BooleanSet `parser:"'flush' @('global')?"`
}

type Group

type Group struct {
	Selected ValueOrBraceList[Operation] `parser:"'group' @@"`
}

type Host

type Host struct {
	Negate   BooleanSet     `parser:"@('!')?"`
	Address  *Address       `parser:"( ( @@"`
	Weight   *Value[Number] `parser:"('weight' @@)? )"`
	AsString *Value[Text]   `parser:"| ('<' @@ '>') )"`
}

type HostFrom

type HostFrom struct {
	FirstPort *HostFromFirstPort             `parser:"@@"`
	FirstOs   *HostFromFirstOs               `parser:"| @@"`
	Target    *ValueOrBraceList[HostsTarget] `parser:"| ('from' @@"`
	Port      *Port                          `parser:"@@?"`
	Os        *Os                            `parser:"@@? )"`
}

type HostFromFirstOs

type HostFromFirstOs struct {
	Os *Os `parser:"'from' @@"`
}

type HostFromFirstPort

type HostFromFirstPort struct {
	Port *Port `parser:"'from' @@"`
	Os   *Os   `parser:"@@?"`
}

type HostTo

type HostTo struct {
	OnlyPort *Port                          `parser:"  ('to' @@)"`
	Target   *ValueOrBraceList[HostsTarget] `parser:"| ('to' @@"`
	Port     *Port                          `parser:"@@?)"`
}

type Hosts

type Hosts struct {
	All         BooleanSet     `parser:"@('all')"`
	HostsFromTo []*HostsFromTo `parser:"| @@+"`
}

type HostsFromTo

type HostsFromTo struct {
	From *HostFrom `parser:"@@"`
	To   *HostTo   `parser:"| @@"`
}

type HostsTarget

type HostsTarget struct {
	Any     BooleanSet   `parser:"( @('any')"`
	NoRoute BooleanSet   `parser:"| @('no-route')"`
	Self    BooleanSet   `parser:"| @('self')"`
	Route   *Value[Text] `parser:"| ('route' @@)"`
	Host    *Host        `parser:"| @@ )"`
}

type IP

type IP struct {
	Mask    *netipx.IPRange `parser:"@IPRange"`
	CIDR    *netip.Prefix   `parser:"| @CIDR"`
	Address *netip.Addr     `parser:"| @Address"`
}

type IcmpCode

type IcmpCode struct {
	Name         *Value[Text]   `parser:"( @@"`
	Number       *Value[Number] `parser:"| @@)"`
	CodeAsName   *Value[Text]   `parser:"( 'code' (@@"`
	CodeAsNumber *Value[Number] `parser:"| @@) )?"`
}

type IcmpType

type IcmpType struct {
	Codes ValueOrBraceList[IcmpCode] `parser:"'icmp-type' @@"`
}

type IcmpType6

type IcmpType6 struct {
	Codes ValueOrBraceList[IcmpCode] `parser:"'icmp6-type' @@"`
}

type IfSpecEntry

type IfSpecEntry struct {
	Negate                    BooleanSet  `parser:"'!'?"`
	InterfaceOrInterfaceGroup Value[Text] `parser:"@@"`
}

type Label

type Label struct {
	Text Value[Text] `parser:"'label' @@"`
}

type LimitItem

type LimitItem struct {
	Variable string        `parser:"@('states' | 'frags' | 'src-nodes' | 'tables' | 'table-entries')"`
	Value    Value[Number] `parser:"@@"`
}

type LimitOption

type LimitOption struct {
	Limit ValueOrBraceList[LimitItem] `parser:"'limit' @@"`
}

type Line

type Line struct {
	Option        *Option        `parser:"@@"`
	PfRule        *PfRule        `parser:"| @@"`
	Comment       *Comment       `parser:"| @Comment"`
	AntiSpoofRule *AntiSpoofRule `parser:"| @@"`
	Assignment    *Assignment    `parser:"| @@"`
	// QueueRule *QueueRule     `parser:"| @@"`
	AnchorRule *AnchorRule `parser:"| @@"`
	// LoadAnchor *LoadAnchor    `parser:"| @@"`
	TableRule *TableRule `parser:"| @@"`
}

type Literal

type Literal struct {
	Address Address       `parser:"@@"`
	String  Value[Text]   `parser:"| @@"`
	Number  Value[Number] `parser:"| @@"`
}

type Log

type Log struct {
	Options *ValueOrRawList[LogOption] `parser:"'log' ('(' @@ ')')?"`
}

type LogOption

type LogOption struct {
	All     BooleanSet   `parser:"@('all')"`
	Matches BooleanSet   `parser:"| @('matches')"`
	User    BooleanSet   `parser:"| @('user')"`
	To      *Value[Text] `parser:"| ('to' @@)"`
}

type LoginInterfaceOption

type LoginInterfaceOption struct {
	None      BooleanSet  `parser:"'logininterface' ( @('none')"`
	Interface Value[Text] `parser:"| @@)"`
}

type MaxPacketRate

type MaxPacketRate struct {
	Packets Value[Number]  `parser:"'max-pkt-rate' @@"`
	Seconds *Value[Number] `parser:"('/' @@)?"`
}

type MaxSrcConnRage

type MaxSrcConnRage struct {
	Packets Value[Number] `parser:"'max-src-conn-rate' @@"`
	Seconds Value[Number] `parser:"'/' @@"`
}

type NatTo

type NatTo struct {
	Host       ValueOrBraceList[Host] `parser:"'nat-to' @@"`
	PortSpec   *PortSpec              `parser:"@@?"`
	PoolType   *PoolType              `parser:"@@?"`
	StaticPort BooleanSet             `parser:"@('static-port')?"`
}

type Number

type Number struct {
	Value int `parser:"@Number"`
}

type Operation

type Operation struct {
	Binary *Binary `parser:"@@"`
	Unary  *Unary  `parser:"| @@"`
}

type OptimizatioOption

type OptimizatioOption struct {
	Value string `parser:"'optimization' @('default' | 'normal' | 'high-latency' | 'satellite' | 'aggressive' | 'convervative')"`
}

type Option

type Option struct {
	Timeout             *TimeoutOption             `parser:"'set' (@@"`
	RulesetOptimization *RulesetOptimizationOption `parser:"| @@"`
	Optimizatio         *OptimizatioOption         `parser:"| @@"`
	Limit               *LimitOption               `parser:"| @@"`
	BlockPolicy         *BlockPolicyOption         `parser:"| @@"`
	StatePolicy         *StatePolicyOption         `parser:"| @@"`
	StateDefaults       *StateDefaultsOption       `parser:"| @@"`
	FingerPrints        *FingerPrintsOption        `parser:"| @@"`
	SkipOn              *SkipOnOption              `parser:"| @@"`
	Debug               *DebugOption               `parser:"| @@"`
	Reassemble          *ReassembleOption          `parser:"| @@"`
	Other               *OtherOption               `parser:"| @@)"`
}

type Os

type Os struct {
	Selected ValueOrBraceList[Value[Text]] `parser:"'os' @@"`
}

type OtherOption

type OtherOption struct {
	Key   string         `parser:"@Ident"`
	Value Value[Literal] `parser:"@@"`
}

type Parentheses

type Parentheses[T any] struct {
	Value T `parser:"('(' @@ ')') | @@"`
}

type PfRule

type PfRule struct {
	Action        Action                        `parser:"@@"`
	Options       []*PfRuleOption               `parser:"@@*"`
	Hosts         *Hosts                        `parser:"@@?"`
	FilterOptions *ValueOrRawList[FilterOption] `parser:"@@?"`
}

type PfRuleOn

type PfRuleOn struct {
	IfSpec  *IfSpec        `parser:"'on' ( @@"`
	Rdomain *Value[Number] `parser:"| ('rdomain' @@))"`
}

type PfRuleOption

type PfRuleOption struct {
	Direction     *string        `parser:"@('in' | 'out')"`
	Log           *Log           `parser:"| @@"`
	Quick         BooleanSet     `parser:"| @('quick')"`
	On            *PfRuleOn      `parser:"| @@"`
	AddressFamily *AddressFamily `parser:"| @@"`
	ProtoSpec     *ProtoSpec     `parser:"| @@"`
}

type PoolType

type PoolType struct {
	Bitmask       BooleanSet  `parser:"@('bitmask')"`
	LeastStates   BooleanSet  `parser:"| @('least-states')"`
	Random        BooleanSet  `parser:"| @('random')"`
	RoundRobin    BooleanSet  `parser:"| @('round-robin')"`
	SourceHash    *SourceHash `parser:"| @@"`
	StickyAddress BooleanSet  `parser:"| @('sticky-address')"`
}

type Port

type Port struct {
	Ports ValueOrBraceList[Operation] `parser:"'port' @@"`
}

type PortSpec

type PortSpec struct {
	Name             *Value[Text]   `parser:"'port' ( @@"`
	Number           *Value[Number] `parser:"| @@ )"`
	RangedToWildcard BooleanSet     `parser:"(':' ( @('*')"`
	RangedToNumber   *Value[Number] `parser:"| @@"`
	RangedToName     *Value[Text]   `parser:"| @@ ))?"`
}

type ProtoSpec

type ProtoSpec struct {
	Protocol ValueOrBraceList[Protocol] `parser:"'proto' @@"`
}

type Protocol

type Protocol struct {
	Name   *Value[Text]   `parser:"@@"`
	Number *Value[Number] `parser:"| @@"`
}

type RdrTo

type RdrTo struct {
	Host     ValueOrBraceList[Host] `parser:"'rdr-to' @@"`
	PortSpec *PortSpec              `parser:"@@?"`
	PoolType *PoolType              `parser:"@@?"`
}

type ReassembleOption

type ReassembleOption struct {
	Reassemble BooleanSet `parser:"'reassemble' (@('yes') | 'no')"`
	NoDf       BooleanSet `parser:"@('no-df')?"`
}

type RulesetOptimizationOption

type RulesetOptimizationOption struct {
	Value string `parser:"'ruleset-optimization' @('none' | 'basic' | 'profile')"`
}

type ScrubOption

type ScrubOption struct {
	NoDf          BooleanSet     `parser:"@('no-df')"`
	MinTtl        *Value[Number] `parser:"| ('min-ttl' @@)"`
	MaxMss        *Value[Number] `parser:"| ('max-mss' @@)"`
	ReassembleTcp BooleanSet     `parser:"| @('reassemble' 'tcp')"`
	RandomId      BooleanSet     `parser:"| @('random-id')"`
}

type ScrubOptions

type ScrubOptions struct {
	Options ValueOrRawList[ScrubOption] `parser:"@@"`
}

type SkipOnOption

type SkipOnOption struct {
	IfSpec IfSpec `parser:"'skip' 'on' @@"`
}

type SourceHash

type SourceHash struct {
	Value *Value[Text] `parser:"'source-hash' @@?"`
}

type State

type State struct {
	Mode    *string                      `parser:"@('no' | 'keep' | 'modulate' | 'synproxy') 'state'"`
	Options *ValueOrRawList[StateOption] `parser:"('(' @@ ')')?"`
}

type StateDefaultsOption

type StateDefaultsOption struct {
	Defaults ValueOrRawList[StateOption] `parser:"'state-defaults' @@"`
}

type StateOption

type StateOption struct {
	Max            *Value[Number]      `parser:"('max' @@)"`
	NoSync         BooleanSet          `parser:"| @('no-sync')"`
	Timeout        *Timeout            `parser:"| @@"`
	Sloppy         BooleanSet          `parser:"| @('sloppy')"`
	Pflow          BooleanSet          `parser:"| @('pflow')"`
	SourceTrack    string              `parser:"| ('source-track' @('rule' | 'global'))"`
	MaxSrcNodes    *Value[Number]      `parser:"| ('max-src-nodes' @@)"`
	MaxSrcStates   *Value[Number]      `parser:"| ('max-src-states' @@)"`
	MaxSrcConn     *Value[Number]      `parser:"| ('max-src-conn' @@)"`
	MaxSrcConnRate *MaxSrcConnRage     `parser:"| @@"`
	Overload       *StateOverloadEntry `parser:"| @@"`
	IfFloating     BooleanSet          `parser:"| @('if-floating')"`
	Floating       BooleanSet          `parser:"| @('floating')"`
}

type StateOverloadEntry

type StateOverloadEntry struct {
	Value Value[Text]              `parser:"'overload' '<' @@ '>'"`
	Flush *FlushStateOverloadEntry `parser:"@@?"`
}

type StatePolicyOption

type StatePolicyOption struct {
	Policy string `parser:"'state-policy' @('if-bound' | 'floating')"`
}

type String

type String struct {
	Value string `parser:"@String"`
}

type TableAddress

type TableAddress struct {
	Hostname *string       `parser:"@Hostname"`
	IfSpec   *IfSpec       `parser:"| @@"`
	Self     BooleanSet    `parser:"| @('self')"`
	Prefix   *netip.Prefix `parser:"| @CIDR"`
	Address  *netip.Addr   `parser:"| @Address"`
}

type TableAddressSpec

type TableAddressSpec struct {
	Negate BooleanSet   `parser:"@('!')?"`
	Target TableAddress `parser:"@@"`
}

type TableOption

type TableOption struct {
	Persist   BooleanSet                          `parser:"@('persist')"`
	Const     BooleanSet                          `parser:"| @('const')"`
	Counters  BooleanSet                          `parser:"| @('counters')"`
	File      *Value[Text]                        `parser:"| ('file' @@)"`
	Addresses *ValueOrBraceList[TableAddressSpec] `parser:"| @@"`
}

type TableRule

type TableRule struct {
	Name    Value[Text]    `parser:"'table' '<' @@ '>'"`
	Options []*TableOption `parser:"@@+"`
}

type Tag

type Tag struct {
	Text Value[Text] `parser:"'tag' @@"`
}

type Tagged

type Tagged struct {
	Negate BooleanSet  `parser:"@('!')?"`
	Text   Value[Text] `parser:"'tagged' @@"`
}

type Text

type Text struct {
	Value string `parser:"@(String | Ident | Hostname | Filename)"`
}

type Timeout

type Timeout struct {
	Variable string        `` /* 321-byte string literal not displayed */
	Value    Value[Number] `parser:"@@"`
}

type TimeoutOption

type TimeoutOption struct {
	Timeout ValueOrBraceList[Timeout] `parser:"'timeout' @@"`
}

type Tos

type Tos struct {
	Selected string `parser:"@('lowdelay' | 'throughput' | 'reliability')"`
	Number   int    `parser:"@Hexnumber"`
}

type Unary

type Unary struct {
	Operator string         `parser:"@('=' | '!=' | '<' | '<=' | '>' | '>=')?"`
	Number   *Value[Number] `parser:"( @@ "`
	Name     *Value[Text]   `parser:"| @@ )"`
}

type User

type User struct {
	Selected ValueOrBraceList[Operation] `parser:"'user' @@"`
}

type Value

type Value[T any] struct {
	Direct      *T        `parser:"@@"`
	Variable    *Variable `parser:"| @@"`
	Parentheses *Value[T] `parser:"| '(' @@ ')'"`
}

type ValueOrBraceList

type ValueOrBraceList[T any] struct {
	Values []Value[T] `parser:"@@ | ('{' @@ (',' @@)* '}')"`
}

type ValueOrRawList

type ValueOrRawList[T any] struct {
	Values []Value[T] `parser:"@@ (','? @@)*"`
}

type Variable

type Variable struct {
	Name string `parser:"@Variable"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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