chore: align ZeroTier link configuration and multicast state

This commit is contained in:
wwqgtxx committed 2026-08-10 00:05:49 +08:00
1 parent 8d7100815e
commit cf98d2d5fd
3 files changed
+20 -28

No files matched your search

+14 -22
View File
@@ -941,7 +941,9 @@ func (z *ZeroTier) applyNetworkConfig(config ZT.NetworkConfigData, generation ui
}
return errZeroTierStaleConfig
}
if err = ipLink.ApplyNetworkConfig(config); err != nil {
linkConfig := config
linkConfig.MTU = mtu
if err = ipLink.ApplyNetworkConfig(linkConfig); err != nil {
if replaceDevice {
_ = device.Close()
}
@@ -952,7 +954,9 @@ func (z *ZeroTier) applyNetworkConfig(config ZT.NetworkConfigData, generation ui
z.stateMu.Unlock()
var rollbackErr error
if oldConfig.NetworkID == z.networkID && len(oldConfig.Assigned) != 0 {
rollbackErr = ipLink.ApplyNetworkConfig(oldConfig)
oldLinkConfig := oldConfig
oldLinkConfig.MTU = z.effectiveMTU(oldConfig)
rollbackErr = ipLink.ApplyNetworkConfig(oldLinkConfig)
}
if replaceDevice {
_ = device.Close()
@@ -970,28 +974,8 @@ func (z *ZeroTier) applyNetworkConfig(config ZT.NetworkConfigData, generation ui
z.authURL = ""
z.retryLatestConfig = false
z.configGeneration++
appliedGeneration := z.configGeneration
z.notifyStateLocked()
z.stateMu.Unlock()
var resetErr error
if replaceDevice {
resetErr = ipLink.ResetMulticast()
z.stateMu.RLock()
current = z.runtime == runtime && z.tunDevice == device && z.configGeneration == appliedGeneration
z.stateMu.RUnlock()
if !current {
if replacedDevice != nil {
_ = replacedDevice.Close()
}
if resetErr != nil {
log.Debugln("[ZeroTier](%s) reset multicast subscriptions: %v", z.Name(), resetErr)
}
return errZeroTierStaleConfig
}
}
if resetErr != nil {
log.Debugln("[ZeroTier](%s) reset multicast subscriptions: %v", z.Name(), resetErr)
}
if !replaceDevice {
return nil
}
@@ -1015,6 +999,14 @@ func (z *ZeroTier) configSnapshotCurrentLocked(runtime *zeroTierRuntime, config
func (z *ZeroTier) effectiveMTU(config ZT.NetworkConfigData) uint32 {
mtu := config.MTU
switch {
case mtu == 0:
mtu = ZT.DefaultNetworkMTU
case mtu < ZT.MinNetworkMTU:
mtu = ZT.MinNetworkMTU
case mtu > ZT.MaxNetworkMTU:
mtu = ZT.MaxNetworkMTU
}
if z.option.MTU != 0 && uint32(z.option.MTU) < mtu {
mtu = uint32(z.option.MTU)
}
+2 -2
View File
@@ -27,7 +27,7 @@ require (
github.com/metacubex/jls-tls v0.0.0-20260723084315-67adc0e2f796
github.com/metacubex/kcp-go v0.0.0-20260105040817-550693377604
github.com/metacubex/mhurl v0.1.0
github.com/metacubex/mipstack v0.0.0-20260808050503-d7b2821f2a69
github.com/metacubex/mipstack v0.0.0-20260809155845-fbe138b8c54a
github.com/metacubex/mlkem v0.1.0
github.com/metacubex/quic-go v0.61.1-0.20260727080200-2548683b76f4
github.com/metacubex/randv2 v0.2.0
@@ -48,7 +48,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-20260804111226-0ced244971ee
github.com/metacubex/zerotier-go v0.0.0-20260809160028-fc43171876b7
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
+4 -4
View File
@@ -134,8 +134,8 @@ github.com/metacubex/kcp-go v0.0.0-20260105040817-550693377604 h1:hJwCVlE3ojViC3
github.com/metacubex/kcp-go v0.0.0-20260105040817-550693377604/go.mod h1:lpmN3m269b3V5jFCWtffqBLS4U3QQoIid9ugtO+OhVc=
github.com/metacubex/mhurl v0.1.0 h1:ZdW4Zxe3j3uJ89gNytOazHu6kbHn5owutN/VfXOI8GE=
github.com/metacubex/mhurl v0.1.0/go.mod h1:2qpQImCbXoUs6GwJrjuEXKelPyoimsIXr07eNKZdS00=
github.com/metacubex/mipstack v0.0.0-20260808050503-d7b2821f2a69 h1:nTdw7ctE2E7EYgdJ3n6WpWLjGMzfIUnNwU6w5n2pMwk=
github.com/metacubex/mipstack v0.0.0-20260808050503-d7b2821f2a69/go.mod h1:+bbwALZI0pbi2auSG5A3ptdpV2DZ2eLObziXo+P7oj0=
github.com/metacubex/mipstack v0.0.0-20260809155845-fbe138b8c54a h1:kE+YXBiq9r9m95Svskmnn6eNDMGnTTT6slgWfvm9IgM=
github.com/metacubex/mipstack v0.0.0-20260809155845-fbe138b8c54a/go.mod h1:+bbwALZI0pbi2auSG5A3ptdpV2DZ2eLObziXo+P7oj0=
github.com/metacubex/mlkem v0.1.0 h1:wFClitonSFcmipzzQvax75beLQU+D7JuC+VK1RzSL8I=
github.com/metacubex/mlkem v0.1.0/go.mod h1:amhaXZVeYNShuy9BILcR7P0gbeo/QLZsnqCdL8U2PDQ=
github.com/metacubex/nftables v0.0.0-20260426003805-208c2c1ba2cb h1:wk6mHYPURSUvWcUv72gNP79oiylFsscBSDPJ6ieV6Iw=
@@ -186,8 +186,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-20260804111226-0ced244971ee h1:6IeUZwA135uUuIet7i3XiAMRydybI00MqLBA650nwVE=
github.com/metacubex/zerotier-go v0.0.0-20260804111226-0ced244971ee/go.mod h1:8LxQupX5KaZ6lIcBMdaJ3u5xx7+OIRyq87uyyFA1Yto=
github.com/metacubex/zerotier-go v0.0.0-20260809160028-fc43171876b7 h1:bXFmF5Ep5RswACsKTg4fVj/KVbpgHKPF29MXgzhniEQ=
github.com/metacubex/zerotier-go v0.0.0-20260809160028-fc43171876b7/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=