nftdesk

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 15, 2025 License: Apache-2.0 Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nftdesk

PkgGoDev GitHub Go Report Card

This is a thin wrapper around Google's nftables to simplify the programmatic creation of nftables rules by communicating directly with netfilter.

Note: This library is under development. The API might change as I tinker with the design. 🚧

Installation

go get github.com/nickgarlis/nftdesk

Example Usage

import (
	"github.com/nickgarlis/nftdesk"
	"github.com/nickgarlis/nftdesk/expr"
	"github.com/nickgarlis/nftdesk/models"
)

func main() {
	d, err = NewNftDesk()
	if err != nil {
		panic(err)
	}

	table := d.AddTable("my-table", models.TableFamilyIPv4)

	chain := table.AddChain("my-chain")

	_, err := chain.AddRule(
		expr.CtStateExpr().In(expr.CtStateESTABLISHED, expr.CtStateRELATED),
		expr.VerdictExpr().OfKindAccept(),
	)
	if err != nil {
		panic(err)
	}

	err = d.Flush()
	if err != nil {
		panic(err)
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type NftDesk

type NftDesk struct {
	// contains filtered or unexported fields
}

func NewNftDesk

func NewNftDesk() (*NftDesk, error)

func (*NftDesk) AddTable

func (n *NftDesk) AddTable(name string, family models.TableFamily) *models.Table

func (*NftDesk) Flush

func (n *NftDesk) Flush() error

func (*NftDesk) FlushRuleset

func (n *NftDesk) FlushRuleset()

func (*NftDesk) GetTable

func (n *NftDesk) GetTable(name string) (*models.Table, error)

Get a table by name. Returns an error if the table does not exist.

func (*NftDesk) GetTableOfFamily

func (n *NftDesk) GetTableOfFamily(name string, family nftables.TableFamily) (*models.Table, error)

Get a table by name and family. Returns an error if the table does not exist.

func (*NftDesk) HasTable

func (n *NftDesk) HasTable(name string) bool

func (*NftDesk) HasTableOfFamily

func (n *NftDesk) HasTableOfFamily(name string, family nftables.TableFamily) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址