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