Просмотр исходного кода

Fix: in TCP dial, apply IPv6Synthesizer after resolving hostnames

Rod Hynes 8 лет назад
Родитель
Сommit
e4d0808e3a
2 измененных файлов с 17 добавлено и 24 удалено
  1. 0 24
      psiphon/TCPConn.go
  2. 17 0
      psiphon/TCPConn_bind.go

+ 0 - 24
psiphon/TCPConn.go

@@ -104,30 +104,6 @@ func interruptibleTCPDial(addr string, config *DialConfig) (*TCPConn, error) {
 	// when tcpDial, among other things, when makes a blocking syscall.Connect()
 	// when tcpDial, among other things, when makes a blocking syscall.Connect()
 	// call.
 	// call.
 	go func() {
 	go func() {
-		if config.IPv6Synthesizer != nil {
-			// Synthesize an IPv6 address from an IPv4 one
-			// This is for compatibility on DNS64/NAT64 networks
-			host, port, err := net.SplitHostPort(addr)
-			if err != nil {
-				select {
-				case conn.dialResult <- err:
-				default:
-				}
-				return
-			}
-			ip := net.ParseIP(host)
-			if ip != nil && ip.To4() != nil {
-				synthesizedAddr := config.IPv6Synthesizer.IPv6Synthesize(host)
-				// If IPv6Synthesize fails we will try dialing with the
-				// original IPv4 address instead of logging an error. If
-				// the address is unreachable an error will be emitted
-				// from tcpDial.
-				if synthesizedAddr != "" {
-					addr = net.JoinHostPort(synthesizedAddr, port)
-				}
-			}
-		}
-
 		var netConn net.Conn
 		var netConn net.Conn
 		var err error
 		var err error
 		if config.UpstreamProxyUrl != "" {
 		if config.UpstreamProxyUrl != "" {

+ 17 - 0
psiphon/TCPConn_bind.go

@@ -60,6 +60,23 @@ func tcpDial(addr string, config *DialConfig) (net.Conn, error) {
 		return nil, common.ContextError(errors.New("no IP address"))
 		return nil, common.ContextError(errors.New("no IP address"))
 	}
 	}
 
 
+	// When configured, attempt to synthesize IPv6 addresses from
+	// an IPv4 addresses for compatibility on DNS64/NAT64 networks.
+	// If synthesize fails, try the original addresses.
+	if config.IPv6Synthesizer != nil {
+		for i, ipAddr := range ipAddrs {
+			if ipAddr.To4() != nil {
+				synthesizedIPAddress := config.IPv6Synthesizer.IPv6Synthesize(ipAddr.String())
+				if synthesizedIPAddress != "" {
+					synthesizedAddr := net.ParseIP(synthesizedIPAddress)
+					if synthesizedAddr != nil {
+						ipAddrs[i] = synthesizedAddr
+					}
+				}
+			}
+		}
+	}
+
 	// Iterate over a pseudorandom permutation of the destination
 	// Iterate over a pseudorandom permutation of the destination
 	// IPs and attempt connections.
 	// IPs and attempt connections.
 	//
 	//