Skip to content

Commit 3a7a78f

Browse files
authored
UDS: Keep valid source addr (#4325)
Fixes #4324
1 parent 5679d71 commit 3a7a78f

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

app/proxyman/inbound/worker.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package inbound
22

33
import (
44
"context"
5+
"strings"
56
"sync"
67
"sync/atomic"
78
"time"
@@ -463,9 +464,19 @@ func (w *dsWorker) callback(conn stat.Connection) {
463464
WriteCounter: w.downlinkCounter,
464465
}
465466
}
467+
// For most of time, unix obviously have no source addr. But if we leave it empty, it will cause panic.
468+
// So we use gateway as source for log.
469+
// However, there are some special situations where a valid source address might be available.
470+
// Such as the source address parsed from X-Forwarded-For in websocket.
471+
// In that case, we keep it.
472+
var source net.Destination
473+
if !strings.Contains(conn.RemoteAddr().String(), "unix") {
474+
source = net.DestinationFromAddr(conn.RemoteAddr())
475+
} else {
476+
source = net.UnixDestination(w.address)
477+
}
466478
ctx = session.ContextWithInbound(ctx, &session.Inbound{
467-
// Unix have no source addr, so we use gateway as source for log.
468-
Source: net.UnixDestination(w.address),
479+
Source: source,
469480
Gateway: net.UnixDestination(w.address),
470481
Tag: w.tag,
471482
Conn: conn,

0 commit comments

Comments
 (0)