2015-02-19 17:21:42 -08:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
type networkNamespace struct {
|
|
|
|
path string
|
|
|
|
interfaces []*Interface
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a new network namespace mounted on the provided path.
|
|
|
|
func NewNamespace(path string) (Namespace, error) {
|
2015-02-19 17:44:48 -08:00
|
|
|
if err := reexec(reexecCreateNamespace, path); err != nil {
|
2015-02-19 17:21:42 -08:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &networkNamespace{path: path}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkNamespace) AddInterface(i *Interface) error {
|
2015-02-22 17:24:22 -08:00
|
|
|
// TODO Open pipe, pass fd to child and write serialized Interface on it.
|
2015-02-19 17:44:48 -08:00
|
|
|
if err := reexec(reexecMoveInterface, i.SrcName, i.DstName); err != nil {
|
2015-02-19 17:21:42 -08:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
n.interfaces = append(n.interfaces, i)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkNamespace) Interfaces() []*Interface {
|
|
|
|
return n.interfaces
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *networkNamespace) Path() string {
|
|
|
|
return n.path
|
|
|
|
}
|