mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-12-01 14:18:36 +00:00
Fix network namespace with TCP Fast Open
This commit is contained in:
@@ -284,9 +284,9 @@ func (d *DefaultDialer) DialContext(ctx context.Context, network string, address
|
||||
}
|
||||
}
|
||||
if !address.IsIPv6() {
|
||||
return DialSlowContext(&d.dialer4, ctx, network, address)
|
||||
return DialSlowContext(&d.dialer4, ctx, d.netns, network, address)
|
||||
} else {
|
||||
return DialSlowContext(&d.dialer6, ctx, network, address)
|
||||
return DialSlowContext(&d.dialer6, ctx, d.netns, network, address)
|
||||
}
|
||||
})
|
||||
return d.trackConn(ctx, address, conn, err)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/common/listener"
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
@@ -21,6 +22,7 @@ type slowOpenConn struct {
|
||||
dialer *tfo.Dialer
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
netns string
|
||||
network string
|
||||
destination M.Socksaddr
|
||||
conn atomic.Pointer[net.TCPConn]
|
||||
@@ -31,7 +33,7 @@ type slowOpenConn struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, netns string, network string, destination M.Socksaddr) (net.Conn, error) {
|
||||
if dialer.DisableTFO || N.NetworkName(network) != N.NetworkTCP {
|
||||
switch N.NetworkName(network) {
|
||||
case N.NetworkTCP, N.NetworkUDP:
|
||||
@@ -45,6 +47,7 @@ func DialSlowContext(dialer *tfo.Dialer, ctx context.Context, network string, de
|
||||
dialer: dialer,
|
||||
ctx: dialCtx,
|
||||
cancel: cancel,
|
||||
netns: netns,
|
||||
network: network,
|
||||
destination: destination,
|
||||
create: make(chan struct{}),
|
||||
@@ -85,7 +88,9 @@ func (c *slowOpenConn) Write(b []byte) (n int, err error) {
|
||||
return 0, os.ErrClosed
|
||||
default:
|
||||
}
|
||||
conn, err := c.dialer.DialContext(c.ctx, c.network, c.destination.String(), b)
|
||||
conn, err := listener.ListenNetworkNamespace[net.Conn](c.ctx, c.netns, func() (net.Conn, error) {
|
||||
return c.dialer.DialContext(c.ctx, c.network, c.destination.String(), b)
|
||||
})
|
||||
if err != nil {
|
||||
c.err = err
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user