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
Euan Kemp 2016-05-27 16:25:14 -07:00
parent 93487867ac
commit c83ad19ae9
1 changed files with 6 additions and 2 deletions

View File

@ -317,10 +317,14 @@ func (plugin *kubenetNetworkPlugin) SetUpPod(namespace string, name string, id k
if err != nil { if err != nil {
return err 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) 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. // Put the container bridge into promiscuous mode to force it to accept hairpin packets.
// TODO: Remove this once the kernel bug (#20096) is fixed. // TODO: Remove this once the kernel bug (#20096) is fixed.