From 30ec1b5081c59ad46f5fecb8ed7cec6d7bec77f0 Mon Sep 17 00:00:00 2001 From: Alessandro Boch Date: Tue, 15 Dec 2015 09:52:03 -0800 Subject: [PATCH] Bridge driver to honor IPv6 network gateway - Currently bridge driver discards the user specified network gateway for IPv6 Signed-off-by: Alessandro Boch --- libnetwork/drivers/bridge/setup_ipv6.go | 7 ++++++ libnetwork/libnetwork_test.go | 29 ++++++++++++++++++++----- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/libnetwork/drivers/bridge/setup_ipv6.go b/libnetwork/drivers/bridge/setup_ipv6.go index 5ce53dd879..2613b3e95a 100644 --- a/libnetwork/drivers/bridge/setup_ipv6.go +++ b/libnetwork/drivers/bridge/setup_ipv6.go @@ -62,6 +62,13 @@ func setupBridgeIPv6(config *networkConfiguration, i *bridgeInterface) error { return nil } + // Store and program user specified bridge network and network gateway + i.bridgeIPv6 = config.AddressIPv6 + i.gatewayIPv6 = config.AddressIPv6.IP + if err := netlink.AddrAdd(i.Link, &netlink.Addr{IPNet: i.bridgeIPv6}); err != nil { + return &IPv6AddrAddError{IP: i.bridgeIPv6, Err: err} + } + // Setting route to global IPv6 subnet logrus.Debugf("Adding route to IPv6 network %s via device %s", config.AddressIPv6.String(), config.BridgeName) err = netlink.RouteAdd(&netlink.Route{ diff --git a/libnetwork/libnetwork_test.go b/libnetwork/libnetwork_test.go index f72b8c19ca..aa4b3b103d 100644 --- a/libnetwork/libnetwork_test.go +++ b/libnetwork/libnetwork_test.go @@ -1005,11 +1005,19 @@ func TestEndpointJoin(t *testing.T) { } // Create network 1 and add 2 endpoint: ep11, ep12 - n1, err := createTestNetwork(bridgeNetType, "testnetwork1", options.Generic{ + netOption := options.Generic{ netlabel.GenericData: options.Generic{ - "BridgeName": "testnetwork1", + "BridgeName": "testnetwork1", + "EnableIPv6": true, + "EnableICC": true, + "EnableIPMasquerade": true, }, - }, nil, nil) + } + ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe90::/64", Gateway: "fe90::22"}} + n1, err := controller.NewNetwork(bridgeNetType, "testnetwork1", + libnetwork.NetworkOptionGeneric(netOption), + libnetwork.NetworkOptionIpam(ipamapi.DefaultIPAM, "", nil, ipamV6ConfList), + libnetwork.NetworkOptionDeferIPv6Alloc(true)) if err != nil { t.Fatal(err) } @@ -1035,10 +1043,16 @@ func TestEndpointJoin(t *testing.T) { if iface.Address() != nil && iface.Address().IP.To4() == nil { t.Fatalf("Invalid IP address returned: %v", iface.Address()) } + if iface.AddressIPv6() != nil && iface.AddressIPv6().IP == nil { + t.Fatalf("Invalid IPv6 address returned: %v", iface.Address()) + } - if info.Gateway().To4() != nil { + if len(info.Gateway()) != 0 { t.Fatalf("Expected empty gateway for an empty endpoint. Instead found a gateway: %v", info.Gateway()) } + if len(info.GatewayIPv6()) != 0 { + t.Fatalf("Expected empty gateway for an empty ipv6 endpoint. Instead found a gateway: %v", info.GatewayIPv6()) + } if info.Sandbox() != nil { 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) { // Validate if ep.Info() only gives valid gateway and sandbox key after has container has joined. info = ep1.Info() - if info.Gateway().To4() == nil { + if len(info.Gateway()) == 0 { t.Fatalf("Expected a valid gateway for a joined endpoint. Instead found an invalid gateway: %v", info.Gateway()) } + if len(info.GatewayIPv6()) == 0 { + t.Fatalf("Expected a valid ipv6 gateway for a joined endpoint. Instead found an invalid gateway: %v", info.GatewayIPv6()) + } if info.Sandbox() == nil { 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) { "BridgeName": "testnetwork", }, } - ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe80::/64"}} + ipamV6ConfList := []*libnetwork.IpamConf{&libnetwork.IpamConf{PreferredPool: "fe99::/64", Gateway: "fe99::9"}} n, err := createTestNetwork("bridge", "testnetwork", netOption, nil, ipamV6ConfList) if err != nil {