Browse code

Bridge driver to honor IPv6 network gateway

- Currently bridge driver discards the user specified
network gateway for IPv6

Signed-off-by: Alessandro Boch <aboch@docker.com>

Alessandro Boch authored on 2015/12/16 02:52:03
Showing 2 changed files
... ...
@@ -62,6 +62,13 @@ func setupBridgeIPv6(config *networkConfiguration, i *bridgeInterface) error {
62 62
 		return nil
63 63
 	}
64 64
 
65
+	// Store and program user specified bridge network and network gateway
66
+	i.bridgeIPv6 = config.AddressIPv6
67
+	i.gatewayIPv6 = config.AddressIPv6.IP
68
+	if err := netlink.AddrAdd(i.Link, &netlink.Addr{IPNet: i.bridgeIPv6}); err != nil {
69
+		return &IPv6AddrAddError{IP: i.bridgeIPv6, Err: err}
70
+	}
71
+
65 72
 	// Setting route to global IPv6 subnet
66 73
 	logrus.Debugf("Adding route to IPv6 network %s via device %s", config.AddressIPv6.String(), config.BridgeName)
67 74
 	err = netlink.RouteAdd(&netlink.Route{
... ...
@@ -1005,11 +1005,19 @@ func TestEndpointJoin(t *testing.T) {
1005 1005
 	}
1006 1006
 
1007 1007
 	// Create network 1 and add 2 endpoint: ep11, ep12
1008
-	n1, err := createTestNetwork(bridgeNetType, "testnetwork1", options.Generic{
1008
+	netOption := options.Generic{
1009 1009
 		netlabel.GenericData: options.Generic{
1010
-			"BridgeName": "testnetwork1",
1010
+			"BridgeName":         "testnetwork1",
1011
+			"EnableIPv6":         true,
1012
+			"EnableICC":          true,
1013
+			"EnableIPMasquerade": true,
1011 1014
 		},
1012
-	}, nil, nil)
1015
+	}
1016
+	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe90::/64", Gateway: "fe90::22"}}
1017
+	n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1",
1018
+		libnetwork.NetworkOptionGeneric(netOption),
1019
+		libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, ipamV6ConfList),
1020
+		libnetwork.NetworkOptionDeferIPv6Alloc(true))
1013 1021
 	if err != nil {
1014 1022
 		t.Fatal(err)
1015 1023
 	}
... ...
@@ -1035,10 +1043,16 @@ func TestEndpointJoin(t *testing.T) {
1035 1035
 	if iface.Address() != nil && iface.Address().IP.To4() == nil {
1036 1036
 		t.Fatalf("Invalid IP address returned: %v", iface.Address())
1037 1037
 	}
1038
+	if iface.AddressIPv6() != nil && iface.AddressIPv6().IP == nil {
1039
+		t.Fatalf("Invalid IPv6 address returned: %v", iface.Address())
1040
+	}
1038 1041
 
1039
-	if info.Gateway().To4() != nil {
1042
+	if len(info.Gateway()) != 0 {
1040 1043
 		t.Fatalf("Expected empty gateway for an empty endpoint. Instead found a gateway: %v", info.Gateway())
1041 1044
 	}
1045
+	if len(info.GatewayIPv6()) != 0 {
1046
+		t.Fatalf("Expected empty gateway for an empty ipv6 endpoint. Instead found a gateway: %v", info.GatewayIPv6())
1047
+	}
1042 1048
 
1043 1049
 	if info.Sandbox() != nil {
1044 1050
 		t.Fatalf("Expected an empty sandbox key for an empty endpoint. Instead found a non-empty sandbox key: %s", info.Sandbox().Key())
... ...
@@ -1090,9 +1104,12 @@ func TestEndpointJoin(t *testing.T) {
1090 1090
 
1091 1091
 	// Validate if ep.Info() only gives valid gateway and sandbox key after has container has joined.
1092 1092
 	info = ep1.Info()
1093
-	if info.Gateway().To4() == nil {
1093
+	if len(info.Gateway()) == 0 {
1094 1094
 		t.Fatalf("Expected a valid gateway for a joined endpoint. Instead found an invalid gateway: %v", info.Gateway())
1095 1095
 	}
1096
+	if len(info.GatewayIPv6()) == 0 {
1097
+		t.Fatalf("Expected a valid ipv6 gateway for a joined endpoint. Instead found an invalid gateway: %v", info.GatewayIPv6())
1098
+	}
1096 1099
 
1097 1100
 	if info.Sandbox() == nil {
1098 1101
 		t.Fatalf("Expected an non-empty sandbox key for a joined endpoint. Instead found a empty sandbox key")
... ...
@@ -1699,7 +1716,7 @@ func TestEnableIPv6(t *testing.T) {
1699 1699
 			"BridgeName": "testnetwork",
1700 1700
 		},
1701 1701
 	}
1702
-	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe80::/64"}}
1702
+	ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe99::/64", Gateway: "fe99::9"}}
1703 1703
 
1704 1704
 	n, err := createTestNetwork("bridge", "testnetwork", netOption, nil, ipamV6ConfList)
1705 1705
 	if err != nil {