diff --git a/internal/batch/rule/rule.go b/internal/batch/rule/rule.go new file mode 100644 index 0000000..1f7bd98 --- /dev/null +++ b/internal/batch/rule/rule.go @@ -0,0 +1,38 @@ +package rule + +import ( + "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 rule struct { + command contract.CommandRun +} + +func New(command contract.CommandRun) nft.Rule { + return &rule{ + command: command, + } +} + +func (r *rule) Add(family family.Type, tableName string, chainName string, expr ...string) error { + args := nftCommand.RuleAdd(family, tableName, chainName, expr...) + return r.command.Run(args...) +} + +func (r *rule) Insert(family family.Type, tableName string, chainName string, expr ...string) error { + args := nftCommand.RuleInsert(family, tableName, chainName, expr...) + return r.command.Run(args...) +} + +func (r *rule) Replace(family family.Type, tableName string, chainName string, handle uint64, expr ...string) error { + args := nftCommand.RuleReplace(family, tableName, chainName, handle, expr...) + return r.command.Run(args...) +} + +func (r *rule) Delete(family family.Type, tableName string, chainName string, handle uint64) error { + args := nftCommand.RuleDelete(family, tableName, chainName, handle) + return r.command.Run(args...) +}