Add chain implementation with Add, Create, Delete, Clear, and Rename methods

This commit is contained in:
2026-04-26 16:05:58 +05:00
parent 7dc8436ad8
commit bc00e46865
+44
View File
@@ -0,0 +1,44 @@
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"
nftCommand "git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/pkg/nft"
)
type chain struct {
command contract.CommandRun
}
func New(command contract.CommandRun) nft.Chain {
return &chain{
command: command,
}
}
func (c *chain) Add(family family.Type, tableName string, chainName string, baseChain chain2.ChainOptions) error {
args := nftCommand.ChainAdd(family, tableName, chainName, baseChain)
return c.command.Run(args...)
}
func (c *chain) Create(family family.Type, tableName string, chainName string, baseChain chain2.ChainOptions) error {
args := nftCommand.ChainCreate(family, tableName, chainName, baseChain)
return c.command.Run(args...)
}
func (c *chain) Delete(family family.Type, tableName string, chainName string) error {
args := nftCommand.ChainDelete(family, tableName, chainName)
return c.command.Run(args...)
}
func (c *chain) Clear(family family.Type, tableName string, chainName string) error {
args := nftCommand.ChainClear(family, tableName, chainName)
return c.command.Run(args...)
}
func (c *chain) Rename(family family.Type, tableName string, oldChainName string, newChainName string) error {
args := nftCommand.ChainRename(family, tableName, oldChainName, newChainName)
return c.command.Run(args...)
}