rule

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2023 License: Apache-2.0 Imports: 4 Imported by: 1

Documentation

Overview

Package rule A library for managing nftables rules

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RuleData

type RuleData struct {
	Exprs []expr.Any
	// we use rule user data to store the ID
	// we do this so we can give each rule a specific id across hosts and etc
	// handles are less deterministic without setting them explicitly and lack context (only ints)
	ID       []byte
	Handle   uint64
	Position uint64
}

RuleData is a struct that is used to create rules in a given table and chain

func NewData

func NewData(id []byte, exprs []expr.Any, handleAndPosition ...uint64) RuleData

Create a new RuleData from an ID and list of nftables expressions

func (RuleData) ToRule

func (r RuleData) ToRule(table *nftables.Table, chain *nftables.Chain) nftables.Rule

type RuleTarget

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

RuleTarget represents a location to manipulate nftables rules

func New

func New(table *nftables.Table, chain *nftables.Chain) RuleTarget

Create a new location to manipulate nftables rules

func (*RuleTarget) Add

func (r *RuleTarget) Add(c *nftables.Conn, ruleData RuleData) (bool, error)

Add a rule with a given ID to a specific table and chain, returns true if the rule was added

func (*RuleTarget) Delete

func (r *RuleTarget) Delete(c *nftables.Conn, ruleData RuleData) (bool, error)

Delete a rule with a given ID from a specific table and chain, returns true if the rule was deleted

func (*RuleTarget) Exists

func (r *RuleTarget) Exists(c *nftables.Conn, ruleData RuleData) (bool, error)

Determine if a rule with a given ID exists in a specific table and chain

func (*RuleTarget) FindRuleByID

func (r *RuleTarget) FindRuleByID(c *nftables.Conn, ruleData RuleData) (*nftables.Rule, error)

func (*RuleTarget) GetTableAndChain

func (r *RuleTarget) GetTableAndChain() (*nftables.Table, *nftables.Chain)

Get the nftables table and chain associated with this RuleTarget

func (*RuleTarget) Insert

func (r *RuleTarget) Insert(c *nftables.Conn, ruleData RuleData) (bool, error)

func (*RuleTarget) List

func (r *RuleTarget) List(c *nftables.Conn) ([]*nftables.Rule, error)

func (*RuleTarget) Update

func (r *RuleTarget) Update(c *nftables.Conn, ruleData RuleData) (bool, error)

func (*RuleTarget) UpdateAll

func (r *RuleTarget) UpdateAll(c *nftables.Conn, rules []RuleData) (bool, int, int, error)

Compare existing and incoming rule IDs adding/removing the difference

First return value is true if the number of rules has changed, false if there were no updates. The second and third return values indicate the number of rules added or removed, respectively.

Jump to

Keyboard shortcuts

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