Documentation ¶
Overview ¶
Package nftables manipulates Linux nftables (the iptables successor).
Index ¶
- Constants
- Variables
- type Chain
- type ChainHook
- type ChainPolicy
- type ChainPriority
- type ChainType
- type Conn
- func (cc *Conn) AddChain(c *Chain) *Chain
- func (cc *Conn) AddObj(o Obj) Obj
- func (cc *Conn) AddRule(r *Rule) *Rule
- func (cc *Conn) AddSet(s *Set, vals []SetElement) error
- func (cc *Conn) AddTable(t *Table) *Table
- func (cc *Conn) DelChain(c *Chain)
- func (cc *Conn) DelRule(r *Rule) error
- func (cc *Conn) DelSet(s *Set)
- func (cc *Conn) DelTable(t *Table)
- func (cc *Conn) Flush() error
- func (cc *Conn) FlushChain(c *Chain)
- func (cc *Conn) FlushRuleset()
- func (cc *Conn) FlushSet(s *Set)
- func (cc *Conn) FlushTable(t *Table)
- func (cc *Conn) GetObj(o Obj) ([]Obj, error)
- func (cc *Conn) GetObjReset(o Obj) ([]Obj, error)
- func (cc *Conn) GetRule(t *Table, c *Chain) ([]*Rule, error)
- func (cc *Conn) GetSetElements(s *Set) ([]SetElement, error)
- func (cc *Conn) GetSets(t *Table) ([]*Set, error)
- func (cc *Conn) InsertRule(r *Rule) *Rule
- func (cc *Conn) ListChains() ([]*Chain, error)
- func (cc *Conn) ListTables() ([]*Table, error)
- func (cc *Conn) ReplaceRule(r *Rule) *Rule
- func (cc *Conn) SetAddElements(s *Set, vals []SetElement) error
- func (cc *Conn) SetDeleteElements(s *Set, vals []SetElement) error
- type CounterObj
- type Obj
- type Rule
- type Set
- type SetDatatype
- type SetElement
- type Table
- type TableFamily
Constants ¶
const SetConcatTypeBits = 6
SetConcatTypeBits defines concatination bits, originally defined in https://git.netfilter.org/iptables/tree/iptables/nft.c?id=26753888720d8e7eb422ae4311348347f5a05cb4#n1002
Variables ¶
var ( TypeInvalid = SetDatatype{Name: "invalid", /* contains filtered or unexported fields */} TypeVerdict = SetDatatype{Name: "verdict", Bytes: 0, /* contains filtered or unexported fields */} TypeInteger = SetDatatype{Name: "integer", Bytes: 4, /* contains filtered or unexported fields */} TypeIPAddr = SetDatatype{Name: "ipv4_addr", Bytes: 4, /* contains filtered or unexported fields */} TypeIP6Addr = SetDatatype{Name: "ipv6_addr", Bytes: 16, /* contains filtered or unexported fields */} TypeEtherAddr = SetDatatype{Name: "ether_addr", Bytes: 6, /* contains filtered or unexported fields */} TypeInetProto = SetDatatype{Name: "inet_proto", Bytes: 1, /* contains filtered or unexported fields */} TypeInetService = SetDatatype{Name: "inet_service", Bytes: 2, /* contains filtered or unexported fields */} TypeMark = SetDatatype{Name: "mark", Bytes: 4, /* contains filtered or unexported fields */} )
NFT datatypes. See: https://git.netfilter.org/nftables/tree/src/datatype.c
Functions ¶
This section is empty.
Types ¶
type Chain ¶
type Chain struct { Name string Table *Table Hooknum ChainHook Priority ChainPriority Type ChainType Policy *ChainPolicy }
A Chain contains Rules. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains
type ChainHook ¶
type ChainHook uint32
ChainHook specifies at which step in packet processing the Chain should be executed. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Base_chain_hooks
const ( ChainHookPrerouting ChainHook = unix.NF_INET_PRE_ROUTING ChainHookInput ChainHook = unix.NF_INET_LOCAL_IN ChainHookForward ChainHook = unix.NF_INET_FORWARD ChainHookOutput ChainHook = unix.NF_INET_LOCAL_OUT ChainHookPostrouting ChainHook = unix.NF_INET_POST_ROUTING ChainHookIngress ChainHook = unix.NF_NETDEV_INGRESS )
Possible ChainHook values.
type ChainPolicy ¶
type ChainPolicy uint32
ChainPolicy defines what this chain default policy will be.
const ( ChainPolicyDrop ChainPolicy = iota ChainPolicyAccept )
Possible ChainPolicy values.
type ChainPriority ¶
type ChainPriority int32
ChainPriority orders the chain relative to Netfilter internal operations. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Base_chain_priority
const ( ChainPriorityFirst ChainPriority = math.MinInt32 ChainPriorityConntrackDefrag ChainPriority = -400 ChainPriorityRaw ChainPriority = -300 ChainPrioritySELinuxFirst ChainPriority = -225 ChainPriorityConntrack ChainPriority = -200 ChainPriorityMangle ChainPriority = -150 ChainPriorityNATDest ChainPriority = -100 ChainPriorityFilter ChainPriority = 0 ChainPrioritySecurity ChainPriority = 50 ChainPriorityNATSource ChainPriority = 100 ChainPrioritySELinuxLast ChainPriority = 225 ChainPriorityConntrackHelper ChainPriority = 300 ChainPriorityConntrackConfirm ChainPriority = math.MaxInt32 ChainPriorityLast ChainPriority = math.MaxInt32 )
Possible ChainPriority values.
type ChainType ¶
type ChainType string
ChainType defines what this chain will be used for. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Base_chain_types
type Conn ¶
type Conn struct { TestDial nltest.Func // for testing only; passed to nltest.Dial NetNS int // Network namespace netlink will interact with. sync.Mutex // contains filtered or unexported fields }
A Conn represents a netlink connection of the nftables family.
All methods return their input, so that variables can be defined from string literals when desired.
Commands are buffered. Flush sends all buffered commands in a single batch.
func (*Conn) AddChain ¶
AddChain adds the specified Chain. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Adding_base_chains
func (*Conn) AddObj ¶
AddObj adds the specified Obj. See also https://wiki.nftables.org/wiki-nftables/index.php/Stateful_objects
func (*Conn) AddSet ¶
func (cc *Conn) AddSet(s *Set, vals []SetElement) error
AddSet adds the specified Set.
func (*Conn) AddTable ¶
AddTable adds the specified Table. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_tables
func (*Conn) DelChain ¶
DelChain deletes the specified Chain. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Deleting_chains
func (*Conn) FlushChain ¶
FlushChain removes all rules within the specified Chain. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_chains#Flushing_chain
func (*Conn) FlushRuleset ¶
func (cc *Conn) FlushRuleset()
FlushRuleset flushes the entire ruleset. See also https://wiki.nftables.org/wiki-nftables/index.php/Operations_at_ruleset_level
func (*Conn) FlushTable ¶
FlushTable removes all rules in all chains within the specified Table. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_tables#Flushing_tables
func (*Conn) GetObjReset ¶
GetObjReset gets the specified Obj and resets it.
func (*Conn) GetSetElements ¶
func (cc *Conn) GetSetElements(s *Set) ([]SetElement, error)
GetSetElements returns the elements in the specified set.
func (*Conn) InsertRule ¶
func (*Conn) ListChains ¶
ListChains returns currently configured chains in the kernel
func (*Conn) ListTables ¶
ListTables returns currently configured tables in the kernel
func (*Conn) ReplaceRule ¶
func (*Conn) SetAddElements ¶
func (cc *Conn) SetAddElements(s *Set, vals []SetElement) error
SetAddElements applies data points to an nftables set.
func (*Conn) SetDeleteElements ¶
func (cc *Conn) SetDeleteElements(s *Set, vals []SetElement) error
SetDeleteElements deletes data points from an nftables set.
type CounterObj ¶
CounterObj implements Obj.
type Obj ¶
type Obj interface {
// contains filtered or unexported methods
}
Obj represents a netfilter stateful object. See also https://wiki.nftables.org/wiki-nftables/index.php/Stateful_objects
type Rule ¶
type Rule struct { Table *Table Chain *Chain Position uint64 Handle uint64 Exprs []expr.Any UserData []byte }
A Rule does something with a packet. See also https://wiki.nftables.org/wiki-nftables/index.php/Simple_rule_management
type Set ¶
type Set struct { Table *Table ID uint32 Name string Anonymous bool Constant bool Interval bool IsMap bool KeyType SetDatatype DataType SetDatatype }
Set represents an nftables set. Anonymous sets are only valid within the context of a single batch.
type SetDatatype ¶
SetDatatype represents a datatype declared by nft.
func (*SetDatatype) GetNFTMagic ¶
func (s *SetDatatype) GetNFTMagic() uint32
GetNFTMagic returns a custom datatype based on user's parameters
func (*SetDatatype) SetNFTMagic ¶
func (s *SetDatatype) SetNFTMagic(nftMagic uint32)
SetNFTMagic returns a custom datatype based on user's parameters
type SetElement ¶
type SetElement struct { Key []byte Val []byte IntervalEnd bool // To support vmap, a caller must be able to pass Verdict type of data. // If IsMap is true and VerdictData is not nil, then Val of SetElement will be ignored // and VerdictData will be wrapped into Attribute data. VerdictData *expr.Verdict }
SetElement represents a data point within a set.
type Table ¶
type Table struct { Name string // NFTA_TABLE_NAME Use uint32 // NFTA_TABLE_USE (Number of chains in table) Flags uint32 // NFTA_TABLE_FLAGS Family TableFamily }
A Table contains Chains. See also https://wiki.nftables.org/wiki-nftables/index.php/Configuring_tables
type TableFamily ¶
type TableFamily byte
TableFamily specifies the address family for this table.
const ( TableFamilyINet TableFamily = unix.NFPROTO_INET TableFamilyIPv4 TableFamily = unix.NFPROTO_IPV4 TableFamilyIPv6 TableFamily = unix.NFPROTO_IPV6 TableFamilyARP TableFamily = unix.NFPROTO_ARP TableFamilyNetdev TableFamily = unix.NFPROTO_NETDEV TableFamilyBridge TableFamily = unix.NFPROTO_BRIDGE )
Possible TableFamily values.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package binaryutil contains convenience wrappers around encoding/binary.
|
Package binaryutil contains convenience wrappers around encoding/binary. |
Package expr provides nftables rule expressions.
|
Package expr provides nftables rule expressions. |