github.com/pwn-term/docker@v0.0.0-20210616085119-6e977cce2565/libnetwork/ipams/builtin/builtin_unix.go (about) 1 // +build linux freebsd darwin 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 14 var ( 15 // defaultAddressPool Stores user configured subnet list 16 defaultAddressPool []*ipamutils.NetworkToSplit 17 ) 18 19 // Init registers the built-in ipam service with libnetwork 20 func Init(ic ipamapi.Callback, l, g interface{}) error { 21 var ( 22 ok bool 23 localDs, globalDs datastore.DataStore 24 ) 25 26 if l != nil { 27 if localDs, ok = l.(datastore.DataStore); !ok { 28 return errors.New("incorrect local datastore passed to built-in ipam init") 29 } 30 } 31 32 if g != nil { 33 if globalDs, ok = g.(datastore.DataStore); !ok { 34 return errors.New("incorrect global datastore passed to built-in ipam init") 35 } 36 } 37 38 err := ipamutils.ConfigLocalScopeDefaultNetworks(GetDefaultIPAddressPool()) 39 if err != nil { 40 return err 41 } 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 // SetDefaultIPAddressPool stores default address pool. 54 func SetDefaultIPAddressPool(addressPool []*ipamutils.NetworkToSplit) { 55 defaultAddressPool = addressPool 56 } 57 58 // GetDefaultIPAddressPool returns default address pool. 59 func GetDefaultIPAddressPool() []*ipamutils.NetworkToSplit { 60 return defaultAddressPool 61 }