firewall

package
v3.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2026 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Direction

type Direction string
var (
	DirectionIn  Direction = "in"  // 传入
	DirectionOut Direction = "out" // 传出
)

type FireForwardInfo

type FireForwardInfo struct {
	Port       uint     `json:"port"`        // 1-65535
	Protocol   Protocol `json:"protocol"`    // tcp udp tcp/udp
	TargetIP   string   `json:"target_ip"`   // 目标地址
	TargetPort uint     `json:"target_port"` // 1-65535
}

type FireInfo

type FireInfo struct {
	Type      Type      `json:"type"`       // rich or normal
	Family    string    `json:"family"`     // ipv4 ipv6
	Address   string    `json:"address"`    // 源地址或目标地址
	PortStart uint      `json:"port_start"` // 1-65535
	PortEnd   uint      `json:"port_end"`   // 1-65535
	Protocol  Protocol  `json:"protocol"`   // tcp udp tcp/udp
	Strategy  Strategy  `json:"strategy"`   // accept drop reject mark
	Direction Direction `json:"direction"`  // in out 入站或出站
}

type Firewall

type Firewall interface {
	// Status 获取防火墙运行状态
	Status() (bool, error)
	// Enable 启用防火墙
	Enable() error
	// Disable 禁用防火墙
	Disable() error

	// ListRule 列出所有规则
	ListRule() ([]FireInfo, error)
	// Port 添加/删除端口规则
	Port(rule FireInfo, operation Operation) error
	// RichRules 添加/删除富规则(IP/高级规则)
	RichRules(rule FireInfo, operation Operation) error

	// ListForward 列出所有转发规则
	ListForward() ([]FireForwardInfo, error)
	// Forward 添加/删除转发规则
	Forward(rule Forward, operation Operation) error

	// PingStatus 获取 Ping 状态(true 为允许)
	PingStatus() (bool, error)
	// UpdatePingStatus 更新 Ping 状态
	UpdatePingStatus(status bool) error
}

Firewall 防火墙统一接口

func NewFirewall

func NewFirewall() Firewall

NewFirewall 自动检测系统防火墙类型并返回对应实现

type Forward

type Forward struct {
	Protocol   Protocol `json:"protocol"`    // tcp udp tcp/udp
	Port       uint     `json:"port"`        // 1-65535
	TargetIP   string   `json:"target_ip"`   // 目标地址
	TargetPort uint     `json:"target_port"` // 1-65535
}

type Operation

type Operation string
var (
	OperationAdd    Operation = "add"    // 添加
	OperationRemove Operation = "remove" // 移除
)

type Protocol

type Protocol string
var (
	ProtocolTCP    Protocol = "tcp"     // tcp
	ProtocolUDP    Protocol = "udp"     // udp
	ProtocolTCPUDP Protocol = "tcp/udp" // tcp/udp
)

type Strategy

type Strategy string
var (
	StrategyAccept Strategy = "accept" // 接受
	StrategyDrop   Strategy = "drop"   // 丢弃
	StrategyReject Strategy = "reject" // 拒绝
	StrategyMark   Strategy = "mark"   // 标记
)

type Type

type Type string
var (
	TypeRich   Type = "rich"   // rich
	TypeNormal Type = "normal" // normal
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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