ipc

package
v1.0.27 Latest Latest
Warning

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

Go to latest
Published: Jan 7, 2026 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultSocketPath is the default daemon socket location
	DefaultSocketPath = "/run/nftban/nftband.sock"

	// DefaultTimeout is the default request timeout
	DefaultTimeout = 30 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client provides IPC communication with nftband daemon

func NewClient

func NewClient() *Client

NewClient creates a new IPC client with default settings

func NewClientWithSocket

func NewClientWithSocket(socketPath string) *Client

NewClientWithSocket creates a client with custom socket path

func (*Client) AddElement

func (c *Client) AddElement(table, set, element string, timeout int) (*Response, error)

AddElement adds an element to a set

func (*Client) ApplyRuleset

func (c *Client) ApplyRuleset(filePath string, checkOnly bool) (*Response, error)

ApplyRuleset applies a ruleset from file

func (*Client) Ban

func (c *Client) Ban(ip string, timeout int, reason, source string) (*Response, error)

Ban bans an IP address

func (*Client) Call

func (c *Client) Call(method string, params map[string]any) (*Response, error)

Call sends a request to the daemon and returns the response

func (*Client) Check

func (c *Client) Check(ip string) (*Response, error)

Check checks if an IP is banned

func (*Client) DeleteElement

func (c *Client) DeleteElement(table, set, element string) (*Response, error)

DeleteElement removes an element from a set

func (*Client) FlushSet

func (c *Client) FlushSet(table, set string) (*Response, error)

FlushSet removes all elements from a set

func (*Client) IsConnected

func (c *Client) IsConnected() bool

IsConnected checks if daemon is reachable

func (*Client) LoadCIDRs

func (c *Client) LoadCIDRs(setType string, cidrs []string) (*Response, error)

LoadCIDRs loads CIDRs into blacklist or whitelist sets setType should be "blacklist" or "whitelist" If cidrs is nil/empty, loads from feeds/trust directories

func (*Client) LoadPorts

func (c *Client) LoadPorts() (*Response, error)

LoadPorts loads ports into nftables port sets

func (*Client) Modules

func (c *Client) Modules() (*Response, error)

Modules gets module statuses

func (*Client) PersistBan

func (c *Client) PersistBan(ip, reason, source string) (*Response, error)

PersistBan adds an IP to persistent blacklist files This is for permanent bans that survive reboots

func (*Client) Ping

func (c *Client) Ping() error

Ping checks if the daemon is alive

func (*Client) SetTimeout

func (c *Client) SetTimeout(d time.Duration)

SetTimeout sets the request timeout

func (*Client) SnapshotProfile added in v1.0.26

func (c *Client) SnapshotProfile(profileType string, duration int) (*Response, error)

SnapshotProfile triggers a pprof profile capture profileType: "heap", "goroutine", or "cpu" duration: seconds for CPU profile (only used for cpu type, default 30s)

func (*Client) Stats added in v1.0.26

func (c *Client) Stats() (*Response, error)

Stats returns current daemon runtime statistics

func (*Client) StatsHistory added in v1.0.26

func (c *Client) StatsHistory(days int) (*Response, error)

StatsHistory returns historical daily stats for specified number of days days: number of days to retrieve (1-30)

func (*Client) Status

func (c *Client) Status() (*Response, error)

Status gets daemon status

func (*Client) Sync

func (c *Client) Sync() (*Response, error)

Sync performs a full differential sync of whitelists/blacklists/ports

func (*Client) Unban

func (c *Client) Unban(ip string) (*Response, error)

Unban unbans an IP address

func (*Client) UnpersistBan

func (c *Client) UnpersistBan(ip string) (*Response, error)

UnpersistBan removes an IP from all persistent blacklist files

type Request

type Request struct {
	Method string         `json:"method"`
	Params map[string]any `json:"params,omitempty"`
}

Request represents a request to the daemon

type Response

type Response struct {
	Success bool   `json:"success"`
	Data    any    `json:"data,omitempty"`
	Error   string `json:"error,omitempty"`
}

Response represents a response from the daemon

Jump to

Keyboard shortcuts

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