New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check parameter --ip --ip6 --link-local-ip in docker network connect
#30807
Conversation
e8f8072
to
5a3fd12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this makes sense. |
container/container.go
Outdated
for _, ips := range ipam.LinkLocalIPs { | ||
if ip := net.ParseIP(ips); ip != nil { | ||
ipList = append(ipList, ip) | ||
if len(ipam.LinkLocalIPs) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You do not need to check the length of the list.
container/container.go
Outdated
if len(ipam.LinkLocalIPs) > 0 { | ||
for _, ips := range ipam.LinkLocalIPs { | ||
if ip := net.ParseIP(ips); ip != nil { | ||
ipList = append(ipList, ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
perhaps continue
here, instead of else
?
container/container.go
Outdated
} | ||
} | ||
if ipam.IPv4Address != "" { | ||
|
||
if ip := net.ParseIP(ipam.IPv4Address); ip == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given we are parsing again later for
libnetwork.CreateOptionIpam(net.ParseIP(ipam.IPv4Address), net.ParseIP(ipam.IPv6Address), ipList, nil))
I think we should define var ip, ip6 net.IP
and change these to
if ip6 = net.ParseIP(ipam.IPv6Address); ip == nil && ipam.IPv6Address != "" {
return nil, fmt.Errorf("Error parsing parameter ip value(%s)", ipam.IPv6Address)
}
and later change to
`libnetwork.CreateOptionIpam(ip, ip6, ipList, nil))`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aboch Has been modified,thank you!
e780226
to
d69cb1e
Compare
container/container.go
Outdated
var ipList []net.IP | ||
var ip, ip6 net.IP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please create a var block
container/container.go
Outdated
for _, ips := range ipam.LinkLocalIPs { | ||
if ip := net.ParseIP(ips); ip != nil { | ||
ipList = append(ipList, ip) | ||
if linkip := net.ParseIP(ips); linkip == nil && ips != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you also add a llIP
to the above var block, you can improve readability here dropping the else block
if llIP = net.ParseIP(ips); linkip == nil && ips != "" {
return nil, fmt.Errorf("Error....)
}
ipList = append(ipList, llIP)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have refactoring code,thank you! @aboch
d69cb1e
to
40a4457
Compare
container/container.go
Outdated
} | ||
|
||
if ip = net.ParseIP(ipam.IPv4Address); ip == nil && ipam.IPv4Address != "" { | ||
return nil, fmt.Errorf("Error parsing parameter ip value(%s)", ipam.IPv4Address) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to conform these errors to the errors docker already returns for invalid IP on docker run
As an example, I see
invalid IPv4 address: 3.3.3.333
invalid IPv6 address: 2001:db8:12345678::1
container/container.go
Outdated
var ipList []net.IP | ||
var ip, ip6, linkip net.IP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
container/container.go
Outdated
if ip := net.ParseIP(ips); ip != nil { | ||
ipList = append(ipList, ip) | ||
if linkip = net.ParseIP(ips); linkip == nil && ips != "" { | ||
return nil, fmt.Errorf("Error parsing parameter link-local-ip value(%s):%s", ipam.LinkLocalIPs, ips) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so here we should probably return
invalid link-local IP address: ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @aboch
I have modified
Signed-off-by: chchliang <chen.chuanliang@zte.com.cn>
40a4457
to
b7ce6ce
Compare
Looks good to me. |
LGTM |
LGTM 💃 |
Signed-off-by: chchliang chen.chuanliang@zte.com.cn
- What I did
Execute
docker network connect --ip=aa network1 xxx
but successful,i think ip address invalid,should be failure. like --ip6 --link-local-ip- How I did it
To add check code in container/container.go
if epConfig != nil {
ipam := epConfig.IPAMConfig
*- How to verify it
docker network connect --ip=aa network1 59bb1359f671
Error response from daemon: Invalid IPv4 address:aa