1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Merge pull request #1564 from aboch/ll

Fix bug in link-local unmarshalling
This commit is contained in:
Madhu Venugopal 2016-11-21 11:29:06 -08:00 committed by GitHub
commit afcec80137
2 changed files with 23 additions and 4 deletions

View file

@ -114,12 +114,12 @@ func (epi *endpointInterface) UnmarshalJSON(b []byte) error {
} }
} }
if v, ok := epMap["llAddrs"]; ok { if v, ok := epMap["llAddrs"]; ok {
list := v.([]string) list := v.([]interface{})
epi.llAddrs = make([]*net.IPNet, 0, len(list)) epi.llAddrs = make([]*net.IPNet, 0, len(list))
for _, llS := range list { for _, llS := range list {
ll, err := types.ParseCIDR(llS) ll, err := types.ParseCIDR(llS.(string))
if err != nil { 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) epi.llAddrs = append(epi.llAddrs, ll)
} }

View file

@ -175,6 +175,12 @@ func TestEndpointMarshalling(t *testing.T) {
} }
nw6.IP = ip 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{ e := &endpoint{
name: "Bau", name: "Bau",
id: "efghijklmno", id: "efghijklmno",
@ -191,6 +197,7 @@ func TestEndpointMarshalling(t *testing.T) {
dstPrefix: "eth", dstPrefix: "eth",
v4PoolID: "poolpool", v4PoolID: "poolpool",
v6PoolID: "poolv6", v6PoolID: "poolv6",
llAddrs: lla,
}, },
} }
@ -218,7 +225,7 @@ func compareEndpointInterface(a, b *endpointInterface) bool {
return false return false
} }
return a.srcName == b.srcName && a.dstPrefix == b.dstPrefix && a.v4PoolID == b.v4PoolID && a.v6PoolID == b.v6PoolID && 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 { func compareIpamConfList(listA, listB []*IpamConf) bool {
@ -285,6 +292,18 @@ func compareAddresses(a, b map[string]*net.IPNet) bool {
return true 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) { func TestAuxAddresses(t *testing.T) {
c, err := New() c, err := New()
if err != nil { if err != nil {