From c83ad19ae920dc6b3a97e26c4b99fb3b0c19e87e Mon Sep 17 00:00:00 2001 From: Euan Kemp Date: Fri, 27 May 2016 16:25:14 -0700 Subject: [PATCH] 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. --- pkg/kubelet/network/kubenet/kubenet_linux.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/kubelet/network/kubenet/kubenet_linux.go b/pkg/kubelet/network/kubenet/kubenet_linux.go index 9ff155b2df8..db22b3afd7b 100644 --- a/pkg/kubelet/network/kubenet/kubenet_linux.go +++ b/pkg/kubelet/network/kubenet/kubenet_linux.go @@ -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.