Track proxy addr and real peer addr in SOCKS mode

This commit is contained in:
Neil Alexander 2020-05-09 10:53:58 +01:00
parent fbf59184ee
commit 58345ac198
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

@ -61,6 +61,7 @@ type tcpOptions struct {
linkOptions linkOptions
upgrade *TcpUpgrade upgrade *TcpUpgrade
socksProxyAddr string socksProxyAddr string
socksPeerAddr string
} }
func (l *TcpListener) Stop() { func (l *TcpListener) Stop() {
@ -290,6 +291,7 @@ func (t *tcp) call(saddr string, options tcpOptions, sintf string) {
return return
} }
t.waitgroup.Add(1) t.waitgroup.Add(1)
options.socksPeerAddr = saddr
t.handler(conn, false, options) t.handler(conn, false, options)
} else { } else {
dst, err := net.ResolveTCPAddr("tcp", saddr) dst, err := net.ResolveTCPAddr("tcp", saddr)
@ -379,10 +381,10 @@ func (t *tcp) handler(sock net.Conn, incoming bool, options tcpOptions) {
stream.init(sock) stream.init(sock)
var name, proto, local, remote string var name, proto, local, remote string
if options.socksProxyAddr != "" { if options.socksProxyAddr != "" {
name = "socks://" + sock.RemoteAddr().String() + "/" + options.socksProxyAddr name = "socks://" + sock.RemoteAddr().String() + "/" + options.socksPeerAddr
proto = "socks" proto = "socks"
local, _, _ = net.SplitHostPort(sock.LocalAddr().String()) local, _, _ = net.SplitHostPort(sock.LocalAddr().String())
remote, _, _ = net.SplitHostPort(options.socksProxyAddr) remote, _, _ = net.SplitHostPort(options.socksPeerAddr)
} else { } else {
if upgraded { if upgraded {
proto = options.upgrade.name proto = options.upgrade.name