summaryrefslogtreecommitdiff
path: root/libpod
diff options
context:
space:
mode:
authorDoug Rabson <dfr@rabson.org>2022-09-07 15:35:48 +0100
committerDoug Rabson <dfr@rabson.org>2022-09-12 16:11:25 +0100
commitc5f64d9f587ec6df7bb6def4983e7996c35ae7e9 (patch)
tree52dccf183344b24798ba71487ff623b29130b19a /libpod
parent36cfd05a7d90b4c620d308274d6488225d49ed6c (diff)
downloadpodman-c5f64d9f587ec6df7bb6def4983e7996c35ae7e9.tar.gz
podman-c5f64d9f587ec6df7bb6def4983e7996c35ae7e9.tar.bz2
podman-c5f64d9f587ec6df7bb6def4983e7996c35ae7e9.zip
libpod: Re-work the container's network state to help code sharing
This replaces the NetworkJail string field with a struct pointer named NetNS. This does not try to emulate the complete NetNS interface but does help to re-use code that just refers to c.state.NetNS. [NO NEW TESTS NEEDED] Signed-off-by: Doug Rabson <dfr@rabson.org>
Diffstat (limited to 'libpod')
-rw-r--r--libpod/boltdb_state_freebsd.go14
-rw-r--r--libpod/container_freebsd.go15
-rw-r--r--libpod/container_internal_freebsd.go18
3 files changed, 32 insertions, 15 deletions
diff --git a/libpod/boltdb_state_freebsd.go b/libpod/boltdb_state_freebsd.go
index d7f2736fc..d0a2d4f28 100644
--- a/libpod/boltdb_state_freebsd.go
+++ b/libpod/boltdb_state_freebsd.go
@@ -6,12 +6,20 @@ package libpod
// replaceNetNS handle network namespace transitions after updating a
// container's state.
func replaceNetNS(netNSPath string, ctr *Container, newState *ContainerState) error {
- // On FreeBSD, we just record the network jail's name in our state.
- newState.NetworkJail = netNSPath
+ if netNSPath != "" {
+ // On FreeBSD, we just record the network jail's name in our state.
+ newState.NetNS = &jailNetNS{Name: netNSPath}
+ } else {
+ newState.NetNS = nil
+ }
return nil
}
// getNetNSPath retrieves the netns path to be stored in the database
func getNetNSPath(ctr *Container) string {
- return ctr.state.NetworkJail
+ if ctr.state.NetNS != nil {
+ return ctr.state.NetNS.Name
+ } else {
+ return ""
+ }
}
diff --git a/libpod/container_freebsd.go b/libpod/container_freebsd.go
index 7292ba37a..87fb494dd 100644
--- a/libpod/container_freebsd.go
+++ b/libpod/container_freebsd.go
@@ -4,11 +4,20 @@
package libpod
type containerPlatformState struct {
- // NetworkJail is the name of the container's network VNET
+ // NetNS is the name of the container's network VNET
// jail. Will only be set if config.CreateNetNS is true, or
// the container was told to join another container's network
// namespace.
- NetworkJail string `json:"-"`
+ NetNS *jailNetNS `json:"-"`
+}
+
+type jailNetNS struct {
+ Name string `json:"-"`
+}
+
+func (ns *jailNetNS) Path() string {
+ // The jail name approximately corresponds to the Linux netns path
+ return ns.Name
}
func networkDisabled(c *Container) (bool, error) {
@@ -16,7 +25,7 @@ func networkDisabled(c *Container) (bool, error) {
return false, nil
}
if !c.config.PostConfigureNetNS {
- return c.state.NetworkJail == "", nil
+ return c.state.NetNS != nil, nil
}
return false, nil
}
diff --git a/libpod/container_internal_freebsd.go b/libpod/container_internal_freebsd.go
index 6dedfbee1..e571cb38b 100644
--- a/libpod/container_internal_freebsd.go
+++ b/libpod/container_internal_freebsd.go
@@ -26,8 +26,8 @@ var (
// Network stubs to decouple container_internal_freebsd.go from
// networking_freebsd.go so they can be reviewed separately.
-func (r *Runtime) createNetNS(ctr *Container) (netJail string, q map[string]types.StatusBlock, retErr error) {
- return "", nil, errors.New("not implemented (*Runtime) createNetNS")
+func (r *Runtime) createNetNS(ctr *Container) (netJail *jailNetNS, q map[string]types.StatusBlock, retErr error) {
+ return nil, nil, errors.New("not implemented (*Runtime) createNetNS")
}
func (r *Runtime) teardownNetNS(ctr *Container) error {
@@ -51,7 +51,7 @@ func (c *Container) unmountSHM(path string) error {
func (c *Container) prepare() error {
var (
wg sync.WaitGroup
- jailName string
+ ctrNS *jailNetNS
networkStatus map[string]types.StatusBlock
createNetNSErr, mountStorageErr error
mountPoint string
@@ -63,9 +63,9 @@ func (c *Container) prepare() error {
go func() {
defer wg.Done()
// Set up network namespace if not already set up
- noNetNS := c.state.NetworkJail == ""
+ noNetNS := c.state.NetNS == nil
if c.config.CreateNetNS && noNetNS && !c.config.PostConfigureNetNS {
- jailName, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
+ ctrNS, networkStatus, createNetNSErr = c.runtime.createNetNS(c)
if createNetNSErr != nil {
return
}
@@ -74,7 +74,7 @@ func (c *Container) prepare() error {
defer tmpStateLock.Unlock()
// Assign NetNS attributes to container
- c.state.NetworkJail = jailName
+ c.state.NetNS = ctrNS
c.state.NetworkStatus = networkStatus
}
}()
@@ -164,7 +164,7 @@ func (c *Container) addNetworkContainer(g *generate.Generator, ctr string) error
if err != nil {
return fmt.Errorf("retrieving dependency %s of container %s from state: %w", ctr, c.ID(), err)
}
- g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetworkJail)
+ g.AddAnnotation("org.freebsd.parentJail", nsCtr.state.NetNS.Name)
return nil
}
@@ -187,7 +187,7 @@ func openDirectory(path string) (fd int, err error) {
func (c *Container) addNetworkNamespace(g *generate.Generator) error {
if c.config.CreateNetNS {
- g.AddAnnotation("org.freebsd.parentJail", c.state.NetworkJail)
+ g.AddAnnotation("org.freebsd.parentJail", c.state.NetNS.Name)
}
return nil
}
@@ -272,7 +272,7 @@ func (c *Container) isSlirp4netnsIPv6() (bool, error) {
// check for net=none
func (c *Container) hasNetNone() bool {
- return c.state.NetworkJail == ""
+ return c.state.NetNS == nil
}
func setVolumeAtime(mountPoint string, st os.FileInfo) error {