Explorar el Código

Fix name resolution for host names in config (#431)

Nathan Brown hace 4 años
padre
commit
1499be3e40
Se han modificado 2 ficheros con 14 adiciones y 8 borrados
  1. 4 6
      main.go
  2. 10 2
      udp_all.go

+ 4 - 6
main.go

@@ -299,19 +299,17 @@ func Main(config *Config, configTest bool, buildVersion string, logger *logrus.L
 		if ok {
 			for _, v := range vals {
 				ip, port, err := parseIPAndPort(fmt.Sprintf("%v", v))
-				if err == nil {
-					lightHouse.AddRemote(ip2int(vpnIp), NewUDPAddr(ip, port), true)
-				} else {
+				if err != nil {
 					return nil, NewContextualError("Static host address could not be parsed", m{"vpnIp": vpnIp}, err)
 				}
+				lightHouse.AddRemote(ip2int(vpnIp), NewUDPAddr(ip, port), true)
 			}
 		} else {
 			ip, port, err := parseIPAndPort(fmt.Sprintf("%v", v))
-			if err == nil {
-				lightHouse.AddRemote(ip2int(vpnIp), NewUDPAddr(ip, port), true)
-			} else {
+			if err != nil {
 				return nil, NewContextualError("Static host address could not be parsed", m{"vpnIp": vpnIp}, err)
 			}
+			lightHouse.AddRemote(ip2int(vpnIp), NewUDPAddr(ip, port), true)
 		}
 	}
 

+ 10 - 2
udp_all.go

@@ -56,7 +56,15 @@ func parseIPAndPort(s string) (net.IP, uint16, error) {
 		return nil, 0, err
 	}
 
+	addr, err := net.ResolveIPAddr("ip", rIp)
+	if err != nil {
+		return nil, 0, err
+	}
+
 	iPort, err := strconv.Atoi(sPort)
-	ip := net.ParseIP(rIp)
-	return ip, uint16(iPort), nil
+	if err != nil {
+		return nil, 0, err
+	}
+
+	return addr.IP, uint16(iPort), nil
 }