UDS: prevent crash when proxy udp (#3967)

* net: Prevent nil pointer err in NetAddr()

* Fix dsworker saddr problem
This commit is contained in:
风扇滑翔翼 2024-11-04 23:39:04 +08:00 committed by GitHub
parent ccc4b7b2cf
commit 057e6284b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 8 additions and 5 deletions

View file

@ -464,7 +464,8 @@ func (w *dsWorker) callback(conn stat.Connection) {
}
}
ctx = session.ContextWithInbound(ctx, &session.Inbound{
Source: net.DestinationFromAddr(conn.RemoteAddr()),
// Unix have no source addr, so we use gateway as source for log.
Source: net.UnixDestination(w.address),
Gateway: net.UnixDestination(w.address),
Tag: w.tag,
Conn: conn,

View file

@ -89,11 +89,13 @@ func UnixDestination(address Address) Destination {
// NetAddr returns the network address in this Destination in string form.
func (d Destination) NetAddr() string {
addr := ""
if d.Address != nil {
if d.Network == Network_TCP || d.Network == Network_UDP {
addr = d.Address.String() + ":" + d.Port.String()
} else if d.Network == Network_UNIX {
addr = d.Address.String()
}
}
return addr
}