-
Notifications
You must be signed in to change notification settings - Fork 18.6k
/
builtin.go
43 lines (35 loc) · 1.11 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
42
43
package builtin
import (
"net"
"github.com/docker/docker/libnetwork/ipam"
"github.com/docker/docker/libnetwork/ipamapi"
"github.com/docker/docker/libnetwork/ipamutils"
)
var (
// defaultAddressPool Stores user configured subnet list
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
}