From bf1f1c28da201cc89c9adf762375c48641ca0c98 Mon Sep 17 00:00:00 2001 From: carlory Date: Mon, 5 Feb 2018 11:28:47 +0800 Subject: [PATCH 1/3] fix no valid addresses caused by lack of ip's version --- pkg/hns/endpoint_windows.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/hns/endpoint_windows.go b/pkg/hns/endpoint_windows.go index 76c482178..980dfcb7c 100644 --- a/pkg/hns/endpoint_windows.go +++ b/pkg/hns/endpoint_windows.go @@ -17,11 +17,13 @@ package hns import ( - "github.com/Microsoft/hcsshim" - "github.com/containernetworking/cni/pkg/types/current" + "fmt" "log" "net" "strings" + + "github.com/Microsoft/hcsshim" + "github.com/containernetworking/cni/pkg/types/current" ) // ConstructEndpointName constructs enpointId which is used to identify an endpoint from HNS @@ -123,7 +125,17 @@ func ConstructResult(hnsNetwork *hcsshim.HNSNetwork, hnsEndpoint *hcsshim.HNSEnd return nil, err } + var ipVersion string + if ipv4 := hnsEndpoint.IPAddress.To4(); ipv4 != nil { + ipVersion = "4" + } else if ipv6 := hnsEndpoint.Address.To16(); ipv6 != nil { + ipVersion = "6" + } else { + return nil, fmt.Errorf("the Address of hnsEndpoint isn't a valid ipv4 or ipv6 Address.") + } + resultIPConfig := ¤t.IPConfig{ + Version: ipVersion, Address: net.IPNet{ IP: hnsEndpoint.IPAddress, Mask: ipSubnet.Mask}, From e94fdb726be6013bb26291e9524ebd4597e2ac08 Mon Sep 17 00:00:00 2001 From: carlory Date: Mon, 5 Feb 2018 11:35:44 +0800 Subject: [PATCH 2/3] fix nit --- pkg/hns/endpoint_windows.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/hns/endpoint_windows.go b/pkg/hns/endpoint_windows.go index 980dfcb7c..dc725bff2 100644 --- a/pkg/hns/endpoint_windows.go +++ b/pkg/hns/endpoint_windows.go @@ -128,10 +128,10 @@ func ConstructResult(hnsNetwork *hcsshim.HNSNetwork, hnsEndpoint *hcsshim.HNSEnd var ipVersion string if ipv4 := hnsEndpoint.IPAddress.To4(); ipv4 != nil { ipVersion = "4" - } else if ipv6 := hnsEndpoint.Address.To16(); ipv6 != nil { + } else if ipv6 := hnsEndpoint.IPAddress.To16(); ipv6 != nil { ipVersion = "6" } else { - return nil, fmt.Errorf("the Address of hnsEndpoint isn't a valid ipv4 or ipv6 Address.") + return nil, fmt.Errorf("the IPAddress of hnsEndpoint isn't a valid ipv4 or ipv6 Address.") } resultIPConfig := ¤t.IPConfig{ From 0c36c117b101b5c42c504dfe812ef69950bfb78c Mon Sep 17 00:00:00 2001 From: carlory Date: Tue, 6 Feb 2018 10:55:32 +0800 Subject: [PATCH 3/3] fmt err --- pkg/hns/endpoint_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/hns/endpoint_windows.go b/pkg/hns/endpoint_windows.go index dc725bff2..e20637406 100644 --- a/pkg/hns/endpoint_windows.go +++ b/pkg/hns/endpoint_windows.go @@ -131,7 +131,7 @@ func ConstructResult(hnsNetwork *hcsshim.HNSNetwork, hnsEndpoint *hcsshim.HNSEnd } else if ipv6 := hnsEndpoint.IPAddress.To16(); ipv6 != nil { ipVersion = "6" } else { - return nil, fmt.Errorf("the IPAddress of hnsEndpoint isn't a valid ipv4 or ipv6 Address.") + return nil, fmt.Errorf("[win-cni] The IPAddress of hnsEndpoint isn't a valid ipv4 or ipv6 Address.") } resultIPConfig := ¤t.IPConfig{