Browse code

Check parameter --ip --ip6 --link-local-ip in

Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>

chchliang authored on 2017/02/08 11:14:11
Showing 1 changed files
... ...
@@ -667,15 +667,32 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
667 667
 
668 668
 	if epConfig != nil {
669 669
 		ipam := epConfig.IPAMConfig
670
-		if ipam != nil && (ipam.IPv4Address != "" || ipam.IPv6Address != "" || len(ipam.LinkLocalIPs) > 0) {
671
-			var ipList []net.IP
670
+
671
+		if ipam != nil {
672
+			var (
673
+				ipList          []net.IP
674
+				ip, ip6, linkip net.IP
675
+			)
676
+
672 677
 			for _, ips := range ipam.LinkLocalIPs {
673
-				if ip := net.ParseIP(ips); ip != nil {
674
-					ipList = append(ipList, ip)
678
+				if linkip = net.ParseIP(ips); linkip == nil && ips != "" {
679
+					return nil, fmt.Errorf("Invalid link-local IP address:%s", ipam.LinkLocalIPs)
675 680
 				}
681
+				ipList = append(ipList, linkip)
682
+
683
+			}
684
+
685
+			if ip = net.ParseIP(ipam.IPv4Address); ip == nil && ipam.IPv4Address != "" {
686
+				return nil, fmt.Errorf("Invalid IPv4 address:%s)", ipam.IPv4Address)
676 687
 			}
688
+
689
+			if ip6 = net.ParseIP(ipam.IPv6Address); ip6 == nil && ipam.IPv6Address != "" {
690
+				return nil, fmt.Errorf("Invalid IPv6 address:%s)", ipam.IPv6Address)
691
+			}
692
+
677 693
 			createOptions = append(createOptions,
678
-				libnetwork.CreateOptionIpam(net.ParseIP(ipam.IPv4Address), net.ParseIP(ipam.IPv6Address), ipList, nil))
694
+				libnetwork.CreateOptionIpam(ip, ip6, ipList, nil))
695
+
679 696
 		}
680 697
 
681 698
 		for _, alias := range epConfig.Aliases {