2014-02-18 16:56:11 -08:00
|
|
|
package network
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetupVeth sets up an existing network namespace with the specified
|
|
|
|
// network configuration.
|
2014-02-19 15:33:44 -08:00
|
|
|
func SetupVeth(config *libcontainer.Network, tempVethName string) error {
|
|
|
|
if err := InterfaceDown(tempVethName); err != nil {
|
|
|
|
return fmt.Errorf("interface down %s %s", tempVethName, err)
|
2014-02-18 16:56:11 -08:00
|
|
|
}
|
2014-02-19 15:33:44 -08:00
|
|
|
if err := ChangeInterfaceName(tempVethName, "eth0"); err != nil {
|
|
|
|
return fmt.Errorf("change %s to eth0 %s", tempVethName, err)
|
2014-02-18 16:56:11 -08:00
|
|
|
}
|
|
|
|
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
|
|
|
|
}
|