Refactor to consolidate APIs into contract package and introduce NFT interface for better modularity and maintainability.
This commit is contained in:
+4
-43
@@ -2,55 +2,16 @@ package chain
|
||||
|
||||
import (
|
||||
chain2 "git.kor-elf.net/kor-elf-shield/go-nftables-client/chain"
|
||||
"git.kor-elf.net/kor-elf-shield/go-nftables-client/contract"
|
||||
"git.kor-elf.net/kor-elf-shield/go-nftables-client/contract/nft"
|
||||
"git.kor-elf.net/kor-elf-shield/go-nftables-client/family"
|
||||
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/command"
|
||||
)
|
||||
|
||||
// API for working with chains.
|
||||
type API interface {
|
||||
// Add adds a new chain.
|
||||
//
|
||||
// This command is equivalent to:
|
||||
// nft add chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name}
|
||||
// nft add chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type (filter|route|nat) hook (ingress|prerouting|forward|input|output|postrouting|egress) priority (priority_value = int32) ;}'
|
||||
// nft add chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type filter hook (forward|input|output) priority (priority_value = int32) ; policy (accept|drop) ;}'
|
||||
// nft add chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type (filter|route|nat) hook (ingress|egress) device {device} priority (priority_value = int32) ;}'
|
||||
Add(family family.Type, tableName string, chainName string, baseChain chain2.ChainOptions) error
|
||||
|
||||
// Create creates a new chain.
|
||||
// Similar to the Add, but returns an error if the chain already exists.
|
||||
//
|
||||
// This command is equivalent to:
|
||||
// nft create chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name}
|
||||
// nft create chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type (filter|route|nat) hook (ingress|prerouting|forward|input|output|postrouting|egress) priority (priority_value = int32) ;}'
|
||||
// nft create chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type filter hook (forward|input|output) priority (priority_value = int32) ; policy (accept|drop) ;}'
|
||||
// nft create chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name} '{ type (filter|route|nat) hook (ingress|egress) device {device} priority (priority_value = int32) ;}'
|
||||
Create(family family.Type, tableName string, chainName string, baseChain chain2.ChainOptions) error
|
||||
|
||||
// Delete deletes a chain.
|
||||
//
|
||||
// This command is equivalent to:
|
||||
// nft delete chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name}
|
||||
Delete(family family.Type, tableName string, chainName string) error
|
||||
|
||||
// Clear clears all rules in a chain.
|
||||
//
|
||||
// This command is equivalent to:
|
||||
// nft flush chain (ip|ip6|inet|arp|bridge) {table_name} {chain_name}
|
||||
Clear(family family.Type, tableName string, chainName string) error
|
||||
|
||||
// Rename renames a chain.
|
||||
//
|
||||
// This command is equivalent to:
|
||||
// nft rename chain (ip|ip6|inet|arp|bridge) {table_name} {old_chain_name} {new_chain_name}
|
||||
Rename(family family.Type, tableName string, oldChainName string, newChainName string) error
|
||||
}
|
||||
|
||||
type chain struct {
|
||||
command command.NFT
|
||||
command contract.Command
|
||||
}
|
||||
|
||||
func New(command command.NFT) API {
|
||||
func New(command contract.Command) nft.Chain {
|
||||
return &chain{
|
||||
command: command,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user