mirror of https://github.com/k3s-io/k3s
kubenet: Fix ipv4 validity check
The length of an IP can be 4 or 16, and even if 16 it can be a valid ipv4 address. This check is the more-correct way to handle this, and it also provides more granular error messages.pull/6/head
parent
93487867ac
commit
c83ad19ae9
|
@ -317,10 +317,14 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if res.IP4 == nil || len(res.IP4.IP.IP) != net.IPv4len {
|
||||
if res.IP4 == nil {
|
||||
return fmt.Errorf("CNI plugin reported no IPv4 address for container %v.", id)
|
||||
}
|
||||
plugin.podIPs[id] = res.IP4.IP.IP.String()
|
||||
ip4 := res.IP4.IP.IP.To4()
|
||||
if ip4 == nil {
|
||||
return fmt.Errorf("CNI plugin reported an invalid IPv4 address for container %v: %+v.", id, res.IP4)
|
||||
}
|
||||
plugin.podIPs[id] = ip4.String()
|
||||
|
||||
// Put the container bridge into promiscuous mode to force it to accept hairpin packets.
|
||||
// TODO: Remove this once the kernel bug (#20096) is fixed.
|
||||
|
|
Loading…
Reference in New Issue