Documentation
¶
Index ¶
- Constants
- Variables
- func AddJumpRule(fromChainName, toChainName, tableName string) error
- func AddRules(rules *Rules) error
- func ConfigureFirewall(oldInterface, newInterface, bridgeName string) error
- func CreateStandardFilterTable(conn *nftables.Conn) error
- func CreateStandardNATTable(conn *nftables.Conn) error
- func CreateTableFromConfig(conn *nftables.Conn, config TableConfig) error
- func EnsureStandardFirewallInfrastructure(conn *nftables.Conn) error
- func NewChain(opts ...Option) (*nftables.Chain, *nftables.Table, error)
- func RemoveRules(rules *Rules) error
- type ChainConfig
- type NewRule
- func ForwardOutboundRule(chainName, tableName, hostIf, internalIf string) NewRule
- func ForwardReturnTrafficRule(chainName, tableName, hostIf, internalIf string) NewRule
- func MasqueradeRule(chainName, tableName, interfaceName string) NewRule
- func PortRule(port uint16, proto, chainName, tableName string) NewRule
- func ReverseMasqueradeRule(chainName, tableName, hostLink string, vmSubnet *net.IPNet) NewRule
- type Option
- func Create() Option
- func WithChainType(chainType nftables.ChainType) Option
- func WithHook(hook *nftables.ChainHook) Option
- func WithName(chainName string) Option
- func WithPolicy(policy *nftables.ChainPolicy) Option
- func WithPriority(priority *nftables.ChainPriority) Option
- func WithinTable(tableName string) Option
- type Rules
- type TableConfig
Constants ¶
const ( FilterTable = "filter" NATTable = "nat" InputChain = "INPUT" ForwardChain = "FORWARD" OutputChain = "OUTPUT" PreroutingChain = "PREROUTING" PostRoutingChain = "POSTROUTING" )
Variables ¶
var ( StandardFilterTable = TableConfig{ Name: FilterTable, Family: nftables.TableFamilyINet, Chains: []ChainConfig{ { Name: InputChain, Table: FilterTable, Create: true, Type: &[]nftables.ChainType{nftables.ChainTypeFilter}[0], Hook: nftables.ChainHookInput, Priority: nftables.ChainPriorityFilter, Policy: getChainPolicyAccept(), }, { Name: ForwardChain, Table: FilterTable, Create: true, Type: &[]nftables.ChainType{nftables.ChainTypeFilter}[0], Hook: nftables.ChainHookForward, Priority: nftables.ChainPriorityFilter, Policy: getChainPolicyAccept(), }, { Name: OutputChain, Table: FilterTable, Create: true, Type: &[]nftables.ChainType{nftables.ChainTypeFilter}[0], Hook: nftables.ChainHookOutput, Priority: nftables.ChainPriorityFilter, Policy: getChainPolicyAccept(), }, }, } StandardNATTable = TableConfig{ Name: NATTable, Family: nftables.TableFamilyIPv4, Chains: []ChainConfig{ { Name: PreroutingChain, Table: NATTable, Create: true, Type: &[]nftables.ChainType{nftables.ChainTypeNAT}[0], Hook: nftables.ChainHookPrerouting, Priority: nftables.ChainPriorityNATDest, Policy: getChainPolicyAccept(), }, { Name: PostRoutingChain, Table: NATTable, Create: true, Type: &[]nftables.ChainType{nftables.ChainTypeNAT}[0], Hook: nftables.ChainHookPostrouting, Priority: nftables.ChainPriorityNATSource, Policy: getChainPolicyAccept(), }, }, } )
Predefined standard table configurations
Functions ¶
func AddJumpRule ¶
func ConfigureFirewall ¶
func CreateStandardFilterTable ¶
CreateStandardFilterTable creates the standard filter table with INPUT, FORWARD, OUTPUT chains
func CreateStandardNATTable ¶
CreateStandardNATTable creates the standard NAT table with PREROUTING, POSTROUTING chains
func CreateTableFromConfig ¶
func CreateTableFromConfig(conn *nftables.Conn, config TableConfig) error
CreateTableFromConfig creates a table and its chains based on the provided configuration
func EnsureStandardFirewallInfrastructure ¶
EnsureStandardFirewallInfrastructure creates both filter and NAT tables
func RemoveRules ¶
Types ¶
type ChainConfig ¶
type NewRule ¶
func ForwardOutboundRule ¶
func MasqueradeRule ¶
func ReverseMasqueradeRule ¶
ReverseMasqueradeRule SNATs incoming connections to the VM so that the VM sees this host (hostLink's IP) as the source instead of the real external caller. The VM can always reply to its directly attached gateway; it usually can't reply to an arbitrary external IP because it has no route for it. The original source is restored by conntrack on the way back out.
vmSubnet excludes VM-originated traffic so it falls through to the outbound MasqueradeRule on the uplink instead of being SNAT'd here.
type Option ¶
type Option func(*ChainConfig)
func WithChainType ¶
func WithPolicy ¶
func WithPolicy(policy *nftables.ChainPolicy) Option
func WithPriority ¶
func WithPriority(priority *nftables.ChainPriority) Option
func WithinTable ¶
type TableConfig ¶
type TableConfig struct {
Name string
Family nftables.TableFamily
Chains []ChainConfig // Now using the unified ChainConfig
}
TableConfig defines the configuration for a complete table