mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
daemon: add ULA prefix by default
So far, Moby only had IPv4 prefixes in its 'default-address-pools'. To get dynamic IPv6 subnet allocations, users had to redefine this parameter to include IPv6 base network(s). This is needlessly complex and against Moby's 'batteries-included' principle. This change generates a ULA base network by deriving a ULA Global ID from the Engine's Host ID and put that base network into 'default-address-pools'. This Host ID is stable over time (except if users remove their '/var/lib/docker/engine-id') and thus the GID is stable too. This ULA base network won't be put into 'default-address-pools' if users have manually configured it. This is loosely based on https://datatracker.ietf.org/doc/html/rfc4193#section-3.2.2. Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package daemon // import "github.com/docker/docker/daemon"
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
@@ -313,3 +314,30 @@ func TestFindNetworkErrorType(t *testing.T) {
|
||||
t.Error("The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDeriveULABaseNetwork checks that for a given hostID, the derived prefix is stable over time.
|
||||
func TestDeriveULABaseNetwork(t *testing.T) {
|
||||
testcases := []struct {
|
||||
name string
|
||||
hostID string
|
||||
expPrefix netip.Prefix
|
||||
}{
|
||||
{
|
||||
name: "Empty hostID",
|
||||
expPrefix: netip.MustParsePrefix("fd42:98fc:1c14::/48"),
|
||||
},
|
||||
{
|
||||
name: "499d4bc0-b0b3-416f-b1ee-cf6486315593",
|
||||
hostID: "499d4bc0-b0b3-416f-b1ee-cf6486315593",
|
||||
expPrefix: netip.MustParsePrefix("fd62:fb69:18af::/48"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testcases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
nw := deriveULABaseNetwork(tc.hostID)
|
||||
assert.Equal(t, nw.Base, tc.expPrefix)
|
||||
assert.Equal(t, nw.Size, 64)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user