iptables

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FwdTable  = "nat"
	FwdChain  = "PREROUTING"
	FwdTarget = "DNAT"
)

Functions

This section is empty.

Types

type Hooks added in v1.2.0

type Hooks struct {
	OnCreate string `json:"on-create,omitempty" yaml:"on-create,omitempty"`
	OnDelete string `json:"on-delete,omitempty" yaml:"on-delete,omitempty"`
}

Hooks holds optional commands run after the corresponding forward lifecycle event. Each command is executed through "sh -c".

type IPTablesInstance added in v0.9.1

type IPTablesInstance struct {
	*iptables.IPTables
}

func NewIPTablesInstance added in v0.9.1

func NewIPTablesInstance() (*IPTablesInstance, error)

func (*IPTablesInstance) CreateForward added in v0.9.1

func (ipt *IPTablesInstance) CreateForward(rule *Rule) error

func (*IPTablesInstance) DeleteAllForwards added in v0.9.1

func (ipt *IPTablesInstance) DeleteAllForwards() error

func (*IPTablesInstance) DeleteForwardById added in v0.9.1

func (ipt *IPTablesInstance) DeleteForwardById(ruleId int) error

func (*IPTablesInstance) DeleteForwardByRule added in v0.9.1

func (ipt *IPTablesInstance) DeleteForwardByRule(rule *Rule) error

func (*IPTablesInstance) ListForward added in v0.9.1

func (ipt *IPTablesInstance) ListForward(outputFormat string) (map[int]string, error)

func (*IPTablesInstance) ValidateForward added in v0.9.1

func (ipt *IPTablesInstance) ValidateForward(rule *Rule) error

type Rule added in v0.7.1

type Rule struct {
	Iface   string `json:"iface" yaml:"iface" default:"lo"`
	Proto   string `json:"proto" yaml:"proto" default:"tcp"`
	Dport   int    `json:"dport" yaml:"dport"`
	Saddr   string `json:"saddr" yaml:"saddr"`
	Sport   int    `json:"sport" yaml:"sport"`
	Comment string `json:"comment,omitempty" yaml:"comment,omitempty"`
	// Hooks are commands executed after a forward is created or deleted.
	// They are not part of the rule's iptables representation nor its
	// identity hash, so changing a hook never churns the underlying forward.
	Hooks *Hooks `json:"hooks,omitempty" yaml:"hooks,omitempty"`
}

func ExtractRuleInfo added in v0.9.1

func ExtractRuleInfo(rawRule string) (*Rule, error)

ExtractRuleInfo extract forward information from rule if it matches the requirements. Returns the Rule struct and error

func NewRule added in v0.9.1

func NewRule(iface string, proto string, dport int, saddr string, sport int) *Rule

func (*Rule) HookEnv added in v1.2.0

func (rule *Rule) HookEnv() []string

HookEnv returns the rule's fields as KEY=VALUE strings to be exposed as environment variables to a hook command.

func (*Rule) String added in v0.9.1

func (rule *Rule) String() []string

String returns a list of string that compose the iptables rule. Eg: -t nat -A PREROUTING -i eth0 -p tcp -m tcp --dport 3000 -m comment --comment fwdctl -j DNAT --to-destination 192.168.199.105:80

Jump to

Keyboard shortcuts

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