mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
34671f2010
Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package network
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
|
)
|
|
|
|
// SetupVeth sets up an existing network namespace with the specified
|
|
// network configuration.
|
|
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(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)
|
|
}
|
|
|
|
if err := SetMtu("eth0", config.Mtu); err != nil {
|
|
return fmt.Errorf("set eth0 mtu to %d %s", config.Mtu, err)
|
|
}
|
|
if err := InterfaceUp("eth0"); err != nil {
|
|
return fmt.Errorf("eth0 up %s", err)
|
|
}
|
|
|
|
if err := SetMtu("lo", config.Mtu); err != nil {
|
|
return fmt.Errorf("set lo mtu to %d %s", config.Mtu, err)
|
|
}
|
|
if err := InterfaceUp("lo"); err != nil {
|
|
return fmt.Errorf("lo up %s", err)
|
|
}
|
|
|
|
if config.Gateway != "" {
|
|
if err := SetDefaultGateway(config.Gateway); err != nil {
|
|
return fmt.Errorf("set gateway to %s %s", config.Gateway, err)
|
|
}
|
|
}
|
|
return nil
|
|
}
|