From 69c2f8d6dbf2ba1608188ec1b4fb6685a8c12aba Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Sun, 20 Nov 2016 21:25:01 -0800 Subject: [PATCH] Fix bug in link-local unmarshalling Signed-off-by: Alessandro Boch --- libnetwork/endpoint_info.go | 6 +++--- libnetwork/libnetwork_internal_test.go | 21 ++++++++++++++++++++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/libnetwork/endpoint_info.go b/libnetwork/endpoint_info.go index 6814de0089..4e9592a56d 100644 --- a/libnetwork/endpoint_info.go +++ b/libnetwork/endpoint_info.go @@ -114,12 +114,12 @@ func (epi *endpointInterface) UnmarshalJSON(b []byte) error { } } if v, ok := epMap["llAddrs"]; ok { - list := v.([]string) + list := v.([]interface{}) epi.llAddrs = make([]*net.IPNet, 0, len(list)) for _, llS := range list { - ll, err := types.ParseCIDR(llS) + ll, err := types.ParseCIDR(llS.(string)) if err != nil { - return types.InternalErrorf("failed to decode endpoint interface link-local address (%s) after json unmarshal: %v", llS, err) + return types.InternalErrorf("failed to decode endpoint interface link-local address (%v) after json unmarshal: %v", llS, err) } epi.llAddrs = append(epi.llAddrs, ll) } diff --git a/libnetwork/libnetwork_internal_test.go b/libnetwork/libnetwork_internal_test.go index 8adee2a4d8..e4e90151f5 100644 --- a/libnetwork/libnetwork_internal_test.go +++ b/libnetwork/libnetwork_internal_test.go @@ -175,6 +175,12 @@ func TestEndpointMarshalling(t *testing.T) { } nw6.IP = ip + var lla []*net.IPNet + for _, nw := range []string{"169.254.0.1/16", "169.254.1.1/16", "169.254.2.2/16"} { + ll, _ := types.ParseCIDR(nw) + lla = append(lla, ll) + } + e := &endpoint{ name: "Bau", id: "efghijklmno", @@ -191,6 +197,7 @@ func TestEndpointMarshalling(t *testing.T) { dstPrefix: "eth", v4PoolID: "poolpool", v6PoolID: "poolv6", + llAddrs: lla, }, } @@ -218,7 +225,7 @@ func compareEndpointInterface(a, b *endpointInterface) bool { return false } return a.srcName == b.srcName && a.dstPrefix == b.dstPrefix && a.v4PoolID == b.v4PoolID && a.v6PoolID == b.v6PoolID && - types.CompareIPNet(a.addr, b.addr) && types.CompareIPNet(a.addrv6, b.addrv6) + types.CompareIPNet(a.addr, b.addr) && types.CompareIPNet(a.addrv6, b.addrv6) && compareNwLists(a.llAddrs, b.llAddrs) } func compareIpamConfList(listA, listB []*IpamConf) bool { @@ -285,6 +292,18 @@ func compareAddresses(a, b map[string]*net.IPNet) bool { return true } +func compareNwLists(a, b []*net.IPNet) bool { + if len(a) != len(b) { + return false + } + for k := range a { + if !types.CompareIPNet(a[k], b[k]) { + return false + } + } + return true +} + func TestAuxAddresses(t *testing.T) { c, err := New() if err != nil {