2021-08-23 09:14:53 -04:00
|
|
|
//go:build windows
|
2016-01-29 20:08:11 -05:00
|
|
|
// +build windows
|
|
|
|
|
|
|
|
package builtin
|
|
|
|
|
|
|
|
import (
|
2016-11-21 20:29:53 -05:00
|
|
|
"errors"
|
2016-10-12 19:55:20 -04:00
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
"github.com/docker/docker/libnetwork/datastore"
|
|
|
|
"github.com/docker/docker/libnetwork/ipam"
|
|
|
|
"github.com/docker/docker/libnetwork/ipamapi"
|
|
|
|
"github.com/docker/docker/libnetwork/ipamutils"
|
2016-01-29 20:08:11 -05:00
|
|
|
|
2021-04-05 20:24:47 -04:00
|
|
|
windowsipam "github.com/docker/docker/libnetwork/ipams/windowsipam"
|
2016-01-29 20:08:11 -05:00
|
|
|
)
|
|
|
|
|
2018-01-18 17:30:51 -05:00
|
|
|
var (
|
|
|
|
// defaultAddressPool Stores user configured subnet list
|
|
|
|
defaultAddressPool []*ipamutils.NetworkToSplit
|
|
|
|
)
|
|
|
|
|
2016-10-12 19:55:20 -04:00
|
|
|
// InitDockerDefault registers the built-in ipam service with libnetwork
|
|
|
|
func InitDockerDefault(ic ipamapi.Callback, l, g interface{}) error {
|
|
|
|
var (
|
|
|
|
ok bool
|
|
|
|
localDs, globalDs datastore.DataStore
|
|
|
|
)
|
|
|
|
|
|
|
|
if l != nil {
|
|
|
|
if localDs, ok = l.(datastore.DataStore); !ok {
|
2016-11-21 20:29:53 -05:00
|
|
|
return errors.New("incorrect local datastore passed to built-in ipam init")
|
2016-10-12 19:55:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if g != nil {
|
|
|
|
if globalDs, ok = g.(datastore.DataStore); !ok {
|
2016-11-21 20:29:53 -05:00
|
|
|
return errors.New("incorrect global datastore passed to built-in ipam init")
|
2016-10-12 19:55:20 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 15:46:59 -04:00
|
|
|
ipamutils.ConfigLocalScopeDefaultNetworks(nil)
|
2016-10-12 19:55:20 -04:00
|
|
|
|
|
|
|
a, err := ipam.NewAllocator(localDs, globalDs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cps := &ipamapi.Capability{RequiresRequestReplay: true}
|
|
|
|
|
|
|
|
return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
|
|
|
|
}
|
|
|
|
|
2016-01-29 20:08:11 -05:00
|
|
|
// Init registers the built-in ipam service with libnetwork
|
|
|
|
func Init(ic ipamapi.Callback, l, g interface{}) error {
|
2016-10-12 19:55:20 -04:00
|
|
|
initFunc := windowsipam.GetInit(windowsipam.DefaultIPAM)
|
|
|
|
|
|
|
|
err := InitDockerDefault(ic, l, g)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-01-29 20:08:11 -05:00
|
|
|
|
|
|
|
return initFunc(ic, l, g)
|
|
|
|
}
|
2018-01-18 17:30:51 -05:00
|
|
|
|
|
|
|
// SetDefaultIPAddressPool stores default address pool .
|
|
|
|
func SetDefaultIPAddressPool(addressPool []*ipamutils.NetworkToSplit) {
|
|
|
|
defaultAddressPool = addressPool
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetDefaultIPAddressPool returns default address pool .
|
|
|
|
func GetDefaultIPAddressPool() []*ipamutils.NetworkToSplit {
|
|
|
|
return defaultAddressPool
|
|
|
|
}
|