2015-02-27 12:11:53 -05:00
|
|
|
package bridge
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"io/ioutil"
|
|
|
|
"testing"
|
|
|
|
|
2015-04-13 14:40:42 -04:00
|
|
|
"github.com/docker/libnetwork/netutils"
|
2015-02-27 12:11:53 -05:00
|
|
|
"github.com/vishvananda/netlink"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestSetupIPv6(t *testing.T) {
|
2015-04-13 14:40:42 -04:00
|
|
|
defer netutils.SetupTestNetNS(t)()
|
2015-02-27 12:11:53 -05:00
|
|
|
|
2015-04-15 01:25:42 -04:00
|
|
|
config, br := setupTestInterface(t)
|
|
|
|
if err := setupBridgeIPv6(config, br); err != nil {
|
2015-02-27 12:11:53 -05:00
|
|
|
t.Fatalf("Failed to setup bridge IPv6: %v", err)
|
|
|
|
}
|
|
|
|
|
2015-04-15 01:25:42 -04:00
|
|
|
procSetting, err := ioutil.ReadFile(fmt.Sprintf("/proc/sys/net/ipv6/conf/%s/disable_ipv6", config.BridgeName))
|
2015-02-27 12:11:53 -05:00
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to read disable_ipv6 kernel setting: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if expected := []byte("0\n"); bytes.Compare(expected, procSetting) != 0 {
|
|
|
|
t.Fatalf("Invalid kernel setting disable_ipv6: expected %q, got %q", string(expected), string(procSetting))
|
|
|
|
}
|
|
|
|
|
|
|
|
addrsv6, err := netlink.AddrList(br.Link, netlink.FAMILY_V6)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("Failed to list device IPv6 addresses: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var found bool
|
|
|
|
for _, addr := range addrsv6 {
|
2015-03-04 16:25:43 -05:00
|
|
|
if bridgeIPv6Str == addr.IPNet.String() {
|
2015-02-27 12:11:53 -05:00
|
|
|
found = true
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !found {
|
2015-03-04 16:25:43 -05:00
|
|
|
t.Fatalf("Bridge device does not have requested IPv6 address %v", bridgeIPv6Str)
|
2015-02-27 12:11:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|