github.com/Heebron/moby@v0.0.0-20221111184709-6eab4f55faf7/libnetwork/ipams/builtin/builtin_windows.go (about) 1 //go:build windows 2 // +build windows 3 4 package builtin 5 6 import ( 7 "errors" 8 9 "github.com/docker/docker/libnetwork/datastore" 10 "github.com/docker/docker/libnetwork/ipam" 11 "github.com/docker/docker/libnetwork/ipamapi" 12 "github.com/docker/docker/libnetwork/ipamutils" 13 14 windowsipam "github.com/docker/docker/libnetwork/ipams/windowsipam" 15 ) 16 17 var ( 18 // defaultAddressPool Stores user configured subnet list 19 defaultAddressPool []*ipamutils.NetworkToSplit 20 ) 21 22 // InitDockerDefault registers the built-in ipam service with libnetwork 23 func InitDockerDefault(ic ipamapi.Callback, l, g interface{}) error { 24 var ( 25 ok bool 26 localDs, globalDs datastore.DataStore 27 ) 28 29 if l != nil { 30 if localDs, ok = l.(datastore.DataStore); !ok { 31 return errors.New("incorrect local datastore passed to built-in ipam init") 32 } 33 } 34 35 if g != nil { 36 if globalDs, ok = g.(datastore.DataStore); !ok { 37 return errors.New("incorrect global datastore passed to built-in ipam init") 38 } 39 } 40 41 ipamutils.ConfigLocalScopeDefaultNetworks(nil) 42 43 a, err := ipam.NewAllocator(localDs, globalDs) 44 if err != nil { 45 return err 46 } 47 48 cps := &ipamapi.Capability{RequiresRequestReplay: true} 49 50 return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps) 51 } 52 53 // Init registers the built-in ipam service with libnetwork 54 func Init(ic ipamapi.Callback, l, g interface{}) error { 55 initFunc := windowsipam.GetInit(windowsipam.DefaultIPAM) 56 57 err := InitDockerDefault(ic, l, g) 58 if err != nil { 59 return err 60 } 61 62 return initFunc(ic, l, g) 63 } 64 65 // SetDefaultIPAddressPool stores default address pool . 66 func SetDefaultIPAddressPool(addressPool []*ipamutils.NetworkToSplit) { 67 defaultAddressPool = addressPool 68 } 69 70 // GetDefaultIPAddressPool returns default address pool . 71 func GetDefaultIPAddressPool() []*ipamutils.NetworkToSplit { 72 return defaultAddressPool 73 }