portforward

package
v0.7.2 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 28 Imported by: 0 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.

Documentation

Overview

Package portforward 实现 TCP/UDP 端口转发模块。

Index

Constants

View Source
const ID = "portforward"

ID 是模块标识。

Variables

This section is empty.

Functions

This section is empty.

Types

type Module

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

Module 是端口转发模块。

func New

func New() *Module

New 创建模块实例。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) ImportLucky

func (m *Module) ImportLucky(doc luckyimport.Document, opts luckyimport.Options) (*luckyimport.Report, error)

ImportLucky 实现 luckyimport.Importer。

func (*Module) ImportRules

func (m *Module) ImportRules(rules []Rule) (int, error)

ImportRules 追加导入规则(由 Lucky 导入器调用),返回导入数量。

func (*Module) Init

func (m *Module) Init(env module.Env) error

Init 实现 module.Module。

func (*Module) Metrics added in v0.5.0

func (m *Module) Metrics() []module.Sample

Metrics 实现 module.Metricer:每条运行中规则的连接数与流量。

func (*Module) Routes

func (m *Module) Routes(r module.Router)

Routes 实现 module.Module。

func (*Module) Start

func (m *Module) Start(ctx context.Context) error

Start 实现 module.Module。

func (*Module) Stop

func (m *Module) Stop() error

Stop 实现 module.Module。

func (*Module) Summary

func (m *Module) Summary() []module.SummaryItem

Summary 实现 module.Summarizer。

func (*Module) Title

func (m *Module) Title() string

Title 实现 module.Module。

type Rule

type Rule struct {
	Key    string `json:"key"`
	Name   string `json:"name"`
	Enable bool   `json:"enable"`
	// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
	Group         string   `json:"group"`
	Protocols     []string `json:"protocols"`
	ListenAddress string   `json:"listenAddress"`
	ListenPorts   string   `json:"listenPorts"`
	// AutoFirewall 为 true 时在本机防火墙(nftables / iptables / ip6tables 的 input 链)放行监听成功的端口,
	// 连续端口合并为一条规则,绑定具体地址时只放行发往该地址的连接,只监听回环地址时不放行;规则停止时撤销
	AutoFirewall    bool     `json:"autoFirewall"`
	TargetAddresses []string `json:"targetAddresses"`
	TargetPorts     string   `json:"targetPorts"`
	// MaxConnections 是该规则每个 TCP 端口的最大并发连接数,0 表示使用全局默认值
	MaxConnections int `json:"maxConnections"`
	// MaxConnsPerSource 是每个 TCP 端口上单个来源(IPv4 地址、IPv6 /64)的最大并发连接数,0 表示使用全局默认值;
	// 回环与内网来源不受此限制
	MaxConnsPerSource int `json:"maxConnsPerSource"`
	// UDPSessionTimeout 是 UDP 会话空闲超时(秒),0 表示使用全局默认值
	UDPSessionTimeout int `json:"udpSessionTimeout"`
	// ProxyProtocol 非空时,TCP 连接目标后先发送 PROXY 协议头(v1 或 v2),把真实客户端地址告诉下游
	// (haproxy accept-proxy、nginx proxy_protocol、Gately Web 服务"接收 PROXY 协议")。目标必须支持,否则连接会被拒绝。
	ProxyProtocol string `json:"proxyProtocol"`
	// Mode 只用于拒绝旧版接口提交的分流规则:SNI 与协议分流已移到独立的「协议分流」模块,这里必须为空
	Mode string `json:"mode,omitempty"`
	// Access 为来源 IP 访问控制(白名单 / 黑名单),在连接目标之前判断;封禁表中的地址无论何种模式都会被拒绝
	iplist.Access
	Remark string `json:"remark"`
}

Rule 是一条端口转发规则。

func (*Rule) Validate

func (r *Rule) Validate() error

Validate 校验规则并清理输入中的空白。

type RuleView

type RuleView struct {
	Rule
	Running bool          `json:"running"`
	Error   string        `json:"error,omitempty"`
	Details []string      `json:"details,omitempty"`
	Stats   StatsSnapshot `json:"stats"`
	// Firewall 为自动放行防火墙的结果说明,未开启或规则未运行时为空
	Firewall string `json:"firewall,omitempty"`
	// FirewallFailed 表示自动放行有端口放行失败(例如没有权限),界面据此提示
	FirewallFailed bool `json:"firewallFailed,omitempty"`
}

RuleView 是带运行状态的规则,用于 API 输出。

type Settings

type Settings struct {
	Enable                bool `json:"enable"`
	DefaultMaxConnections int  `json:"defaultMaxConnections"`
	// DefaultMaxConnsPerSource 是单个来源的默认最大并发连接数,0 表示取所在端口最大连接数的一半:
	// 单个来源最多占用一半名额,其余来源总能连接;家庭使用中一个来源的并发连接远少于这个数
	DefaultMaxConnsPerSource int `json:"defaultMaxConnsPerSource"`
	// PerSourceExempt 为不受单来源上限约束的来源(IP 或 CIDR),例如把所有访客汇聚成同一个来源的公网中转或前置代理;
	// 回环与内网来源本来就不受限制,不必填写
	PerSourceExempt          []string `json:"perSourceExempt"`
	DefaultUDPSessionTimeout int      `json:"defaultUDPSessionTimeout"`
	MaxUDPSessions           int      `json:"maxUDPSessions"`
	// DialTimeout 是连接目标的超时(秒)
	DialTimeout int `json:"dialTimeout"`
	// FirstDataTimeout 是 TCP 连接建立后等待任一方发送数据的最长时间(秒),超时仍没有任何数据的空连接被断开,
	// 0 表示默认 60 秒。正常协议总有一方在连接后立即发言,只建立连接不发数据的连接只会占用名额
	FirstDataTimeout int `json:"firstDataTimeout"`
}

Settings 是模块级配置。

type StatsSnapshot

type StatsSnapshot struct {
	ActiveConns int64 `json:"activeConns"`
	TotalConns  int64 `json:"totalConns"`
	BytesIn     int64 `json:"bytesIn"`
	BytesOut    int64 `json:"bytesOut"`
	// Denied 为不满足来源 IP 访问控制而被拒绝的次数:TCP 按连接、UDP 按数据包计数
	Denied int64 `json:"denied"`
}

StatsSnapshot 是统计的快照,用于 API 输出。

Jump to

Keyboard shortcuts

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