OptionExecRoot did not configure the controller it was passed to: it set the directory for all network namespaces in package osl, which every controller in the process shared. The overlay driver found that directory by generating a sandbox key for a made-up ID and taking the key's parent directory. Replace it with OptionNetnsDir, available on Linux and FreeBSD, which sets the directory in the controller's config. OptionExecRoot was a no-op on Windows. The controller generates its sandboxes' keys from the directory, and the overlay driver is given the directory when it is registered and builds its own keys. Each overlay driver instance scans its own directory for the VNIs of the sandboxes a previous run of the daemon left behind. The controller creates the directory when it is created, instead of osl creating the package-wide directory when it first creates a namespace. The daemon still keeps the namespaces in <exec-root>/netns. The directory has no default: on Linux and FreeBSD, the controller refuses to create a sandbox when none is configured, as does the overlay driver, so a test which leaves out the option fails instead of leaving network namespaces behind in a directory shared with the host. Tests which create sandboxes keep them in a temporary directory, and unmount the namespaces left in it when they end. The key formats do not change on Linux. On FreeBSD, sandbox keys become paths in the directory, as on Linux. Drop GenerateKey's lookup of an existing key for an ID starting with "-": no caller passes such an ID. Signed-off-by: Cory Snider <csnider@mirantis.com> Assisted-By: Claude Opus 5.5
67 lines
2.3 KiB
Go
67 lines
2.3 KiB
Go
package libnetwork
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/moby/moby/v2/daemon/libnetwork/config"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/datastore"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/driverapi"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/bridge"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/host"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/ipvlan"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/macvlan"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/null"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drivers/overlay"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/drvregistry"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/internal/rlkclient"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/portmappers/nat"
|
|
"github.com/moby/moby/v2/daemon/libnetwork/portmappers/routed"
|
|
)
|
|
|
|
func registerNetworkDrivers(r driverapi.Registerer, cfg *config.Config, store *datastore.Store, pms *drvregistry.PortMappers) error {
|
|
for _, nr := range []struct {
|
|
ntype string
|
|
register func() error
|
|
}{
|
|
{
|
|
ntype: bridge.NetworkType,
|
|
register: func() error {
|
|
return bridge.Register(r, store, pms, cfg.BridgeConfig)
|
|
},
|
|
},
|
|
{ntype: host.NetworkType, register: func() error { return host.Register(r) }},
|
|
{ntype: ipvlan.NetworkType, register: func() error { return ipvlan.Register(r, store) }},
|
|
{ntype: macvlan.NetworkType, register: func() error { return macvlan.Register(r, store) }},
|
|
{ntype: null.NetworkType, register: func() error { return null.Register(r) }},
|
|
{ntype: overlay.NetworkType, register: func() error { return overlay.Register(r, cfg.NetnsDir) }},
|
|
} {
|
|
if err := nr.register(); err != nil {
|
|
return fmt.Errorf("failed to register %q driver: %w", nr.ntype, err)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func registerPortMappers(ctx context.Context, r *drvregistry.PortMappers, cfg *config.Config) error {
|
|
var pdc *rlkclient.PortDriverClient
|
|
if cfg.Rootless {
|
|
var err error
|
|
pdc, err = rlkclient.NewPortDriverClient(ctx)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to create port driver client: %w", err)
|
|
}
|
|
}
|
|
|
|
if err := nat.Register(r, nat.Config{RlkClient: pdc}); err != nil {
|
|
return fmt.Errorf("registering nat portmapper: %w", err)
|
|
}
|
|
|
|
if err := routed.Register(r); err != nil {
|
|
return fmt.Errorf("registering routed portmapper: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|