Implement init veth creation
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
This commit is contained in:
parent
e25ebdd06c
commit
8430fbf11e
6 changed files with 63 additions and 67 deletions
|
@ -3,18 +3,16 @@ package network
|
|||
import (
|
||||
"fmt"
|
||||
"github.com/dotcloud/docker/pkg/libcontainer"
|
||||
"os"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
// SetupVeth sets up an existing network namespace with the specified
|
||||
// network configuration.
|
||||
func SetupVeth(config *libcontainer.Network) error {
|
||||
if err := InterfaceDown(config.TempVethName); err != nil {
|
||||
return fmt.Errorf("interface down %s %s", config.TempVethName, err)
|
||||
func SetupVeth(config *libcontainer.Network, tempVethName string) error {
|
||||
if err := InterfaceDown(tempVethName); err != nil {
|
||||
return fmt.Errorf("interface down %s %s", tempVethName, err)
|
||||
}
|
||||
if err := ChangeInterfaceName(config.TempVethName, "eth0"); err != nil {
|
||||
return fmt.Errorf("change %s to eth0 %s", config.TempVethName, err)
|
||||
if err := ChangeInterfaceName(tempVethName, "eth0"); err != nil {
|
||||
return fmt.Errorf("change %s to eth0 %s", tempVethName, err)
|
||||
}
|
||||
if err := SetInterfaceIp("eth0", config.IP); err != nil {
|
||||
return fmt.Errorf("set eth0 ip %s", err)
|
||||
|
@ -41,29 +39,3 @@ func SetupVeth(config *libcontainer.Network) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetupNamespaceMountDir prepares a new root for use as a mount
|
||||
// source for bind mounting namespace fd to an outside path
|
||||
func SetupNamespaceMountDir(root string) error {
|
||||
if err := os.MkdirAll(root, 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
// make sure mounts are not unmounted by other mnt namespaces
|
||||
if err := syscall.Mount("", root, "none", syscall.MS_SHARED|syscall.MS_REC, ""); err != nil && err != syscall.EINVAL {
|
||||
return err
|
||||
}
|
||||
if err := syscall.Mount(root, root, "none", syscall.MS_BIND, ""); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// DeleteNetworkNamespace unmounts the binding path and removes the
|
||||
// file so that no references to the fd are present and the network
|
||||
// namespace is automatically cleaned up
|
||||
func DeleteNetworkNamespace(bindingPath string) error {
|
||||
if err := syscall.Unmount(bindingPath, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return os.Remove(bindingPath)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue