docker: detect defaultNetworkMtu from default route

Docker-DCO-1.1-Signed-off-by: Johan Euphrosine <proppy@google.com> (github: google)
This commit is contained in:
Johan Euphrosine 2014-02-01 03:38:39 -08:00
parent a446b34719
commit 4d0a026c98
3 changed files with 31 additions and 7 deletions

View file

@ -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
}

View file

@ -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")

View file

@ -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")
}