Skip to content

Commit

Permalink
libnetwork vendoring
Browse files Browse the repository at this point in the history
Vendoring libnetwork @ 9f0563ea8f430d8828553aac97161cbff4056436

Brings in:
    * Support for overlay network driver in 3.10+ kernels
    * Freebsd compilation fixes
    * Remove .dockerinit dependency
    * IPAM driver capability support
    * Network internal mode support
    * Misc. fixes

Signed-off-by: Jana Radhakrishnan <[email protected]>
  • Loading branch information
mrjana committed Dec 22, 2015
1 parent 312c826 commit f0904af
Show file tree
Hide file tree
Showing 23 changed files with 474 additions and 69 deletions.
3 changes: 1 addition & 2 deletions docs/userguide/networking/get-started-overlay.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ network. Docker Engine supports multi-host networking out-of-the-box through the
`overlay` network driver. Unlike `bridge` networks, overlay networks require
some pre-existing conditions before you can create one. These conditions are:

* A host with a 3.16 kernel version or higher.
* Access to a key-value store. Docker supports Consul, Etcd, and ZooKeeper (Distributed store) key-value stores.
* A cluster of hosts with connectivity to the key-value store.
* A properly configured Engine `daemon` on each host in the cluster.
Expand Down Expand Up @@ -46,7 +45,7 @@ key-value stores. This example uses Consul.

1. Log into a system prepared with the prerequisite Docker Engine, Docker Machine, and VirtualBox software.

2. Provision a VirtualBox machine called `mh-keystore`.
2. Provision a VirtualBox machine called `mh-keystore`.

$ docker-machine create -d virtualbox mh-keystore

Expand Down
2 changes: 1 addition & 1 deletion hack/vendor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ clone git golang.org/x/net 47990a1ba55743e6ef1affd3a14e5bac8553615d https://gith
clone git github.com/docker/go-units v0.2.0

#get libnetwork packages
clone git github.com/docker/libnetwork bbd6e6d8ca1e7c9b42f6f53277b0bde72847ff90
clone git github.com/docker/libnetwork 9f0563ea8f430d8828553aac97161cbff4056436
clone git github.com/armon/go-metrics eb0af217e5e9747e41dd5303755356b62d28e3ec
clone git github.com/hashicorp/go-msgpack 71c2886f5a673a35f909803f38ece5810165097b
clone git github.com/hashicorp/memberlist 9a1e242e454d2443df330bdd51a436d5a9058fc4
Expand Down
15 changes: 12 additions & 3 deletions vendor/src/github.com/docker/libnetwork/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ type driverData struct {
}

type ipamData struct {
driver ipamapi.Ipam
driver ipamapi.Ipam
capability *ipamapi.Capability
// default address spaces are provided by ipam driver at registration time
defaultLocalAddressSpace, defaultGlobalAddressSpace string
}
Expand Down Expand Up @@ -306,7 +307,7 @@ func (c *controller) RegisterDriver(networkType string, driver driverapi.Driver,
return nil
}

func (c *controller) RegisterIpamDriver(name string, driver ipamapi.Ipam) error {
func (c *controller) registerIpamDriver(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error {
if !config.IsValidName(name) {
return ErrInvalidName(name)
}
Expand All @@ -322,14 +323,22 @@ func (c *controller) RegisterIpamDriver(name string, driver ipamapi.Ipam) error
return types.InternalErrorf("ipam driver %q failed to return default address spaces: %v", name, err)
}
c.Lock()
c.ipamDrivers[name] = &ipamData{driver: driver, defaultLocalAddressSpace: locAS, defaultGlobalAddressSpace: glbAS}
c.ipamDrivers[name] = &ipamData{driver: driver, defaultLocalAddressSpace: locAS, defaultGlobalAddressSpace: glbAS, capability: caps}
c.Unlock()

log.Debugf("Registering ipam driver: %q", name)

return nil
}

func (c *controller) RegisterIpamDriver(name string, driver ipamapi.Ipam) error {
return c.registerIpamDriver(name, driver, &ipamapi.Capability{})
}

func (c *controller) RegisterIpamDriverWithCapabilities(name string, driver ipamapi.Ipam, caps *ipamapi.Capability) error {
return c.registerIpamDriver(name, driver, caps)
}

// NewNetwork creates a new network of the specified network type. The options
// are network specific and modeled in a generic way.
func (c *controller) NewNetwork(networkType, name string, options ...NetworkOption) (Network, error) {
Expand Down
3 changes: 3 additions & 0 deletions vendor/src/github.com/docker/libnetwork/default_gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,9 @@ func (sb *sandbox) needDefaultGW() bool {
if ep.getNetwork().Type() == "null" || ep.getNetwork().Type() == "host" {
continue
}
if ep.getNetwork().Internal() {
return false
}
if ep.joinInfo.disableGatewayService {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ func parseNetworkOptions(id string, option options.Generic) (*networkConfigurati
config.EnableIPv6 = val.(bool)
}

if val, ok := option[netlabel.Internal]; ok {
if internal, ok := val.(bool); ok && internal {
return nil, &driverapi.ErrNotImplemented{}
}
}

// Finally validate the configuration
if err = config.Validate(); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,6 @@ func isPacketForwardingEnabled(ipVer ipVersion, iface string) (bool, error) {
}

func isRunningInContainer() bool {
_, err := os.Stat("/.dockerinit")
_, err := os.Stat("/.dockerenv")
return !os.IsNotExist(err)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
131 changes: 131 additions & 0 deletions vendor/src/github.com/docker/libnetwork/drivers/overlay/filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
package overlay

import (
"fmt"
"sync"

"github.com/Sirupsen/logrus"
"github.com/docker/libnetwork/iptables"
)

const globalChain = "DOCKER-OVERLAY"

var filterOnce sync.Once

func rawIPTables(args ...string) error {
if output, err := iptables.Raw(args...); err != nil {
return fmt.Errorf("unable to add overlay filter: %v", err)
} else if len(output) != 0 {
return fmt.Errorf("unable to add overlay filter: %s", string(output))
}

return nil
}

func chainExists(cname string) bool {
if _, err := iptables.Raw("-L", cname); err != nil {
return false
}

return true
}

func setupGlobalChain() {
if err := rawIPTables("-N", globalChain); err != nil {
logrus.Debugf("could not create global overlay chain: %v", err)
}

if err := rawIPTables("-A", globalChain, "-j", "RETURN"); err != nil {
logrus.Debugf("could not install default return chain in the overlay global chain: %v", err)
}
}

func setNetworkChain(cname string, remove bool) error {
// Initialize the onetime global overlay chain
filterOnce.Do(setupGlobalChain)

exists := chainExists(cname)

opt := "-N"
// In case of remove, make sure to flush the rules in the chain
if remove && exists {
if err := rawIPTables("-F", cname); err != nil {
return fmt.Errorf("failed to flush overlay network chain %s rules: %v", cname, err)
}
opt = "-X"
}

if (!remove && !exists) || (remove && exists) {
if err := rawIPTables(opt, cname); err != nil {
return fmt.Errorf("failed network chain operation %q for chain %s: %v", opt, cname, err)
}
}

if !remove {
if !iptables.Exists(iptables.Filter, cname, "-j", "DROP") {
if err := rawIPTables("-A", cname, "-j", "DROP"); err != nil {
return fmt.Errorf("failed adding default drop rule to overlay network chain %s: %v", cname, err)
}
}
}

return nil
}

func addNetworkChain(cname string) error {
return setNetworkChain(cname, false)
}

func removeNetworkChain(cname string) error {
return setNetworkChain(cname, true)
}

func setFilters(cname, brName string, remove bool) error {
opt := "-I"
if remove {
opt = "-D"
}

// Everytime we set filters for a new subnet make sure to move the global overlay hook to the top of the both the OUTPUT and forward chains
if !remove {
for _, chain := range []string{"OUTPUT", "FORWARD"} {
exists := iptables.Exists(iptables.Filter, chain, "-j", globalChain)
if exists {
if err := rawIPTables("-D", chain, "-j", globalChain); err != nil {
return fmt.Errorf("failed to delete overlay hook in chain %s while moving the hook: %v", chain, err)
}
}

if err := rawIPTables("-I", chain, "-j", globalChain); err != nil {
return fmt.Errorf("failed to insert overlay hook in chain %s: %v", chain, err)
}
}
}

// Insert/Delete the rule to jump to per-bridge chain
exists := iptables.Exists(iptables.Filter, globalChain, "-o", brName, "-j", cname)
if (!remove && !exists) || (remove && exists) {
if err := rawIPTables(opt, globalChain, "-o", brName, "-j", cname); err != nil {
return fmt.Errorf("failed to add per-bridge filter rule for bridge %s, network chain %s: %v", brName, cname, err)
}
}

exists = iptables.Exists(iptables.Filter, cname, "-i", brName, "-j", "ACCEPT")
if (!remove && exists) || (remove && !exists) {
return nil
}

if err := rawIPTables(opt, cname, "-i", brName, "-j", "ACCEPT"); err != nil {
return fmt.Errorf("failed to add overlay filter rile for network chain %s, bridge %s: %v", cname, brName, err)
}

return nil
}

func addFilters(cname, brName string) error {
return setFilters(cname, brName, false)
}

func removeFilters(cname, brName string) error {
return setFilters(cname, brName, true)
}
Loading

0 comments on commit f0904af

Please sign in to comment.