github.com/rawahars/moby@v24.0.4+incompatible/libnetwork/ipams/windowsipam/windowsipam.go (about) 1 package windowsipam 2 3 import ( 4 "net" 5 6 "github.com/docker/docker/libnetwork/ipamapi" 7 "github.com/docker/docker/libnetwork/types" 8 "github.com/sirupsen/logrus" 9 ) 10 11 const ( 12 localAddressSpace = "LocalDefault" 13 globalAddressSpace = "GlobalDefault" 14 ) 15 16 // DefaultIPAM defines the default ipam-driver for local-scoped windows networks 17 const DefaultIPAM = "windows" 18 19 var ( 20 defaultPool, _ = types.ParseCIDR("0.0.0.0/0") 21 ) 22 23 type allocator struct { 24 } 25 26 // Register registers the built-in ipam service with libnetwork 27 func Register(ipamName string, r ipamapi.Registerer) error { 28 return r.RegisterIpamDriver(ipamName, &allocator{}) 29 } 30 31 func (a *allocator) GetDefaultAddressSpaces() (string, string, error) { 32 return localAddressSpace, globalAddressSpace, nil 33 } 34 35 // RequestPool returns an address pool along with its unique id. This is a null ipam driver. It allocates the 36 // subnet user asked and does not validate anything. Doesn't support subpool allocation 37 func (a *allocator) RequestPool(addressSpace, pool, subPool string, options map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { 38 logrus.Debugf("RequestPool(%s, %s, %s, %v, %t)", addressSpace, pool, subPool, options, v6) 39 if subPool != "" || v6 { 40 return "", nil, nil, types.InternalErrorf("This request is not supported by null ipam driver") 41 } 42 43 var ipNet *net.IPNet 44 var err error 45 46 if pool != "" { 47 _, ipNet, err = net.ParseCIDR(pool) 48 if err != nil { 49 return "", nil, nil, err 50 } 51 } else { 52 ipNet = defaultPool 53 } 54 55 return ipNet.String(), ipNet, nil, nil 56 } 57 58 // ReleasePool releases the address pool - always succeeds 59 func (a *allocator) ReleasePool(poolID string) error { 60 logrus.Debugf("ReleasePool(%s)", poolID) 61 return nil 62 } 63 64 // RequestAddress returns an address from the specified pool ID. 65 // Always allocate the 0.0.0.0/32 ip if no preferred address was specified 66 func (a *allocator) RequestAddress(poolID string, prefAddress net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) { 67 logrus.Debugf("RequestAddress(%s, %v, %v)", poolID, prefAddress, opts) 68 _, ipNet, err := net.ParseCIDR(poolID) 69 70 if err != nil { 71 return nil, nil, err 72 } 73 74 if prefAddress != nil { 75 return &net.IPNet{IP: prefAddress, Mask: ipNet.Mask}, nil, nil 76 } 77 78 return nil, nil, nil 79 } 80 81 // ReleaseAddress releases the address - always succeeds 82 func (a *allocator) ReleaseAddress(poolID string, address net.IP) error { 83 logrus.Debugf("ReleaseAddress(%s, %v)", poolID, address) 84 return nil 85 } 86 87 func (a *allocator) IsBuiltIn() bool { 88 return true 89 }