Remove reserved

This commit is contained in:
Shtorm
2026-05-29 14:34:11 +03:00
parent 88f7f88f3f
commit 9f89dcf4e0
8 changed files with 23 additions and 62 deletions

2
go.mod
View File

@@ -211,7 +211,7 @@ require (
lukechampine.com/blake3 v1.4.1 lukechampine.com/blake3 v1.4.1
) )
replace github.com/sagernet/wireguard-go => github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.1 replace github.com/sagernet/wireguard-go => github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.2
replace github.com/sagernet/tailscale => github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2 replace github.com/sagernet/tailscale => github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2

4
go.sum
View File

@@ -385,8 +385,8 @@ github.com/shtorm-7/sing-mux v0.3.4-extended-1.0.0 h1:a5OoXr3e2ACbM6vDIaaGL44IdH
github.com/shtorm-7/sing-mux v0.3.4-extended-1.0.0/go.mod h1:QvlKMyNBNrQoyX4x+gq028uPbLM2XeRpWtDsWBJbFSk= github.com/shtorm-7/sing-mux v0.3.4-extended-1.0.0/go.mod h1:QvlKMyNBNrQoyX4x+gq028uPbLM2XeRpWtDsWBJbFSk=
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2 h1:hSMjh97OszszOd8HrzpaYUQH9dWRRBluJCbwQyz8ZOk= github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2 h1:hSMjh97OszszOd8HrzpaYUQH9dWRRBluJCbwQyz8ZOk=
github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2/go.mod h1:TYIIqO5sZpWq873rLIeO2usszSMUpR3h6WdqVVs65ug= github.com/shtorm-7/tailscale v1.92.4-sing-box-1.13-mod.7-extended-1.0.2/go.mod h1:TYIIqO5sZpWq873rLIeO2usszSMUpR3h6WdqVVs65ug=
github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.1 h1:SrDp4NPW6NHjCQSXDYmTYx4pqxvmqFt4DwdRk+odV3w= github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.2 h1:oEvk13VPsypigqNK/rlcqC63gTj0ANJAnzUwlZkOia4=
github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.1/go.mod h1:Me2JlCDYHxnd0mnuX7L5LXAeDHCltI7vSKq3eTE6SVE= github.com/shtorm-7/wireguard-go v0.0.2-beta.1-extended-1.4.2/go.mod h1:Me2JlCDYHxnd0mnuX7L5LXAeDHCltI7vSKq3eTE6SVE=
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8= github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8 h1:TG/diQgUe0pntT/2D9tmUCz4VNwm9MfrtPr0SU2qSX8=
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E= github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8/go.mod h1:P5HUIBuIWKbyjl083/loAegFkfbFNx5i2qEP4CNbm7E=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=

View File

@@ -30,7 +30,6 @@ type WireGuardPeer struct {
PreSharedKey string `json:"pre_shared_key,omitempty"` PreSharedKey string `json:"pre_shared_key,omitempty"`
AllowedIPs badoption.Listable[netip.Prefix] `json:"allowed_ips,omitempty"` AllowedIPs badoption.Listable[netip.Prefix] `json:"allowed_ips,omitempty"`
PersistentKeepaliveInterval uint16 `json:"persistent_keepalive_interval,omitempty"` PersistentKeepaliveInterval uint16 `json:"persistent_keepalive_interval,omitempty"`
Reserved []uint8 `json:"reserved,omitempty"`
} }
type WireGuardAmnezia struct { type WireGuardAmnezia struct {

View File

@@ -119,7 +119,6 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
netip.MustParsePrefix("::/0"), netip.MustParsePrefix("::/0"),
}, },
PersistentKeepaliveInterval: options.PersistentKeepaliveInterval, PersistentKeepaliveInterval: options.PersistentKeepaliveInterval,
Reserved: options.Reserved,
}, },
}, },
MTU: 1280, MTU: 1280,

View File

@@ -130,7 +130,6 @@ func NewEndpoint(ctx context.Context, router adapter.Router, logger log.ContextL
PreSharedKey: it.PreSharedKey, PreSharedKey: it.PreSharedKey,
AllowedIPs: it.AllowedIPs, AllowedIPs: it.AllowedIPs,
PersistentKeepaliveInterval: it.PersistentKeepaliveInterval, PersistentKeepaliveInterval: it.PersistentKeepaliveInterval,
Reserved: it.Reserved,
} }
}), }),
Workers: options.Workers, Workers: options.Workers,

View File

@@ -21,32 +21,28 @@ import (
var _ conn.Bind = (*ClientBind)(nil) var _ conn.Bind = (*ClientBind)(nil)
type ClientBind struct { type ClientBind struct {
ctx context.Context ctx context.Context
logger logger.Logger logger logger.Logger
pauseManager pause.Manager pauseManager pause.Manager
bindCtx context.Context bindCtx context.Context
bindDone context.CancelFunc bindDone context.CancelFunc
dialer N.Dialer dialer N.Dialer
reservedForEndpoint map[netip.AddrPort][3]uint8 connAccess sync.Mutex
connAccess sync.Mutex conn *wireConn
conn *wireConn done chan struct{}
done chan struct{} isConnect bool
isConnect bool connectAddr netip.AddrPort
connectAddr netip.AddrPort
reserved [3]uint8
} }
func NewClientBind(ctx context.Context, logger logger.Logger, dialer N.Dialer, isConnect bool, connectAddr netip.AddrPort, reserved [3]uint8) *ClientBind { func NewClientBind(ctx context.Context, logger logger.Logger, dialer N.Dialer, isConnect bool, connectAddr netip.AddrPort) *ClientBind {
return &ClientBind{ return &ClientBind{
ctx: ctx, ctx: ctx,
logger: logger, logger: logger,
pauseManager: service.FromContext[pause.Manager](ctx), pauseManager: service.FromContext[pause.Manager](ctx),
dialer: dialer, dialer: dialer,
reservedForEndpoint: make(map[netip.AddrPort][3]uint8), done: make(chan struct{}),
done: make(chan struct{}), isConnect: isConnect,
isConnect: isConnect, connectAddr: connectAddr,
connectAddr: connectAddr,
reserved: reserved,
} }
} }
@@ -134,10 +130,6 @@ func (c *ClientBind) receive(packets [][]byte, sizes []int, eps []conn.Endpoint)
return return
} }
sizes[0] = n sizes[0] = n
if n > 3 {
b := packets[0]
clear(b[1:4])
}
eps[0] = remoteEndpoint(M.SocksaddrFromNet(addr).Unwrap().AddrPort()) eps[0] = remoteEndpoint(M.SocksaddrFromNet(addr).Unwrap().AddrPort())
count = 1 count = 1
return return
@@ -174,13 +166,6 @@ func (c *ClientBind) Send(bufs [][]byte, ep conn.Endpoint, offset int) error {
if offset > 0 { if offset > 0 {
buf = buf[offset:] buf = buf[offset:]
} }
if len(buf) > 3 {
reserved, loaded := c.reservedForEndpoint[destination]
if !loaded {
reserved = c.reserved
}
copy(buf[1:4], reserved[:])
}
_, err = udpConn.WriteToUDPAddrPort(buf, destination) _, err = udpConn.WriteToUDPAddrPort(buf, destination)
if err != nil { if err != nil {
udpConn.Close() udpConn.Close()
@@ -202,10 +187,6 @@ func (c *ClientBind) BatchSize() int {
return 1 return 1
} }
func (c *ClientBind) SetReservedForEndpoint(destination netip.AddrPort, reserved [3]byte) {
c.reservedForEndpoint[destination] = reserved
}
type wireConn struct { type wireConn struct {
net.PacketConn net.PacketConn
conn net.Conn conn net.Conn

View File

@@ -82,12 +82,6 @@ func NewEndpoint(options EndpointOptions) (*Endpoint, error) {
if len(rawPeer.AllowedIPs) == 0 { if len(rawPeer.AllowedIPs) == 0 {
return nil, E.New("missing allowed ips for peer ", peerIndex) return nil, E.New("missing allowed ips for peer ", peerIndex)
} }
if len(rawPeer.Reserved) > 0 {
if len(rawPeer.Reserved) != 3 {
return nil, E.New("invalid reserved value for peer ", peerIndex, ", required 3 bytes, got ", len(peer.reserved))
}
copy(peer.reserved[:], rawPeer.Reserved[:])
}
peers = append(peers, peer) peers = append(peers, peer)
} }
var allowedPrefixBuilder netipx.IPSetBuilder var allowedPrefixBuilder netipx.IPSetBuilder
@@ -162,21 +156,12 @@ func (e *Endpoint) Start(resolve bool) error {
var ( var (
isConnect bool isConnect bool
connectAddr netip.AddrPort connectAddr netip.AddrPort
reserved [3]uint8
) )
if len(e.peers) == 1 && e.peers[0].endpoint.IsValid() { if len(e.peers) == 1 && e.peers[0].endpoint.IsValid() {
isConnect = true isConnect = true
connectAddr = e.peers[0].endpoint connectAddr = e.peers[0].endpoint
reserved = e.peers[0].reserved
}
bind = NewClientBind(e.options.Context, e.options.Logger, e.options.Dialer, isConnect, connectAddr, reserved)
}
if isWgListener || len(e.peers) > 1 {
for _, peer := range e.peers {
if peer.reserved != [3]uint8{} {
bind.SetReservedForEndpoint(peer.endpoint, peer.reserved)
}
} }
bind = NewClientBind(e.options.Context, e.options.Logger, e.options.Dialer, isConnect, connectAddr)
} }
err := e.tunDevice.Start() err := e.tunDevice.Start()
if err != nil { if err != nil {
@@ -336,7 +321,6 @@ type peerConfig struct {
preSharedKeyHex string preSharedKeyHex string
allowedIPs []netip.Prefix allowedIPs []netip.Prefix
keepalive uint16 keepalive uint16
reserved [3]uint8
} }
func (c peerConfig) GenerateIpcLines() string { func (c peerConfig) GenerateIpcLines() string {

View File

@@ -39,7 +39,6 @@ type PeerOptions struct {
PreSharedKey string PreSharedKey string
AllowedIPs []netip.Prefix AllowedIPs []netip.Prefix
PersistentKeepaliveInterval uint16 PersistentKeepaliveInterval uint16
Reserved []uint8
} }
type AmneziaOptions struct { type AmneziaOptions struct {