From 4d0a026c98721da874a03f5b6993045bae95842a Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Sat, 1 Feb 2014 03:38:39 -0800 Subject: [PATCH 1/4] docker: detect defaultNetworkMtu from default route Docker-DCO-1.1-Signed-off-by: Johan Euphrosine (github: google) --- config.go | 13 +++++++++++-- docker/docker.go | 9 +++++---- networkdriver/utils.go | 16 +++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/config.go b/config.go index 40d885810..e7f87ace7 100644 --- a/config.go +++ b/config.go @@ -1,12 +1,14 @@ package docker import ( - "github.com/dotcloud/docker/engine" "net" + + "github.com/dotcloud/docker/engine" + "github.com/dotcloud/docker/networkdriver" ) const ( - DefaultNetworkMtu = 1500 + defaultNetworkMtu = 1500 DisableNetworkBridge = "none" ) @@ -53,3 +55,10 @@ func DaemonConfigFromJob(job *engine.Job) *DaemonConfig { return config } + +func GetDefaultNetworkMtu() int { + if iface, err := networkdriver.GetDefaultRouteIface(); err == nil { + return iface.MTU + } + return defaultNetworkMtu +} diff --git a/docker/docker.go b/docker/docker.go index aaeced95f..8d4ae7fce 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -2,15 +2,16 @@ package main import ( "fmt" + "log" + "os" + "strings" + "github.com/dotcloud/docker" "github.com/dotcloud/docker/api" "github.com/dotcloud/docker/engine" flag "github.com/dotcloud/docker/pkg/mflag" "github.com/dotcloud/docker/sysinit" "github.com/dotcloud/docker/utils" - "log" - "os" - "strings" ) var ( @@ -42,7 +43,7 @@ func main() { flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication") flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver") flHosts = docker.NewListOpts(docker.ValidateHost) - flMtu = flag.Int([]string{"#mtu", "-mtu"}, docker.DefaultNetworkMtu, "Set the containers network mtu") + flMtu = flag.Int([]string{"#mtu", "-mtu"}, docker.GetDefaultNetworkMtu(), "Set the containers network mtu") ) flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers") flag.Var(&flHosts, []string{"H", "-host"}, "tcp://host:port, unix://path/to/socket, fd://* or fd://socketfd to use in daemon mode. Multiple sockets can be specified") diff --git a/networkdriver/utils.go b/networkdriver/utils.go index 6f6dbe4f1..611ca7586 100644 --- a/networkdriver/utils.go +++ b/networkdriver/utils.go @@ -3,8 +3,9 @@ package networkdriver import ( "encoding/binary" "fmt" - "github.com/dotcloud/docker/pkg/netlink" "net" + + "github.com/dotcloud/docker/pkg/netlink" ) var ( @@ -100,3 +101,16 @@ func GetIfaceAddr(name string) (net.Addr, error) { } return addrs4[0], nil } + +func GetDefaultRouteIface() (*net.Interface, error) { + rs, err := netlink.NetworkGetRoutes() + if err != nil { + return nil, fmt.Errorf("unable to get routes: %v", err) + } + for _, r := range rs { + if r.Default { + return r.Iface, nil + } + } + return nil, fmt.Errorf("no default route") +} From 1b9c5edc6c7acbe894c4b2db3e3e4a1f1353ccc5 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Mon, 3 Feb 2014 14:27:40 -0800 Subject: [PATCH 2/4] networkdriver: add ErrNoDefaultRoute Docker-DCO-1.1-Signed-off-by: Johan Euphrosine (github: google) --- networkdriver/utils.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/networkdriver/utils.go b/networkdriver/utils.go index 611ca7586..0a4ef70c9 100644 --- a/networkdriver/utils.go +++ b/networkdriver/utils.go @@ -2,6 +2,7 @@ package networkdriver import ( "encoding/binary" + "errors" "fmt" "net" @@ -10,6 +11,7 @@ import ( var ( networkGetRoutesFct = netlink.NetworkGetRoutes + ErrNoDefaultRoute = errors.New("no default route") ) func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error { @@ -103,7 +105,7 @@ func GetIfaceAddr(name string) (net.Addr, error) { } func GetDefaultRouteIface() (*net.Interface, error) { - rs, err := netlink.NetworkGetRoutes() + rs, err := networkGetRoutesFct() if err != nil { return nil, fmt.Errorf("unable to get routes: %v", err) } @@ -112,5 +114,5 @@ func GetDefaultRouteIface() (*net.Interface, error) { return r.Iface, nil } } - return nil, fmt.Errorf("no default route") + return nil, ErrNoDefaultRoute } From 92e61f89aad35c3103e0db1c6dacecc0c588bd2e Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Mon, 3 Feb 2014 15:36:39 -0800 Subject: [PATCH 3/4] docker/config: update -mtu flag default Docker-DCO-1.1-Signed-off-by: Johan Euphrosine (github: google) --- config.go | 2 +- docker/docker.go | 2 +- integration/utils_test.go | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/config.go b/config.go index e7f87ace7..fc04c9ff1 100644 --- a/config.go +++ b/config.go @@ -49,7 +49,7 @@ func DaemonConfigFromJob(job *engine.Job) *DaemonConfig { if mtu := job.GetenvInt("Mtu"); mtu != 0 { config.Mtu = mtu } else { - config.Mtu = DefaultNetworkMtu + config.Mtu = GetDefaultNetworkMtu() } config.DisableNetwork = job.Getenv("BridgeIface") == DisableNetworkBridge diff --git a/docker/docker.go b/docker/docker.go index 8d4ae7fce..d92f4d98e 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -43,7 +43,7 @@ func main() { flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication") flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver") flHosts = docker.NewListOpts(docker.ValidateHost) - flMtu = flag.Int([]string{"#mtu", "-mtu"}, docker.GetDefaultNetworkMtu(), "Set the containers network mtu") + flMtu = flag.Int([]string{"#mtu", "-mtu"}, 0, "Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if not default route is available") ) flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers") flag.Var(&flHosts, []string{"H", "-host"}, "tcp://host:port, unix://path/to/socket, fd://* or fd://socketfd to use in daemon mode. Multiple sockets can be specified") diff --git a/integration/utils_test.go b/integration/utils_test.go index 060a44713..450cb7527 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -4,9 +4,6 @@ import ( "archive/tar" "bytes" "fmt" - "github.com/dotcloud/docker" - "github.com/dotcloud/docker/engine" - "github.com/dotcloud/docker/utils" "io" "io/ioutil" "net/http" @@ -16,6 +13,10 @@ import ( "strings" "testing" "time" + + "github.com/dotcloud/docker" + "github.com/dotcloud/docker/engine" + "github.com/dotcloud/docker/utils" ) // This file contains utility functions for docker's unit test suite. @@ -32,7 +33,7 @@ func mkRuntime(f utils.Fataler) *docker.Runtime { config := &docker.DaemonConfig{ Root: root, AutoRestart: false, - Mtu: docker.DefaultNetworkMtu, + Mtu: docker.GetDefaultNetworkMtu(), } eng, err := engine.New(root) From ab1482e9c25b3c27b48d97ac84e60efb39ae8af7 Mon Sep 17 00:00:00 2001 From: Johan Euphrosine Date: Mon, 3 Feb 2014 16:01:38 -0800 Subject: [PATCH 4/4] docs/cli: add mtu option Docker-DCO-1.1-Signed-off-by: Johan Euphrosine (github: google) --- docs/sources/reference/commandline/cli.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/sources/reference/commandline/cli.rst b/docs/sources/reference/commandline/cli.rst index a4d302286..ae7708030 100644 --- a/docs/sources/reference/commandline/cli.rst +++ b/docs/sources/reference/commandline/cli.rst @@ -80,6 +80,7 @@ Commands -r, --restart=true: Restart previously running containers -s, --storage-driver="": Force the docker runtime to use a specific storage driver -v, --version=false: Print version information and quit + -mtu, --mtu=0: Set the containers network MTU; if no value is provided: default to the default route MTU or 1500 if not default route is available The Docker daemon is the persistent process that manages containers. Docker uses the same binary for both the daemon and client. To run the daemon you provide the ``-d`` flag.