netbird

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 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 netbird 托管 NetBird 守护进程并通过 netbird 命令完成登录与状态展示, 把本机加入 NetBird 官方云或自建管理服务的组网。 支持多个实例:每个实例是一个独立的守护进程(状态目录、控制地址与进程互不相同),可分别加入不同的 NetBird 网络。

Index

Constants

View Source
const DefaultManagementURL = "https://api.netbird.io:443"

DefaultManagementURL 是 NetBird 官方云的管理服务地址。

View Source
const ID = "netbird"

ID 是模块标识。

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnView

type ConnView struct {
	URL       string `json:"url"`
	Connected bool   `json:"connected"`
	Error     string `json:"error,omitempty"`
}

ConnView 是管理服务或信令服务的连接状态。

type Instance added in v0.6.5

type Instance struct {
	Key  string `json:"key"`
	Name string `json:"name"`
	// Group 为列表中的分组名称,只影响管理界面的展示,留空为未分组
	Group  string `json:"group"`
	Enable bool   `json:"enable"`
	Options
	Remark string `json:"remark"`
	// LegacyStateDir 表示实例由 0.6.4 及更早版本的单实例配置迁移而来:stateDir 留空时沿用升级前的默认目录
	// <配置目录>/netbird,节点身份不变。由服务端维护,修改时保留原值,复制时清除
	LegacyStateDir bool `json:"legacyStateDir,omitempty"`
}

Instance 是一个 NetBird 实例:独立的状态目录、控制地址与守护进程,可分别加入不同的 NetBird 网络。

func (*Instance) CLIArgs added in v0.6.5

func (in *Instance) CLIArgs(configDir string) []string

CLIArgs 生成 netbird 命令的全局参数。

func (*Instance) DaemonArgs added in v0.6.5

func (in *Instance) DaemonArgs(configDir string) []string

DaemonArgs 生成托管守护进程的命令行参数;日志输出到标准输出,由 Gately 收集。

func (*Instance) DaemonEnvList added in v0.6.5

func (in *Instance) DaemonEnvList(configDir string) []string

DaemonEnvList 返回传给守护进程的环境变量(KEY=VALUE 形式):状态目录、用户态网络及其本机转发与 SOCKS5 地址, 最后是用户填写的变量,同名时以用户的为准。格式错误的行已在 Validate 中拒绝。

func (*Instance) Validate added in v0.6.5

func (in *Instance) Validate() error

Validate 校验并规范化实例。与其他实例之间的冲突由 checkConflicts 检查。

type InstanceView added in v0.6.5

type InstanceView struct {
	Instance
	// State 为托管的守护进程状态
	State proc.State `json:"state"`
	// Error 为启动流程的错误(含与其他实例冲突而未启动的原因)
	Error string `json:"error"`
	// DefaultStateDir 为 stateDir 留空时使用的状态目录,新增实例(尚无 key)时为空
	DefaultStateDir string `json:"defaultStateDir"`
	// DefaultManagementURL 为 managementUrl 留空时使用的 NetBird 官方云地址
	DefaultManagementURL string `json:"defaultManagementUrl"`
}

InstanceView 是界面展示的实例,设置密钥已脱敏。

type Module

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

Module 是 NetBird 模块。

func New

func New() *Module

New 创建模块。

func (*Module) ID

func (m *Module) ID() string

ID 实现 module.Module。

func (*Module) Init

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

Init 实现 module.Module。

func (*Module) ProgramInstallers

func (m *Module) ProgramInstallers() []*binstall.Installer

ProgramInstallers 返回模块托管的程序安装器,供 Gately 自动检查更新时一并检查托管程序。

func (*Module) Routes

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

Routes 实现 module.Module。

func (*Module) SetHTTPClient

func (m *Module) SetHTTPClient(fn func() *http.Client)

SetHTTPClient 实现 module.HTTPClientAware。

func (*Module) Start

func (m *Module) Start(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 Options added in v0.6.5

type Options struct {
	// ManageDaemon 为 true 时由 Gately 运行 netbird 守护进程(netbird service run);
	// 为 false 时使用系统已安装的 NetBird 服务,只负责 netbird up 与状态展示
	ManageDaemon bool `json:"manageDaemon"`
	// StateDir 保存登录状态与 WireGuard 密钥,留空为配置目录下的 netbird/<实例 key>;通过 NB_STATE_DIR 传给守护进程。
	// 可填已有的状态目录以沿用原节点身份
	StateDir string `json:"stateDir"`
	// DaemonAddr 为守护进程的控制地址,形如 unix:///path/netbird.sock 或 tcp://127.0.0.1:41731;
	// 托管时留空为状态目录下的 netbird.sock,外部守护进程留空使用系统默认
	DaemonAddr string `json:"daemonAddr"`
	// Userspace 使用用户态网络(netstack),无需 TUN 设备与特权,适合容器;此时本机服务经 SOCKS5 访问其他节点
	Userspace bool `json:"userspace"`
	// LocalForwarding 在用户态网络下把其他节点发往本机组网地址的连接转交给本机网络栈,
	// 这样才能从组网访问本机服务(包括只监听 127.0.0.1 的服务,仍受管理端访问策略约束);内核模式下本就可以访问
	LocalForwarding bool `json:"localForwarding"`
	// Socks5 为用户态网络下 SOCKS5 代理的监听地址(IP:端口),留空为 NetBird 默认的 127.0.0.1:1080
	Socks5 string `json:"socks5"`
	// SetupKey 为管理端生成的设置密钥,留空时需要在状态面板中打开登录链接完成认证
	SetupKey string `json:"setupKey"`
	// ManagementURL 为管理服务地址,留空使用 NetBird 官方云;自建时填写自己的地址
	ManagementURL string `json:"managementUrl"`
	Hostname      string `json:"hostname"`
	// Port 为 WireGuard UDP 监听端口,0 表示使用 NetBird 默认的 51820
	Port int `json:"port"`
	// AcceptRoutes 接受管理端下发给本机的网络路由(访问其他路由节点后面的网段)
	AcceptRoutes bool `json:"acceptRoutes"`
	// ServerRoutes 允许本机作为路由节点,转发管理端配置给本机的网段
	ServerRoutes bool `json:"serverRoutes"`
	// AcceptDNS 使用管理端下发的 DNS 配置
	AcceptDNS bool `json:"acceptDns"`
	// BlockInbound 拒绝来自组网的所有入站连接,优先于管理端的访问策略
	BlockInbound bool `json:"blockInbound"`
	// ExtraUpArgs 追加到 netbird up 之后,以空白分隔
	ExtraUpArgs string `json:"extraUpArgs"`
	// DaemonExtraArgs 追加到 netbird service run 之后,以空白分隔
	DaemonExtraArgs string `json:"daemonExtraArgs"`
	// DaemonEnv 是传给守护进程的环境变量,每行一个 KEY=VALUE
	DaemonEnv string `json:"daemonEnv"`
}

Options 是一个 NetBird 守护进程的运行与登录参数。

func DefaultOptions added in v0.6.5

func DefaultOptions() Options

DefaultOptions 是新实例的默认参数:托管守护进程并使用用户态网络,允许从组网访问本机服务,允许作为路由节点。

func (*Options) UpArgs added in v0.6.5

func (s *Options) UpArgs() []string

UpArgs 生成 netbird up 的参数。开关类参数都显式给出取值,让界面配置成为唯一的事实来源: netbird 只更新命令行中出现的参数,未出现的沿用上次保存的值。设置密钥经环境变量传递,见 UpEnv。

func (*Options) UpEnv added in v0.6.5

func (s *Options) UpEnv() []string

UpEnv 返回执行 netbird up 时追加的环境变量。设置密钥不放在命令行中,避免出现在进程列表里。

func (*Options) Validate added in v0.6.5

func (s *Options) Validate() error

Validate 校验并规范化单个守护进程的参数。

type PeerView

type PeerView struct {
	Name     string   `json:"name"`
	FQDN     string   `json:"fqdn"`
	IPs      []string `json:"ips"`
	Online   bool     `json:"online"`
	Status   string   `json:"status"`
	ConnType string   `json:"connType,omitempty"`
	Relay    string   `json:"relay,omitempty"`
	// LatencyMs 为延迟毫秒数,0 表示未知
	LatencyMs float64   `json:"latencyMs,omitempty"`
	Routes    []string  `json:"routes,omitempty"`
	RxBytes   int64     `json:"rxBytes"`
	TxBytes   int64     `json:"txBytes"`
	LastSeen  time.Time `json:"lastSeen,omitempty"`
}

PeerView 是界面展示的节点。

type SelfView

type SelfView struct {
	Name   string   `json:"name"`
	FQDN   string   `json:"fqdn"`
	IPs    []string `json:"ips"`
	WgPort int      `json:"wgPort,omitempty"`
	// Kernel 表示使用内核 WireGuard,否则为用户态实现
	Kernel bool `json:"kernel"`
}

SelfView 是本机在组网中的信息。

type Settings

type Settings struct {
	// NetbirdPath 为空时依次在配置目录 bin 与 PATH 下查找
	NetbirdPath string `json:"netbirdPath"`
	// InstallProxy 为在线安装使用的下载代理,空表示沿用全局“更新代理”;只通过安装接口修改
	InstallProxy string `json:"installProxy"`
}

Settings 是模块级(程序级)设置,所有实例共用。

func (*Settings) Validate

func (s *Settings) Validate()

Validate 校验并规范化程序设置。

type SettingsView added in v0.6.5

type SettingsView struct {
	Settings Settings `json:"settings"`
	// CLI 为实际使用的 netbird 程序路径,找不到时为空
	CLI string `json:"cli"`
	// DefaultManagementURL 为实例 managementUrl 留空时使用的 NetBird 官方云地址
	DefaultManagementURL string `json:"defaultManagementUrl"`
}

SettingsView 是 GET /settings 的返回内容。

type StatusView

type StatusView struct {
	// Key、Name 为实例的 key 与名称
	Key     string     `json:"key"`
	Name    string     `json:"name"`
	Enable  bool       `json:"enable"`
	Daemon  proc.State `json:"daemon"`
	CLI     string     `json:"cli"`
	Version string     `json:"version"`
	// Error 为启动流程或状态查询的错误
	Error string `json:"error"`
	// DaemonStatus 为 Idle、Connecting、Connected、NeedsLogin、LoginFailed 或 SessionExpired
	DaemonStatus string `json:"daemonStatus"`
	AuthURL      string `json:"authUrl,omitempty"`
	// AuthCode 为设备码登录时需要在登录页输入的代码,链接已包含代码时为空
	AuthCode       string     `json:"authCode,omitempty"`
	Management     *ConnView  `json:"management,omitempty"`
	Signal         *ConnView  `json:"signal,omitempty"`
	RelaysTotal    int        `json:"relaysTotal"`
	RelaysUp       int        `json:"relaysUp"`
	Self           *SelfView  `json:"self,omitempty"`
	PeersConnected int        `json:"peersConnected"`
	Peers          []PeerView `json:"peers"`
}

StatusView 是一个实例的连接状态。

Jump to

Keyboard shortcuts

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