diff --git a/daemon/container_windows.go b/daemon/container_windows.go index e56b7e2d1a..7d885c3c3d 100644 --- a/daemon/container_windows.go +++ b/daemon/container_windows.go @@ -183,3 +183,7 @@ func (container *Container) unmountIpcMounts() error { func (container *Container) ipcMounts() []execdriver.Mount { return nil } + +func getDefaultRouteMtu() (int, error) { + return -1, errSystemNotSupported +} diff --git a/daemon/daemon.go b/daemon/daemon.go index 8cb227583b..185cc9aa16 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -10,7 +10,6 @@ import ( "fmt" "io" "io/ioutil" - "net" "os" "path/filepath" "regexp" @@ -53,7 +52,6 @@ import ( "github.com/docker/docker/volume/local" "github.com/docker/docker/volume/store" "github.com/docker/libnetwork" - "github.com/vishvananda/netlink" ) var ( @@ -1077,25 +1075,6 @@ func setDefaultMtu(config *Config) { var errNoDefaultRoute = errors.New("no default route was found") -// getDefaultRouteMtu returns the MTU for the default route's interface. -func getDefaultRouteMtu() (int, error) { - routes, err := netlink.RouteList(nil, 0) - if err != nil { - return 0, err - } - for _, r := range routes { - // a nil Dst means that this is the default route. - if r.Dst == nil { - i, err := net.InterfaceByIndex(r.LinkIndex) - if err != nil { - continue - } - return i.MTU, nil - } - } - return 0, errNoDefaultRoute -} - // verifyContainerSettings performs validation of the hostconfig and config // structures. func (daemon *Daemon) verifyContainerSettings(ctx context.Context, hostConfig *runconfig.HostConfig, config *runconfig.Config) ([]string, error) { diff --git a/daemon/daemon_unix.go b/daemon/daemon_unix.go index 0ae7d95d89..1fc3fd64b5 100644 --- a/daemon/daemon_unix.go +++ b/daemon/daemon_unix.go @@ -28,6 +28,7 @@ import ( "github.com/docker/libnetwork/netlabel" "github.com/docker/libnetwork/options" "github.com/opencontainers/runc/libcontainer/label" + "github.com/vishvananda/netlink" ) const ( @@ -554,3 +555,22 @@ func (daemon *Daemon) newBaseContainer(id string) Container { VolumesRW: make(map[string]bool), } } + +// getDefaultRouteMtu returns the MTU for the default route's interface. +func getDefaultRouteMtu() (int, error) { + routes, err := netlink.RouteList(nil, 0) + if err != nil { + return 0, err + } + for _, r := range routes { + // a nil Dst means that this is the default route. + if r.Dst == nil { + i, err := net.InterfaceByIndex(r.LinkIndex) + if err != nil { + continue + } + return i.MTU, nil + } + } + return 0, errNoDefaultRoute +}