- 协议: InitMessage 增加 ip6/prefix6/server_ip6 字段(omitempty,向后兼容) - TUN: Device 接口新增 ConfigureIPv6, macOS 用 ifconfig inet6, Linux 用 ip -6 addr add - 路由: full 模式自动添加 ::/1+8000::/1, v6 服务器旁路 /128, resolveHosts 双栈解析 - 会话: setupTUN 解析 v6 字段并配置 TUN+路由, connectOnce 传 v6 给 stats/日志 - 统计: SetConnected(ip,ip6), Snapshot.AssignedIP6 - DB: connection_logs 增加 assigned_ip6 列 + migrateV3 幂等迁移 - UI: 状态卡片新增独立 IPv6 行, 始终可见(未获取显示 IPv6: —) - 文档: 同步 client-development.md 至服务端 IPv6 版本
34 lines
1.3 KiB
Go
34 lines
1.3 KiB
Go
// Package tun provides a cross-platform TUN virtual network card
|
|
// abstraction. Each platform implements the Device interface.
|
|
//
|
|
// On macOS the TUN device is a utunN interface created via the
|
|
// songgao/water library (same as the server). Configuration uses
|
|
// ifconfig/route commands and requires root privileges.
|
|
package tun
|
|
|
|
import "net"
|
|
|
|
// Device represents a TUN virtual network interface.
|
|
type Device interface {
|
|
// Name returns the OS-assigned interface name (e.g. utun4).
|
|
Name() string
|
|
// Read reads one IP packet from the TUN device.
|
|
Read(p []byte) (int, error)
|
|
// Write writes one IP packet to the TUN device.
|
|
Write(p []byte) (int, error)
|
|
// Configure sets the interface address, prefix, and peer IP.
|
|
Configure(localIP net.IP, prefix int, peerIP net.IP) error
|
|
// ConfigureIPv6 sets a secondary IPv6 address and prefix on the
|
|
// interface. Unlike Configure, there is no peer IP because macOS
|
|
// utun IPv6 does not use the point-to-point aliasing form.
|
|
ConfigureIPv6(localIP6 net.IP, prefix6 int) error
|
|
// SetMTU sets the interface MTU.
|
|
SetMTU(mtu int) error
|
|
// Close destroys the TUN device.
|
|
Close() error
|
|
}
|
|
|
|
// Create creates a new TUN device. If name is empty, the OS assigns
|
|
// a name (utunN on macOS, tunN on Linux).
|
|
func Create(name string) (Device, error) { return createTUN(name) }
|