lib/relay: Correctly get IP from remote addr via proxy (fixes #3223)
Correctly handles addresses, and fixes one more panicing place. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3230
This commit is contained in:
committed by
Audrius Butkevicius
parent
a775dd2b79
commit
4970bd7f65
@@ -55,7 +55,7 @@ func GetInvitationFromRelay(uri *url.URL, id syncthingprotocol.DeviceID, certs [
|
|||||||
l.Debugln("Received invitation", msg, "via", conn.LocalAddr())
|
l.Debugln("Received invitation", msg, "via", conn.LocalAddr())
|
||||||
ip := net.IP(msg.Address)
|
ip := net.IP(msg.Address)
|
||||||
if len(ip) == 0 || ip.IsUnspecified() {
|
if len(ip) == 0 || ip.IsUnspecified() {
|
||||||
msg.Address = conn.RemoteAddr().(*net.TCPAddr).IP[:]
|
msg.Address = remoteIPBytes(conn)
|
||||||
}
|
}
|
||||||
return msg, nil
|
return msg, nil
|
||||||
default:
|
default:
|
||||||
@@ -144,3 +144,11 @@ func configForCerts(certs []tls.Certificate) *tls.Config {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func remoteIPBytes(conn net.Conn) []byte {
|
||||||
|
addr := conn.RemoteAddr().String()
|
||||||
|
if host, _, err := net.SplitHostPort(addr); err == nil {
|
||||||
|
addr = host
|
||||||
|
}
|
||||||
|
return net.ParseIP(addr)[:]
|
||||||
|
}
|
||||||
|
|||||||
@@ -122,8 +122,7 @@ func (c *staticClient) Serve() {
|
|||||||
case protocol.SessionInvitation:
|
case protocol.SessionInvitation:
|
||||||
ip := net.IP(msg.Address)
|
ip := net.IP(msg.Address)
|
||||||
if len(ip) == 0 || ip.IsUnspecified() {
|
if len(ip) == 0 || ip.IsUnspecified() {
|
||||||
ip := net.ParseIP(c.conn.RemoteAddr().String())
|
msg.Address = remoteIPBytes(c.conn)
|
||||||
msg.Address = ip[:]
|
|
||||||
}
|
}
|
||||||
c.invitations <- msg
|
c.invitations <- msg
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user