Explorar o código

Merge pull request #44965 from akerouanton/libnetwork-dead-code

libnetwork/overlay: remove dead code
Sebastiaan van Stijn %!s(int64=2) %!d(string=hai) anos
pai
achega
0154746b9f

+ 0 - 171
libnetwork/cmd/ovrouter/ovrouter.go

@@ -1,171 +0,0 @@
-//go:build linux
-// +build linux
-
-package main
-
-import (
-	"fmt"
-	"net"
-	"os"
-	"os/signal"
-
-	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/drivers/overlay"
-	"github.com/docker/docker/libnetwork/netlabel"
-	"github.com/docker/docker/libnetwork/types"
-	"github.com/docker/docker/pkg/reexec"
-	"github.com/vishvananda/netlink"
-)
-
-type router struct {
-	d driverapi.Driver
-}
-
-type endpoint struct {
-	addr *net.IPNet
-	mac  net.HardwareAddr
-	name string
-}
-
-func (r *router) RegisterDriver(name string, driver driverapi.Driver, c driverapi.Capability) error {
-	r.d = driver
-	return nil
-}
-
-func (ep *endpoint) Interface() driverapi.InterfaceInfo {
-	return nil
-}
-
-func (ep *endpoint) SetMacAddress(mac net.HardwareAddr) error {
-	if ep.mac != nil {
-		return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", ep.mac, mac)
-	}
-	if mac == nil {
-		return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
-	}
-	ep.mac = types.GetMacCopy(mac)
-	return nil
-}
-
-func (ep *endpoint) SetIPAddress(address *net.IPNet) error {
-	if address.IP == nil {
-		return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
-	}
-	if address.IP.To4() == nil {
-		return types.NotImplementedErrorf("do not support ipv6 yet")
-	}
-	if ep.addr != nil {
-		return types.ForbiddenErrorf("endpoint interface IP present (%s). Cannot be modified with %s.", ep.addr, address)
-	}
-	ep.addr = types.GetIPNetCopy(address)
-	return nil
-}
-
-func (ep *endpoint) MacAddress() net.HardwareAddr {
-	return types.GetMacCopy(ep.mac)
-}
-
-func (ep *endpoint) Address() *net.IPNet {
-	return types.GetIPNetCopy(ep.addr)
-}
-
-func (ep *endpoint) AddressIPv6() *net.IPNet {
-	return nil
-}
-
-func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo {
-	return ep
-}
-
-func (ep *endpoint) SetNames(srcName, dstPrefix string) error {
-	ep.name = srcName
-	return nil
-}
-
-func (ep *endpoint) SetGateway(net.IP) error {
-	return nil
-}
-
-func (ep *endpoint) SetGatewayIPv6(net.IP) error {
-	return nil
-}
-
-func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int,
-	nextHop net.IP) error {
-	return nil
-}
-
-func (ep *endpoint) AddTableEntry(tableName string, key string, value []byte) error {
-	return nil
-}
-
-func (ep *endpoint) DisableGatewayService() {}
-
-func main() {
-	if reexec.Init() {
-		return
-	}
-
-	opt := make(map[string]interface{})
-	if len(os.Args) > 1 {
-		opt[netlabel.OverlayBindInterface] = os.Args[1]
-	}
-	if len(os.Args) > 2 {
-		opt[netlabel.OverlayNeighborIP] = os.Args[2]
-	}
-	if len(os.Args) > 3 {
-		opt[netlabel.GlobalKVProvider] = os.Args[3]
-	}
-	if len(os.Args) > 4 {
-		opt[netlabel.GlobalKVProviderURL] = os.Args[4]
-	}
-
-	r := &router{}
-	if err := overlay.Register(r, opt); err != nil {
-		fmt.Printf("Failed to initialize overlay driver: %v\n", err)
-		os.Exit(1)
-	}
-
-	if err := r.d.CreateNetwork("testnetwork",
-		map[string]interface{}{}, nil, nil, nil); err != nil {
-		fmt.Printf("Failed to create network in the driver: %v\n", err)
-		os.Exit(1)
-	}
-
-	ep := &endpoint{}
-	if err := r.d.CreateEndpoint("testnetwork", "testep",
-		ep, map[string]interface{}{}); err != nil {
-		fmt.Printf("Failed to create endpoint in the driver: %v\n", err)
-		os.Exit(1)
-	}
-
-	if err := r.d.Join("testnetwork", "testep",
-		"", ep, map[string]interface{}{}); err != nil {
-		fmt.Printf("Failed to join an endpoint in the driver: %v\n", err)
-		os.Exit(1)
-	}
-
-	link, err := netlink.LinkByName(ep.name)
-	if err != nil {
-		fmt.Printf("Failed to find the container interface with name %s: %v\n",
-			ep.name, err)
-		os.Exit(1)
-	}
-
-	ipAddr := &netlink.Addr{IPNet: ep.addr, Label: ""}
-	if err := netlink.AddrAdd(link, ipAddr); err != nil {
-		fmt.Printf("Failed to add address to the interface: %v\n", err)
-		os.Exit(1)
-	}
-
-	sigCh := make(chan os.Signal, 1)
-	signal.Notify(sigCh, os.Interrupt)
-
-	for range sigCh {
-		if err := r.d.Leave("testnetwork", "testep"); err != nil {
-			fmt.Printf("Error leaving: %v", err)
-		}
-		overlay.Fini(r.d)
-		os.Exit(0)
-	}
-}

+ 0 - 153
libnetwork/drivers/overlay/filter.go

@@ -1,153 +0,0 @@
-//go:build linux
-// +build linux
-
-package overlay
-
-import (
-	"fmt"
-	"sync"
-
-	"github.com/docker/docker/libnetwork/iptables"
-	"github.com/sirupsen/logrus"
-)
-
-const globalChain = "DOCKER-OVERLAY"
-
-var filterOnce sync.Once
-
-var filterChan = make(chan struct{}, 1)
-
-func filterWait() func() {
-	filterChan <- struct{}{}
-	return func() { <-filterChan }
-}
-
-func chainExists(cname string) bool {
-	// TODO IPv6 support
-	iptable := iptables.GetIptable(iptables.IPv4)
-	if _, err := iptable.Raw("-L", cname); err != nil {
-		return false
-	}
-
-	return true
-}
-
-func setupGlobalChain() {
-	// TODO IPv6 support
-	iptable := iptables.GetIptable(iptables.IPv4)
-	// Because of an ungraceful shutdown, chain could already be present
-	if !chainExists(globalChain) {
-		if err := iptable.RawCombinedOutput("-N", globalChain); err != nil {
-			logrus.Errorf("could not create global overlay chain: %v", err)
-			return
-		}
-	}
-
-	if !iptable.Exists(iptables.Filter, globalChain, "-j", "RETURN") {
-		if err := iptable.RawCombinedOutput("-A", globalChain, "-j", "RETURN"); err != nil {
-			logrus.Errorf("could not install default return chain in the overlay global chain: %v", err)
-		}
-	}
-}
-
-func setNetworkChain(cname string, remove bool) error {
-	// TODO IPv6 support
-	iptable := iptables.GetIptable(iptables.IPv4)
-	// 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 := iptable.RawCombinedOutput("-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 := iptable.RawCombinedOutput(opt, cname); err != nil {
-			return fmt.Errorf("failed network chain operation %q for chain %s: %v", opt, cname, err)
-		}
-	}
-
-	if !remove {
-		if !iptable.Exists(iptables.Filter, cname, "-j", "DROP") {
-			if err := iptable.RawCombinedOutput("-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 {
-	defer filterWait()()
-
-	return setNetworkChain(cname, false)
-}
-
-func removeNetworkChain(cname string) error {
-	defer filterWait()()
-
-	return setNetworkChain(cname, true)
-}
-
-func setFilters(cname, brName string, remove bool) error {
-	opt := "-I"
-	if remove {
-		opt = "-D"
-	}
-	// TODO IPv6 support
-	iptable := iptables.GetIptable(iptables.IPv4)
-
-	// Every time 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 := iptable.Exists(iptables.Filter, chain, "-j", globalChain)
-			if exists {
-				if err := iptable.RawCombinedOutput("-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 := iptable.RawCombinedOutput("-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 := iptable.Exists(iptables.Filter, globalChain, "-o", brName, "-j", cname)
-	if (!remove && !exists) || (remove && exists) {
-		if err := iptable.RawCombinedOutput(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 = iptable.Exists(iptables.Filter, cname, "-i", brName, "-j", "ACCEPT")
-	if (!remove && exists) || (remove && !exists) {
-		return nil
-	}
-
-	if err := iptable.RawCombinedOutput(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 {
-	defer filterWait()()
-
-	return setFilters(cname, brName, false)
-}
-
-func removeFilters(cname, brName string) error {
-	defer filterWait()()
-
-	return setFilters(cname, brName, true)
-}

+ 1 - 19
libnetwork/drivers/overlay/joinleave.go

@@ -46,11 +46,7 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
 		return fmt.Errorf("could not find subnet for endpoint %s", eid)
 	}
 
-	if err := n.obtainVxlanID(s); err != nil {
-		return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
-	}
-
-	if err := n.joinSandbox(s, false, true); err != nil {
+	if err := n.joinSandbox(s, true); err != nil {
 		return fmt.Errorf("network sandbox join failed: %v", err)
 	}
 
@@ -63,10 +59,6 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
 
 	ep.ifName = containerIfName
 
-	if err = d.writeEndpointToStore(ep); err != nil {
-		return fmt.Errorf("failed to update overlay endpoint %.7s to local data store: %v", ep.id, err)
-	}
-
 	// Set the container interface and its peer MTU to 1450 to allow
 	// for 50 bytes vxlan encap (inner eth header(14) + outer IP(20) +
 	// outer UDP(8) + vxlan header(8))
@@ -134,8 +126,6 @@ func (d *driver) Join(nid, eid string, sboxKey string, jinfo driverapi.JoinInfo,
 		logrus.Errorf("overlay: Failed adding table entry to joininfo: %v", err)
 	}
 
-	d.pushLocalEndpointEvent("join", nid, eid)
-
 	return nil
 }
 
@@ -219,14 +209,6 @@ func (d *driver) Leave(nid, eid string) error {
 		return types.InternalMaskableErrorf("could not find endpoint with id %s", eid)
 	}
 
-	if d.notifyCh != nil {
-		d.notifyCh <- ovNotify{
-			action: "leave",
-			nw:     n,
-			ep:     ep,
-		}
-	}
-
 	d.peerDelete(nid, eid, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), true)
 
 	n.leaveSandbox()

+ 5 - 132
libnetwork/drivers/overlay/ov_endpoint.go

@@ -4,30 +4,23 @@
 package overlay
 
 import (
-	"encoding/json"
 	"fmt"
 	"net"
 
-	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/driverapi"
 	"github.com/docker/docker/libnetwork/netutils"
 	"github.com/docker/docker/libnetwork/ns"
-	"github.com/docker/docker/libnetwork/types"
 	"github.com/sirupsen/logrus"
 )
 
 type endpointTable map[string]*endpoint
 
-const overlayEndpointPrefix = "overlay/endpoint"
-
 type endpoint struct {
-	id       string
-	nid      string
-	ifName   string
-	mac      net.HardwareAddr
-	addr     *net.IPNet
-	dbExists bool
-	dbIndex  uint64
+	id     string
+	nid    string
+	ifName string
+	mac    net.HardwareAddr
+	addr   *net.IPNet
 }
 
 func (n *network) endpoint(eid string) *endpoint {
@@ -92,10 +85,6 @@ func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
 
 	n.addEndpoint(ep)
 
-	if err := d.writeEndpointToStore(ep); err != nil {
-		return fmt.Errorf("failed to update overlay endpoint %.7s to local store: %v", ep.id, err)
-	}
-
 	return nil
 }
 
@@ -118,10 +107,6 @@ func (d *driver) DeleteEndpoint(nid, eid string) error {
 
 	n.deleteEndpoint(eid)
 
-	if err := d.deleteEndpointFromStore(ep); err != nil {
-		logrus.Warnf("Failed to delete overlay endpoint %.7s from local store: %v", ep.id, err)
-	}
-
 	if ep.ifName == "" {
 		return nil
 	}
@@ -141,115 +126,3 @@ func (d *driver) DeleteEndpoint(nid, eid string) error {
 func (d *driver) EndpointOperInfo(nid, eid string) (map[string]interface{}, error) {
 	return make(map[string]interface{}), nil
 }
-
-func (d *driver) deleteEndpointFromStore(e *endpoint) error {
-	if d.localStore == nil {
-		return fmt.Errorf("overlay local store not initialized, ep not deleted")
-	}
-
-	return d.localStore.DeleteObjectAtomic(e)
-}
-
-func (d *driver) writeEndpointToStore(e *endpoint) error {
-	if d.localStore == nil {
-		return fmt.Errorf("overlay local store not initialized, ep not added")
-	}
-
-	return d.localStore.PutObjectAtomic(e)
-}
-
-func (ep *endpoint) DataScope() string {
-	return datastore.LocalScope
-}
-
-func (ep *endpoint) New() datastore.KVObject {
-	return &endpoint{}
-}
-
-func (ep *endpoint) CopyTo(o datastore.KVObject) error {
-	dstep := o.(*endpoint)
-	*dstep = *ep
-	return nil
-}
-
-func (ep *endpoint) Key() []string {
-	return []string{overlayEndpointPrefix, ep.id}
-}
-
-func (ep *endpoint) KeyPrefix() []string {
-	return []string{overlayEndpointPrefix}
-}
-
-func (ep *endpoint) Index() uint64 {
-	return ep.dbIndex
-}
-
-func (ep *endpoint) SetIndex(index uint64) {
-	ep.dbIndex = index
-	ep.dbExists = true
-}
-
-func (ep *endpoint) Exists() bool {
-	return ep.dbExists
-}
-
-func (ep *endpoint) Skip() bool {
-	return false
-}
-
-func (ep *endpoint) Value() []byte {
-	b, err := json.Marshal(ep)
-	if err != nil {
-		return nil
-	}
-	return b
-}
-
-func (ep *endpoint) SetValue(value []byte) error {
-	return json.Unmarshal(value, ep)
-}
-
-func (ep *endpoint) MarshalJSON() ([]byte, error) {
-	epMap := make(map[string]interface{})
-
-	epMap["id"] = ep.id
-	epMap["nid"] = ep.nid
-	if ep.ifName != "" {
-		epMap["ifName"] = ep.ifName
-	}
-	if ep.addr != nil {
-		epMap["addr"] = ep.addr.String()
-	}
-	if len(ep.mac) != 0 {
-		epMap["mac"] = ep.mac.String()
-	}
-
-	return json.Marshal(epMap)
-}
-
-func (ep *endpoint) UnmarshalJSON(value []byte) error {
-	var (
-		err   error
-		epMap map[string]interface{}
-	)
-
-	json.Unmarshal(value, &epMap)
-
-	ep.id = epMap["id"].(string)
-	ep.nid = epMap["nid"].(string)
-	if v, ok := epMap["mac"]; ok {
-		if ep.mac, err = net.ParseMAC(v.(string)); err != nil {
-			return types.InternalErrorf("failed to decode endpoint interface mac address after json unmarshal: %s", v.(string))
-		}
-	}
-	if v, ok := epMap["addr"]; ok {
-		if ep.addr, err = types.ParseCIDR(v.(string)); err != nil {
-			return types.InternalErrorf("failed to decode endpoint interface ipv4 address after json unmarshal: %v", err)
-		}
-	}
-	if v, ok := epMap["ifName"]; ok {
-		ep.ifName = v.(string)
-	}
-
-	return nil
-}

+ 76 - 638
libnetwork/drivers/overlay/ov_network.go

@@ -4,7 +4,7 @@
 package overlay
 
 import (
-	"encoding/json"
+	"errors"
 	"fmt"
 	"net"
 	"os"
@@ -14,24 +14,19 @@ import (
 	"strings"
 	"sync"
 
-	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/driverapi"
 	"github.com/docker/docker/libnetwork/netlabel"
-	"github.com/docker/docker/libnetwork/netutils"
 	"github.com/docker/docker/libnetwork/ns"
 	"github.com/docker/docker/libnetwork/osl"
-	"github.com/docker/docker/libnetwork/resolvconf"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/hashicorp/go-multierror"
 	"github.com/sirupsen/logrus"
 	"github.com/vishvananda/netlink"
-	"github.com/vishvananda/netlink/nl"
 	"github.com/vishvananda/netns"
 	"golang.org/x/sys/unix"
 )
 
 var (
-	hostMode    bool
 	networkOnce sync.Once
 	networkMu   sync.Mutex
 	vniTbl      = make(map[uint32]string)
@@ -49,18 +44,9 @@ type subnet struct {
 	gwIP      *net.IPNet
 }
 
-type subnetJSON struct {
-	SubnetIP string
-	GwIP     string
-	Vni      uint32
-}
-
 type network struct {
 	id        string
-	dbIndex   uint64
-	dbExists  bool
 	sbox      osl.Sandbox
-	nlSocket  *nl.NetlinkSocket
 	endpoints endpointTable
 	driver    *driver
 	joinCnt   int
@@ -75,11 +61,11 @@ type network struct {
 
 func init() {
 	// Lock main() to the initial thread to exclude the goroutines executing
-	// func (*network).watchMiss() or func setDefaultVLAN() from being
-	// scheduled onto that thread. Changes to the network namespace of the
-	// initial thread alter /proc/self/ns/net, which would break any code
-	// which (incorrectly) assumes that that file is a handle to the network
-	// namespace for the thread it is currently executing on.
+	// func setDefaultVLAN() from being scheduled onto that thread. Changes to
+	// the network namespace of the initial thread alter /proc/self/ns/net,
+	// which would break any code which (incorrectly) assumes that that file is
+	// a handle to the network namespace for the thread it is currently
+	// executing on.
 	runtime.LockOSThread()
 }
 
@@ -113,37 +99,43 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
 	}
 
 	vnis := make([]uint32, 0, len(ipV4Data))
-	if gval, ok := option[netlabel.GenericData]; ok {
-		optMap := gval.(map[string]string)
-		if val, ok := optMap[netlabel.OverlayVxlanIDList]; ok {
-			logrus.Debugf("overlay: Received vxlan IDs: %s", val)
-			vniStrings := strings.Split(val, ",")
-			for _, vniStr := range vniStrings {
-				vni, err := strconv.Atoi(vniStr)
-				if err != nil {
-					return fmt.Errorf("invalid vxlan id value %q passed", vniStr)
-				}
+	gval, ok := option[netlabel.GenericData]
+	if !ok {
+		return fmt.Errorf("option %s is missing", netlabel.GenericData)
+	}
 
-				vnis = append(vnis, uint32(vni))
-			}
+	optMap := gval.(map[string]string)
+	vnisOpt, ok := optMap[netlabel.OverlayVxlanIDList]
+	if !ok {
+		return errors.New("no VNI provided")
+	}
+	logrus.Debugf("overlay: Received vxlan IDs: %s", vnisOpt)
+	vniStrings := strings.Split(vnisOpt, ",")
+	for _, vniStr := range vniStrings {
+		vni, err := strconv.Atoi(vniStr)
+		if err != nil {
+			return fmt.Errorf("invalid vxlan id value %q passed", vniStr)
 		}
-		if _, ok := optMap[secureOption]; ok {
-			n.secure = true
+
+		vnis = append(vnis, uint32(vni))
+	}
+
+	if _, ok := optMap[secureOption]; ok {
+		n.secure = true
+	}
+	if val, ok := optMap[netlabel.DriverMTU]; ok {
+		var err error
+		if n.mtu, err = strconv.Atoi(val); err != nil {
+			return fmt.Errorf("failed to parse %v: %v", val, err)
 		}
-		if val, ok := optMap[netlabel.DriverMTU]; ok {
-			var err error
-			if n.mtu, err = strconv.Atoi(val); err != nil {
-				return fmt.Errorf("failed to parse %v: %v", val, err)
-			}
-			if n.mtu < 0 {
-				return fmt.Errorf("invalid MTU value: %v", n.mtu)
-			}
+		if n.mtu < 0 {
+			return fmt.Errorf("invalid MTU value: %v", n.mtu)
 		}
 	}
 
-	// If we are getting vnis from libnetwork, either we get for
-	// all subnets or none.
-	if len(vnis) != 0 && len(vnis) < len(ipV4Data) {
+	if len(vnis) == 0 {
+		return errors.New("no VNI provided")
+	} else if len(vnis) < len(ipV4Data) {
 		return fmt.Errorf("insufficient vnis(%d) passed to overlay", len(vnis))
 	}
 
@@ -151,10 +143,7 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
 		s := &subnet{
 			subnetIP: ipd.Pool,
 			gwIP:     ipd.Gateway,
-		}
-
-		if len(vnis) != 0 {
-			s.vni = vnis[i]
+			vni:      vnis[i],
 		}
 
 		n.subnets = append(n.subnets, s)
@@ -166,10 +155,6 @@ func (d *driver) CreateNetwork(id string, option map[string]interface{}, nInfo d
 		return fmt.Errorf("attempt to create overlay network %v that already exists", n.id)
 	}
 
-	if err := n.writeToStore(); err != nil {
-		return fmt.Errorf("failed to update data store for network %v: %v", n.id, err)
-	}
-
 	// Make sure no rule is on the way from any stale secure network
 	if !n.secure {
 		for _, vni := range vnis {
@@ -213,10 +198,7 @@ func (d *driver) DeleteNetwork(nid string) error {
 
 	// This is similar to d.network(), but we need to keep holding the lock
 	// until we are done removing this network.
-	n, ok := d.networks[nid]
-	if !ok {
-		n = d.restoreNetworkFromStore(nid)
-	}
+	n := d.networks[nid]
 	if n == nil {
 		return fmt.Errorf("could not find network with id %s", nid)
 	}
@@ -229,27 +211,11 @@ func (d *driver) DeleteNetwork(nid string) error {
 				}
 			}
 		}
-
-		if err := d.deleteEndpointFromStore(ep); err != nil {
-			logrus.Warnf("Failed to delete overlay endpoint %.7s from local store: %v", ep.id, err)
-		}
 	}
 
 	doPeerFlush = true
 	delete(d.networks, nid)
 
-	vnis, err := n.releaseVxlanID()
-	if err != nil {
-		return err
-	}
-
-	if n.secure {
-		for _, vni := range vnis {
-			programMangle(vni, false)
-			programInput(vni, false)
-		}
-	}
-
 	return nil
 }
 
@@ -261,16 +227,15 @@ func (d *driver) RevokeExternalConnectivity(nid, eid string) error {
 	return nil
 }
 
-func (n *network) joinSandbox(s *subnet, restore bool, incJoinCount bool) error {
+func (n *network) joinSandbox(s *subnet, incJoinCount bool) error {
 	// If there is a race between two go routines here only one will win
 	// the other will wait.
-	networkOnce.Do(networkOnceInit)
+	networkOnce.Do(populateVNITbl)
 
 	n.Lock()
-	// If non-restore initialization occurred and was successful then
-	// tell the peerDB to initialize the sandbox with all the peers
-	// previously received from networkdb.  But only do this after
-	// unlocking the network.  Otherwise we could deadlock with
+	// If initialization was successful then tell the peerDB to initialize the
+	// sandbox with all the peers previously received from networkdb. But only
+	// do this after unlocking the network. Otherwise we could deadlock with
 	// on the peerDB channel while peerDB is waiting for the network lock.
 	var doInitPeerDB bool
 	defer func() {
@@ -281,8 +246,8 @@ func (n *network) joinSandbox(s *subnet, restore bool, incJoinCount bool) error
 	}()
 
 	if !n.sboxInit {
-		n.initErr = n.initSandbox(restore)
-		doInitPeerDB = n.initErr == nil && !restore
+		n.initErr = n.initSandbox()
+		doInitPeerDB = n.initErr == nil
 		// If there was an error, we cannot recover it
 		n.sboxInit = true
 	}
@@ -293,9 +258,9 @@ func (n *network) joinSandbox(s *subnet, restore bool, incJoinCount bool) error
 
 	subnetErr := s.initErr
 	if !s.sboxInit {
-		subnetErr = n.initSubnetSandbox(s, restore)
-		// We can recover from these errors, but not on restore
-		if restore || subnetErr == nil {
+		subnetErr = n.initSubnetSandbox(s)
+		// We can recover from these errors
+		if subnetErr == nil {
 			s.initErr = subnetErr
 			s.sboxInit = true
 		}
@@ -339,12 +304,6 @@ func (n *network) destroySandbox() {
 		}
 
 		for _, s := range n.subnets {
-			if hostMode {
-				if err := removeFilters(n.id[:12], s.brName); err != nil {
-					logrus.Warnf("Could not remove overlay filters: %v", err)
-				}
-			}
-
 			if s.vxlanName != "" {
 				err := deleteInterface(s.vxlanName)
 				if err != nil {
@@ -353,18 +312,6 @@ func (n *network) destroySandbox() {
 			}
 		}
 
-		if hostMode {
-			if err := removeNetworkChain(n.id[:12]); err != nil {
-				logrus.Warnf("could not remove network chain: %v", err)
-			}
-		}
-
-		// Close the netlink socket, this will also release the watchMiss goroutine that is using it
-		if n.nlSocket != nil {
-			n.nlSocket.Close()
-			n.nlSocket = nil
-		}
-
 		n.sbox.Destroy()
 		n.sbox = nil
 	}
@@ -416,45 +363,6 @@ func populateVNITbl() {
 		})
 }
 
-func networkOnceInit() {
-	populateVNITbl()
-
-	if os.Getenv("_OVERLAY_HOST_MODE") != "" {
-		hostMode = true
-		return
-	}
-
-	err := createVxlan("testvxlan", 1, 0)
-	if err != nil {
-		logrus.Errorf("Failed to create testvxlan interface: %v", err)
-		return
-	}
-
-	defer deleteInterface("testvxlan")
-
-	path := "/proc/self/ns/net"
-	hNs, err := netns.GetFromPath(path)
-	if err != nil {
-		logrus.Errorf("Failed to get network namespace from path %s while setting host mode: %v", path, err)
-		return
-	}
-	defer hNs.Close()
-
-	nlh := ns.NlHandle()
-
-	iface, err := nlh.LinkByName("testvxlan")
-	if err != nil {
-		logrus.Errorf("Failed to get link testvxlan while setting host mode: %v", err)
-		return
-	}
-
-	// If we are not able to move the vxlan interface to a namespace
-	// then fallback to host mode
-	if err := nlh.LinkSetNsFd(iface, int(hNs)); err != nil {
-		hostMode = true
-	}
-}
-
 func (n *network) generateVxlanName(s *subnet) string {
 	id := n.id
 	if len(n.id) > 5 {
@@ -477,79 +385,26 @@ func (n *network) getBridgeNamePrefix(s *subnet) string {
 	return fmt.Sprintf("ov-%06x", s.vni)
 }
 
-func checkOverlap(nw *net.IPNet) error {
-	var nameservers []string
-
-	if rc, err := os.ReadFile(resolvconf.Path()); err == nil {
-		nameservers = resolvconf.GetNameserversAsCIDR(rc)
-	}
-
-	if err := netutils.CheckNameserverOverlaps(nameservers, nw); err != nil {
-		return fmt.Errorf("overlay subnet %s failed check with nameserver: %v: %v", nw.String(), nameservers, err)
-	}
-
-	if err := netutils.CheckRouteOverlaps(nw); err != nil {
-		return fmt.Errorf("overlay subnet %s failed check with host route table: %v", nw.String(), err)
-	}
-
-	return nil
-}
-
-func (n *network) restoreSubnetSandbox(s *subnet, brName, vxlanName string) error {
-	// restore overlay osl sandbox
-	ifaces := map[string][]osl.IfaceOption{
-		brName + "+br": {
-			n.sbox.InterfaceOptions().Address(s.gwIP),
-			n.sbox.InterfaceOptions().Bridge(true),
-		},
-	}
-	if err := n.sbox.Restore(ifaces, nil, nil, nil); err != nil {
-		return err
-	}
-
-	ifaces = map[string][]osl.IfaceOption{
-		vxlanName + "+vxlan": {
-			n.sbox.InterfaceOptions().Master(brName),
-		},
-	}
-	return n.sbox.Restore(ifaces, nil, nil, nil)
-}
-
 func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error {
-	if hostMode {
-		// Try to delete stale bridge interface if it exists
-		if err := deleteInterface(brName); err != nil {
-			deleteInterfaceBySubnet(n.getBridgeNamePrefix(s), s)
-		}
-		// Try to delete the vxlan interface by vni if already present
-		deleteVxlanByVNI("", s.vni)
-
-		if err := checkOverlap(s.subnetIP); err != nil {
-			return err
-		}
-	}
+	// Try to find this subnet's vni is being used in some
+	// other namespace by looking at vniTbl that we just
+	// populated in the once init. If a hit is found then
+	// it must a stale namespace from previous
+	// life. Destroy it completely and reclaim resourced.
+	networkMu.Lock()
+	path, ok := vniTbl[s.vni]
+	networkMu.Unlock()
+
+	if ok {
+		deleteVxlanByVNI(path, s.vni)
+		if err := unix.Unmount(path, unix.MNT_FORCE); err != nil {
+			logrus.Errorf("unmount of %s failed: %v", path, err)
+		}
+		os.Remove(path)
 
-	if !hostMode {
-		// Try to find this subnet's vni is being used in some
-		// other namespace by looking at vniTbl that we just
-		// populated in the once init. If a hit is found then
-		// it must a stale namespace from previous
-		// life. Destroy it completely and reclaim resourced.
 		networkMu.Lock()
-		path, ok := vniTbl[s.vni]
+		delete(vniTbl, s.vni)
 		networkMu.Unlock()
-
-		if ok {
-			deleteVxlanByVNI(path, s.vni)
-			if err := unix.Unmount(path, unix.MNT_FORCE); err != nil {
-				logrus.Errorf("unmount of %s failed: %v", path, err)
-			}
-			os.Remove(path)
-
-			networkMu.Lock()
-			delete(vniTbl, s.vni)
-			networkMu.Unlock()
-		}
 	}
 
 	// create a bridge and vxlan device for this subnet and move it to the sandbox
@@ -588,10 +443,6 @@ func (n *network) setupSubnetSandbox(s *subnet, brName, vxlanName string) error
 		return fmt.Errorf("vxlan interface creation failed for subnet %q: %v", s.subnetIP.String(), err)
 	}
 
-	if hostMode {
-		return addFilters(n.id[:12], brName)
-	}
-
 	if err := setDefaultVLAN(sbox); err != nil {
 		// not a fatal error
 		logrus.WithError(err).Error("set bridge default vlan failed")
@@ -651,7 +502,7 @@ func setDefaultVLAN(sbox osl.Sandbox) error {
 }
 
 // Must be called with the network lock
-func (n *network) initSubnetSandbox(s *subnet, restore bool) error {
+func (n *network) initSubnetSandbox(s *subnet) error {
 	brName := n.generateBridgeName(s)
 	vxlanName := n.generateVxlanName(s)
 
@@ -667,14 +518,8 @@ func (n *network) initSubnetSandbox(s *subnet, restore bool) error {
 		}
 	}
 
-	if restore {
-		if err := n.restoreSubnetSandbox(s, brName, vxlanName); err != nil {
-			return err
-		}
-	} else {
-		if err := n.setupSubnetSandbox(s, brName, vxlanName); err != nil {
-			return err
-		}
+	if err := n.setupSubnetSandbox(s, brName, vxlanName); err != nil {
+		return err
 	}
 
 	s.vxlanName = vxlanName
@@ -718,427 +563,39 @@ func (n *network) cleanupStaleSandboxes() {
 		})
 }
 
-func (n *network) initSandbox(restore bool) error {
+func (n *network) initSandbox() error {
 	n.initEpoch++
 
-	if !restore {
-		if hostMode {
-			if err := addNetworkChain(n.id[:12]); err != nil {
-				return err
-			}
-		}
-
-		// If there are any stale sandboxes related to this network
-		// from previous daemon life clean it up here
-		n.cleanupStaleSandboxes()
-	}
-
-	// In the restore case network sandbox already exist; but we don't know
-	// what epoch number it was created with. It has to be retrieved by
-	// searching the net namespaces.
-	var key string
-	if restore {
-		key = osl.GenerateKey("-" + n.id)
-	} else {
-		key = osl.GenerateKey(fmt.Sprintf("%d-", n.initEpoch) + n.id)
-	}
+	// If there are any stale sandboxes related to this network
+	// from previous daemon life clean it up here
+	n.cleanupStaleSandboxes()
 
-	sbox, err := osl.NewSandbox(key, !hostMode, restore)
+	key := osl.GenerateKey(fmt.Sprintf("%d-", n.initEpoch) + n.id)
+	sbox, err := osl.NewSandbox(key, true, false)
 	if err != nil {
-		return fmt.Errorf("could not get network sandbox (oper %t): %v", restore, err)
+		return fmt.Errorf("could not get network sandbox: %v", err)
 	}
 
 	// this is needed to let the peerAdd configure the sandbox
 	n.sbox = sbox
 
-	// If we are in swarm mode, we don't need anymore the watchMiss routine.
-	// This will save 1 thread and 1 netlink socket per network
-	if !n.driver.isSerfAlive() {
-		return nil
-	}
-
-	var nlSock *nl.NetlinkSocket
-	sbox.InvokeFunc(func() {
-		nlSock, err = nl.Subscribe(unix.NETLINK_ROUTE, unix.RTNLGRP_NEIGH)
-		if err != nil {
-			return
-		}
-		// set the receive timeout to not remain stuck on the RecvFrom if the fd gets closed
-		tv := unix.NsecToTimeval(soTimeout.Nanoseconds())
-		err = nlSock.SetReceiveTimeout(&tv)
-	})
-	n.nlSocket = nlSock
-
-	if err == nil {
-		go n.watchMiss(nlSock, key)
-	} else {
-		logrus.Errorf("failed to subscribe to neighbor group netlink messages for overlay network %s in sbox %s: %v",
-			n.id, sbox.Key(), err)
-	}
-
 	return nil
 }
 
-func (n *network) watchMiss(nlSock *nl.NetlinkSocket, nsPath string) {
-	// With the new version of the netlink library the deserialize function makes
-	// requests about the interface of the netlink message. This can succeed only
-	// if this go routine is in the target namespace.
-	origNs, err := netns.Get()
-	if err != nil {
-		logrus.WithError(err).Error("failed to get the initial network namespace")
-		return
-	}
-	defer origNs.Close()
-	newNs, err := netns.GetFromPath(nsPath)
-	if err != nil {
-		logrus.WithError(err).Errorf("failed to get the namespace %s", nsPath)
-		return
-	}
-	defer newNs.Close()
-
-	runtime.LockOSThread()
-	if err = netns.Set(newNs); err != nil {
-		logrus.WithError(err).Errorf("failed to enter the namespace %s", nsPath)
-		runtime.UnlockOSThread()
-		return
-	}
-	defer func() {
-		if err := netns.Set(origNs); err != nil {
-			logrus.WithError(err).Error("failed to restore the thread's initial network namespace")
-			// The error is only fatal for the current thread. Keep this
-			// goroutine locked to the thread to make the runtime replace it
-			// with a clean thread once this goroutine terminates.
-		} else {
-			runtime.UnlockOSThread()
-		}
-	}()
-	for {
-		msgs, _, err := nlSock.Receive()
-		if err != nil {
-			n.Lock()
-			nlFd := nlSock.GetFd()
-			n.Unlock()
-			if nlFd == -1 {
-				// The netlink socket got closed, simply exit to not leak this goroutine
-				return
-			}
-			// When the receive timeout expires the receive will return EAGAIN
-			if err == unix.EAGAIN {
-				// we continue here to avoid spam for timeouts
-				continue
-			}
-			logrus.Errorf("Failed to receive from netlink: %v ", err)
-			continue
-		}
-
-		for _, msg := range msgs {
-			if msg.Header.Type != unix.RTM_GETNEIGH && msg.Header.Type != unix.RTM_NEWNEIGH {
-				continue
-			}
-
-			neigh, err := netlink.NeighDeserialize(msg.Data)
-			if err != nil {
-				logrus.Errorf("Failed to deserialize netlink ndmsg: %v", err)
-				continue
-			}
-
-			var (
-				ip             net.IP
-				mac            net.HardwareAddr
-				l2Miss, l3Miss bool
-			)
-			if neigh.IP.To4() != nil {
-				ip = neigh.IP
-				l3Miss = true
-			} else if neigh.HardwareAddr != nil {
-				mac = []byte(neigh.HardwareAddr)
-				ip = net.IP(mac[2:])
-				l2Miss = true
-			} else {
-				continue
-			}
-
-			// Not any of the network's subnets. Ignore.
-			if !n.contains(ip) {
-				continue
-			}
-
-			if neigh.State&(netlink.NUD_STALE|netlink.NUD_INCOMPLETE) == 0 {
-				continue
-			}
-
-			logrus.Debugf("miss notification: dest IP %v, dest MAC %v", ip, mac)
-			mac, IPmask, vtep, err := n.driver.resolvePeer(n.id, ip)
-			if err != nil {
-				logrus.Errorf("could not resolve peer %q: %v", ip, err)
-				continue
-			}
-			n.driver.peerAdd(n.id, "dummy", ip, IPmask, mac, vtep, l2Miss, l3Miss, false)
-		}
-	}
-}
-
-// Restore a network from the store to the driver if it is present.
-// Must be called with the driver locked!
-func (d *driver) restoreNetworkFromStore(nid string) *network {
-	n := d.getNetworkFromStore(nid)
-	if n != nil {
-		n.driver = d
-		n.endpoints = endpointTable{}
-		d.networks[nid] = n
-	}
-	return n
-}
-
 func (d *driver) network(nid string) *network {
 	d.Lock()
-	n, ok := d.networks[nid]
-	if !ok {
-		n = d.restoreNetworkFromStore(nid)
-	}
+	n := d.networks[nid]
 	d.Unlock()
 
 	return n
 }
 
-func (d *driver) getNetworkFromStore(nid string) *network {
-	if d.store == nil {
-		return nil
-	}
-
-	n := &network{id: nid}
-	if err := d.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
-		return nil
-	}
-
-	return n
-}
-
 func (n *network) sandbox() osl.Sandbox {
 	n.Lock()
 	defer n.Unlock()
 	return n.sbox
 }
 
-func (n *network) vxlanID(s *subnet) uint32 {
-	n.Lock()
-	defer n.Unlock()
-	return s.vni
-}
-
-func (n *network) setVxlanID(s *subnet, vni uint32) {
-	n.Lock()
-	s.vni = vni
-	n.Unlock()
-}
-
-func (n *network) Key() []string {
-	return []string{"overlay", "network", n.id}
-}
-
-func (n *network) KeyPrefix() []string {
-	return []string{"overlay", "network"}
-}
-
-func (n *network) Value() []byte {
-	m := map[string]interface{}{}
-
-	netJSON := []*subnetJSON{}
-
-	for _, s := range n.subnets {
-		sj := &subnetJSON{
-			SubnetIP: s.subnetIP.String(),
-			GwIP:     s.gwIP.String(),
-			Vni:      s.vni,
-		}
-		netJSON = append(netJSON, sj)
-	}
-
-	m["secure"] = n.secure
-	m["subnets"] = netJSON
-	m["mtu"] = n.mtu
-	b, err := json.Marshal(m)
-	if err != nil {
-		return []byte{}
-	}
-
-	return b
-}
-
-func (n *network) Index() uint64 {
-	return n.dbIndex
-}
-
-func (n *network) SetIndex(index uint64) {
-	n.dbIndex = index
-	n.dbExists = true
-}
-
-func (n *network) Exists() bool {
-	return n.dbExists
-}
-
-func (n *network) Skip() bool {
-	return false
-}
-
-func (n *network) SetValue(value []byte) error {
-	var (
-		m       map[string]interface{}
-		newNet  bool
-		isMap   = true
-		netJSON = []*subnetJSON{}
-	)
-
-	if err := json.Unmarshal(value, &m); err != nil {
-		err := json.Unmarshal(value, &netJSON)
-		if err != nil {
-			return err
-		}
-		isMap = false
-	}
-
-	if len(n.subnets) == 0 {
-		newNet = true
-	}
-
-	if isMap {
-		if val, ok := m["secure"]; ok {
-			n.secure = val.(bool)
-		}
-		if val, ok := m["mtu"]; ok {
-			n.mtu = int(val.(float64))
-		}
-		bytes, err := json.Marshal(m["subnets"])
-		if err != nil {
-			return err
-		}
-		if err := json.Unmarshal(bytes, &netJSON); err != nil {
-			return err
-		}
-	}
-
-	for _, sj := range netJSON {
-		subnetIPstr := sj.SubnetIP
-		gwIPstr := sj.GwIP
-		vni := sj.Vni
-
-		subnetIP, _ := types.ParseCIDR(subnetIPstr)
-		gwIP, _ := types.ParseCIDR(gwIPstr)
-
-		if newNet {
-			s := &subnet{
-				subnetIP: subnetIP,
-				gwIP:     gwIP,
-				vni:      vni,
-			}
-			n.subnets = append(n.subnets, s)
-		} else {
-			sNet := n.getMatchingSubnet(subnetIP)
-			if sNet != nil {
-				sNet.vni = vni
-			}
-		}
-	}
-	return nil
-}
-
-func (n *network) DataScope() string {
-	return datastore.GlobalScope
-}
-
-func (n *network) writeToStore() error {
-	if n.driver.store == nil {
-		return nil
-	}
-
-	return n.driver.store.PutObjectAtomic(n)
-}
-
-func (n *network) releaseVxlanID() ([]uint32, error) {
-	n.Lock()
-	nSubnets := len(n.subnets)
-	n.Unlock()
-	if nSubnets == 0 {
-		return nil, nil
-	}
-
-	if n.driver.store != nil {
-		if err := n.driver.store.DeleteObjectAtomic(n); err != nil {
-			if err == datastore.ErrKeyModified || err == datastore.ErrKeyNotFound {
-				// In both the above cases we can safely assume that the key has been removed by some other
-				// instance and so simply get out of here
-				return nil, nil
-			}
-
-			return nil, fmt.Errorf("failed to delete network to vxlan id map: %v", err)
-		}
-	}
-	var vnis []uint32
-	n.Lock()
-	for _, s := range n.subnets {
-		if n.driver.vxlanIdm != nil {
-			vnis = append(vnis, s.vni)
-		}
-		s.vni = 0
-	}
-	n.Unlock()
-
-	for _, vni := range vnis {
-		n.driver.vxlanIdm.Release(uint64(vni))
-	}
-
-	return vnis, nil
-}
-
-func (n *network) obtainVxlanID(s *subnet) error {
-	// return if the subnet already has a vxlan id assigned
-	if n.vxlanID(s) != 0 {
-		return nil
-	}
-
-	if n.driver.store == nil {
-		return fmt.Errorf("no valid vxlan id and no datastore configured, cannot obtain vxlan id")
-	}
-
-	for {
-		if err := n.driver.store.GetObject(datastore.Key(n.Key()...), n); err != nil {
-			return fmt.Errorf("getting network %q from datastore failed %v", n.id, err)
-		}
-
-		if n.vxlanID(s) == 0 {
-			vxlanID, err := n.driver.vxlanIdm.GetID(true)
-			if err != nil {
-				return fmt.Errorf("failed to allocate vxlan id: %v", err)
-			}
-
-			n.setVxlanID(s, uint32(vxlanID))
-			if err := n.writeToStore(); err != nil {
-				n.driver.vxlanIdm.Release(uint64(n.vxlanID(s)))
-				n.setVxlanID(s, 0)
-				if err == datastore.ErrKeyModified {
-					continue
-				}
-				return fmt.Errorf("network %q failed to update data store: %v", n.id, err)
-			}
-			return nil
-		}
-		return nil
-	}
-}
-
-// contains return true if the passed ip belongs to one the network's
-// subnets
-func (n *network) contains(ip net.IP) bool {
-	for _, s := range n.subnets {
-		if s.subnetIP.Contains(ip) {
-			return true
-		}
-	}
-
-	return false
-}
-
 // getSubnetforIP returns the subnet to which the given IP belongs
 func (n *network) getSubnetforIP(ip *net.IPNet) *subnet {
 	for _, s := range n.subnets {
@@ -1154,22 +611,3 @@ func (n *network) getSubnetforIP(ip *net.IPNet) *subnet {
 	}
 	return nil
 }
-
-// getMatchingSubnet return the network's subnet that matches the input
-func (n *network) getMatchingSubnet(ip *net.IPNet) *subnet {
-	if ip == nil {
-		return nil
-	}
-	for _, s := range n.subnets {
-		// first check if the mask lengths are the same
-		i, _ := s.subnetIP.Mask.Size()
-		j, _ := ip.Mask.Size()
-		if i != j {
-			continue
-		}
-		if s.subnetIP.IP.Equal(ip.IP) {
-			return s
-		}
-	}
-	return nil
-}

+ 0 - 230
libnetwork/drivers/overlay/ov_serf.go

@@ -1,230 +0,0 @@
-//go:build linux
-// +build linux
-
-package overlay
-
-import (
-	"fmt"
-	"net"
-	"strings"
-	"time"
-
-	"github.com/hashicorp/serf/serf"
-	"github.com/sirupsen/logrus"
-)
-
-type ovNotify struct {
-	action string
-	ep     *endpoint
-	nw     *network
-}
-
-type logWriter struct{}
-
-func (l *logWriter) Write(p []byte) (int, error) {
-	str := string(p)
-
-	switch {
-	case strings.Contains(str, "[WARN]"):
-		logrus.Warn(str)
-	case strings.Contains(str, "[DEBUG]"):
-		logrus.Debug(str)
-	case strings.Contains(str, "[INFO]"):
-		logrus.Info(str)
-	case strings.Contains(str, "[ERR]"):
-		logrus.Error(str)
-	}
-
-	return len(p), nil
-}
-
-func (d *driver) serfInit() error {
-	var err error
-
-	config := serf.DefaultConfig()
-	config.Init()
-	config.MemberlistConfig.BindAddr = d.advertiseAddress
-
-	d.eventCh = make(chan serf.Event, 4)
-	config.EventCh = d.eventCh
-	config.UserCoalescePeriod = 1 * time.Second
-	config.UserQuiescentPeriod = 50 * time.Millisecond
-
-	config.LogOutput = &logWriter{}
-	config.MemberlistConfig.LogOutput = config.LogOutput
-
-	s, err := serf.Create(config)
-	if err != nil {
-		return fmt.Errorf("failed to create cluster node: %v", err)
-	}
-	defer func() {
-		if err != nil {
-			s.Shutdown()
-		}
-	}()
-
-	d.serfInstance = s
-
-	d.notifyCh = make(chan ovNotify)
-	d.exitCh = make(chan chan struct{})
-
-	go d.startSerfLoop(d.eventCh, d.notifyCh, d.exitCh)
-	return nil
-}
-
-func (d *driver) serfJoin(neighIP string) error {
-	if neighIP == "" {
-		return fmt.Errorf("no neighbor to join")
-	}
-	if _, err := d.serfInstance.Join([]string{neighIP}, true); err != nil {
-		return fmt.Errorf("Failed to join the cluster at neigh IP %s: %v",
-			neighIP, err)
-	}
-	return nil
-}
-
-func (d *driver) notifyEvent(event ovNotify) {
-	ep := event.ep
-
-	ePayload := fmt.Sprintf("%s %s %s %s", event.action, ep.addr.IP.String(),
-		net.IP(ep.addr.Mask).String(), ep.mac.String())
-	eName := fmt.Sprintf("jl %s %s %s", d.serfInstance.LocalMember().Addr.String(),
-		event.nw.id, ep.id)
-
-	if err := d.serfInstance.UserEvent(eName, []byte(ePayload), true); err != nil {
-		logrus.Errorf("Sending user event failed: %v\n", err)
-	}
-}
-
-func (d *driver) processEvent(u serf.UserEvent) {
-	logrus.Debugf("Received user event name:%s, payload:%s LTime:%d \n", u.Name,
-		string(u.Payload), uint64(u.LTime))
-
-	var dummy, action, vtepStr, nid, eid, ipStr, maskStr, macStr string
-	if _, err := fmt.Sscan(u.Name, &dummy, &vtepStr, &nid, &eid); err != nil {
-		fmt.Printf("Failed to scan name string: %v\n", err)
-	}
-
-	if _, err := fmt.Sscan(string(u.Payload), &action,
-		&ipStr, &maskStr, &macStr); err != nil {
-		fmt.Printf("Failed to scan value string: %v\n", err)
-	}
-
-	logrus.Debugf("Parsed data = %s/%s/%s/%s/%s/%s\n", nid, eid, vtepStr, ipStr, maskStr, macStr)
-
-	mac, err := net.ParseMAC(macStr)
-	if err != nil {
-		logrus.Errorf("Failed to parse mac: %v\n", err)
-	}
-
-	if d.serfInstance.LocalMember().Addr.String() == vtepStr {
-		return
-	}
-
-	switch action {
-	case "join":
-		d.peerAdd(nid, eid, net.ParseIP(ipStr), net.IPMask(net.ParseIP(maskStr).To4()), mac, net.ParseIP(vtepStr), false, false, false)
-	case "leave":
-		d.peerDelete(nid, eid, net.ParseIP(ipStr), net.IPMask(net.ParseIP(maskStr).To4()), mac, net.ParseIP(vtepStr), false)
-	}
-}
-
-func (d *driver) processQuery(q *serf.Query) {
-	logrus.Debugf("Received query name:%s, payload:%s\n", q.Name,
-		string(q.Payload))
-
-	var nid, ipStr string
-	if _, err := fmt.Sscan(string(q.Payload), &nid, &ipStr); err != nil {
-		fmt.Printf("Failed to scan query payload string: %v\n", err)
-	}
-
-	pKey, pEntry, err := d.peerDbSearch(nid, net.ParseIP(ipStr))
-	if err != nil {
-		return
-	}
-
-	logrus.Debugf("Sending peer query resp mac %v, mask %s, vtep %s", pKey.peerMac, net.IP(pEntry.peerIPMask).String(), pEntry.vtep)
-	q.Respond([]byte(fmt.Sprintf("%s %s %s", pKey.peerMac.String(), net.IP(pEntry.peerIPMask).String(), pEntry.vtep.String())))
-}
-
-func (d *driver) resolvePeer(nid string, peerIP net.IP) (net.HardwareAddr, net.IPMask, net.IP, error) {
-	if d.serfInstance == nil {
-		return nil, nil, nil, fmt.Errorf("could not resolve peer: serf instance not initialized")
-	}
-
-	qPayload := fmt.Sprintf("%s %s", nid, peerIP.String())
-	resp, err := d.serfInstance.Query("peerlookup", []byte(qPayload), nil)
-	if err != nil {
-		return nil, nil, nil, fmt.Errorf("resolving peer by querying the cluster failed: %v", err)
-	}
-
-	respCh := resp.ResponseCh()
-	select {
-	case r := <-respCh:
-		var macStr, maskStr, vtepStr string
-		if _, err := fmt.Sscan(string(r.Payload), &macStr, &maskStr, &vtepStr); err != nil {
-			return nil, nil, nil, fmt.Errorf("bad response %q for the resolve query: %v", string(r.Payload), err)
-		}
-
-		mac, err := net.ParseMAC(macStr)
-		if err != nil {
-			return nil, nil, nil, fmt.Errorf("failed to parse mac: %v", err)
-		}
-
-		logrus.Debugf("Received peer query response, mac %s, vtep %s, mask %s", macStr, vtepStr, maskStr)
-		return mac, net.IPMask(net.ParseIP(maskStr).To4()), net.ParseIP(vtepStr), nil
-
-	case <-time.After(time.Second):
-		return nil, nil, nil, fmt.Errorf("timed out resolving peer by querying the cluster")
-	}
-}
-
-func (d *driver) startSerfLoop(eventCh chan serf.Event, notifyCh chan ovNotify, exitCh chan chan struct{}) {
-	for {
-		select {
-		case notify, ok := <-notifyCh:
-			if !ok {
-				break
-			}
-
-			d.notifyEvent(notify)
-		case ch, ok := <-exitCh:
-			if !ok {
-				break
-			}
-
-			if err := d.serfInstance.Leave(); err != nil {
-				logrus.Errorf("failed leaving the cluster: %v\n", err)
-			}
-
-			d.serfInstance.Shutdown()
-			close(ch)
-			return
-		case e, ok := <-eventCh:
-			if !ok {
-				break
-			}
-
-			if e.EventType() == serf.EventQuery {
-				d.processQuery(e.(*serf.Query))
-				break
-			}
-
-			u, ok := e.(serf.UserEvent)
-			if !ok {
-				break
-			}
-			d.processEvent(u)
-		}
-	}
-}
-
-func (d *driver) isSerfAlive() bool {
-	d.Lock()
-	serfInstance := d.serfInstance
-	d.Unlock()
-	if serfInstance == nil || serfInstance.State() != serf.SerfAlive {
-		return false
-	}
-	return true
-}

+ 0 - 29
libnetwork/drivers/overlay/ov_utils.go

@@ -5,7 +5,6 @@ package overlay
 
 import (
 	"fmt"
-	"strings"
 	"syscall"
 
 	"github.com/docker/docker/libnetwork/drivers/overlay/overlayutils"
@@ -74,34 +73,6 @@ func createVxlan(name string, vni uint32, mtu int) error {
 	return nil
 }
 
-func deleteInterfaceBySubnet(brPrefix string, s *subnet) error {
-	nlh := ns.NlHandle()
-	links, err := nlh.LinkList()
-	if err != nil {
-		return fmt.Errorf("failed to list interfaces while deleting bridge interface by subnet: %v", err)
-	}
-
-	for _, l := range links {
-		name := l.Attrs().Name
-		if _, ok := l.(*netlink.Bridge); ok && strings.HasPrefix(name, brPrefix) {
-			addrList, err := nlh.AddrList(l, netlink.FAMILY_V4)
-			if err != nil {
-				logrus.Errorf("error getting AddressList for bridge %s", name)
-				continue
-			}
-			for _, addr := range addrList {
-				if netutils.NetworkOverlaps(addr.IPNet, s.subnetIP) {
-					err = nlh.LinkDel(l)
-					if err != nil {
-						logrus.Errorf("error deleting bridge (%s) with subnet %v: %v", name, addr.IPNet, err)
-					}
-				}
-			}
-		}
-	}
-	return nil
-}
-
 func deleteInterface(name string) error {
 	link, err := ns.NlHandle().LinkByName(name)
 	if err != nil {

+ 1 - 220
libnetwork/drivers/overlay/overlay.go

@@ -7,17 +7,11 @@ package overlay
 
 import (
 	"fmt"
-	"net"
 	"sync"
 
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/discoverapi"
 	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/idm"
-	"github.com/docker/docker/libnetwork/netlabel"
-	"github.com/docker/docker/libnetwork/osl"
-	"github.com/docker/docker/libnetwork/types"
-	"github.com/hashicorp/serf/serf"
 	"github.com/sirupsen/logrus"
 )
 
@@ -25,31 +19,18 @@ const (
 	networkType  = "overlay"
 	vethPrefix   = "veth"
 	vethLen      = len(vethPrefix) + 7
-	vxlanIDStart = 256
-	vxlanIDEnd   = (1 << 24) - 1
 	vxlanEncap   = 50
 	secureOption = "encrypted"
 )
 
-var initVxlanIdm = make(chan (bool), 1)
-
 type driver struct {
-	eventCh          chan serf.Event
-	notifyCh         chan ovNotify
-	exitCh           chan chan struct{}
 	bindAddress      string
 	advertiseAddress string
-	neighIP          string
 	config           map[string]interface{}
 	peerDb           peerNetworkMap
 	secMap           *encrMap
-	serfInstance     *serf.Serf
 	networks         networkTable
-	store            datastore.DataStore
-	localStore       datastore.DataStore
-	vxlanIdm         *idm.Idm
 	initOS           sync.Once
-	joinOnce         sync.Once
 	localJoinOnce    sync.Once
 	keys             []*key
 	peerOpMu         sync.Mutex
@@ -71,132 +52,13 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error {
 		config: config,
 	}
 
-	if data, ok := config[netlabel.GlobalKVClient]; ok {
-		var err error
-		dsc, ok := data.(discoverapi.DatastoreConfigData)
-		if !ok {
-			return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
-		}
-		d.store, err = datastore.NewDataStoreFromConfig(dsc)
-		if err != nil {
-			return types.InternalErrorf("failed to initialize data store: %v", err)
-		}
-	}
-
-	if data, ok := config[netlabel.LocalKVClient]; ok {
-		var err error
-		dsc, ok := data.(discoverapi.DatastoreConfigData)
-		if !ok {
-			return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
-		}
-		d.localStore, err = datastore.NewDataStoreFromConfig(dsc)
-		if err != nil {
-			return types.InternalErrorf("failed to initialize local data store: %v", err)
-		}
-	}
-
-	if err := d.restoreEndpoints(); err != nil {
-		logrus.Warnf("Failure during overlay endpoints restore: %v", err)
-	}
-
 	return r.RegisterDriver(networkType, d, c)
 }
 
-// Endpoints are stored in the local store. Restore them and reconstruct the overlay sandbox
-func (d *driver) restoreEndpoints() error {
-	if d.localStore == nil {
-		logrus.Warn("Cannot restore overlay endpoints because local datastore is missing")
-		return nil
-	}
-	kvol, err := d.localStore.List(datastore.Key(overlayEndpointPrefix), &endpoint{})
-	if err != nil && err != datastore.ErrKeyNotFound {
-		return fmt.Errorf("failed to read overlay endpoint from store: %v", err)
-	}
-
-	if err == datastore.ErrKeyNotFound {
-		return nil
-	}
-	for _, kvo := range kvol {
-		ep := kvo.(*endpoint)
-		n := d.network(ep.nid)
-		if n == nil {
-			logrus.Debugf("Network (%.7s) not found for restored endpoint (%.7s)", ep.nid, ep.id)
-			logrus.Debugf("Deleting stale overlay endpoint (%.7s) from store", ep.id)
-			if err := d.deleteEndpointFromStore(ep); err != nil {
-				logrus.Debugf("Failed to delete stale overlay endpoint (%.7s) from store", ep.id)
-			}
-			continue
-		}
-		n.addEndpoint(ep)
-
-		s := n.getSubnetforIP(ep.addr)
-		if s == nil {
-			return fmt.Errorf("could not find subnet for endpoint %s", ep.id)
-		}
-
-		if err := n.joinSandbox(s, true, true); err != nil {
-			return fmt.Errorf("restore network sandbox failed: %v", err)
-		}
-
-		Ifaces := make(map[string][]osl.IfaceOption)
-		vethIfaceOption := make([]osl.IfaceOption, 1)
-		vethIfaceOption = append(vethIfaceOption, n.sbox.InterfaceOptions().Master(s.brName))
-		Ifaces["veth+veth"] = vethIfaceOption
-
-		err := n.sbox.Restore(Ifaces, nil, nil, nil)
-		if err != nil {
-			n.leaveSandbox()
-			return fmt.Errorf("failed to restore overlay sandbox: %v", err)
-		}
-
-		d.peerAdd(ep.nid, ep.id, ep.addr.IP, ep.addr.Mask, ep.mac, net.ParseIP(d.advertiseAddress), false, false, true)
-	}
-	return nil
-}
-
-// Fini cleans up the driver resources
-func Fini(drv driverapi.Driver) {
-	d := drv.(*driver)
-
-	if d.exitCh != nil {
-		waitCh := make(chan struct{})
-
-		d.exitCh <- waitCh
-
-		<-waitCh
-	}
-}
-
 func (d *driver) configure() error {
 	// Apply OS specific kernel configs if needed
 	d.initOS.Do(applyOStweaks)
 
-	if d.store == nil {
-		return nil
-	}
-
-	if d.vxlanIdm == nil {
-		return d.initializeVxlanIdm()
-	}
-
-	return nil
-}
-
-func (d *driver) initializeVxlanIdm() error {
-	var err error
-
-	initVxlanIdm <- true
-	defer func() { <-initVxlanIdm }()
-
-	if d.vxlanIdm != nil {
-		return nil
-	}
-
-	d.vxlanIdm, err = idm.New(d.store, "vxlan-id", vxlanIDStart, vxlanIDEnd)
-	if err != nil {
-		return fmt.Errorf("failed to initialize vxlan id manager: %v", err)
-	}
-
 	return nil
 }
 
@@ -208,27 +70,8 @@ func (d *driver) IsBuiltIn() bool {
 	return true
 }
 
-func validateSelf(node string) error {
-	advIP := net.ParseIP(node)
-	if advIP == nil {
-		return fmt.Errorf("invalid self address (%s)", node)
-	}
-
-	addrs, err := net.InterfaceAddrs()
-	if err != nil {
-		return fmt.Errorf("Unable to get interface addresses %v", err)
-	}
-	for _, addr := range addrs {
-		ip, _, err := net.ParseCIDR(addr.String())
-		if err == nil && ip.Equal(advIP) {
-			return nil
-		}
-	}
-	return fmt.Errorf("Multi-Host overlay networking requires cluster-advertise(%s) to be configured with a local ip-address that is reachable within the cluster", advIP.String())
-}
-
 func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
-	if self && !d.isSerfAlive() {
+	if self {
 		d.Lock()
 		d.advertiseAddress = advertiseAddress
 		d.bindAddress = bindAddress
@@ -239,68 +82,6 @@ func (d *driver) nodeJoin(advertiseAddress, bindAddress string, self bool) {
 		d.localJoinOnce.Do(func() {
 			d.peerDBUpdateSelf()
 		})
-
-		// If there is no cluster store there is no need to start serf.
-		if d.store != nil {
-			if err := validateSelf(advertiseAddress); err != nil {
-				logrus.Warn(err.Error())
-			}
-			err := d.serfInit()
-			if err != nil {
-				logrus.Errorf("initializing serf instance failed: %v", err)
-				d.Lock()
-				d.advertiseAddress = ""
-				d.bindAddress = ""
-				d.Unlock()
-				return
-			}
-		}
-	}
-
-	d.Lock()
-	if !self {
-		d.neighIP = advertiseAddress
-	}
-	neighIP := d.neighIP
-	d.Unlock()
-
-	if d.serfInstance != nil && neighIP != "" {
-		var err error
-		d.joinOnce.Do(func() {
-			err = d.serfJoin(neighIP)
-			if err == nil {
-				d.pushLocalDb()
-			}
-		})
-		if err != nil {
-			logrus.Errorf("joining serf neighbor %s failed: %v", advertiseAddress, err)
-			d.Lock()
-			d.joinOnce = sync.Once{}
-			d.Unlock()
-			return
-		}
-	}
-}
-
-func (d *driver) pushLocalEndpointEvent(action, nid, eid string) {
-	n := d.network(nid)
-	if n == nil {
-		logrus.Debugf("Error pushing local endpoint event for network %s", nid)
-		return
-	}
-	ep := n.endpoint(eid)
-	if ep == nil {
-		logrus.Debugf("Error pushing local endpoint event for ep %s / %s", nid, eid)
-		return
-	}
-
-	if !d.isSerfAlive() {
-		return
-	}
-	d.notifyCh <- ovNotify{
-		action: "join",
-		nw:     n,
-		ep:     ep,
 	}
 }
 

+ 0 - 134
libnetwork/drivers/overlay/overlay_test.go

@@ -4,24 +4,11 @@
 package overlay
 
 import (
-	"context"
-	"fmt"
-	"net"
-	"os"
-	"path/filepath"
-	"syscall"
 	"testing"
-	"time"
 
-	"github.com/docker/docker/libnetwork/datastore"
-	"github.com/docker/docker/libnetwork/discoverapi"
 	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/pkg/plugingetter"
-	"github.com/docker/libkv/store"
 	"github.com/docker/libkv/store/boltdb"
-	"github.com/vishvananda/netlink/nl"
-	"golang.org/x/sys/unix"
 )
 
 func init() {
@@ -35,64 +22,6 @@ type driverTester struct {
 
 const testNetworkType = "overlay"
 
-func setupDriver(t *testing.T) *driverTester {
-	dt := &driverTester{t: t}
-	config := make(map[string]interface{})
-
-	tmp, err := os.CreateTemp(t.TempDir(), "libnetwork-")
-	if err != nil {
-		t.Fatalf("Error creating temp file: %v", err)
-	}
-	err = tmp.Close()
-	if err != nil {
-		t.Fatalf("Error closing temp file: %v", err)
-	}
-	defaultPrefix := filepath.Join(os.TempDir(), "libnetwork", "test", "overlay")
-
-	config[netlabel.GlobalKVClient] = discoverapi.DatastoreConfigData{
-		Scope:    datastore.GlobalScope,
-		Provider: "boltdb",
-		Address:  filepath.Join(defaultPrefix, filepath.Base(tmp.Name())),
-		Config: &store.Config{
-			Bucket:            "libnetwork",
-			ConnectionTimeout: 3 * time.Second,
-		},
-	}
-
-	if err := Register(dt, config); err != nil {
-		t.Fatal(err)
-	}
-
-	iface, err := net.InterfaceByName("eth0")
-	if err != nil {
-		t.Fatal(err)
-	}
-	addrs, err := iface.Addrs()
-	if err != nil || len(addrs) == 0 {
-		t.Fatal(err)
-	}
-	data := discoverapi.NodeDiscoveryData{
-		Address: addrs[0].String(),
-		Self:    true,
-	}
-	dt.d.DiscoverNew(discoverapi.NodeDiscovery, data)
-	return dt
-}
-
-func cleanupDriver(t *testing.T, dt *driverTester) {
-	ch := make(chan struct{})
-	go func() {
-		Fini(dt.d)
-		close(ch)
-	}()
-
-	select {
-	case <-ch:
-	case <-time.After(10 * time.Second):
-		t.Fatal("test timed out because Fini() did not return on time")
-	}
-}
-
 func (dt *driverTester) GetPluginGetter() plugingetter.PluginGetter {
 	return nil
 }
@@ -119,36 +48,6 @@ func TestOverlayInit(t *testing.T) {
 	}
 }
 
-func TestOverlayFiniWithoutConfig(t *testing.T) {
-	dt := &driverTester{t: t}
-	if err := Register(dt, nil); err != nil {
-		t.Fatal(err)
-	}
-
-	cleanupDriver(t, dt)
-}
-
-func TestOverlayConfig(t *testing.T) {
-	dt := setupDriver(t)
-
-	time.Sleep(1 * time.Second)
-
-	d := dt.d
-	if d.notifyCh == nil {
-		t.Fatal("Driver notify channel wasn't initialized after Config method")
-	}
-
-	if d.exitCh == nil {
-		t.Fatal("Driver serfloop exit channel wasn't initialized after Config method")
-	}
-
-	if d.serfInstance == nil {
-		t.Fatal("Driver serfinstance  hasn't been initialized after Config method")
-	}
-
-	cleanupDriver(t, dt)
-}
-
 func TestOverlayType(t *testing.T) {
 	dt := &driverTester{t: t}
 	if err := Register(dt, nil); err != nil {
@@ -160,36 +59,3 @@ func TestOverlayType(t *testing.T) {
 			dt.d.Type())
 	}
 }
-
-// Test that the netlink socket close unblock the watchMiss to avoid deadlock
-func TestNetlinkSocket(t *testing.T) {
-	// This is the same code used by the overlay driver to create the netlink interface
-	// for the watch miss
-	nlSock, err := nl.Subscribe(syscall.NETLINK_ROUTE, syscall.RTNLGRP_NEIGH)
-	if err != nil {
-		t.Fatal()
-	}
-	// set the receive timeout to not remain stuck on the RecvFrom if the fd gets closed
-	tv := unix.NsecToTimeval(soTimeout.Nanoseconds())
-	err = nlSock.SetReceiveTimeout(&tv)
-	if err != nil {
-		t.Fatal()
-	}
-	n := &network{id: "testnetid"}
-	ch := make(chan error)
-	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
-	defer cancel()
-	go func() {
-		n.watchMiss(nlSock, fmt.Sprintf("/proc/%d/task/%d/ns/net", os.Getpid(), syscall.Gettid()))
-		ch <- nil
-	}()
-	time.Sleep(5 * time.Second)
-	nlSock.Close()
-	select {
-	case <-ch:
-	case <-ctx.Done():
-		{
-			t.Fatalf("Timeout expired")
-		}
-	}
-}

+ 1 - 14
libnetwork/drivers/overlay/peerdb.go

@@ -315,11 +315,7 @@ func (d *driver) peerAddOp(nid, eid string, peerIP net.IP, peerIPMask net.IPMask
 		return fmt.Errorf("couldn't find the subnet %q in network %q", IP.String(), n.id)
 	}
 
-	if err := n.obtainVxlanID(s); err != nil {
-		return fmt.Errorf("couldn't get vxlan id for %q: %v", s.subnetIP.String(), err)
-	}
-
-	if err := n.joinSandbox(s, false, false); err != nil {
+	if err := n.joinSandbox(s, false); err != nil {
 		return fmt.Errorf("subnet sandbox join failed for %q: %v", s.subnetIP.String(), err)
 	}
 
@@ -434,15 +430,6 @@ func (d *driver) peerFlushOp(nid string) error {
 	return nil
 }
 
-func (d *driver) pushLocalDb() {
-	d.peerDbWalk(func(nid string, pKey *peerKey, pEntry *peerEntry) bool {
-		if pEntry.isLocal {
-			d.pushLocalEndpointEvent("join", nid, pEntry.eid)
-		}
-		return false
-	})
-}
-
 func (d *driver) peerDBUpdateSelf() {
 	d.peerDbWalk(func(nid string, pkey *peerKey, pEntry *peerEntry) bool {
 		if pEntry.isLocal {

+ 2 - 31
libnetwork/drivers/windows/overlay/overlay_windows.go

@@ -11,7 +11,6 @@ import (
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/discoverapi"
 	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/libnetwork/types"
 	"github.com/sirupsen/logrus"
 )
@@ -21,12 +20,8 @@ const (
 )
 
 type driver struct {
-	config     map[string]interface{}
-	networks   networkTable
-	store      datastore.DataStore
-	localStore datastore.DataStore
-	once       sync.Once
-	joinOnce   sync.Once
+	config   map[string]interface{}
+	networks networkTable
 	sync.Mutex
 }
 
@@ -42,30 +37,6 @@ func Register(r driverapi.Registerer, config map[string]interface{}) error {
 		config:   config,
 	}
 
-	if data, ok := config[netlabel.GlobalKVClient]; ok {
-		var err error
-		dsc, ok := data.(discoverapi.DatastoreConfigData)
-		if !ok {
-			return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
-		}
-		d.store, err = datastore.NewDataStoreFromConfig(dsc)
-		if err != nil {
-			return types.InternalErrorf("failed to initialize data store: %v", err)
-		}
-	}
-
-	if data, ok := config[netlabel.LocalKVClient]; ok {
-		var err error
-		dsc, ok := data.(discoverapi.DatastoreConfigData)
-		if !ok {
-			return types.InternalErrorf("incorrect data in datastore configuration: %v", data)
-		}
-		d.localStore, err = datastore.NewDataStoreFromConfig(dsc)
-		if err != nil {
-			return types.InternalErrorf("failed to initialize local data store: %v", err)
-		}
-	}
-
 	d.restoreHNSNetworks()
 
 	return r.RegisterDriver(networkType, d, c)

+ 0 - 47
libnetwork/netlabel/labels.go

@@ -32,12 +32,6 @@ const (
 	// DriverMTU constant represents the MTU size for the network driver
 	DriverMTU = DriverPrefix + ".mtu"
 
-	// OverlayBindInterface constant represents overlay driver bind interface
-	OverlayBindInterface = DriverPrefix + ".overlay.bind_interface"
-
-	// OverlayNeighborIP constant represents overlay driver neighbor IP
-	OverlayNeighborIP = DriverPrefix + ".overlay.neighbor_ip"
-
 	// OverlayVxlanIDList constant represents a list of VXLAN Ids as csv
 	OverlayVxlanIDList = DriverPrefix + ".overlay.vxlanid_list"
 
@@ -53,47 +47,6 @@ const (
 	// HostIP is the Source-IP Address used to SNAT container traffic
 	HostIP = Prefix + ".host_ipv4"
 
-	// GlobalKVProvider constant represents the KV provider backend
-	GlobalKVProvider = DriverPrivatePrefix + "globalkv_provider"
-
-	// GlobalKVProviderURL constant represents the KV provider URL
-	GlobalKVProviderURL = DriverPrivatePrefix + "globalkv_provider_url"
-
-	// GlobalKVProviderConfig constant represents the KV provider Config
-	GlobalKVProviderConfig = DriverPrivatePrefix + "globalkv_provider_config"
-
-	// GlobalKVClient constants represents the global kv store client
-	GlobalKVClient = DriverPrivatePrefix + "globalkv_client"
-
-	// LocalKVProvider constant represents the KV provider backend
-	LocalKVProvider = DriverPrivatePrefix + "localkv_provider"
-
-	// LocalKVProviderURL constant represents the KV provider URL
-	LocalKVProviderURL = DriverPrivatePrefix + "localkv_provider_url"
-
-	// LocalKVProviderConfig constant represents the KV provider Config
-	LocalKVProviderConfig = DriverPrivatePrefix + "localkv_provider_config"
-
 	// LocalKVClient constants represents the local kv store client
 	LocalKVClient = DriverPrivatePrefix + "localkv_client"
 )
-
-// MakeKVProvider returns the kvprovider label for the scope
-func MakeKVProvider(scope string) string {
-	return DriverPrivatePrefix + scope + "kv_provider"
-}
-
-// MakeKVProviderURL returns the kvprovider url label for the scope
-func MakeKVProviderURL(scope string) string {
-	return DriverPrivatePrefix + scope + "kv_provider_url"
-}
-
-// MakeKVProviderConfig returns the kvprovider config label for the scope
-func MakeKVProviderConfig(scope string) string {
-	return DriverPrivatePrefix + scope + "kv_provider_config"
-}
-
-// MakeKVClient returns the kv client label for the scope
-func MakeKVClient(scope string) string {
-	return DriverPrivatePrefix + scope + "kv_client"
-}

+ 0 - 52
libnetwork/netutils/utils.go

@@ -62,35 +62,6 @@ func NetworkRange(network *net.IPNet) (net.IP, net.IP) {
 	return firstIP, lastIP
 }
 
-// GetIfaceAddr returns the first IPv4 address and slice of IPv6 addresses for the specified network interface
-func GetIfaceAddr(name string) (net.Addr, []net.Addr, error) {
-	iface, err := net.InterfaceByName(name)
-	if err != nil {
-		return nil, nil, err
-	}
-	addrs, err := iface.Addrs()
-	if err != nil {
-		return nil, nil, err
-	}
-	var addrs4, addrs6 []net.Addr
-	for _, addr := range addrs {
-		ip := (addr.(*net.IPNet)).IP
-		if ip4 := ip.To4(); ip4 != nil {
-			addrs4 = append(addrs4, addr)
-		} else if ip6 := ip.To16(); len(ip6) == net.IPv6len {
-			addrs6 = append(addrs6, addr)
-		}
-	}
-	switch {
-	case len(addrs4) == 0:
-		return nil, nil, fmt.Errorf("interface %v has no IPv4 addresses", name)
-	case len(addrs4) > 1:
-		fmt.Printf("Interface %v has more than 1 IPv4 address. Defaulting to using %v\n",
-			name, (addrs4[0].(*net.IPNet)).IP)
-	}
-	return addrs4[0], addrs6, nil
-}
-
 func genMAC(ip net.IP) net.HardwareAddr {
 	hw := make(net.HardwareAddr, 6)
 	// The first byte of the MAC address has to comply with these rules:
@@ -173,26 +144,3 @@ func ReverseIP(IP string) string {
 
 	return strings.Join(reverseIP, ".")
 }
-
-// ParseAlias parses and validates the specified string as an alias format (name:alias)
-func ParseAlias(val string) (string, string, error) {
-	if val == "" {
-		return "", "", errors.New("empty string specified for alias")
-	}
-	arr := strings.SplitN(val, ":", 3)
-	if len(arr) > 2 {
-		return "", "", errors.New("bad format for alias: " + val)
-	}
-	if len(arr) == 1 {
-		return val, val, nil
-	}
-	return arr[0], arr[1], nil
-}
-
-// ValidateAlias validates that the specified string has a valid alias format (containerName:alias).
-func ValidateAlias(val string) (string, error) {
-	if _, _, err := ParseAlias(val); err != nil {
-		return val, err
-	}
-	return val, nil
-}