mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #3887 from proppy/detect-network-mtu
docker: detect defaultNetworkMtu from default route
This commit is contained in:
commit
b56440fa24
5 changed files with 40 additions and 12 deletions
15
config.go
15
config.go
|
@ -1,12 +1,14 @@
|
||||||
package docker
|
package docker
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/dotcloud/docker/engine"
|
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/engine"
|
||||||
|
"github.com/dotcloud/docker/networkdriver"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
DefaultNetworkMtu = 1500
|
defaultNetworkMtu = 1500
|
||||||
DisableNetworkBridge = "none"
|
DisableNetworkBridge = "none"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -47,9 +49,16 @@ func DaemonConfigFromJob(job *engine.Job) *DaemonConfig {
|
||||||
if mtu := job.GetenvInt("Mtu"); mtu != 0 {
|
if mtu := job.GetenvInt("Mtu"); mtu != 0 {
|
||||||
config.Mtu = mtu
|
config.Mtu = mtu
|
||||||
} else {
|
} else {
|
||||||
config.Mtu = DefaultNetworkMtu
|
config.Mtu = GetDefaultNetworkMtu()
|
||||||
}
|
}
|
||||||
config.DisableNetwork = job.Getenv("BridgeIface") == DisableNetworkBridge
|
config.DisableNetwork = job.Getenv("BridgeIface") == DisableNetworkBridge
|
||||||
|
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultNetworkMtu() int {
|
||||||
|
if iface, err := networkdriver.GetDefaultRouteIface(); err == nil {
|
||||||
|
return iface.MTU
|
||||||
|
}
|
||||||
|
return defaultNetworkMtu
|
||||||
|
}
|
||||||
|
|
|
@ -2,15 +2,16 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/dotcloud/docker"
|
"github.com/dotcloud/docker"
|
||||||
"github.com/dotcloud/docker/api"
|
"github.com/dotcloud/docker/api"
|
||||||
"github.com/dotcloud/docker/engine"
|
"github.com/dotcloud/docker/engine"
|
||||||
flag "github.com/dotcloud/docker/pkg/mflag"
|
flag "github.com/dotcloud/docker/pkg/mflag"
|
||||||
"github.com/dotcloud/docker/sysinit"
|
"github.com/dotcloud/docker/sysinit"
|
||||||
"github.com/dotcloud/docker/utils"
|
"github.com/dotcloud/docker/utils"
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -42,7 +43,7 @@ func main() {
|
||||||
flInterContainerComm = flag.Bool([]string{"#icc", "-icc"}, true, "Enable inter-container communication")
|
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")
|
flGraphDriver = flag.String([]string{"s", "-storage-driver"}, "", "Force the docker runtime to use a specific storage driver")
|
||||||
flHosts = docker.NewListOpts(docker.ValidateHost)
|
flHosts = docker.NewListOpts(docker.ValidateHost)
|
||||||
flMtu = flag.Int([]string{"#mtu", "-mtu"}, docker.DefaultNetworkMtu, "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(&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")
|
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")
|
||||||
|
|
|
@ -80,6 +80,7 @@ Commands
|
||||||
-r, --restart=true: Restart previously running containers
|
-r, --restart=true: Restart previously running containers
|
||||||
-s, --storage-driver="": Force the docker runtime to use a specific storage driver
|
-s, --storage-driver="": Force the docker runtime to use a specific storage driver
|
||||||
-v, --version=false: Print version information and quit
|
-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
|
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.
|
daemon and client. To run the daemon you provide the ``-d`` flag.
|
||||||
|
|
|
@ -4,9 +4,6 @@ import (
|
||||||
"archive/tar"
|
"archive/tar"
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker"
|
|
||||||
"github.com/dotcloud/docker/engine"
|
|
||||||
"github.com/dotcloud/docker/utils"
|
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -16,6 +13,10 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"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.
|
// 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{
|
config := &docker.DaemonConfig{
|
||||||
Root: root,
|
Root: root,
|
||||||
AutoRestart: false,
|
AutoRestart: false,
|
||||||
Mtu: docker.DefaultNetworkMtu,
|
Mtu: docker.GetDefaultNetworkMtu(),
|
||||||
}
|
}
|
||||||
|
|
||||||
eng, err := engine.New(root)
|
eng, err := engine.New(root)
|
||||||
|
|
|
@ -2,13 +2,16 @@ package networkdriver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/dotcloud/docker/pkg/netlink"
|
|
||||||
"net"
|
"net"
|
||||||
|
|
||||||
|
"github.com/dotcloud/docker/pkg/netlink"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
networkGetRoutesFct = netlink.NetworkGetRoutes
|
networkGetRoutesFct = netlink.NetworkGetRoutes
|
||||||
|
ErrNoDefaultRoute = errors.New("no default route")
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error {
|
func CheckNameserverOverlaps(nameservers []string, toCheck *net.IPNet) error {
|
||||||
|
@ -100,3 +103,16 @@ func GetIfaceAddr(name string) (net.Addr, error) {
|
||||||
}
|
}
|
||||||
return addrs4[0], nil
|
return addrs4[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetDefaultRouteIface() (*net.Interface, error) {
|
||||||
|
rs, err := networkGetRoutesFct()
|
||||||
|
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, ErrNoDefaultRoute
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue