Refactor rule commands to use nftCommand utilities for improved code reuse

This commit is contained in:
2026-04-26 16:12:24 +05:00
parent bc00e46865
commit 8d9c3e7f7b
2 changed files with 35 additions and 9 deletions
+30
View File
@@ -0,0 +1,30 @@
package nft
import (
"strconv"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/family"
)
func RuleAdd(family family.Type, tableName string, chainName string, expr ...string) []string {
args := []string{"add", "rule", family.String(), tableName, chainName}
args = append(args, expr...)
return args
}
func RuleInsert(family family.Type, tableName string, chainName string, expr ...string) []string {
args := []string{"insert", "rule", family.String(), tableName, chainName}
args = append(args, expr...)
return args
}
func RuleReplace(family family.Type, tableName string, chainName string, handle uint64, expr ...string) []string {
args := []string{"replace", "rule", family.String(), tableName, chainName, "handle", strconv.Itoa(int(handle))}
args = append(args, expr...)
return args
}
func RuleDelete(family family.Type, tableName string, chainName string, handle uint64) []string {
args := []string{"delete", "rule", family.String(), tableName, chainName, "handle", strconv.Itoa(int(handle))}
return args
}