1
0
mirror of https://github.com/MetaCubeX/mihomo.git synced 2026-10-10 04:03:11 +08:00

feat: add Zerotier outbound support

This commit is contained in:
wwqgtxx
2026-08-01 01:43:40 +08:00
parent 26c635f69b
commit b082515057
10 changed files with 1181 additions and 0 deletions
File diff suppressed because it is too large Load Diff
+40
View File
@@ -0,0 +1,40 @@
//go:build !with_gvisor || no_zerotier
package outbound
import "fmt"
type ZeroTier struct {
*Base
}
type ZeroTierOption struct {
BasicOption
Name string `proxy:"name"`
Network string `proxy:"network"`
StateDir string `proxy:"state-dir,omitempty"`
Planet string `proxy:"planet,omitempty"`
MTU int `proxy:"mtu,omitempty"`
PhysicalMTU int `proxy:"physical-mtu,omitempty"`
UDP bool `proxy:"udp,omitempty"`
RemoteDnsResolve bool `proxy:"remote-dns-resolve,omitempty"`
Dns []string `proxy:"dns,omitempty"`
LowBandwidth bool `proxy:"low-bandwidth,omitempty"`
EncryptedHello bool `proxy:"encrypted-hello,omitempty"`
PrimaryPort int `proxy:"primary-port,omitempty"`
SecondaryPort int `proxy:"secondary-port,omitempty"`
TCPFallbackMode string `proxy:"tcp-fallback-mode,omitempty"`
TCPFallbackRelay string `proxy:"tcp-fallback-relay,omitempty"`
Orbit []ZeroTierOrbitOption `proxy:"orbit,omitempty"`
RemoteTraceTarget string `proxy:"remote-trace-target,omitempty"`
RemoteTraceLevel uint64 `proxy:"remote-trace-level,omitempty"`
}
type ZeroTierOrbitOption struct {
World string `proxy:"world"`
Seed string `proxy:"seed"`
}
func NewZeroTier(ZeroTierOption) (*ZeroTier, error) {
return nil, fmt.Errorf("ZeroTier support is disabled by \"no_zerotier\" build tag or not include \"with_gvisor\" build tag")
}
+7
View File
@@ -209,6 +209,13 @@ func ParseProxy(mapping map[string]any, options ...ProxyOption) (C.Proxy, error)
break
}
proxy, err = outbound.NewTailscale(*tailscaleOption)
case "zerotier":
zeroTierOption := &outbound.ZeroTierOption{BasicOption: basicOption}
err = decoder.Decode(mapping, zeroTierOption)
if err != nil {
break
}
proxy, err = outbound.NewZeroTier(*zeroTierOption)
default:
return nil, fmt.Errorf("unsupport proxy type: %s", proxyType)
}
+3
View File
@@ -52,6 +52,7 @@ const (
ShadowQuic
OpenVPN
Tailscale
ZeroTier
GostRelay
)
@@ -234,6 +235,8 @@ func (at AdapterType) String() string {
return "OpenVPN"
case Tailscale:
return "Tailscale"
case ZeroTier:
return "ZeroTier"
case GostRelay:
return "GostRelay"
case Relay:
+5
View File
@@ -0,0 +1,5 @@
//go:build no_zerotier
package features
const NoZeroTier = true
+5
View File
@@ -0,0 +1,5 @@
//go:build !no_zerotier
package features
const NoZeroTier = false
+3
View File
@@ -13,6 +13,9 @@ func Tags() (tags []string) {
if NoTailscale {
tags = append(tags, "no_tailscale")
}
if NoZeroTier {
tags = append(tags, "no_zerotier")
}
if WithGVisor {
tags = append(tags, "with_gvisor")
}
+27
View File
@@ -1357,6 +1357,33 @@ proxies: # socks5
# routing-mark: 6666 # Linux 下配置 fwmark
# ip-version: ipv4-prefer # 可选:dual/ipv4/ipv6/ipv4-prefer/ipv6-prefer
# zerotier
- name: "zerotier"
type: zerotier
network: "0123456789abcdef" # 16-digit ZeroTier network ID
# state-dir: ./zerotier-node # persistent node identity; defaults to an isolated directory derived from network and outbound name
# planet: ./planet # optional private planet file; replaces the built-in Earth planet
# mtu: 1400 # optional local MTU override; cannot exceed the controller MTU
# physical-mtu: 1432 # optional ZeroTier UDP payload MTU (510-10324; default 1432)
# primary-port: 0 # primary UDP port; 0 selects an available port
# secondary-port: 0 # second UDP port; 0 selects an available port, -1 disables it
# tcp-fallback-mode: auto # auto uses relay after UDP failure; force uses relay only; disable turns relay off
# tcp-fallback-relay: 204.80.128.1:443
# remote-trace-target: "0123456789" # optional node ID receiving global diagnostic traces
# remote-trace-level: 0 # 0 normal, 10 verbose, 15 rules, 20 debug, 30 insane
# low-bandwidth: false # reduce background traffic and network configuration refresh frequency
# encrypted-hello: false # use protocol-13 extended encryption for outgoing HELLO packets
# orbit: # optional federated root worlds (moons)
# - world: "0123456789abcdef" # 16-digit moon world ID
# seed: "0123456789" # 10-digit node ID of one moon root
udp: true
# remote-dns-resolve: true # resolve destination names through ZeroTier using controller-provided DNS servers
# dns: [10.147.17.1] # optional override for controller-provided DNS servers
# dialer-proxy: "ss1" # carry ZeroTier wire traffic through another outbound
# interface-name: "WLAN"
# routing-mark: 6666
# ip-version: ipv4-prefer
# openvpn
- name: "openvpn"
type: openvpn
+1
View File
@@ -47,6 +47,7 @@ require (
github.com/metacubex/tls v0.1.7
github.com/metacubex/utls v1.8.7
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f
github.com/metacubex/zerotier-go v0.0.0-20260801024226-9489b55343a4
github.com/mroth/weightedrand/v2 v2.1.0
github.com/openacid/low v0.1.21
github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e
+2
View File
@@ -184,6 +184,8 @@ github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f h1:FGBPRb1z
github.com/metacubex/wireguard-go v0.0.0-20250820062549-a6cecdd7f57f/go.mod h1:oPGcV994OGJedmmxrcK9+ni7jUEMGhR+uVQAdaduIP4=
github.com/metacubex/yamux v0.0.0-20250918083631-dd5f17c0be49 h1:lhlqpYHopuTLx9xQt22kSA9HtnyTDmk5XjjQVCGHe2E=
github.com/metacubex/yamux v0.0.0-20250918083631-dd5f17c0be49/go.mod h1:MBeEa9IVBphH7vc3LNtW6ZujVXFizotPo3OEiHQ+TNU=
github.com/metacubex/zerotier-go v0.0.0-20260801024226-9489b55343a4 h1:P7SMQP+mnVDug3tPHvgPdeWtUBqEfCE/IzOhf9eXKXk=
github.com/metacubex/zerotier-go v0.0.0-20260801024226-9489b55343a4/go.mod h1:8LxQupX5KaZ6lIcBMdaJ3u5xx7+OIRyq87uyyFA1Yto=
github.com/miekg/dns v1.1.63 h1:8M5aAw6OMZfFXTT7K5V0Eu5YiiL8l7nUAkyN6C9YwaY=
github.com/miekg/dns v1.1.63/go.mod h1:6NGHfjhpmr5lt3XPLuyfDJi5AXbNIPM9PY6H6sF1Nfs=
github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc=