firewall

package
v0.3.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package firewall filters sandbox outgoing traffic.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action int
const (
	Deny Action = iota
	Allow
	Ask
)

func (Action) String

func (a Action) String() string

type Firewall

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

func New

func New(pid int, rules *RuleSet, resolver dns.Resolver) (*Firewall, error)

New creates and starts the firewall. Installs nftables rules in the network namespace of the process pid, which send the first packet of each new connection to a queue. The queue logs and allows each connection attempt.

The caller should call the Firewall.Stop() function on program termination.

func (*Firewall) LookupNetIP

func (f *Firewall) LookupNetIP(ctx context.Context, network, domainRooted string) ([]netip.Addr, error)

LookupNetIP resolves address taking into account Firewall filtering rules.

func (*Firewall) Stop

func (f *Firewall) Stop()

Stop closes Firewall sockets. After stopping the Firewall existing rules continue to apply, no new connections are allowed.

type Rule

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

Rule defines an action to take by the firewall and the traffic destination to which the action applies.

type RuleSet

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

RuleSet holds indexed firewall rules.

func NewRuleSet

func NewRuleSet(cfg *config.Firewall) (*RuleSet, error)

NewRuleSet creates a RuleSet as configured by the cfg. For now, only inline rules are handled.

func (*RuleSet) Add

func (rs *RuleSet) Add(r Rule)

Add adds the rule to the set. Of equally specific rules matching the same traffic, the one added later is used.

func (*RuleSet) ConnectionAction

func (rs *RuleSet) ConnectionAction(domain string, addr netip.Addr, port int, proto string) Action

ConnectionAction returns the action for a connection to addr and port with the proto ("tcp", "udp" or empty for other protocols, which match only rules without ports and protocol). domain is the lowercase name without the trailing dot that addr was resolved from, empty if not known.

func (*RuleSet) ResolverAction

func (rs *RuleSet) ResolverAction(domain string) Action

ResolverAction returns the action for a DNS query for the domain.

Jump to

Keyboard shortcuts

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