netbird

package
v0.6.4 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: Apache-2.0 Imports: 25 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 官方云或自建管理服务的组网。

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 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 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 {
	Enable bool `json:"enable"`
	// ManageDaemon 为 true 时由 Gately 运行 netbird 守护进程(netbird service run);
	// 为 false 时使用系统已安装的 NetBird 服务,只负责 netbird up 与状态展示
	ManageDaemon bool   `json:"manageDaemon"`
	NetbirdPath  string `json:"netbirdPath"`
	// StateDir 保存登录状态与 WireGuard 密钥,留空为配置目录下的 netbird 子目录;通过 NB_STATE_DIR 传给守护进程
	StateDir string `json:"stateDir"`
	// DaemonAddr 为守护进程的控制地址,形如 unix:///path/netbird.sock 或 tcp://127.0.0.1:41731;
	// 托管时留空为 StateDir 下的 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"`
	// InstallProxy 为在线安装使用的下载代理,空表示沿用全局“更新代理”;只通过安装接口修改
	InstallProxy string `json:"installProxy"`
}

Settings 是 NetBird 配置。

func DefaultSettings

func DefaultSettings() Settings

DefaultSettings 是首次使用的默认配置:托管守护进程并使用用户态网络,允许从组网访问本机服务,允许作为路由节点。

func (*Settings) CLIArgs

func (s *Settings) CLIArgs(configDir string) []string

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

func (*Settings) DaemonArgs

func (s *Settings) DaemonArgs(configDir string) []string

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

func (*Settings) DaemonEnvList

func (s *Settings) DaemonEnvList(configDir string) []string

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

func (*Settings) UpArgs

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

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

func (*Settings) UpEnv

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

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

func (*Settings) Validate

func (s *Settings) Validate() error

Validate 校验并规范化配置。

type StatusView

type StatusView struct {
	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 是 /status 接口的返回内容。

Jump to

Keyboard shortcuts

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