Use netlink directly instead of /bin/ip in Sysinit

The sysinit code only uses /bin/ip to set a default gateway. This
is pretty easy to do via netlink directly, so we can avoid
the ip dependency.
This commit is contained in:
Alexander Larsson 2013-09-17 15:02:12 +02:00 committed by Victor Vieux
parent bf61d41d6c
commit 607c1a520e
1 changed files with 10 additions and 1 deletions

View File

@ -3,8 +3,10 @@ package docker
import (
"flag"
"fmt"
"github.com/dotcloud/docker/netlink"
"github.com/dotcloud/docker/utils"
"log"
"net"
"os"
"os/exec"
"strconv"
@ -17,7 +19,14 @@ func setupNetworking(gw string) {
if gw == "" {
return
}
if _, err := ip("route", "add", "default", "via", gw); err != nil {
ip := net.ParseIP(gw)
if ip == nil {
log.Fatalf("Unable to set up networking, %s is not a valid IP", gw)
return
}
if err := netlink.AddDefaultGw(ip); err != nil {
log.Fatalf("Unable to set up networking: %v", err)
}
}