Add Rule API for managing nftables rules, including Add, Insert, Replace, and Delete operations

This commit is contained in:
2025-10-22 22:43:33 +05:00
parent 90b232aa05
commit 2ac9272293
2 changed files with 78 additions and 0 deletions

10
nft.go
View File

@@ -7,6 +7,7 @@ import (
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/chain"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/command"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/rule"
"git.kor-elf.net/kor-elf-shield/go-nftables-client/internal/table"
)
@@ -33,12 +34,16 @@ type NFT interface {
// Chain returns an API for working with chains.
Chain() chain.API
// Rule returns an API for working with rules.
Rule() rule.API
}
type nft struct {
command command.NFT
table table.API
chain chain.API
rule rule.API
}
// New Returns a client for working with nftables.
@@ -66,6 +71,7 @@ func NewWithPath(path string) (NFT, error) {
command: nftCommand,
table: table.New(nftCommand),
chain: chain.New(nftCommand),
rule: rule.New(nftCommand),
}, nil
}
@@ -116,6 +122,10 @@ func (n *nft) Chain() chain.API {
return n.chain
}
func (n *nft) Rule() rule.API {
return n.rule
}
func (n *nft) Command() command.NFT {
return n.command
}