mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-02-22 16:50:43 +00:00
UDS: Use UnixListenerWrapper & UnixConnWrapper (#4413)
Fixes https://github.com/XTLS/Xray-core/issues/4411 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
parent
52381a3c03
commit
b38a53e629
@ -547,8 +547,8 @@ func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) {
|
|||||||
conn = pc.Raw()
|
conn = pc.Raw()
|
||||||
// 8192 > 4096, there is no need to process pc's bufReader
|
// 8192 > 4096, there is no need to process pc's bufReader
|
||||||
}
|
}
|
||||||
if uc, ok := conn.(*internet.UDSWrapperConn); ok {
|
if uc, ok := conn.(*internet.UnixConnWrapper); ok {
|
||||||
conn = uc.Conn
|
conn = uc.UnixConn
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return conn, readCounter, writerCounter
|
return conn, readCounter, writerCounter
|
||||||
|
@ -44,32 +44,32 @@ func getControlFunc(ctx context.Context, sockopt *SocketConfig, controllers []co
|
|||||||
// For some reason, other component of ray will assume the listener is a TCP listener and have valid remote address.
|
// For some reason, other component of ray will assume the listener is a TCP listener and have valid remote address.
|
||||||
// But in fact it doesn't. So we need to wrap the listener to make it return 0.0.0.0(unspecified) as remote address.
|
// But in fact it doesn't. So we need to wrap the listener to make it return 0.0.0.0(unspecified) as remote address.
|
||||||
// If other issues encountered, we should able to fix it here.
|
// If other issues encountered, we should able to fix it here.
|
||||||
type listenUDSWrapper struct {
|
type UnixListenerWrapper struct {
|
||||||
net.Listener
|
*net.UnixListener
|
||||||
locker *FileLocker
|
locker *FileLocker
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listenUDSWrapper) Accept() (net.Conn, error) {
|
func (l *UnixListenerWrapper) Accept() (net.Conn, error) {
|
||||||
conn, err := l.Listener.Accept()
|
conn, err := l.UnixListener.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &UDSWrapperConn{Conn: conn}, nil
|
return &UnixConnWrapper{UnixConn: conn.(*net.UnixConn)}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *listenUDSWrapper) Close() error {
|
func (l *UnixListenerWrapper) Close() error {
|
||||||
if l.locker != nil {
|
if l.locker != nil {
|
||||||
l.locker.Release()
|
l.locker.Release()
|
||||||
l.locker = nil
|
l.locker = nil
|
||||||
}
|
}
|
||||||
return l.Listener.Close()
|
return l.UnixListener.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
type UDSWrapperConn struct {
|
type UnixConnWrapper struct {
|
||||||
net.Conn
|
*net.UnixConn
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conn *UDSWrapperConn) RemoteAddr() net.Addr {
|
func (conn *UnixConnWrapper) RemoteAddr() net.Addr {
|
||||||
return &net.TCPAddr{
|
return &net.TCPAddr{
|
||||||
IP: []byte{0, 0, 0, 0},
|
IP: []byte{0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
|
|||||||
locker.Release()
|
locker.Release()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
l = &listenUDSWrapper{Listener: l, locker: locker}
|
l = &UnixListenerWrapper{UnixListener: l.(*net.UnixListener), locker: locker}
|
||||||
if filePerm == nil {
|
if filePerm == nil {
|
||||||
return l, nil
|
return l, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user