Browse Source

Merge pull request #45908 from corhere/libn/drop-swarmkit-cruft

libnetwork: drop cruft formerly needed by Swarmkit
Bjorn Neergaard 2 years ago
parent
commit
c57097bcd4
31 changed files with 159 additions and 1458 deletions
  1. 0 213
      libnetwork/bitseq/sequence.go
  2. 0 325
      libnetwork/bitseq/sequence_test.go
  3. 0 128
      libnetwork/bitseq/store.go
  4. 0 8
      libnetwork/driverapi/driverapi.go
  5. 0 7
      libnetwork/drivers/bridge/brmanager/brmanager.go
  6. 0 7
      libnetwork/drivers/host/host.go
  7. 0 7
      libnetwork/drivers/ipvlan/ivmanager/ivmanager.go
  8. 0 7
      libnetwork/drivers/macvlan/mvmanager/mvmanager.go
  9. 0 7
      libnetwork/drivers/overlay/ovmanager/ovmanager.go
  10. 0 8
      libnetwork/drivers/remote/driver.go
  11. 0 73
      libnetwork/drvregistry/drvregistry.go
  12. 0 147
      libnetwork/drvregistry/drvregistry_test.go
  13. 19 0
      libnetwork/drvregistry/networks_test.go
  14. 0 76
      libnetwork/idm/idm.go
  15. 0 294
      libnetwork/idm/idm_test.go
  16. 0 10
      libnetwork/ipamapi/contract.go
  17. 0 17
      libnetwork/ipams/builtin/builtin_unix.go
  18. 0 17
      libnetwork/ipams/builtin/builtin_windows.go
  19. 0 7
      libnetwork/ipams/null/null.go
  20. 0 7
      libnetwork/ipams/remote/remote.go
  21. 1 1
      vendor.mod
  22. 2 2
      vendor.sum
  23. 69 0
      vendor/github.com/moby/swarmkit/v2/internal/idm/idm.go
  24. 3 4
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_darwin.go
  25. 5 8
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_ipam.go
  26. 7 8
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_network_linux.go
  27. 12 7
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_network_windows.go
  28. 4 11
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/manager.go
  29. 30 41
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/networkallocator.go
  30. 5 10
      vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/portallocator.go
  31. 2 1
      vendor/modules.txt

+ 0 - 213
libnetwork/bitseq/sequence.go

@@ -1,213 +0,0 @@
-// Package bitseq provides a structure and utilities for representing a long
-// bitmask which is persisted in a datastore. It is backed by [bitmap.Bitmap]
-// which operates directly on the encoded representation, without uncompressing.
-package bitseq
-
-import (
-	"encoding/json"
-	"fmt"
-	"sync"
-
-	"github.com/docker/docker/libnetwork/bitmap"
-	"github.com/docker/docker/libnetwork/datastore"
-	"github.com/docker/docker/libnetwork/types"
-)
-
-var (
-	// ErrNoBitAvailable is returned when no more bits are available to set
-	ErrNoBitAvailable = bitmap.ErrNoBitAvailable
-	// ErrBitAllocated is returned when the specific bit requested is already set
-	ErrBitAllocated = bitmap.ErrBitAllocated
-)
-
-// Handle contains the sequence representing the bitmask and its identifier
-type Handle struct {
-	app      string
-	id       string
-	dbIndex  uint64
-	dbExists bool
-	store    datastore.DataStore
-	bm       *bitmap.Bitmap
-	mu       sync.Mutex
-}
-
-// NewHandle returns a thread-safe instance of the bitmask handler
-func NewHandle(app string, ds datastore.DataStore, id string, numElements uint64) (*Handle, error) {
-	h := &Handle{
-		bm:    bitmap.New(numElements),
-		app:   app,
-		id:    id,
-		store: ds,
-	}
-
-	if h.store == nil {
-		return h, nil
-	}
-
-	// Get the initial status from the ds if present.
-	if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
-		return nil, err
-	}
-
-	// If the handle is not in store, write it.
-	if !h.Exists() {
-		if err := h.writeToStore(); err != nil {
-			return nil, fmt.Errorf("failed to write bitsequence to store: %v", err)
-		}
-	}
-
-	return h, nil
-}
-
-func (h *Handle) getCopy() *Handle {
-	return &Handle{
-		bm:       bitmap.Copy(h.bm),
-		app:      h.app,
-		id:       h.id,
-		dbIndex:  h.dbIndex,
-		dbExists: h.dbExists,
-		store:    h.store,
-	}
-}
-
-// SetAnyInRange atomically sets the first unset bit in the specified range in the sequence and returns the corresponding ordinal
-func (h *Handle) SetAnyInRange(start, end uint64, serial bool) (uint64, error) {
-	return h.apply(func(b *bitmap.Bitmap) (uint64, error) { return b.SetAnyInRange(start, end, serial) })
-}
-
-// SetAny atomically sets the first unset bit in the sequence and returns the corresponding ordinal
-func (h *Handle) SetAny(serial bool) (uint64, error) {
-	return h.apply(func(b *bitmap.Bitmap) (uint64, error) { return b.SetAny(serial) })
-}
-
-// Set atomically sets the corresponding bit in the sequence
-func (h *Handle) Set(ordinal uint64) error {
-	_, err := h.apply(func(b *bitmap.Bitmap) (uint64, error) { return 0, b.Set(ordinal) })
-	return err
-}
-
-// Unset atomically unsets the corresponding bit in the sequence
-func (h *Handle) Unset(ordinal uint64) error {
-	_, err := h.apply(func(b *bitmap.Bitmap) (uint64, error) { return 0, b.Unset(ordinal) })
-	return err
-}
-
-// IsSet atomically checks if the ordinal bit is set. In case ordinal
-// is outside of the bit sequence limits, false is returned.
-func (h *Handle) IsSet(ordinal uint64) bool {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return h.bm.IsSet(ordinal)
-}
-
-// set/reset the bit
-func (h *Handle) apply(op func(*bitmap.Bitmap) (uint64, error)) (uint64, error) {
-	for {
-		var store datastore.DataStore
-		h.mu.Lock()
-		store = h.store
-		if store != nil {
-			h.mu.Unlock() // The lock is acquired in the GetObject
-			if err := store.GetObject(datastore.Key(h.Key()...), h); err != nil && err != datastore.ErrKeyNotFound {
-				return 0, err
-			}
-			h.mu.Lock() // Acquire the lock back
-		}
-
-		// Create a private copy of h and work on it
-		nh := h.getCopy()
-
-		ret, err := op(nh.bm)
-		if err != nil {
-			h.mu.Unlock()
-			return ret, err
-		}
-
-		if h.store != nil {
-			h.mu.Unlock()
-			// Attempt to write private copy to store
-			if err := nh.writeToStore(); err != nil {
-				if _, ok := err.(types.RetryError); !ok {
-					return ret, fmt.Errorf("internal failure while setting the bit: %v", err)
-				}
-				// Retry
-				continue
-			}
-			h.mu.Lock()
-		}
-
-		// Previous atomic push was successful. Save private copy to local copy
-		h.bm = nh.bm
-		h.dbExists = nh.dbExists
-		h.dbIndex = nh.dbIndex
-		h.mu.Unlock()
-		return ret, nil
-	}
-}
-
-// Destroy removes from the datastore the data belonging to this handle
-func (h *Handle) Destroy() error {
-	for {
-		if err := h.deleteFromStore(); err != nil {
-			if _, ok := err.(types.RetryError); !ok {
-				return fmt.Errorf("internal failure while destroying the sequence: %v", err)
-			}
-			// Fetch latest
-			if err := h.store.GetObject(datastore.Key(h.Key()...), h); err != nil {
-				if err == datastore.ErrKeyNotFound { // already removed
-					return nil
-				}
-				return fmt.Errorf("failed to fetch from store when destroying the sequence: %v", err)
-			}
-			continue
-		}
-		return nil
-	}
-}
-
-// Bits returns the length of the bit sequence
-func (h *Handle) Bits() uint64 {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return h.bm.Bits()
-}
-
-// Unselected returns the number of bits which are not selected
-func (h *Handle) Unselected() uint64 {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return h.bm.Unselected()
-}
-
-func (h *Handle) String() string {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return fmt.Sprintf("App: %s, ID: %s, DBIndex: 0x%x, %s",
-		h.app, h.id, h.dbIndex, h.bm)
-}
-
-type jsonMessage struct {
-	ID       string         `json:"id"`
-	Sequence *bitmap.Bitmap `json:"sequence"`
-}
-
-// MarshalJSON encodes h into a JSON message.
-func (h *Handle) MarshalJSON() ([]byte, error) {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	m := jsonMessage{ID: h.id, Sequence: h.bm}
-	return json.Marshal(m)
-}
-
-// UnmarshalJSON decodes a JSON message into h.
-func (h *Handle) UnmarshalJSON(data []byte) error {
-	var m jsonMessage
-	if err := json.Unmarshal(data, &m); err != nil {
-		return err
-	}
-
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	h.id, h.bm = m.ID, m.Sequence
-	return nil
-}

+ 0 - 325
libnetwork/bitseq/sequence_test.go

@@ -1,325 +0,0 @@
-package bitseq
-
-import (
-	"fmt"
-	"math/rand"
-	"os"
-	"path/filepath"
-	"testing"
-	"time"
-
-	"github.com/docker/docker/libnetwork/datastore"
-	store "github.com/docker/docker/libnetwork/internal/kvstore"
-	"github.com/docker/docker/libnetwork/internal/kvstore/boltdb"
-)
-
-var defaultPrefix = filepath.Join(os.TempDir(), "libnetwork", "test", "bitseq")
-
-func init() {
-	boltdb.Register()
-}
-
-func randomLocalStore() (datastore.DataStore, error) {
-	tmp, err := os.CreateTemp("", "libnetwork-")
-	if err != nil {
-		return nil, fmt.Errorf("Error creating temp file: %v", err)
-	}
-	if err := tmp.Close(); err != nil {
-		return nil, fmt.Errorf("Error closing temp file: %v", err)
-	}
-	return datastore.NewDataStore(datastore.ScopeCfg{
-		Client: datastore.ScopeClientCfg{
-			Provider: "boltdb",
-			Address:  filepath.Join(defaultPrefix, filepath.Base(tmp.Name())),
-			Config: &store.Config{
-				Bucket:            "libnetwork",
-				ConnectionTimeout: 3 * time.Second,
-			},
-		},
-	})
-}
-
-const blockLen = 32
-
-// This one tests an allocation pattern which unveiled an issue in pushReservation
-// Specifically a failure in detecting when we are in the (B) case (the bit to set
-// belongs to the last block of the current sequence). Because of a bug, code
-// was assuming the bit belonged to a block in the middle of the current sequence.
-// Which in turn caused an incorrect allocation when requesting a bit which is not
-// in the first or last sequence block.
-func TestSetAnyInRange(t *testing.T) {
-	numBits := uint64(8 * blockLen)
-	hnd, err := NewHandle("", nil, "", numBits)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err := hnd.Set(0); err != nil {
-		t.Fatal(err)
-	}
-
-	if err := hnd.Set(255); err != nil {
-		t.Fatal(err)
-	}
-
-	o, err := hnd.SetAnyInRange(128, 255, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 128 {
-		t.Fatalf("Unexpected ordinal: %d", o)
-	}
-
-	o, err = hnd.SetAnyInRange(128, 255, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if o != 129 {
-		t.Fatalf("Unexpected ordinal: %d", o)
-	}
-
-	o, err = hnd.SetAnyInRange(246, 255, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 246 {
-		t.Fatalf("Unexpected ordinal: %d", o)
-	}
-
-	o, err = hnd.SetAnyInRange(246, 255, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 247 {
-		t.Fatalf("Unexpected ordinal: %d", o)
-	}
-}
-
-func TestRandomAllocateDeallocate(t *testing.T) {
-	ds, err := randomLocalStore()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	numBits := int(16 * blockLen)
-	hnd, err := NewHandle("bitseq-test/data/", ds, "test1", uint64(numBits))
-	if err != nil {
-		t.Fatal(err)
-	}
-	defer func() {
-		if err := hnd.Destroy(); err != nil {
-			t.Fatal(err)
-		}
-	}()
-
-	seed := time.Now().Unix()
-	rng := rand.New(rand.NewSource(seed))
-
-	// Allocate all bits using a random pattern
-	pattern := rng.Perm(numBits)
-	for _, bit := range pattern {
-		err := hnd.Set(uint64(bit))
-		if err != nil {
-			t.Errorf("Unexpected failure on allocation of %d: %v.\nSeed: %d.\n%s", bit, err, seed, hnd)
-		}
-	}
-	if unselected := hnd.Unselected(); unselected != 0 {
-		t.Errorf("Expected full sequence. Instead found %d free bits. Seed: %d.\n%s", unselected, seed, hnd)
-	}
-
-	// Deallocate all bits using a random pattern
-	pattern = rng.Perm(numBits)
-	for _, bit := range pattern {
-		err := hnd.Unset(uint64(bit))
-		if err != nil {
-			t.Errorf("Unexpected failure on deallocation of %d: %v.\nSeed: %d.\n%s", bit, err, seed, hnd)
-		}
-	}
-	if unselected := hnd.Unselected(); unselected != uint64(numBits) {
-		t.Errorf("Expected full sequence. Instead found %d free bits. Seed: %d.\n%s", unselected, seed, hnd)
-	}
-}
-
-func TestRetrieveFromStore(t *testing.T) {
-	ds, err := randomLocalStore()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	numBits := int(8 * blockLen)
-	hnd, err := NewHandle("bitseq-test/data/", ds, "test1", uint64(numBits))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	// Allocate first half of the bits
-	for i := 0; i < numBits/2; i++ {
-		_, err := hnd.SetAny(false)
-		if err != nil {
-			t.Fatalf("Unexpected failure on allocation %d: %v\n%s", i, err, hnd)
-		}
-	}
-	hnd0 := hnd.String()
-
-	// Retrieve same handle
-	hnd, err = NewHandle("bitseq-test/data/", ds, "test1", uint64(numBits))
-	if err != nil {
-		t.Fatal(err)
-	}
-	hnd1 := hnd.String()
-
-	if hnd1 != hnd0 {
-		t.Fatalf("%v\n%v", hnd0, hnd1)
-	}
-
-	err = hnd.Destroy()
-	if err != nil {
-		t.Fatal(err)
-	}
-}
-
-func testSetRollover(t *testing.T, serial bool) {
-	ds, err := randomLocalStore()
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	numBlocks := uint32(8)
-	numBits := int(numBlocks * blockLen)
-	hnd, err := NewHandle("bitseq-test/data/", ds, "test1", uint64(numBits))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	// Allocate first half of the bits
-	for i := 0; i < numBits/2; i++ {
-		_, err := hnd.SetAny(serial)
-		if err != nil {
-			t.Fatalf("Unexpected failure on allocation %d: %v\n%s", i, err, hnd)
-		}
-	}
-
-	if unselected := hnd.Unselected(); unselected != uint64(numBits/2) {
-		t.Fatalf("Expected full sequence. Instead found %d free bits. %s", unselected, hnd)
-	}
-
-	seed := time.Now().Unix()
-	rng := rand.New(rand.NewSource(seed))
-
-	// Deallocate half of the allocated bits following a random pattern
-	pattern := rng.Perm(numBits / 2)
-	for i := 0; i < numBits/4; i++ {
-		bit := pattern[i]
-		err := hnd.Unset(uint64(bit))
-		if err != nil {
-			t.Fatalf("Unexpected failure on deallocation of %d: %v.\nSeed: %d.\n%s", bit, err, seed, hnd)
-		}
-	}
-	if unselected := hnd.Unselected(); unselected != uint64(3*numBits/4) {
-		t.Fatalf("Unexpected free bits: found %d free bits.\nSeed: %d.\n%s", unselected, seed, hnd)
-	}
-
-	// request to allocate for remaining half of the bits
-	for i := 0; i < numBits/2; i++ {
-		_, err := hnd.SetAny(serial)
-		if err != nil {
-			t.Fatalf("Unexpected failure on allocation %d: %v\nSeed: %d\n%s", i, err, seed, hnd)
-		}
-	}
-
-	// At this point all the bits must be allocated except the randomly unallocated bits
-	// which were unallocated in the first half of the bit sequence
-	if unselected := hnd.Unselected(); unselected != uint64(numBits/4) {
-		t.Fatalf("Unexpected number of unselected bits %d, Expected %d", unselected, numBits/4)
-	}
-
-	for i := 0; i < numBits/4; i++ {
-		_, err := hnd.SetAny(serial)
-		if err != nil {
-			t.Fatalf("Unexpected failure on allocation %d: %v\nSeed: %d\n%s", i, err, seed, hnd)
-		}
-	}
-	// Now requesting to allocate the unallocated random bits (qurter of the number of bits) should
-	// leave no more bits that can be allocated.
-	if hnd.Unselected() != 0 {
-		t.Fatalf("Unexpected number of unselected bits %d, Expected %d", hnd.Unselected(), 0)
-	}
-
-	err = hnd.Destroy()
-	if err != nil {
-		t.Fatal(err)
-	}
-}
-
-func TestSetRollover(t *testing.T) {
-	testSetRollover(t, false)
-}
-
-func TestSetRolloverSerial(t *testing.T) {
-	testSetRollover(t, true)
-}
-
-func TestMarshalJSON(t *testing.T) {
-	const expectedID = "my-bitseq"
-	expected := []byte("hello libnetwork")
-	hnd, err := NewHandle("", nil, expectedID, uint64(len(expected)*8))
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	for i, c := range expected {
-		for j := 0; j < 8; j++ {
-			if c&(1<<j) == 0 {
-				continue
-			}
-			if err := hnd.Set(uint64(i*8 + j)); err != nil {
-				t.Fatal(err)
-			}
-		}
-	}
-
-	hstr := hnd.String()
-	t.Log(hstr)
-	marshaled, err := hnd.MarshalJSON()
-	if err != nil {
-		t.Fatalf("MarshalJSON() err = %v", err)
-	}
-	t.Logf("%s", marshaled)
-
-	// Serializations of hnd as would be marshaled by versions of the code
-	// found in the wild. We need to support unmarshaling old versions to
-	// maintain backwards compatibility with sequences persisted on disk.
-	const (
-		goldenV0 = `{"id":"my-bitseq","sequence":"AAAAAAAAAIAAAAAAAAAAPRamNjYAAAAAAAAAAfYENpYAAAAAAAAAAUZ2pi4AAAAAAAAAAe72TtYAAAAAAAAAAQ=="}`
-	)
-
-	if string(marshaled) != goldenV0 {
-		t.Errorf("MarshalJSON() output differs from golden. Please add a new golden case to this test.")
-	}
-
-	for _, tt := range []struct {
-		name string
-		data []byte
-	}{
-		{name: "Live", data: marshaled},
-		{name: "Golden-v0", data: []byte(goldenV0)},
-	} {
-		tt := tt
-		t.Run("UnmarshalJSON="+tt.name, func(t *testing.T) {
-			hnd2, err := NewHandle("", nil, "", 0)
-			if err != nil {
-				t.Fatal(err)
-			}
-			if err := hnd2.UnmarshalJSON(tt.data); err != nil {
-				t.Errorf("UnmarshalJSON() err = %v", err)
-			}
-
-			h2str := hnd2.String()
-			t.Log(h2str)
-			if hstr != h2str {
-				t.Errorf("Unmarshaled a different bitseq: want %q, got %q", hstr, h2str)
-			}
-		})
-	}
-}

+ 0 - 128
libnetwork/bitseq/store.go

@@ -1,128 +0,0 @@
-package bitseq
-
-import (
-	"encoding/json"
-
-	"github.com/docker/docker/libnetwork/bitmap"
-	"github.com/docker/docker/libnetwork/datastore"
-	"github.com/docker/docker/libnetwork/types"
-)
-
-// Key provides the Key to be used in KV Store
-func (h *Handle) Key() []string {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return []string{h.app, h.id}
-}
-
-// KeyPrefix returns the immediate parent key that can be used for tree walk
-func (h *Handle) KeyPrefix() []string {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return []string{h.app}
-}
-
-// Value marshals the data to be stored in the KV store
-func (h *Handle) Value() []byte {
-	b, err := json.Marshal(h)
-	if err != nil {
-		return nil
-	}
-	return b
-}
-
-// SetValue unmarshals the data from the KV store
-func (h *Handle) SetValue(value []byte) error {
-	return json.Unmarshal(value, h)
-}
-
-// Index returns the latest DB Index as seen by this object
-func (h *Handle) Index() uint64 {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return h.dbIndex
-}
-
-// SetIndex method allows the datastore to store the latest DB Index into this object
-func (h *Handle) SetIndex(index uint64) {
-	h.mu.Lock()
-	h.dbIndex = index
-	h.dbExists = true
-	h.mu.Unlock()
-}
-
-// Exists method is true if this object has been stored in the DB.
-func (h *Handle) Exists() bool {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-	return h.dbExists
-}
-
-// New method returns a handle based on the receiver handle
-func (h *Handle) New() datastore.KVObject {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-
-	return &Handle{
-		app:   h.app,
-		store: h.store,
-	}
-}
-
-// CopyTo deep copies the handle into the passed destination object
-func (h *Handle) CopyTo(o datastore.KVObject) error {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-
-	dstH := o.(*Handle)
-	if h == dstH {
-		return nil
-	}
-	dstH.mu.Lock()
-	defer dstH.mu.Unlock()
-	dstH.bm = bitmap.Copy(h.bm)
-	dstH.app = h.app
-	dstH.id = h.id
-	dstH.dbIndex = h.dbIndex
-	dstH.dbExists = h.dbExists
-	dstH.store = h.store
-
-	return nil
-}
-
-// Skip provides a way for a KV Object to avoid persisting it in the KV Store
-func (h *Handle) Skip() bool {
-	return false
-}
-
-// DataScope method returns the storage scope of the datastore
-func (h *Handle) DataScope() string {
-	h.mu.Lock()
-	defer h.mu.Unlock()
-
-	return h.store.Scope()
-}
-
-func (h *Handle) writeToStore() error {
-	h.mu.Lock()
-	store := h.store
-	h.mu.Unlock()
-	if store == nil {
-		return nil
-	}
-	err := store.PutObjectAtomic(h)
-	if err == datastore.ErrKeyModified {
-		return types.RetryErrorf("failed to perform atomic write (%v). Retry might fix the error", err)
-	}
-	return err
-}
-
-func (h *Handle) deleteFromStore() error {
-	h.mu.Lock()
-	store := h.store
-	h.mu.Unlock()
-	if store == nil {
-		return nil
-	}
-	return store.DeleteObjectAtomic(h)
-}

+ 0 - 8
libnetwork/driverapi/driverapi.go

@@ -4,7 +4,6 @@ import (
 	"net"
 
 	"github.com/docker/docker/libnetwork/discoverapi"
-	"github.com/docker/docker/pkg/plugingetter"
 )
 
 // NetworkPluginEndpointType represents the Endpoint Type used by Plugin system
@@ -161,13 +160,6 @@ type Registerer interface {
 	RegisterDriver(name string, driver Driver, capability Capability) error
 }
 
-// DriverCallback provides a Callback interface for Drivers into LibNetwork
-type DriverCallback interface {
-	Registerer
-	// GetPluginGetter returns the pluginv2 getter.
-	GetPluginGetter() plugingetter.PluginGetter
-}
-
 // Capability represents the high level capabilities of the drivers which libnetwork can make use of
 type Capability struct {
 	DataScope         string

+ 0 - 7
libnetwork/drivers/bridge/brmanager/brmanager.go

@@ -11,13 +11,6 @@ const networkType = "bridge"
 
 type driver struct{}
 
-// Init registers a new instance of bridge manager driver.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc)
-}
-
 // Register registers a new instance of the bridge manager driver with r.
 func Register(r driverapi.Registerer) error {
 	return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{

+ 0 - 7
libnetwork/drivers/host/host.go

@@ -16,13 +16,6 @@ type driver struct {
 	sync.Mutex
 }
 
-// Init registers a new instance of host driver.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc)
-}
-
 func Register(r driverapi.Registerer) error {
 	return r.RegisterDriver(NetworkType, &driver{}, driverapi.Capability{
 		DataScope:         datastore.LocalScope,

+ 0 - 7
libnetwork/drivers/ipvlan/ivmanager/ivmanager.go

@@ -11,13 +11,6 @@ const networkType = "ipvlan"
 
 type driver struct{}
 
-// Init registers a new instance of the ipvlan manager driver.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc)
-}
-
 // Register registers a new instance of the ipvlan manager driver.
 func Register(r driverapi.Registerer) error {
 	return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{

+ 0 - 7
libnetwork/drivers/macvlan/mvmanager/mvmanager.go

@@ -11,13 +11,6 @@ const networkType = "macvlan"
 
 type driver struct{}
 
-// Init registers a new instance of the macvlan manager driver.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc)
-}
-
 // Register registers a new instance of the macvlan manager driver.
 func Register(r driverapi.Registerer) error {
 	return r.RegisterDriver(networkType, &driver{}, driverapi.Capability{

+ 0 - 7
libnetwork/drivers/overlay/ovmanager/ovmanager.go

@@ -46,13 +46,6 @@ type network struct {
 	subnets []*subnet
 }
 
-// Init registers a new instance of the overlay driver.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc)
-}
-
 // Register registers a new instance of the overlay driver.
 func Register(r driverapi.Registerer) error {
 	return r.RegisterDriver(networkType, newDriver(), driverapi.Capability{

+ 0 - 8
libnetwork/drivers/remote/driver.go

@@ -29,14 +29,6 @@ func newDriver(name string, client *plugins.Client) driverapi.Driver {
 	return &driver{networkType: name, endpoint: client}
 }
 
-// Init makes sure a remote driver is registered when a network driver
-// plugin is activated.
-//
-// Deprecated: use [Register].
-func Init(dc driverapi.DriverCallback, _ map[string]interface{}) error {
-	return Register(dc, dc.GetPluginGetter())
-}
-
 // Register makes sure a remote driver is registered with r when a network
 // driver plugin is activated.
 func Register(r driverapi.Registerer, pg plugingetter.PluginGetter) error {

+ 0 - 73
libnetwork/drvregistry/drvregistry.go

@@ -1,73 +0,0 @@
-package drvregistry
-
-import (
-	"fmt"
-
-	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/ipamapi"
-	"github.com/docker/docker/pkg/plugingetter"
-)
-
-// DrvRegistry holds the registry of all network drivers and IPAM drivers that it knows about.
-type DrvRegistry struct {
-	Networks
-	IPAMs
-	pluginGetter plugingetter.PluginGetter
-}
-
-var (
-	_ driverapi.DriverCallback = (*DrvRegistry)(nil)
-	_ ipamapi.Callback         = (*DrvRegistry)(nil)
-)
-
-// InitFunc defines the driver initialization function signature.
-type InitFunc func(driverapi.DriverCallback, map[string]interface{}) error
-
-// Placeholder is a type for function arguments which need to be present for Swarmkit
-// to compile, but for which the only acceptable value is nil.
-type Placeholder *struct{}
-
-// New returns a new legacy driver registry.
-//
-// Deprecated: use the separate [Networks] and [IPAMs] registries.
-func New(lDs, gDs Placeholder, dfn DriverNotifyFunc, ifn Placeholder, pg plugingetter.PluginGetter) (*DrvRegistry, error) {
-	return &DrvRegistry{
-		Networks:     Networks{Notify: dfn},
-		pluginGetter: pg,
-	}, nil
-}
-
-// AddDriver adds a network driver to the registry.
-//
-// Deprecated: call fn(r, config) directly.
-func (r *DrvRegistry) AddDriver(_ string, fn InitFunc, config map[string]interface{}) error {
-	return fn(r, config)
-}
-
-// IPAMDefaultAddressSpaces returns the default address space strings for the passed IPAM driver name.
-//
-// Deprecated: call GetDefaultAddressSpaces() on the IPAM driver.
-func (r *DrvRegistry) IPAMDefaultAddressSpaces(name string) (string, string, error) {
-	d, _ := r.IPAM(name)
-
-	if d == nil {
-		return "", "", fmt.Errorf("ipam %s not found", name)
-	}
-
-	return d.GetDefaultAddressSpaces()
-}
-
-// GetPluginGetter returns the plugingetter
-func (r *DrvRegistry) GetPluginGetter() plugingetter.PluginGetter {
-	return r.pluginGetter
-}
-
-// Driver returns the network driver instance registered under name, and its capability.
-func (r *DrvRegistry) Driver(name string) (driverapi.Driver, *driverapi.Capability) {
-	d, c := r.Networks.Driver(name)
-
-	if c == (driverapi.Capability{}) {
-		return d, nil
-	}
-	return d, &c
-}

+ 0 - 147
libnetwork/drvregistry/drvregistry_test.go

@@ -1,147 +0,0 @@
-package drvregistry
-
-import (
-	"runtime"
-	"sort"
-	"testing"
-
-	"github.com/docker/docker/libnetwork/datastore"
-	"github.com/docker/docker/libnetwork/driverapi"
-	"github.com/docker/docker/libnetwork/ipamapi"
-	builtinIpam "github.com/docker/docker/libnetwork/ipams/builtin"
-	nullIpam "github.com/docker/docker/libnetwork/ipams/null"
-	remoteIpam "github.com/docker/docker/libnetwork/ipams/remote"
-	"gotest.tools/v3/assert"
-	is "gotest.tools/v3/assert/cmp"
-)
-
-const mockDriverName = "mock-driver"
-
-type mockDriver struct {
-	driverapi.Driver
-}
-
-var mockDriverCaps = driverapi.Capability{DataScope: datastore.LocalScope}
-
-var md = mockDriver{}
-
-func mockDriverInit(reg driverapi.DriverCallback, opt map[string]interface{}) error {
-	return reg.RegisterDriver(mockDriverName, &md, mockDriverCaps)
-}
-
-func (m *mockDriver) Type() string {
-	return mockDriverName
-}
-
-func (m *mockDriver) IsBuiltIn() bool {
-	return true
-}
-
-func getNew(t *testing.T) *DrvRegistry {
-	reg, err := New(nil, nil, nil, nil, nil)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	err = initIPAMDrivers(reg)
-	if err != nil {
-		t.Fatal(err)
-	}
-	return reg
-}
-
-func initIPAMDrivers(r *DrvRegistry) error {
-	for _, fn := range [](func(ipamapi.Callback, interface{}, interface{}) error){
-		builtinIpam.Init, //nolint:staticcheck
-		remoteIpam.Init,  //nolint:staticcheck
-		nullIpam.Init,    //nolint:staticcheck
-	} {
-		if err := fn(r, nil, nil); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}
-
-func TestNew(t *testing.T) {
-	getNew(t)
-}
-
-func TestAddDriver(t *testing.T) {
-	reg := getNew(t)
-
-	err := reg.AddDriver(mockDriverName, mockDriverInit, nil)
-	assert.NilError(t, err)
-}
-
-func TestAddDuplicateDriver(t *testing.T) {
-	reg := getNew(t)
-
-	err := reg.AddDriver(mockDriverName, mockDriverInit, nil)
-	assert.NilError(t, err)
-
-	// Try adding the same driver
-	err = reg.AddDriver(mockDriverName, mockDriverInit, nil)
-	assert.Check(t, is.ErrorContains(err, ""))
-}
-
-func TestIPAMDefaultAddressSpaces(t *testing.T) {
-	reg := getNew(t)
-
-	as1, as2, err := reg.IPAMDefaultAddressSpaces("default")
-	assert.NilError(t, err)
-	assert.Check(t, as1 != "")
-	assert.Check(t, as2 != "")
-}
-
-func TestDriver(t *testing.T) {
-	reg := getNew(t)
-
-	err := reg.AddDriver(mockDriverName, mockDriverInit, nil)
-	assert.NilError(t, err)
-
-	d, cap := reg.Driver(mockDriverName)
-	assert.Check(t, d != nil)
-	assert.Check(t, cap != nil)
-}
-
-func TestIPAM(t *testing.T) {
-	reg := getNew(t)
-
-	i, cap := reg.IPAM("default")
-	assert.Check(t, i != nil)
-	assert.Check(t, cap != nil)
-}
-
-func TestWalkIPAMs(t *testing.T) {
-	reg := getNew(t)
-
-	ipams := make([]string, 0, 2)
-	reg.WalkIPAMs(func(name string, driver ipamapi.Ipam, cap *ipamapi.Capability) bool {
-		ipams = append(ipams, name)
-		return false
-	})
-
-	sort.Strings(ipams)
-	expected := []string{"default", "null"}
-	if runtime.GOOS == "windows" {
-		expected = append(expected, "windows")
-	}
-	assert.Check(t, is.DeepEqual(ipams, expected))
-}
-
-func TestWalkDrivers(t *testing.T) {
-	reg := getNew(t)
-
-	err := reg.AddDriver(mockDriverName, mockDriverInit, nil)
-	assert.NilError(t, err)
-
-	var driverName string
-	reg.WalkDrivers(func(name string, driver driverapi.Driver, capability driverapi.Capability) bool {
-		driverName = name
-		return false
-	})
-
-	assert.Check(t, is.Equal(driverName, mockDriverName))
-}

+ 19 - 0
libnetwork/drvregistry/networks_test.go

@@ -3,11 +3,30 @@ package drvregistry
 import (
 	"testing"
 
+	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/driverapi"
 	"gotest.tools/v3/assert"
 	is "gotest.tools/v3/assert/cmp"
 )
 
+const mockDriverName = "mock-driver"
+
+type mockDriver struct {
+	driverapi.Driver
+}
+
+var mockDriverCaps = driverapi.Capability{DataScope: datastore.LocalScope}
+
+var md = mockDriver{}
+
+func (m *mockDriver) Type() string {
+	return mockDriverName
+}
+
+func (m *mockDriver) IsBuiltIn() bool {
+	return true
+}
+
 func TestNetworks(t *testing.T) {
 	t.Run("RegisterDriver", func(t *testing.T) {
 		var reg Networks

+ 0 - 76
libnetwork/idm/idm.go

@@ -1,76 +0,0 @@
-// Package idm manages reservation/release of numerical ids from a configured set of contiguous ids
-package idm
-
-import (
-	"errors"
-	"fmt"
-
-	"github.com/docker/docker/libnetwork/bitseq"
-	"github.com/docker/docker/libnetwork/datastore"
-)
-
-// Idm manages the reservation/release of numerical ids from a contiguous set
-type Idm struct {
-	start  uint64
-	end    uint64
-	handle *bitseq.Handle
-}
-
-// New returns an instance of id manager for a [start,end] set of numerical ids
-func New(ds datastore.DataStore, id string, start, end uint64) (*Idm, error) {
-	if id == "" {
-		return nil, errors.New("Invalid id")
-	}
-	if end <= start {
-		return nil, fmt.Errorf("Invalid set range: [%d, %d]", start, end)
-	}
-
-	h, err := bitseq.NewHandle("idm", ds, id, 1+end-start)
-	if err != nil {
-		return nil, fmt.Errorf("failed to initialize bit sequence handler: %s", err.Error())
-	}
-
-	return &Idm{start: start, end: end, handle: h}, nil
-}
-
-// GetID returns the first available id in the set
-func (i *Idm) GetID(serial bool) (uint64, error) {
-	if i.handle == nil {
-		return 0, errors.New("ID set is not initialized")
-	}
-	ordinal, err := i.handle.SetAny(serial)
-	return i.start + ordinal, err
-}
-
-// GetSpecificID tries to reserve the specified id
-func (i *Idm) GetSpecificID(id uint64) error {
-	if i.handle == nil {
-		return errors.New("ID set is not initialized")
-	}
-
-	if id < i.start || id > i.end {
-		return errors.New("Requested id does not belong to the set")
-	}
-
-	return i.handle.Set(id - i.start)
-}
-
-// GetIDInRange returns the first available id in the set within a [start,end] range
-func (i *Idm) GetIDInRange(start, end uint64, serial bool) (uint64, error) {
-	if i.handle == nil {
-		return 0, errors.New("ID set is not initialized")
-	}
-
-	if start < i.start || end > i.end {
-		return 0, errors.New("Requested range does not belong to the set")
-	}
-
-	ordinal, err := i.handle.SetAnyInRange(start-i.start, end-i.start, serial)
-
-	return i.start + ordinal, err
-}
-
-// Release releases the specified id
-func (i *Idm) Release(id uint64) {
-	i.handle.Unset(id - i.start)
-}

+ 0 - 294
libnetwork/idm/idm_test.go

@@ -1,294 +0,0 @@
-package idm
-
-import (
-	"testing"
-)
-
-func TestNew(t *testing.T) {
-	_, err := New(nil, "", 0, 1)
-	if err == nil {
-		t.Fatal("Expected failure, but succeeded")
-	}
-
-	_, err = New(nil, "myset", 1<<10, 0)
-	if err == nil {
-		t.Fatal("Expected failure, but succeeded")
-	}
-
-	i, err := New(nil, "myset", 0, 10)
-	if err != nil {
-		t.Fatalf("Unexpected failure: %v", err)
-	}
-	if i.handle == nil {
-		t.Fatal("set is not initialized")
-	}
-	if i.start != 0 {
-		t.Fatal("unexpected start")
-	}
-	if i.end != 10 {
-		t.Fatal("unexpected end")
-	}
-}
-
-func TestAllocate(t *testing.T) {
-	i, err := New(nil, "myids", 50, 52)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err = i.GetSpecificID(49); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-
-	if err = i.GetSpecificID(53); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-
-	o, err := i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 50 {
-		t.Fatalf("Unexpected first id returned: %d", o)
-	}
-
-	err = i.GetSpecificID(50)
-	if err == nil {
-		t.Fatal(err)
-	}
-
-	o, err = i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 51 {
-		t.Fatalf("Unexpected id returned: %d", o)
-	}
-
-	o, err = i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 52 {
-		t.Fatalf("Unexpected id returned: %d", o)
-	}
-
-	o, err = i.GetID(false)
-	if err == nil {
-		t.Fatalf("Expected failure but succeeded: %d", o)
-	}
-
-	i.Release(50)
-
-	o, err = i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 50 {
-		t.Fatal("Unexpected id returned")
-	}
-
-	i.Release(52)
-	err = i.GetSpecificID(52)
-	if err != nil {
-		t.Fatal(err)
-	}
-}
-
-func TestUninitialized(t *testing.T) {
-	i := &Idm{}
-
-	if _, err := i.GetID(false); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-
-	if err := i.GetSpecificID(44); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-}
-
-func TestAllocateInRange(t *testing.T) {
-	i, err := New(nil, "myset", 5, 10)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	o, err := i.GetIDInRange(6, 6, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 6 {
-		t.Fatalf("Unexpected id returned. Expected: 6. Got: %d", o)
-	}
-
-	if err = i.GetSpecificID(6); err == nil {
-		t.Fatalf("Expected failure but succeeded")
-	}
-
-	o, err = i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 5 {
-		t.Fatalf("Unexpected id returned. Expected: 5. Got: %d", o)
-	}
-
-	i.Release(6)
-
-	o, err = i.GetID(false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 6 {
-		t.Fatalf("Unexpected id returned. Expected: 6. Got: %d", o)
-	}
-
-	for n := 7; n <= 10; n++ {
-		o, err := i.GetIDInRange(7, 10, false)
-		if err != nil {
-			t.Fatal(err)
-		}
-		if o != uint64(n) {
-			t.Fatalf("Unexpected id returned. Expected: %d. Got: %d", n, o)
-		}
-	}
-
-	if err = i.GetSpecificID(7); err == nil {
-		t.Fatalf("Expected failure but succeeded")
-	}
-
-	if err = i.GetSpecificID(10); err == nil {
-		t.Fatalf("Expected failure but succeeded")
-	}
-
-	i.Release(10)
-
-	o, err = i.GetIDInRange(5, 10, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 10 {
-		t.Fatalf("Unexpected id returned. Expected: 10. Got: %d", o)
-	}
-
-	i.Release(5)
-
-	o, err = i.GetIDInRange(5, 10, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 5 {
-		t.Fatalf("Unexpected id returned. Expected: 5. Got: %d", o)
-	}
-
-	for n := 5; n <= 10; n++ {
-		i.Release(uint64(n))
-	}
-
-	for n := 5; n <= 10; n++ {
-		o, err := i.GetIDInRange(5, 10, false)
-		if err != nil {
-			t.Fatal(err)
-		}
-		if o != uint64(n) {
-			t.Fatalf("Unexpected id returned. Expected: %d. Got: %d", n, o)
-		}
-	}
-
-	for n := 5; n <= 10; n++ {
-		if err = i.GetSpecificID(uint64(n)); err == nil {
-			t.Fatalf("Expected failure but succeeded for id: %d", n)
-		}
-	}
-
-	// New larger set
-	ul := uint64((1 << 24) - 1)
-	i, err = New(nil, "newset", 0, ul)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	o, err = i.GetIDInRange(4096, ul, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 4096 {
-		t.Fatalf("Unexpected id returned. Expected: 4096. Got: %d", o)
-	}
-
-	o, err = i.GetIDInRange(4096, ul, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 4097 {
-		t.Fatalf("Unexpected id returned. Expected: 4097. Got: %d", o)
-	}
-
-	o, err = i.GetIDInRange(4096, ul, false)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 4098 {
-		t.Fatalf("Unexpected id returned. Expected: 4098. Got: %d", o)
-	}
-}
-
-func TestAllocateSerial(t *testing.T) {
-	i, err := New(nil, "myids", 50, 55)
-	if err != nil {
-		t.Fatal(err)
-	}
-
-	if err = i.GetSpecificID(49); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-
-	if err = i.GetSpecificID(56); err == nil {
-		t.Fatal("Expected failure but succeeded")
-	}
-
-	o, err := i.GetID(true)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 50 {
-		t.Fatalf("Unexpected first id returned: %d", o)
-	}
-
-	err = i.GetSpecificID(50)
-	if err == nil {
-		t.Fatal(err)
-	}
-
-	o, err = i.GetID(true)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 51 {
-		t.Fatalf("Unexpected id returned: %d", o)
-	}
-
-	o, err = i.GetID(true)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 52 {
-		t.Fatalf("Unexpected id returned: %d", o)
-	}
-
-	i.Release(50)
-
-	o, err = i.GetID(true)
-	if err != nil {
-		t.Fatal(err)
-	}
-	if o != 53 {
-		t.Fatal("Unexpected id returned")
-	}
-
-	i.Release(52)
-	err = i.GetSpecificID(52)
-	if err != nil {
-		t.Fatal(err)
-	}
-}

+ 0 - 10
libnetwork/ipamapi/contract.go

@@ -5,7 +5,6 @@ import (
 	"net"
 
 	"github.com/docker/docker/libnetwork/types"
-	"github.com/docker/docker/pkg/plugingetter"
 )
 
 // IPAM plugin types
@@ -28,15 +27,6 @@ type Registerer interface {
 	RegisterIpamDriverWithCapabilities(name string, driver Ipam, capability *Capability) error
 }
 
-// Callback is a legacy interface for registering an IPAM instance into LibNetwork.
-//
-// The narrower [Registerer] interface is preferred for new code.
-type Callback interface {
-	Registerer
-	// GetPluginGetter returns the pluginv2 getter.
-	GetPluginGetter() plugingetter.PluginGetter
-}
-
 // Well-known errors returned by IPAM
 var (
 	ErrIpamInternalError   = types.InternalErrorf("IPAM Internal Error")

+ 0 - 17
libnetwork/ipams/builtin/builtin_unix.go

@@ -3,26 +3,9 @@
 package builtin
 
 import (
-	"errors"
-
 	"github.com/docker/docker/libnetwork/ipamapi"
 )
 
-// Init registers the built-in ipam service with libnetwork
-//
-// Deprecated: use [Register].
-func Init(ic ipamapi.Callback, l, g interface{}) error {
-	if l != nil {
-		return errors.New("non-nil local datastore passed to built-in ipam init")
-	}
-
-	if g != nil {
-		return errors.New("non-nil global datastore passed to built-in ipam init")
-	}
-
-	return Register(ic)
-}
-
 // Register registers the built-in ipam service with libnetwork.
 func Register(r ipamapi.Registerer) error {
 	return registerBuiltin(r)

+ 0 - 17
libnetwork/ipams/builtin/builtin_windows.go

@@ -3,27 +3,10 @@
 package builtin
 
 import (
-	"errors"
-
 	"github.com/docker/docker/libnetwork/ipamapi"
 	"github.com/docker/docker/libnetwork/ipams/windowsipam"
 )
 
-// Init registers the built-in ipam services with libnetwork.
-//
-// Deprecated: use [Register].
-func Init(ic ipamapi.Callback, l, g interface{}) error {
-	if l != nil {
-		return errors.New("non-nil local datastore passed to built-in ipam init")
-	}
-
-	if g != nil {
-		return errors.New("non-nil global datastore passed to built-in ipam init")
-	}
-
-	return Register(ic)
-}
-
 // Register registers the built-in ipam services with libnetwork.
 func Register(r ipamapi.Registerer) error {
 	if err := registerBuiltin(r); err != nil {

+ 0 - 7
libnetwork/ipams/null/null.go

@@ -69,13 +69,6 @@ func (a *allocator) IsBuiltIn() bool {
 	return true
 }
 
-// Init registers the null ipam driver with ic.
-//
-// Deprecated: use [Register].
-func Init(ic ipamapi.Callback, l, g interface{}) error {
-	return Register(ic)
-}
-
 // Register registers the null ipam driver with r.
 func Register(r ipamapi.Registerer) error {
 	return r.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{})

+ 0 - 7
libnetwork/ipams/remote/remote.go

@@ -31,13 +31,6 @@ func newAllocator(name string, client *plugins.Client) ipamapi.Ipam {
 	return a
 }
 
-// Init registers a remote ipam when its plugin is activated.
-//
-// Deprecated: use [Register].
-func Init(cb ipamapi.Callback, l, g interface{}) error {
-	return Register(cb, cb.GetPluginGetter())
-}
-
 // Register registers a remote ipam when its plugin is activated.
 func Register(cb ipamapi.Registerer, pg plugingetter.PluginGetter) error {
 	newPluginHandler := func(name string, client *plugins.Client) {

+ 1 - 1
vendor.mod

@@ -65,7 +65,7 @@ require (
 	github.com/moby/locker v1.0.1
 	github.com/moby/patternmatcher v0.5.0
 	github.com/moby/pubsub v1.0.0
-	github.com/moby/swarmkit/v2 v2.0.0-20230627115642-ad0f3ae162fa
+	github.com/moby/swarmkit/v2 v2.0.0-20230707182847-6f78b8199b05
 	github.com/moby/sys/mount v0.3.3
 	github.com/moby/sys/mountinfo v0.6.2
 	github.com/moby/sys/sequential v0.5.0

+ 2 - 2
vendor.sum

@@ -1064,8 +1064,8 @@ github.com/moby/patternmatcher v0.5.0 h1:YCZgJOeULcxLw1Q+sVR636pmS7sPEn1Qo2iAN6M
 github.com/moby/patternmatcher v0.5.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
 github.com/moby/pubsub v1.0.0 h1:jkp/imWsmJz2f6LyFsk7EkVeN2HxR/HTTOY8kHrsxfA=
 github.com/moby/pubsub v1.0.0/go.mod h1:bXSO+3h5MNXXCaEG+6/NlAIk7MMZbySZlnB+cUQhKKc=
-github.com/moby/swarmkit/v2 v2.0.0-20230627115642-ad0f3ae162fa h1:9IilX0rZvnrQA+a0Cr9a9LKpudNrOWhT3Fy7T4yKcPc=
-github.com/moby/swarmkit/v2 v2.0.0-20230627115642-ad0f3ae162fa/go.mod h1:pC/nyFbvVvSV+Gm1rARMgMR3FrCumwEyoMjqVwEzJvA=
+github.com/moby/swarmkit/v2 v2.0.0-20230707182847-6f78b8199b05 h1:lvMq6zHXnGp6i+6iYDs1Uw9Q5bqiAYd6Sz08hZoxSmY=
+github.com/moby/swarmkit/v2 v2.0.0-20230707182847-6f78b8199b05/go.mod h1:XUMlwIIC+wrwBDMUjxEvk5Z8FPoIPM8LdBw7w/Zu1rg=
 github.com/moby/sys/mount v0.1.0/go.mod h1:FVQFLDRWwyBjDTBNQXDlWnSFREqOo3OKX9aqhmeoo74=
 github.com/moby/sys/mount v0.1.1/go.mod h1:FVQFLDRWwyBjDTBNQXDlWnSFREqOo3OKX9aqhmeoo74=
 github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs=

+ 69 - 0
vendor/github.com/moby/swarmkit/v2/internal/idm/idm.go

@@ -0,0 +1,69 @@
+// Package idm manages reservation/release of numerical ids from a configured set of contiguous ids.
+package idm
+
+import (
+	"errors"
+	"fmt"
+
+	"github.com/docker/docker/libnetwork/bitmap"
+)
+
+// IDM manages the reservation/release of numerical ids from a contiguous set.
+//
+// An IDM instance is not safe for concurrent use.
+type IDM struct {
+	start  uint64
+	end    uint64
+	handle *bitmap.Bitmap
+}
+
+// New returns an instance of id manager for a [start,end] set of numerical ids.
+func New(start, end uint64) (*IDM, error) {
+	if end <= start {
+		return nil, fmt.Errorf("invalid set range: [%d, %d]", start, end)
+	}
+
+	return &IDM{start: start, end: end, handle: bitmap.New(1 + end - start)}, nil
+}
+
+// GetID returns the first available id in the set.
+func (i *IDM) GetID(serial bool) (uint64, error) {
+	if i.handle == nil {
+		return 0, errors.New("ID set is not initialized")
+	}
+	ordinal, err := i.handle.SetAny(serial)
+	return i.start + ordinal, err
+}
+
+// GetSpecificID tries to reserve the specified id.
+func (i *IDM) GetSpecificID(id uint64) error {
+	if i.handle == nil {
+		return errors.New("ID set is not initialized")
+	}
+
+	if id < i.start || id > i.end {
+		return errors.New("requested id does not belong to the set")
+	}
+
+	return i.handle.Set(id - i.start)
+}
+
+// GetIDInRange returns the first available id in the set within a [start,end] range.
+func (i *IDM) GetIDInRange(start, end uint64, serial bool) (uint64, error) {
+	if i.handle == nil {
+		return 0, errors.New("ID set is not initialized")
+	}
+
+	if start < i.start || end > i.end {
+		return 0, errors.New("requested range does not belong to the set")
+	}
+
+	ordinal, err := i.handle.SetAnyInRange(start-i.start, end-i.start, serial)
+
+	return i.start + ordinal, err
+}
+
+// Release releases the specified id.
+func (i *IDM) Release(id uint64) {
+	i.handle.Unset(id - i.start)
+}

+ 3 - 4
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_darwin.go

@@ -1,14 +1,13 @@
 package cnmallocator
 
 import (
+	"github.com/docker/docker/libnetwork/driverapi"
 	"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
-	"github.com/docker/docker/libnetwork/drivers/remote"
 	"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
 )
 
-var initializers = []initializer{
-	{remote.Init, "remote"},
-	{ovmanager.Init, "overlay"},
+var initializers = map[string]func(driverapi.Registerer) error{
+	"overlay": ovmanager.Register,
 }
 
 // PredefinedNetworks returns the list of predefined network structures

+ 5 - 8
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_ipam.go

@@ -4,16 +4,14 @@ import (
 	"strconv"
 	"strings"
 
-	"github.com/docker/docker/libnetwork/drvregistry"
 	"github.com/docker/docker/libnetwork/ipamapi"
 	builtinIpam "github.com/docker/docker/libnetwork/ipams/builtin"
 	nullIpam "github.com/docker/docker/libnetwork/ipams/null"
-	remoteIpam "github.com/docker/docker/libnetwork/ipams/remote"
 	"github.com/docker/docker/libnetwork/ipamutils"
 	"github.com/sirupsen/logrus"
 )
 
-func initIPAMDrivers(r *drvregistry.DrvRegistry, netConfig *NetworkConfig) error {
+func initIPAMDrivers(r ipamapi.Registerer, netConfig *NetworkConfig) error {
 	var addressPool []*ipamutils.NetworkToSplit
 	var str strings.Builder
 	str.WriteString("Subnetlist - ")
@@ -40,12 +38,11 @@ func initIPAMDrivers(r *drvregistry.DrvRegistry, netConfig *NetworkConfig) error
 		logrus.Infof("Swarm initialized global default address pool to: " + str.String())
 	}
 
-	for _, fn := range [](func(ipamapi.Callback, interface{}, interface{}) error){
-		builtinIpam.Init,
-		remoteIpam.Init,
-		nullIpam.Init,
+	for _, fn := range [](func(ipamapi.Registerer) error){
+		builtinIpam.Register,
+		nullIpam.Register,
 	} {
-		if err := fn(r, nil, nil); err != nil {
+		if err := fn(r); err != nil {
 			return err
 		}
 	}

+ 7 - 8
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_network_linux.go

@@ -1,22 +1,21 @@
 package cnmallocator
 
 import (
+	"github.com/docker/docker/libnetwork/driverapi"
 	"github.com/docker/docker/libnetwork/drivers/bridge/brmanager"
 	"github.com/docker/docker/libnetwork/drivers/host"
 	"github.com/docker/docker/libnetwork/drivers/ipvlan/ivmanager"
 	"github.com/docker/docker/libnetwork/drivers/macvlan/mvmanager"
 	"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
-	"github.com/docker/docker/libnetwork/drivers/remote"
 	"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
 )
 
-var initializers = []initializer{
-	{remote.Init, "remote"},
-	{ovmanager.Init, "overlay"},
-	{mvmanager.Init, "macvlan"},
-	{brmanager.Init, "bridge"},
-	{ivmanager.Init, "ipvlan"},
-	{host.Init, "host"},
+var initializers = map[string]func(driverapi.Registerer) error{
+	"overlay": ovmanager.Register,
+	"macvlan": mvmanager.Register,
+	"bridge":  brmanager.Register,
+	"ipvlan":  ivmanager.Register,
+	"host":    host.Register,
 }
 
 // PredefinedNetworks returns the list of predefined network structures

+ 12 - 7
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/drivers_network_windows.go

@@ -1,17 +1,16 @@
 package cnmallocator
 
 import (
+	"github.com/docker/docker/libnetwork/driverapi"
 	"github.com/docker/docker/libnetwork/drivers/overlay/ovmanager"
-	"github.com/docker/docker/libnetwork/drivers/remote"
 	"github.com/moby/swarmkit/v2/manager/allocator/networkallocator"
 )
 
-var initializers = []initializer{
-	{remote.Init, "remote"},
-	{ovmanager.Init, "overlay"},
-	{StubManagerInit("internal"), "internal"},
-	{StubManagerInit("l2bridge"), "l2bridge"},
-	{StubManagerInit("nat"), "nat"},
+var initializers = map[string]func(driverapi.Registerer) error{
+	"overlay":  ovmanager.Register,
+	"internal": stubManager("internal"),
+	"l2bridge": stubManager("l2bridge"),
+	"nat":      stubManager("nat"),
 }
 
 // PredefinedNetworks returns the list of predefined network structures
@@ -20,3 +19,9 @@ func PredefinedNetworks() []networkallocator.PredefinedNetworkData {
 		{Name: "nat", Driver: "nat"},
 	}
 }
+
+func stubManager(ntype string) func(driverapi.Registerer) error {
+	return func(r driverapi.Registerer) error {
+		return RegisterManager(r, ntype)
+	}
+}

+ 4 - 11
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/manager.go

@@ -11,19 +11,12 @@ type manager struct {
 	networkType string
 }
 
-func StubManagerInit(networkType string) func(dc driverapi.DriverCallback, config map[string]interface{}) error {
-	return func(dc driverapi.DriverCallback, config map[string]interface{}) error {
-		return RegisterManager(dc, networkType)
-	}
-}
-
-// Register registers a new instance of the manager driver for networkType with r.
-func RegisterManager(r driverapi.DriverCallback, networkType string) error {
-	c := driverapi.Capability{
+// RegisterManager registers a new instance of the manager driver for networkType with r.
+func RegisterManager(r driverapi.Registerer, networkType string) error {
+	return r.RegisterDriver(networkType, &manager{networkType: networkType}, driverapi.Capability{
 		DataScope:         datastore.LocalScope,
 		ConnectivityScope: datastore.LocalScope,
-	}
-	return r.RegisterDriver(networkType, &manager{networkType: networkType}, c)
+	})
 }
 
 func (d *manager) NetworkAllocate(id string, option map[string]string, ipV4Data, ipV6Data []driverapi.IPAMData) (map[string]string, error) {

+ 30 - 41
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/networkallocator.go

@@ -8,8 +8,10 @@ import (
 
 	"github.com/docker/docker/libnetwork/datastore"
 	"github.com/docker/docker/libnetwork/driverapi"
+	"github.com/docker/docker/libnetwork/drivers/remote"
 	"github.com/docker/docker/libnetwork/drvregistry"
 	"github.com/docker/docker/libnetwork/ipamapi"
+	remoteipam "github.com/docker/docker/libnetwork/ipams/remote"
 	"github.com/docker/docker/libnetwork/netlabel"
 	"github.com/docker/docker/pkg/plugingetter"
 	"github.com/moby/swarmkit/v2/api"
@@ -30,9 +32,14 @@ const (
 // like managing network and IPAM drivers and also creating and
 // deleting networks and the associated resources.
 type cnmNetworkAllocator struct {
-	// The driver register which manages all internal and external
-	// IPAM and network drivers.
-	drvRegistry *drvregistry.DrvRegistry
+	// The plugin getter instance used to get network and IPAM driver plugins.
+	pg plugingetter.PluginGetter
+
+	// The driver registry for all internal and external IPAM drivers.
+	ipamRegistry drvregistry.IPAMs
+
+	// The driver registry for all internal and external network drivers.
+	networkRegistry drvregistry.Networks
 
 	// The port allocator instance for allocating node ports
 	portAllocator *portAllocator
@@ -81,11 +88,6 @@ type networkDriver struct {
 	capability *driverapi.Capability
 }
 
-type initializer struct {
-	fn    drvregistry.InitFunc
-	ntype string
-}
-
 // NetworkConfig is used to store network related cluster config in the Manager.
 type NetworkConfig struct {
 	// DefaultAddrPool specifies default subnet pool for global scope networks
@@ -106,22 +108,24 @@ func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocat
 		services: make(map[string]struct{}),
 		tasks:    make(map[string]struct{}),
 		nodes:    make(map[string]map[string]struct{}),
+		pg:       pg,
 	}
 
-	// There are no driver configurations and notification
-	// functions as of now.
-	reg, err := drvregistry.New(nil, nil, nil, nil, pg)
-	if err != nil {
-		return nil, err
+	for ntype, i := range initializers {
+		if err := i(&na.networkRegistry); err != nil {
+			return nil, fmt.Errorf("failed to register %q network driver: %w", ntype, err)
+		}
 	}
-
-	if err := initializeDrivers(reg); err != nil {
-		return nil, err
+	if err := remote.Register(&na.networkRegistry, pg); err != nil {
+		return nil, fmt.Errorf("failed to initialize network driver plugins: %w", err)
 	}
 
-	if err = initIPAMDrivers(reg, netConfig); err != nil {
+	if err := initIPAMDrivers(&na.ipamRegistry, netConfig); err != nil {
 		return nil, err
 	}
+	if err := remoteipam.Register(&na.ipamRegistry, pg); err != nil {
+		return nil, fmt.Errorf("failed to initialize IPAM driver plugins: %w", err)
+	}
 
 	pa, err := newPortAllocator()
 	if err != nil {
@@ -129,7 +133,6 @@ func New(pg plugingetter.PluginGetter, netConfig *NetworkConfig) (networkallocat
 	}
 
 	na.portAllocator = pa
-	na.drvRegistry = reg
 	return na, nil
 }
 
@@ -816,28 +819,27 @@ func (na *cnmNetworkAllocator) resolveDriver(n *api.Network) (*networkDriver, er
 		dName = n.Spec.DriverConfig.Name
 	}
 
-	d, drvcap := na.drvRegistry.Driver(dName)
+	d, drvcap := na.networkRegistry.Driver(dName)
 	if d == nil {
 		err := na.loadDriver(dName)
 		if err != nil {
 			return nil, err
 		}
 
-		d, drvcap = na.drvRegistry.Driver(dName)
+		d, drvcap = na.networkRegistry.Driver(dName)
 		if d == nil {
 			return nil, fmt.Errorf("could not resolve network driver %s", dName)
 		}
 	}
 
-	return &networkDriver{driver: d, capability: drvcap, name: dName}, nil
+	return &networkDriver{driver: d, capability: &drvcap, name: dName}, nil
 }
 
 func (na *cnmNetworkAllocator) loadDriver(name string) error {
-	pg := na.drvRegistry.GetPluginGetter()
-	if pg == nil {
+	if na.pg == nil {
 		return errors.New("plugin store is uninitialized")
 	}
-	_, err := pg.Get(name, driverapi.NetworkPluginEndpointType, plugingetter.Lookup)
+	_, err := na.pg.Get(name, driverapi.NetworkPluginEndpointType, plugingetter.Lookup)
 	return err
 }
 
@@ -853,7 +855,7 @@ func (na *cnmNetworkAllocator) resolveIPAM(n *api.Network) (ipamapi.Ipam, string
 		dOptions = n.Spec.IPAM.Driver.Options
 	}
 
-	ipam, _ := na.drvRegistry.IPAM(dName)
+	ipam, _ := na.ipamRegistry.IPAM(dName)
 	if ipam == nil {
 		return nil, "", nil, fmt.Errorf("could not resolve IPAM driver %s", dName)
 	}
@@ -893,7 +895,7 @@ func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string,
 
 	// We don't support user defined address spaces yet so just
 	// retrieve default address space names for the driver.
-	_, asName, err := na.drvRegistry.IPAMDefaultAddressSpaces(dName)
+	_, asName, err := ipam.GetDefaultAddressSpaces()
 	if err != nil {
 		return nil, err
 	}
@@ -978,15 +980,6 @@ func (na *cnmNetworkAllocator) allocatePools(n *api.Network) (map[string]string,
 	return pools, nil
 }
 
-func initializeDrivers(reg *drvregistry.DrvRegistry) error {
-	for _, i := range initializers {
-		if err := reg.AddDriver(i.ntype, i.fn, nil); err != nil {
-			return err
-		}
-	}
-	return nil
-}
-
 func serviceNetworks(s *api.Service) []*api.NetworkAttachmentConfig {
 	// Always prefer NetworkAttachmentConfig in the TaskSpec
 	if len(s.Spec.Task.Networks) == 0 && len(s.Spec.Networks) != 0 {
@@ -1011,12 +1004,8 @@ func (na *cnmNetworkAllocator) IsVIPOnIngressNetwork(vip *api.Endpoint_VirtualIP
 // IsBuiltInDriver returns whether the passed driver is an internal network driver
 func IsBuiltInDriver(name string) bool {
 	n := strings.ToLower(name)
-	for _, d := range initializers {
-		if n == d.ntype {
-			return true
-		}
-	}
-	return false
+	_, ok := initializers[n]
+	return ok
 }
 
 // setIPAMSerialAlloc sets the ipam allocation method to serial

+ 5 - 10
vendor/github.com/moby/swarmkit/v2/manager/allocator/cnmallocator/portallocator.go

@@ -1,10 +1,8 @@
 package cnmallocator
 
 import (
-	"fmt"
-
-	"github.com/docker/docker/libnetwork/idm"
 	"github.com/moby/swarmkit/v2/api"
+	"github.com/moby/swarmkit/v2/internal/idm"
 )
 
 const (
@@ -34,8 +32,8 @@ type portAllocator struct {
 
 type portSpace struct {
 	protocol         api.PortConfig_Protocol
-	masterPortSpace  *idm.Idm
-	dynamicPortSpace *idm.Idm
+	masterPortSpace  *idm.IDM
+	dynamicPortSpace *idm.IDM
 }
 
 type allocatedPorts map[api.PortConfig]map[uint32]*api.PortConfig
@@ -118,15 +116,12 @@ func newPortAllocator() (*portAllocator, error) {
 }
 
 func newPortSpace(protocol api.PortConfig_Protocol) (*portSpace, error) {
-	masterName := fmt.Sprintf("%s-master-ports", protocol)
-	dynamicName := fmt.Sprintf("%s-dynamic-ports", protocol)
-
-	master, err := idm.New(nil, masterName, masterPortStart, masterPortEnd)
+	master, err := idm.New(masterPortStart, masterPortEnd)
 	if err != nil {
 		return nil, err
 	}
 
-	dynamic, err := idm.New(nil, dynamicName, dynamicPortStart, dynamicPortEnd)
+	dynamic, err := idm.New(dynamicPortStart, dynamicPortEnd)
 	if err != nil {
 		return nil, err
 	}

+ 2 - 1
vendor/modules.txt

@@ -777,7 +777,7 @@ github.com/moby/patternmatcher
 # github.com/moby/pubsub v1.0.0
 ## explicit; go 1.19
 github.com/moby/pubsub
-# github.com/moby/swarmkit/v2 v2.0.0-20230627115642-ad0f3ae162fa
+# github.com/moby/swarmkit/v2 v2.0.0-20230707182847-6f78b8199b05
 ## explicit; go 1.18
 github.com/moby/swarmkit/v2/agent
 github.com/moby/swarmkit/v2/agent/configs
@@ -798,6 +798,7 @@ github.com/moby/swarmkit/v2/ca/pkcs8
 github.com/moby/swarmkit/v2/connectionbroker
 github.com/moby/swarmkit/v2/identity
 github.com/moby/swarmkit/v2/internal/csi/capability
+github.com/moby/swarmkit/v2/internal/idm
 github.com/moby/swarmkit/v2/ioutils
 github.com/moby/swarmkit/v2/log
 github.com/moby/swarmkit/v2/manager