From 566ff54d0ddffbeb3ba2e5f1e400db8528faf0a7 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Thu, 19 Dec 2013 15:16:54 -0800 Subject: [PATCH] Allow mtu to be configured at daemon start --- config.go | 6 ++++++ container.go | 2 +- docker/docker.go | 2 ++ docs/sources/commandline/cli.rst | 1 + integration/utils_test.go | 1 + network.go | 2 +- 6 files changed, 12 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 1f743f6290..5a6de7a873 100644 --- a/config.go +++ b/config.go @@ -18,6 +18,7 @@ type DaemonConfig struct { DefaultIp net.IP InterContainerCommunication bool GraphDriver string + Mtu int } // ConfigFromJob creates and returns a new DaemonConfig object @@ -41,5 +42,10 @@ func ConfigFromJob(job *engine.Job) *DaemonConfig { config.DefaultIp = net.ParseIP(job.Getenv("DefaultIp")) config.InterContainerCommunication = job.GetenvBool("InterContainerCommunication") config.GraphDriver = job.Getenv("GraphDriver") + if mtu := job.GetenvInt("Mtu"); mtu != -1 { + config.Mtu = mtu + } else { + config.Mtu = DefaultNetworkMtu + } return &config } diff --git a/container.go b/container.go index 1c55fbbe91..bb591669af 100644 --- a/container.go +++ b/container.go @@ -582,7 +582,7 @@ func (container *Container) Start() (err error) { params = append(params, "-g", network.Gateway, "-i", fmt.Sprintf("%s/%d", network.IPAddress, network.IPPrefixLen), - "-mtu", "1500", + "-mtu", strconv.Itoa(container.runtime.config.Mtu), ) } diff --git a/docker/docker.go b/docker/docker.go index a0108630bd..1b5457984c 100644 --- a/docker/docker.go +++ b/docker/docker.go @@ -40,6 +40,7 @@ func main() { flInterContainerComm = flag.Bool("icc", true, "Enable inter-container communication") flGraphDriver = flag.String("s", "", "Force the docker runtime to use a specific storage driver") flHosts = docker.NewListOpts(docker.ValidateHost) + flMtu = flag.Int("mtu", docker.DefaultNetworkMtu, "Set the containers network mtu") ) flag.Var(&flDns, "dns", "Force docker to use specific DNS servers") flag.Var(&flHosts, "H", "Multiple tcp://host:port or unix://path/to/socket to bind in daemon mode, single connection otherwise") @@ -87,6 +88,7 @@ func main() { job.Setenv("DefaultIp", *flDefaultIp) job.SetenvBool("InterContainerCommunication", *flInterContainerComm) job.Setenv("GraphDriver", *flGraphDriver) + job.SetenvInt("Mtu", *flMtu) if err := job.Run(); err != nil { log.Fatal(err) } diff --git a/docs/sources/commandline/cli.rst b/docs/sources/commandline/cli.rst index fc18066533..523dc24ad8 100644 --- a/docs/sources/commandline/cli.rst +++ b/docs/sources/commandline/cli.rst @@ -37,6 +37,7 @@ To list available commands, either run ``docker`` with no parameters or execute -icc=true: Enable inter-container communication -ip="0.0.0.0": Default IP address to use when binding container ports -iptables=true: Disable docker's addition of iptables rules + -mtu=1500: Set the containers network mtu -p="/var/run/docker.pid": Path to use for daemon PID file -r=true: Restart previously running containers -s="": Force the docker runtime to use a specific storage driver diff --git a/integration/utils_test.go b/integration/utils_test.go index 8ee1a0af08..85ba13d698 100644 --- a/integration/utils_test.go +++ b/integration/utils_test.go @@ -32,6 +32,7 @@ func mkRuntime(f utils.Fataler) *docker.Runtime { config := &docker.DaemonConfig{ Root: root, AutoRestart: false, + Mtu: docker.DefaultNetworkMtu, } r, err := docker.NewRuntimeFromDirectory(config) if err != nil { diff --git a/network.go b/network.go index 09db965bb0..cccb7c52e1 100644 --- a/network.go +++ b/network.go @@ -19,6 +19,7 @@ import ( const ( DefaultNetworkBridge = "docker0" DisableNetworkBridge = "none" + DefaultNetworkMtu = 1500 portRangeStart = 49153 portRangeEnd = 65535 siocBRADDBR = 0x89a0 @@ -118,7 +119,6 @@ func CreateBridgeIface(config *DaemonConfig) error { "192.168.44.1/24", } - nameservers := []string{} resolvConf, _ := utils.GetResolvConf() // we don't check for an error here, because we don't really care