diff --git a/adapter/inbound/http.go b/adapter/inbound/http.go index f7d45399fb..148f4e007c 100644 --- a/adapter/inbound/http.go +++ b/adapter/inbound/http.go @@ -12,8 +12,8 @@ func NewHTTP(target socks5.Addr, srcConn net.Conn, conn net.Conn, additions ...A metadata := parseSocksAddr(target) metadata.NetWork = C.TCP metadata.Type = C.HTTP - metadata.RawSrcAddr = srcConn.RemoteAddr() - metadata.RawDstAddr = srcConn.LocalAddr() + metadata.RawSrcAddr = srcConn.LocalAddr() + metadata.RawDstAddr = srcConn.RemoteAddr() ApplyAdditions(metadata, WithSrcAddr(srcConn.RemoteAddr()), WithInAddr(srcConn.LocalAddr())) ApplyAdditions(metadata, additions...) return conn, metadata diff --git a/adapter/inbound/https.go b/adapter/inbound/https.go index 55f6731a43..f38265c1c4 100644 --- a/adapter/inbound/https.go +++ b/adapter/inbound/https.go @@ -11,6 +11,8 @@ import ( func NewHTTPS(request *http.Request, conn net.Conn, additions ...Addition) (net.Conn, *C.Metadata) { metadata := parseHTTPAddr(request) metadata.Type = C.HTTPS + metadata.RawSrcAddr = conn.LocalAddr() + metadata.RawDstAddr = conn.RemoteAddr() ApplyAdditions(metadata, WithSrcAddr(conn.RemoteAddr()), WithInAddr(conn.LocalAddr())) ApplyAdditions(metadata, additions...) return conn, metadata diff --git a/listener/sing/sing.go b/listener/sing/sing.go index 10390e7326..0d4bb92657 100644 --- a/listener/sing/sing.go +++ b/listener/sing/sing.go @@ -129,6 +129,12 @@ func (h *ListenerHandler) NewConnection(ctx context.Context, conn net.Conn, meta NetWork: C.TCP, Type: h.Type, } + if metadata.Source.IsIP() && metadata.Source.Fqdn == "" { + cMetadata.RawSrcAddr = metadata.Source.Unwrap().TCPAddr() + } + if metadata.Destination.IsIP() && metadata.Destination.Fqdn == "" { + cMetadata.RawDstAddr = metadata.Destination.Unwrap().TCPAddr() + } inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(metadata.Destination), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr())) inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...) inbound.ApplyAdditions(cMetadata, h.Additions...) @@ -185,6 +191,12 @@ func (h *ListenerHandler) NewPacketConnection(ctx context.Context, conn network. NetWork: C.UDP, Type: h.Type, } + if metadata.Source.IsIP() && metadata.Source.Fqdn == "" { + cMetadata.RawSrcAddr = metadata.Source.Unwrap().UDPAddr() + } + if dest.IsIP() && dest.Fqdn == "" { + cMetadata.RawDstAddr = dest.Unwrap().UDPAddr() + } inbound.ApplyAdditions(cMetadata, inbound.WithDstAddr(dest), inbound.WithSrcAddr(metadata.Source), inbound.WithInAddr(conn.LocalAddr())) inbound.ApplyAdditions(cMetadata, getAdditions(ctx)...) inbound.ApplyAdditions(cMetadata, h.Additions...)