File tree 1 file changed +13
-2
lines changed
1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package inbound
2
2
3
3
import (
4
4
"context"
5
+ "strings"
5
6
"sync"
6
7
"sync/atomic"
7
8
"time"
@@ -463,9 +464,19 @@ func (w *dsWorker) callback(conn stat.Connection) {
463
464
WriteCounter : w .downlinkCounter ,
464
465
}
465
466
}
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
+ }
466
478
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 ,
469
480
Gateway : net .UnixDestination (w .address ),
470
481
Tag : w .tag ,
471
482
Conn : conn ,
You can’t perform that action at this time.
0 commit comments