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