Fixed: gViosr func
This commit is contained in:
parent
65a289e16f
commit
6eab1f158a
2 changed files with 42 additions and 6 deletions
|
@ -1,10 +1,10 @@
|
||||||
//go:build !no_gvisor
|
|
||||||
|
|
||||||
package gvisor
|
package gvisor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Dreamacro/clash/common/pool"
|
||||||
"github.com/Dreamacro/clash/listener/tun/ipstack/gvisor/adapter"
|
"github.com/Dreamacro/clash/listener/tun/ipstack/gvisor/adapter"
|
||||||
"github.com/Dreamacro/clash/listener/tun/ipstack/gvisor/option"
|
"github.com/Dreamacro/clash/listener/tun/ipstack/gvisor/option"
|
||||||
"github.com/Dreamacro/clash/log"
|
"github.com/Dreamacro/clash/log"
|
||||||
|
@ -20,17 +20,17 @@ import (
|
||||||
const (
|
const (
|
||||||
// defaultWndSize if set to zero, the default
|
// defaultWndSize if set to zero, the default
|
||||||
// receive window buffer size is used instead.
|
// receive window buffer size is used instead.
|
||||||
defaultWndSize = 0
|
defaultWndSize = pool.RelayBufferSize
|
||||||
|
|
||||||
// maxConnAttempts specifies the maximum number
|
// maxConnAttempts specifies the maximum number
|
||||||
// of in-flight tcp connection attempts.
|
// of in-flight tcp connection attempts.
|
||||||
maxConnAttempts = 2 << 10
|
maxConnAttempts = 1 << 10
|
||||||
|
|
||||||
// tcpKeepaliveCount is the maximum number of
|
// tcpKeepaliveCount is the maximum number of
|
||||||
// TCP keep-alive probes to send before giving up
|
// TCP keep-alive probes to send before giving up
|
||||||
// and killing the connection if no response is
|
// and killing the connection if no response is
|
||||||
// obtained from the other end.
|
// obtained from the other end.
|
||||||
tcpKeepaliveCount = 9
|
tcpKeepaliveCount = 8
|
||||||
|
|
||||||
// tcpKeepaliveIdle specifies the time a connection
|
// tcpKeepaliveIdle specifies the time a connection
|
||||||
// must remain idle before the first TCP keepalive
|
// must remain idle before the first TCP keepalive
|
||||||
|
@ -66,18 +66,26 @@ func withTCPHandler(handle adapter.TCPHandleFunc) option.Option {
|
||||||
r.Complete(true)
|
r.Complete(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer r.Complete(false)
|
|
||||||
|
|
||||||
err = setSocketOptions(s, ep)
|
err = setSocketOptions(s, ep)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
ep.Close()
|
||||||
r.Complete(true)
|
r.Complete(true)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer r.Complete(false)
|
||||||
|
|
||||||
conn := &tcpConn{
|
conn := &tcpConn{
|
||||||
TCPConn: gonet.NewTCPConn(&wq, ep),
|
TCPConn: gonet.NewTCPConn(&wq, ep),
|
||||||
id: id,
|
id: id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conn.RemoteAddr() == nil {
|
||||||
|
log.Warnln("[STACK] endpoint is not connected, current state: %v", tcp.EndpointState(ep.State()))
|
||||||
|
_ = conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
handle(conn)
|
handle(conn)
|
||||||
})
|
})
|
||||||
s.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
|
s.SetTransportProtocolHandler(tcp.ProtocolNumber, tcpForwarder.HandlePacket)
|
||||||
|
@ -125,3 +133,17 @@ type tcpConn struct {
|
||||||
func (c *tcpConn) ID() *stack.TransportEndpointID {
|
func (c *tcpConn) ID() *stack.TransportEndpointID {
|
||||||
return &c.id
|
return &c.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *tcpConn) LocalAddr() net.Addr {
|
||||||
|
return &net.TCPAddr{
|
||||||
|
IP: net.IP(c.id.LocalAddress),
|
||||||
|
Port: int(c.id.LocalPort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *tcpConn) RemoteAddr() net.Addr {
|
||||||
|
return &net.TCPAddr{
|
||||||
|
IP: net.IP(c.id.RemoteAddress),
|
||||||
|
Port: int(c.id.RemotePort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -49,6 +49,20 @@ func (c *udpConn) ID() *stack.TransportEndpointID {
|
||||||
return &c.id
|
return &c.id
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *udpConn) LocalAddr() net.Addr {
|
||||||
|
return &net.UDPAddr{
|
||||||
|
IP: net.IP(c.id.LocalAddress),
|
||||||
|
Port: int(c.id.LocalPort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *udpConn) RemoteAddr() net.Addr {
|
||||||
|
return &net.UDPAddr{
|
||||||
|
IP: net.IP(c.id.RemoteAddress),
|
||||||
|
Port: int(c.id.RemotePort),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type packet struct {
|
type packet struct {
|
||||||
pc adapter.UDPConn
|
pc adapter.UDPConn
|
||||||
rAddr net.Addr
|
rAddr net.Addr
|
||||||
|
|
Loading…
Reference in a new issue