Skip to content

Commit

Permalink
Fixes moby#13211 linkLocalIPv6FromMac
Browse files Browse the repository at this point in the history
Kudos to gissehel for his great work on investigation and the fabulous bug report!

Signed-off-by: Malte Janduda <mail@janduda.net>
  • Loading branch information
MalteJ committed May 14, 2015
1 parent b2ad931 commit f09b789
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
7 changes: 6 additions & 1 deletion daemon/networkdriver/bridge/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,12 @@ func linkLocalIPv6FromMac(mac string) (string, error) {

hw[0] ^= 0x2

return fmt.Sprintf("fe80::%x%x:%xff:fe%x:%x%x/64", hw[0], hw[1], hw[2], hw[3], hw[4], hw[5]), nil
return fmt.Sprintf("fe80::%x:%x:%x:%x/64",
0x100*int(hw[0])+int(hw[1]),
0x100*int(hw[2])+0xff,
0xFE00+int(hw[3]),
0x100*int(hw[4])+int(hw[5])),
nil
}

// Allocate a network interface
Expand Down
26 changes: 26 additions & 0 deletions daemon/networkdriver/bridge/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,32 @@ func TestIPv6InterfaceAllocationRequest(t *testing.T) {
_ = newInterfaceAllocation(t, subnet, "", "", expectedIP, true)
}

func TestIPv6LinkLocalIPv6FromMac(t *testing.T) {
hw1 := "02:42:ac:11:00:12"
expectedIpv6Addr1 := "fe80::42:acff:fe11:12/64"

hw2 := "02:42:ac:11:01:02"
expectedIpv6Addr2 := "fe80::42:acff:fe11:102/64"

ipv6Addr1, err := linkLocalIPv6FromMac(hw1)
if err != nil {
t.Fatalf("Could not build IPv6 address from MAC address %s", hw1)
}

ipv6Addr2, err := linkLocalIPv6FromMac(hw2)
if err != nil {
t.Fatalf("Could not build IPv6 address from MAC address %s", hw2)
}

if ipv6Addr1 != expectedIpv6Addr1 {
t.Fatalf("MAC address %s results in link local IPv6 address %s - should be %s", hw1, ipv6Addr1, expectedIpv6Addr1)
}

if ipv6Addr2 != expectedIpv6Addr2 {
t.Fatalf("MAC address %s results in link local IPv6 address %s - should be %s", hw2, ipv6Addr2, expectedIpv6Addr2)
}
}

func TestMacAddrGeneration(t *testing.T) {
ip := net.ParseIP("192.168.0.1")
mac := generateMacAddr(ip).String()
Expand Down

0 comments on commit f09b789

Please sign in to comment.