Skip to content

Commit de5ca68

Browse files
authoredMar 6, 2017
Merge pull request moby#30807 from chchliang/networkproject
Check parameter --ip --ip6 --link-local-ip in `docker network connect`
2 parents a2bf823 + b7ce6ce commit de5ca68

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed
 

‎container/container.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,32 @@ func (container *Container) BuildCreateEndpointOptions(n libnetwork.Network, epC
667667

668668
if epConfig != nil {
669669
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+
672677
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)
675680
}
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)
676687
}
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+
677693
createOptions = append(createOptions,
678-
libnetwork.CreateOptionIpam(net.ParseIP(ipam.IPv4Address), net.ParseIP(ipam.IPv6Address), ipList, nil))
694+
libnetwork.CreateOptionIpam(ip, ip6, ipList, nil))
695+
679696
}
680697

681698
for _, alias := range epConfig.Aliases {

0 commit comments

Comments
 (0)
Please sign in to comment.