Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in link-local unmarshalling #1564

Merged
merged 1 commit into from
Nov 21, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions endpoint_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
21 changes: 20 additions & 1 deletion libnetwork_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -191,6 +197,7 @@ func TestEndpointMarshalling(t *testing.T) {
dstPrefix: "eth",
v4PoolID: "poolpool",
v6PoolID: "poolv6",
llAddrs: lla,
},
}

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down