Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDS: Use UnixListenerWrapper & UnixConnWrapper #4413

Merged
merged 2 commits into from
Feb 19, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
UDS: Use UnixListenerWrapper & UnixConnWrapper
  • Loading branch information
RPRX authored Feb 19, 2025
commit 3aefe66cf7047042b84f5776b2bae91b6d43b44f
2 changes: 1 addition & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func UnwrapRawConn(conn net.Conn) (net.Conn, stats.Counter, stats.Counter) {
conn = pc.Raw()
// 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.UnixConn
}
}
Expand Down
20 changes: 10 additions & 10 deletions transport/internet/system_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
// 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.
type listenUDSWrapper struct {
net.Listener
type UnixListenerWrapper struct {
*net.UnixListener
locker *FileLocker
}

func (l *listenUDSWrapper) Accept() (net.Conn, error) {
conn, err := l.Listener.Accept()
func (l *UnixListenerWrapper) Accept() (net.Conn, error) {
conn, err := l.UnixListener.Accept()
if err != nil {
return nil, err
}
return &UDSWrapperConn{UnixConn: conn.(*net.UnixConn)}, nil
return &UnixConnWrapper{UnixConn: conn.(*net.UnixConn)}, nil
}

func (l *listenUDSWrapper) Close() error {
func (l *UnixListenerWrapper) Close() error {
if l.locker != nil {
l.locker.Release()
l.locker = nil
}
return l.Listener.Close()
return l.UnixListener.Close()
}

type UDSWrapperConn struct {
type UnixConnWrapper struct {
*net.UnixConn
}

func (conn *UDSWrapperConn) RemoteAddr() net.Addr {
func (conn *UnixConnWrapper) RemoteAddr() net.Addr {
return &net.TCPAddr{
IP: []byte{0, 0, 0, 0},
}
Expand Down Expand Up @@ -136,7 +136,7 @@ func (dl *DefaultListener) Listen(ctx context.Context, addr net.Addr, sockopt *S
locker.Release()
return nil, err
}
l = &listenUDSWrapper{Listener: l, locker: locker}
l = &UnixListenerWrapper{UnixListener: l.(*net.UnixListener), locker: locker}
if filePerm == nil {
return l, nil
}
Expand Down