mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #13953 from crosbymichael/network-mtu
Get Mtu from default route
This commit is contained in:
commit
b81f2ee5f2
1 changed files with 30 additions and 0 deletions
|
@ -36,6 +36,7 @@ import (
|
|||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/trust"
|
||||
"github.com/docker/libcontainer/netlink"
|
||||
"github.com/docker/libnetwork"
|
||||
)
|
||||
|
||||
|
@ -589,6 +590,8 @@ func (daemon *Daemon) RegisterLinks(container *Container, hostConfig *runconfig.
|
|||
}
|
||||
|
||||
func NewDaemon(config *Config, registryService *registry.Service) (daemon *Daemon, err error) {
|
||||
setDefaultMtu(config)
|
||||
|
||||
// Ensure we have compatible configuration options
|
||||
if err := checkConfigOptions(config); err != nil {
|
||||
return nil, err
|
||||
|
@ -981,3 +984,30 @@ func (daemon *Daemon) newBaseContainer(id string) CommonContainer {
|
|||
root: daemon.containerRoot(id),
|
||||
}
|
||||
}
|
||||
|
||||
func setDefaultMtu(config *Config) {
|
||||
// do nothing if the config does not have the default 0 value.
|
||||
if config.Mtu != 0 {
|
||||
return
|
||||
}
|
||||
config.Mtu = defaultNetworkMtu
|
||||
if routeMtu, err := getDefaultRouteMtu(); err == nil {
|
||||
config.Mtu = routeMtu
|
||||
}
|
||||
}
|
||||
|
||||
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.NetworkGetRoutes()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
for _, r := range routes {
|
||||
if r.Default {
|
||||
return r.Iface.MTU, nil
|
||||
}
|
||||
}
|
||||
return 0, errNoDefaultRoute
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue