summaryrefslogtreecommitdiff
path: root/libpod/container_linux.go
diff options
context:
space:
mode:
Diffstat (limited to 'libpod/container_linux.go')
-rw-r--r--libpod/container_linux.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/libpod/container_linux.go b/libpod/container_linux.go
index 823a590dd..2330f27a7 100644
--- a/libpod/container_linux.go
+++ b/libpod/container_linux.go
@@ -4,6 +4,7 @@ package libpod
import (
"github.com/containernetworking/plugins/pkg/ns"
+ "github.com/sirupsen/logrus"
)
type containerPlatformState struct {
@@ -13,3 +14,40 @@ type containerPlatformState struct {
// told to join another container's network namespace
NetNS ns.NetNS `json:"-"`
}
+
+func (ctr *Container) setNamespace(netNSPath string, newState *containerState) error {
+ if netNSPath != "" {
+ // Check if the container's old state has a good netns
+ if ctr.state.NetNS != nil && netNSPath == ctr.state.NetNS.Path() {
+ newState.NetNS = ctr.state.NetNS
+ } else {
+ // Tear down the existing namespace
+ if err := ctr.runtime.teardownNetNS(ctr); err != nil {
+ logrus.Warnf(err.Error())
+ }
+
+ // Open the new network namespace
+ ns, err := joinNetNS(netNSPath)
+ if err == nil {
+ newState.NetNS = ns
+ } else {
+ logrus.Errorf("error joining network namespace for container %s", ctr.ID())
+ ctr.valid = false
+ }
+ }
+ } else {
+ // The container no longer has a network namespace
+ // Tear down the old one
+ if err := ctr.runtime.teardownNetNS(ctr); err != nil {
+ logrus.Warnf(err.Error())
+ }
+ }
+ return nil
+}
+
+func (ctr *Container) setNamespaceStatePath() string {
+ if ctr.state.NetNS != nil {
+ return ctr.state.NetNS.Path()
+ }
+ return ""
+}