github.com/Prakhar-Agarwal-byte/moby@v0.0.0-20231027092010-a14e3e8ab87e/libnetwork/ipams/null/null.go (about) 1 // Package null implements the null ipam driver. Null ipam driver satisfies ipamapi contract, 2 // but does not effectively reserve/allocate any address pool or address 3 package null 4 5 import ( 6 "net" 7 8 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/ipamapi" 9 "github.com/Prakhar-Agarwal-byte/moby/libnetwork/types" 10 ) 11 12 const ( 13 defaultAddressSpace = "null" 14 defaultPoolCIDR = "0.0.0.0/0" 15 defaultPoolID = defaultAddressSpace + "/" + defaultPoolCIDR 16 ) 17 18 var defaultPool, _ = types.ParseCIDR(defaultPoolCIDR) 19 20 type allocator struct{} 21 22 func (a *allocator) GetDefaultAddressSpaces() (string, string, error) { 23 return defaultAddressSpace, defaultAddressSpace, nil 24 } 25 26 func (a *allocator) RequestPool(addressSpace, requestedPool, requestedSubPool string, _ map[string]string, v6 bool) (string, *net.IPNet, map[string]string, error) { 27 if addressSpace != defaultAddressSpace { 28 return "", nil, nil, types.InvalidParameterErrorf("unknown address space: %s", addressSpace) 29 } 30 if requestedPool != "" { 31 return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle specific address pool requests") 32 } 33 if requestedSubPool != "" { 34 return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle specific address subpool requests") 35 } 36 if v6 { 37 return "", nil, nil, types.InvalidParameterErrorf("null ipam driver does not handle IPv6 address pool pool requests") 38 } 39 return defaultPoolID, defaultPool, nil, nil 40 } 41 42 func (a *allocator) ReleasePool(poolID string) error { 43 return nil 44 } 45 46 func (a *allocator) RequestAddress(poolID string, ip net.IP, opts map[string]string) (*net.IPNet, map[string]string, error) { 47 if poolID != defaultPoolID { 48 return nil, nil, types.InvalidParameterErrorf("unknown pool id: %s", poolID) 49 } 50 return nil, nil, nil 51 } 52 53 func (a *allocator) ReleaseAddress(poolID string, ip net.IP) error { 54 if poolID != defaultPoolID { 55 return types.InvalidParameterErrorf("unknown pool id: %s", poolID) 56 } 57 return nil 58 } 59 60 func (a *allocator) IsBuiltIn() bool { 61 return true 62 } 63 64 // Register registers the null ipam driver with r. 65 func Register(r ipamapi.Registerer) error { 66 return r.RegisterIpamDriver(ipamapi.NullIPAM, &allocator{}) 67 }