Update WireGuard and Tailscale

This commit is contained in:
世界
2025-09-15 19:52:28 +08:00
parent 12b055989b
commit 7f3ea8dbd8
8 changed files with 21 additions and 40 deletions

View File

@@ -356,18 +356,8 @@ func (d *DefaultDialer) ListenSerialInterfacePacket(ctx context.Context, destina
return trackPacketConn(packetConn, nil) return trackPacketConn(packetConn, nil)
} }
func (d *DefaultDialer) ListenPacketCompat(network, address string) (net.PacketConn, error) { func (d *DefaultDialer) WireGuardControl() control.Func {
udpListener := d.udpListener return d.udpListener.Control
udpListener.Control = control.Append(udpListener.Control, func(network, address string, conn syscall.RawConn) error {
for _, wgControlFn := range WgControlFns {
err := wgControlFn(network, address, conn)
if err != nil {
return err
}
}
return nil
})
return udpListener.ListenPacket(context.Background(), network, address)
} }
func trackConn(conn net.Conn, err error) (net.Conn, error) { func trackConn(conn net.Conn, err error) (net.Conn, error) {

View File

@@ -1,13 +1,9 @@
package dialer package dialer
import ( import (
"net"
"github.com/sagernet/sing/common/control" "github.com/sagernet/sing/common/control"
) )
type WireGuardListener interface { type WireGuardListener interface {
ListenPacketCompat(network, address string) (net.PacketConn, error) WireGuardControl() control.Func
} }
var WgControlFns []control.Func

2
go.mod
View File

@@ -25,7 +25,7 @@ require (
github.com/sagernet/cors v1.2.1 github.com/sagernet/cors v1.2.1
github.com/sagernet/fswatch v0.1.1 github.com/sagernet/fswatch v0.1.1
github.com/sagernet/gomobile v0.1.8 github.com/sagernet/gomobile v0.1.8
github.com/sagernet/gvisor v0.0.0-20250909151924-850a370d8506 github.com/sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1
github.com/sagernet/quic-go v0.54.0-sing-box-mod.3 github.com/sagernet/quic-go v0.54.0-sing-box-mod.3
github.com/sagernet/sing v0.8.0-beta.6 github.com/sagernet/sing v0.8.0-beta.6
github.com/sagernet/sing-mux v0.3.4 github.com/sagernet/sing-mux v0.3.4

4
go.sum
View File

@@ -149,8 +149,8 @@ github.com/sagernet/fswatch v0.1.1 h1:YqID+93B7VRfqIH3PArW/XpJv5H4OLEVWDfProGoRQ
github.com/sagernet/fswatch v0.1.1/go.mod h1:nz85laH0mkQqJfaOrqPpkwtU1znMFNVTpT/5oRsVz/o= github.com/sagernet/fswatch v0.1.1/go.mod h1:nz85laH0mkQqJfaOrqPpkwtU1znMFNVTpT/5oRsVz/o=
github.com/sagernet/gomobile v0.1.8 h1:vXgoN0pjsMONAaYCTdsKBX2T1kxuS7sbT/mZ7PElGoo= github.com/sagernet/gomobile v0.1.8 h1:vXgoN0pjsMONAaYCTdsKBX2T1kxuS7sbT/mZ7PElGoo=
github.com/sagernet/gomobile v0.1.8/go.mod h1:A8l3FlHi2D/+mfcd4HHvk5DGFPW/ShFb9jHP5VmSiDY= github.com/sagernet/gomobile v0.1.8/go.mod h1:A8l3FlHi2D/+mfcd4HHvk5DGFPW/ShFb9jHP5VmSiDY=
github.com/sagernet/gvisor v0.0.0-20250909151924-850a370d8506 h1:x/t3XqWshOlWqRuumpvbUvjtEr/6mJuBXAVovPefbUg= github.com/sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1 h1:AzCE2RhBjLJ4WIWc/GejpNh+z30d5H1hwaB0nD9eY3o=
github.com/sagernet/gvisor v0.0.0-20250909151924-850a370d8506/go.mod h1:QkkPEJLw59/tfxgapHta14UL5qMUah5NXhO0Kw2Kan4= github.com/sagernet/gvisor v0.0.0-20250811.0-sing-box-mod.1/go.mod h1:NJKBtm9nVEK3iyOYWsUlrDQuoGh4zJ4KOPhSYVidvQ4=
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis= github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a h1:ObwtHN2VpqE0ZNjr6sGeT00J8uU7JF4cNUdb44/Duis=
github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= github.com/sagernet/netlink v0.0.0-20240612041022-b9a21c07ac6a/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
github.com/sagernet/nftables v0.3.0-beta.4 h1:kbULlAwAC3jvdGAC1P5Fa3GSxVwQJibNenDW2zaXr8I= github.com/sagernet/nftables v0.3.0-beta.4 h1:kbULlAwAC3jvdGAC1P5Fa3GSxVwQJibNenDW2zaXr8I=

View File

@@ -1,10 +0,0 @@
package wireguard
import (
"github.com/sagernet/sing-box/common/dialer"
"github.com/sagernet/wireguard-go/conn"
)
func init() {
dialer.WgControlFns = conn.ControlFns
}

View File

@@ -36,7 +36,7 @@ import (
aTLS "github.com/sagernet/sing/common/tls" aTLS "github.com/sagernet/sing/common/tls"
"github.com/sagernet/sing/service" "github.com/sagernet/sing/service"
"github.com/sagernet/sing/service/filemanager" "github.com/sagernet/sing/service/filemanager"
"github.com/sagernet/tailscale/client/tailscale" "github.com/sagernet/tailscale/client/local"
"github.com/sagernet/tailscale/derp" "github.com/sagernet/tailscale/derp"
"github.com/sagernet/tailscale/derp/derphttp" "github.com/sagernet/tailscale/derp/derphttp"
"github.com/sagernet/tailscale/net/netmon" "github.com/sagernet/tailscale/net/netmon"
@@ -244,7 +244,7 @@ func (d *Service) Start(stage adapter.StartStage) error {
} }
case adapter.StartStatePostStart: case adapter.StartStatePostStart:
if len(d.verifyClientEndpoint) > 0 { if len(d.verifyClientEndpoint) > 0 {
var endpoints []*tailscale.LocalClient var endpoints []*local.Client
endpointManager := service.FromContext[adapter.EndpointManager](d.ctx) endpointManager := service.FromContext[adapter.EndpointManager](d.ctx)
for _, endpointTag := range d.verifyClientEndpoint { for _, endpointTag := range d.verifyClientEndpoint {
endpoint, loaded := endpointManager.Get(endpointTag) endpoint, loaded := endpointManager.Get(endpointTag)
@@ -343,7 +343,8 @@ func (d *Service) startMeshWithHost(derpServer *derp.Server, server *option.DERP
}) })
add := func(m derp.PeerPresentMessage) { derpServer.AddPacketForwarder(m.Key, meshClient) } add := func(m derp.PeerPresentMessage) { derpServer.AddPacketForwarder(m.Key, meshClient) }
remove := func(m derp.PeerGoneMessage) { derpServer.RemovePacketForwarder(m.Peer, meshClient) } remove := func(m derp.PeerGoneMessage) { derpServer.RemovePacketForwarder(m.Peer, meshClient) }
go meshClient.RunWatchConnectionLoop(context.Background(), derpServer.PublicKey(), logf, add, remove) notifyError := func(err error) { d.logger.Error(err) }
go meshClient.RunWatchConnectionLoop(context.Background(), derpServer.PublicKey(), logf, add, remove, notifyError)
return nil return nil
} }

View File

@@ -162,7 +162,7 @@ func (c *ClientBind) SetMark(mark uint32) error {
return nil return nil
} }
func (c *ClientBind) Send(bufs [][]byte, ep conn.Endpoint) error { func (c *ClientBind) Send(bufs [][]byte, ep conn.Endpoint, offset int) error {
udpConn, err := c.connect() udpConn, err := c.connect()
if err != nil { if err != nil {
c.pauseManager.WaitActive() c.pauseManager.WaitActive()
@@ -170,15 +170,18 @@ func (c *ClientBind) Send(bufs [][]byte, ep conn.Endpoint) error {
return err return err
} }
destination := netip.AddrPort(ep.(remoteEndpoint)) destination := netip.AddrPort(ep.(remoteEndpoint))
for _, b := range bufs { for _, buf := range bufs {
if len(b) > 3 { if offset > 0 {
buf = buf[offset:]
}
if len(buf) > 3 {
reserved, loaded := c.reservedForEndpoint[destination] reserved, loaded := c.reservedForEndpoint[destination]
if !loaded { if !loaded {
reserved = c.reserved reserved = c.reserved
} }
copy(b[1:4], reserved[:]) copy(buf[1:4], reserved[:])
} }
_, err = udpConn.WriteToUDPAddrPort(b, destination) _, err = udpConn.WriteToUDPAddrPort(buf, destination)
if err != nil { if err != nil {
udpConn.Close() udpConn.Close()
return err return err

View File

@@ -14,6 +14,7 @@ import (
"unsafe" "unsafe"
"github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/dialer"
"github.com/sagernet/sing-tun" "github.com/sagernet/sing-tun"
"github.com/sagernet/sing/common" "github.com/sagernet/sing/common"
E "github.com/sagernet/sing/common/exceptions" E "github.com/sagernet/sing/common/exceptions"
@@ -153,9 +154,9 @@ func (e *Endpoint) Start(resolve bool) error {
return nil return nil
} }
var bind conn.Bind var bind conn.Bind
wgListener, isWgListener := common.Cast[conn.Listener](e.options.Dialer) wgListener, isWgListener := common.Cast[dialer.WireGuardListener](e.options.Dialer)
if isWgListener { if isWgListener {
bind = conn.NewStdNetBind(wgListener) bind = conn.NewStdNetBind(wgListener.WireGuardControl())
} else { } else {
var ( var (
isConnect bool isConnect bool