-
Notifications
You must be signed in to change notification settings - Fork 4
/
builtin.go
41 lines (33 loc) · 1.1 KB
/
builtin.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package builtin
import (
"net"
"github.com/docker/docker/libnetwork/ipam"
"github.com/docker/docker/libnetwork/ipamapi"
"github.com/docker/docker/libnetwork/ipamutils"
)
// defaultAddressPool Stores user configured subnet list
var defaultAddressPool []*net.IPNet
// registerBuiltin registers the built-in ipam driver with libnetwork.
func registerBuiltin(ic ipamapi.Registerer) error {
var localAddressPool []*net.IPNet
if len(defaultAddressPool) > 0 {
localAddressPool = append([]*net.IPNet(nil), defaultAddressPool...)
} else {
localAddressPool = ipamutils.GetLocalScopeDefaultNetworks()
}
a, err := ipam.NewAllocator(localAddressPool, ipamutils.GetGlobalScopeDefaultNetworks())
if err != nil {
return err
}
cps := &ipamapi.Capability{RequiresRequestReplay: true}
return ic.RegisterIpamDriverWithCapabilities(ipamapi.DefaultIPAM, a, cps)
}
// SetDefaultIPAddressPool stores default address pool.
func SetDefaultIPAddressPool(addressPool []*ipamutils.NetworkToSplit) error {
nets, err := ipamutils.SplitNetworks(addressPool)
if err != nil {
return err
}
defaultAddressPool = nets
return nil
}